Swappiness


Swappiness is a Linux kernel parameter that controls how assertive the swapping mechanism is. Swapping moves inactive memory pages from physical memory to swap memory on a disk (either in a swap file or a swap partition). The process aims to balance data in RAM and utilizes the swap space when physical memory reaches its limits.

Swappiness can be set to a value from 0 to 200. A low value causes the kernel to prefer to evict pages from the page cache while a higher value causes the kernel to prefer to swap out "cold" memory pages. The default value is 60; setting it higher can cause high latency if cold pages need to be swapped back in, while setting it lower (even 0) may cause high latency when files that had been evicted from the cache need to be read again, but will make interactive programs more responsive as they will be less likely to need to swap back cold pages.

# show value 
cat /proc/sys/vm/swappiness
# or 
sysctl vm.swappiness

#set values
sysctl -w vm.swappiness=10
echo "vm.swappiness = 0" >> /etc/sysctl.conf
# or 
echo "vm.swappiness = 0" > /etc/sysctl.d/10-swappiness.conf