CentOS – Concern About Swap Usage with Nearly 40GB of Free Memory
centosmemoryperformanceswap
I have a production host, below:
The system is using 1GB of swap, while maintaining nearly 40GB of free, unused memory space. Should I be concerned about this, or is it mostly normal?
Best Answer
This is not a problem and is likely normal. Lots of code (and possibly data) is used very rarely so the system will swap it out to free up memory.
Swapping is mostly only a problem if memory is being swapped in and out continuously. It is that kind of activity that kills performance and suggests a problem elsewhere on the system.
If you want to monitor your swap activity you can with several utilities but vmstat is usually quite useful e.g.
Ignore the first line as that is activity since the system started. Note the si and so columns under ---swap--; they should generally be fairly small figures if not 0 for the majority of the time.
Also worth mentioning is that this preemptive swapping can be controlled with a kernel setting. The file at /proc/sys/vm/swappiness contains a number between 0 and 100 that tells the kernel how aggressively to swap out memory. Cat the file to see what this is set to. By default, most Linux distros default this to 60, but if you don't want to see any swapping before memory is exhausted, echo a 0 into the file like this:
Unlike some other OSes that implement the obnoxious out of memory killer or equivalent, Solaris doesn't overcommit memory (unless you are using very specific allocation techniques). When regular memory allocations are made, the OS make sure this memory will be available when required (i.e. reservation). The drawback is you need to have enough virtual memory space to store this potentially partially unused memory.
Free RAM is unrelated but it accounts in virtual memory size too.
Have a look at "swap -s" output when the problem occurs.
Note that you can easily increase the swap area by adding swap files or devices.
Best Answer
This is not a problem and is likely normal. Lots of code (and possibly data) is used very rarely so the system will swap it out to free up memory.
Swapping is mostly only a problem if memory is being swapped in and out continuously. It is that kind of activity that kills performance and suggests a problem elsewhere on the system.
If you want to monitor your swap activity you can with several utilities but
vmstat
is usually quite useful e.g.Ignore the first line as that is activity since the system started. Note the
si
andso
columns under---swap--
; they should generally be fairly small figures if not 0 for the majority of the time.Also worth mentioning is that this preemptive swapping can be controlled with a kernel setting. The file at
/proc/sys/vm/swappiness
contains a number between 0 and 100 that tells the kernel how aggressively to swap out memory. Cat the file to see what this is set to. By default, most Linux distros default this to 60, but if you don't want to see any swapping before memory is exhausted, echo a 0 into the file like this:This can be made permanent by adding
to
/etc/sysctl.conf
.