Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Adding Swap to VPS
New on LowEndTalk? Please Register and read our Community Rules.

Adding Swap to VPS

Is it possible to add swap on a VPS provisioned without any swap? or does it depend on if the terms of the host provider?

Comments

  • If the provider allows it you can manualy add swap, for an linux vps you can use this guide:

    Thanked by 1nocloud
  • thanks, is it common to disallow in the terms? or do most not really care

  • Good question, never saw it mentioned in the terms, I'm assuming that the providers limit the iops of the disk to prevent some kind of iops abuse, so even if you configure a swap I don't see it as a possible violation.

    Thanked by 1nocloud
  • MannDudeMannDude Member, Provider

    I've not heard of a provider disallowing you to set your own swap, though I wouldn't rely on it for anything other than a safe buffer. If you're hitting your swap space constantly, find out why and optimize if able or upgrade to more actual ram if needed.

    Thanked by 2nocloud Daniel15
  • A lot of OSs will create SWAP upon installation with a low RAM capacity. Never heard of it being disallowed.

    Thanked by 1nocloud
  • Here's how you could create a 2GB SWAP file:

    dd if=/dev/zero of=/swapfile bs=1M count=2048
    chmod 600 /swapfile
    mkswap /swapfile
    swapon /swapfile
    

    If you want this to be permanent, then in your /etc/fstab file add this:

    /swapfile swap swap defaults 0 0

    You will now have a 2GB SWAP set up and running.

    If you want to turn off the swap, then you can issue:

    swapoff -a

    This will work on any KVM or Dedicated Server. I'm not sure this will work for LXC or VZ containers though.

    Thanked by 1nocloud
  • ShakibShakib Member, Provider

    @dahartigan said:
    Here's how you could create a 2GB SWAP file:

    dd if=/dev/zero of=/swapfile bs=1M count=2048
    chmod 600 /swapfile
    mkswap /swapfile
    swapon /swapfile
    

    If you want this to be permanent, then in your /etc/fstab file add this:

    /swapfile swap swap defaults 0 0

    You will now have a 2GB SWAP set up and running.

    If you want to turn off the swap, then you can issue:

    swapoff -a

    This will work on any KVM or Dedicated Server. I'm not sure this will work for LXC or VZ containers though.

    Works for LXC.

  • FrankZFrankZ Member
    edited November 25

    @dahartigan said: This will work on any KVM or Dedicated Server. I'm not sure this will work for LXC or VZ containers though.

    Will not work for openVZ.

    EDIT: I did not know that it would work for LXC, going to try it now :)
    EDIT2: Nope did not work on LXC.

    Thanked by 2dahartigan nocloud
  • @FrankZ said:

    @dahartigan said: This will work on any KVM or Dedicated Server. I'm not sure this will work for LXC or VZ containers though.

    Will not work for openVZ.

    EDIT: I did not know that it would work for LXC, going to try it now :)

    Most probably won’t work with LXC. And SWAP is not RAM, so get a larger plan if resources are tight.

  • I'd only suggest adding SWAP if you have a very specific need to.

  • use case is, I have a KVM 4GB, running nginx reverse proxy, wireguard with 5 peers, 2 wordpress, all in docker containers. the ram usage never goes above 2GB so was thinking to get a smaller 2GB VPS, with NVMe and add 2GB swap just in case it ever goes over 2GB. just thinking to save a couple of euros

  • @Kousaka said: Most probably won’t work with LXC. And SWAP is not RAM, so get a larger plan if resources are tight.

    You are correct it did not work with LXC.

    There are good uses and bad uses of swap. If swapping causes consistent load it can cause issues for the provider and you, if no load it's not a problem for anyone.

    As an example I have mail servers that are 2GB Ram 1GB swap.
    The swap only gets used during virus scanner updates three times a day for maybe a
    minute, if no swap it goes oom. I would consider this a good use for swap.

    Thanked by 1nocloud
  • @nocloud said: use case is, I have a KVM 4GB, running nginx reverse proxy, wireguard with 5 peers, 2 wordpress, all in docker containers. the ram usage never goes above 2GB so was thinking to get a smaller 2GB VPS, with NVMe and add 2GB swap just in case it ever goes over 2GB. just thinking to save a couple of euros

    On a web server I personally go by the rule that I never want to have a consistent normal RAM use over 60% to allow for peaks in usage. But that is just me.

    Thanked by 1nocloud
  • ShakibShakib Member, Provider

    My bad.

    swapon: /swapfile: swapon failed: Operation not permitted

    LXC.

Sign In or Register to comment.