***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 swapiness" 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.
First, to obtain the "swapiness" value in the server, run the following command:
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 "swapiness" 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
Do not set the value to 0 unless you intend on disabling swapping completely and have sufficient memory to accommodate all functions. Disabling 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: