0

I've had my first CentOS 7 KVM host setup for about a year now, it is a dual quad-core machine with 32GB of physical memory. I have a dozen VM's running with a total allocated memory of 23GB. This system has 4GB of swap and here is the current usage details....

KiB Mem:  32773552 total, 32564628 used,   208924 free,     2224 buffers
KiB Swap:  4603836 total,  3262108 used,  1341728 free.  9606248 cached Mem

I've read you really don't want a great deal of swap because if it shouldn't be using swap at all. I believe the above shows over 3GB being used now, is this normal? I am not having any performance issues out of this server. I am currently building a new server and comparing to see what is the best amount of swap to use on the new server that should have similar loads?

rwfitzy
  • 223
  • 5
  • 15

1 Answers1

1

It's not as simple as it may seem at first sight. Unused memory is wasted memory and Linux takes this approach even to "unused used" memory. That means memory, which is actually allocated, but has not been used for a while may get swapped out. As it was not needed recently, it is presumed, it won't have great performance impact. Actually, there is another bit to this. Linux, tries to swap out unused pieces of data in advance (while it is idle), while still keeping it in RAM. This way, RAM can be freed almost instantly (when more memory is to be allocated), while not having the performance impact of retreiving the data from swap (in case this older data is not needed). This is called Swap Cache and can be found out by running cat /proc/meminfo | grep SwapCached).

Linux swapping behavior is controled by sysctl vm.swappiness (see wikipedia). It ranges from 0 (no swapping at all), 1 (on recent kernels, only swap when absolutely necessary), to 100 (be very aggressive at swapping data out).

If your server is running fine with not signs of performance problems, keep it as it is. If you see any trouble, you can try tweaking this value.

Fox
  • 3,887
  • 16
  • 23
  • Thanks for the great clarification! So you think I should use the same setup for my new server, don't need any less or more swap space based on the configuration? – rwfitzy Sep 16 '15 at 15:24
  • I'd stick to the golden rule of sysadmin - "If it ain't broken, don't fix it."; There are many guides and suggestions on how to best find the size of swap. Non of them universal enough in my opinion. And if the setup is working, there is no reason to change. You can always shrink it and if you reserve some extra space, you can grow as well if need be (I doubt). – Fox Sep 16 '15 at 16:31