The /proc/sys/vm/swappiness kernel parameter controls the tendency of the kernel to move processes out of physical memory and onto the swap disk. Because disks are much slower than RAM, this can lead to slower response times for system and applications if processes are too aggressively moved out of memory.
Swappiness can have a value of between 0 and 100 where:
- 0 – instructs the kernel to avoid swapping processes out of physical memory for as long as possible.
- 100 – instructs the kernel to aggressively swap processes out of physical memory.
The default value in Red Hat and Ubuntu distributions is 60 which is about right for a server. Reducing the default value of swappiness to somewhere around 10 will probably improve overall performance for a typical Linux desktop installation.
To check the swappiness value:
# cat /proc/sys/vm/swappiness
# sysctl vm.swappiness
To temporarily change the swappiness value to 10:
# sysctl vm.swappiness=10
# echo 10 > /proc/sys/vm/swappiness
To permanently change the swappiness value:
# sysctl -w vm.swappiness=10
or edit /etc/sysctl.conf and reboot or reload using sysctl -p.
For more information, see 2.6 Swapping Behavior.