Introduction
Please Note: All procedures discussed here must be discussed with a qualified system administrator to prevent accidental downtime due to misconfiguration.
For servers with a large amount of RAM, sometimes the "default swappiness" set in the operating system may be too high, resulting in the server attempting to use swap well before it should. Below is how you would change this value.
Procedure
First, to obtain the "swappiness" value in the server, run the following command:
cat /proc/sys/vm/swappiness
On most CentOS servers that have swap enabled, this value is usually 60. This means the server will attempt to use swap when it reaches 60% of the total RAM used. For servers with a large amount of ram, this may cause unnecessary disk I/O usage.
To change the value temporarily, run the following command, changing the number value (a lower value means less "swappiness" and less likely to swap):
sysctl -w vm.swappiness=10
To make the change permanent, the following value in /etc/sysctl.conf
must be set:
vm.swappiness = 10
Setting this value to 0 (zero) forces all dedicated memory to be used before swap is consumed. Dramatically lowering swap on a server that does not have sufficient memory may kill processes to recover memory resulting in possible data loss and corruption. You can read more about the situation here: What is the OOM Killer?
Note: You should discuss with a qualified system administrator the recommended value for your server based on your total memory usage.
For more information on swap, refer to these articles: