Howdy, Stranger!

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


Clearing out Swap RAM on VPS
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Clearing out Swap RAM on VPS

pubcrawlerpubcrawler Banned
edited October 2012 in General

As an end user on VPS, often seeing odd RAM numbers. Like this:
Mem: 65/512MB
Swap: 99/512MB

Clearly, we have plenty of real RAM to stuff things into, no sense hitting a disk swap file.

On our real servers from time to time I clean these up with:
swapoff -a
swapon -a

VPSes won't allow swapoff and on:
swapoff: Not superuser.

Anyone have any ideas on how to accomplish this sort of clean up?

Comments

  • Reboot lol. In all seriousness, why would you need to?

  • Well assuming (slightly) here that the swap is sitting on disk.

    Disk IO is slow, eats IOPs, generally contributes to bad nodes. Slows me down when have to go get from the swap.

    I tend to run swapless machines in my local environments. Not a fan of disk swap chatter and waiting.

  • If this is Xen or KVM, try setting vm.swappiness to 0: http://en.wikipedia.org/wiki/Swappiness

    If it's OpenVZ, have the host do the same on his node.

    @GetKVM_Ash said: In all seriousness, why would you need to?

    If it's OVZ and it's vSwap, his container will be artificially slowed down. The OP didn't specify what virtualization tech was in use, though...

    Thanked by 1pubcrawler
  • Funny, I have a bunch of these odd swappers out there.

    Mem: 8/64MB
    Swap: 4/64MB

    Mem: 40/256MB
    Swap: 4/512MB

    Guess I should question why these are even swapping since our use is nearly 0 on these :)

  • @Damian, thanks!

    I believe these all to be OVZ.

  • rm_rm_ IPv6 Advocate, Veteran
    edited October 2012

    @pubcrawler
    if something is in swap while there's a lot of free RAM, it means those parts (of code, libraries etc) are not used. As soon as they are needed (which may be never), they will be moved back to RAM. And meanwhile, the RAM will be used for a better purpose (i.e. the disk cache).
    In short, don't worry about this.

  • Reboot of course cleared the swap. Suddenly feel like I am running Windows again :)

    Swap still there waiting to be allocated. No idea what started the need for swap since these are fresh machines sitting idle.

    Guess I am one of those folks who knows what the problems are with swap from eons of computing. Time to send tickets asking providers to disable my swap since OVZ won't allow me to disable it.

    Thanked by 1klikli
  • Swapping is just a natural linux process, its not going to slow you down if its just been used for idle applications.

    For instance, one of our VZ/VSwap nodes.

    RAM: 1.17 GB of 15.46 GB Used / 14.29 GB Free
    SWAP: 89.28 MB of 4.01 GB Used / 3.93 GB Free

  • @pubcrawler said: Time to send tickets asking providers to disable my swap since OVZ won't allow me to disable it.

    Or reduce the amount of swap available. Providers feel that vSwap is exactly the same as burst RAM, and need to allocate it as such; will only cause problems.

  • Memory that hasn't been accessed for a long time gets swapped out. The freed memory can then be used for something useful... i.e., applications or file cache.

    Having something sitting in RAM and doing nothing is a waste of RAM.

    As @Damian suggests, you can adjust vm.swappiness, which is the kernel's tendency to swap. '0' means "don't swap unless you really have to". The default value of 60 is more appropriate for a desktop (IMO).

    You can also raise vm.vfs_cache_pressure, which is the kernel's tendency to take memory from the cache when more memory is needed. Default value is 100, try raising it to 200.

    This applies to Xen & KVM, not OpenVZ.

  • DamianDamian Member
    edited October 2012

    @sleddog said: You can also raise vm.vfs_cache_pressure, which is the kernel's tendency to take memory from the cache when more memory is needed. Default value is 100, try raising it to 200.

    Yes, another good point.

    Here's some further discussion on the subject from earlier this year: http://us.generation-nt.com/answer/tuning-swappiness-vfs-cache-pressure-help-206232902.html

    http://doc.opensuse.org/documentation/html/openSUSE/opensuse-tuning/cha.tuning.memory.html#cha.tuning.memory.vm

  • Swappieness... lol.

  • Good thread folks.

    My issues are with OpenVZ.

    Anyone privy to why OpenVZ will not allow end user to adjust kernel options like swapiness?

  • DamianDamian Member
    edited October 2012

    @pubcrawler said: Anyone privy to why OpenVZ will not allow end user to adjust kernel options like swapiness?

    It's not 100% virtualization, it's more like a "jail" or "sandbox". There's only a single kernel running everything; if you were able to adjust swappiness, you'd be adjusting it for everyone. The kernel and it's associated settings are maintained on the host node by the provider.

  • A very good explanation of the differences :)

    @Damian said: It's not 100% virtualization, it's more like a "jail" or "sandbox". There's only a single kernel running everything; if you were able to adjust swappiness, you'd be adjusting it for everyone. The kernel and it's associated settings are maintained on the host node by the provider.

  • Thanks again @Damian!

    I assumed that is how OpenVZ worked, but good to hear about it from someone who knows from the operations side.

Sign In or Register to comment.