Linux swapping

In Linux, we have such kernel parameter as vm.swappiness. According to kernel documentation,

This control is used to define how aggressive the kernel will swap memory pages. Higher values will increase aggressiveness, lower values decrease the amount of swap. A value of 0 instructs the kernel not to initiate swap until the amount of free and file-backed pages is less than the high water mark in a zone.

The default value of this parameter is 60. It means that if all processes running in Linux consume more than 40% of all RAM, they will be swapped out to disk, leading to slower performance of programs.

To avoid such behavior, it is recommended to set value of this parameter to 1. It can be done by command:

sudo sysctl -w vm.swappiness=1

To persist this setting after reboot, run such command:

sudo bash -c "echo "vm.swappiness=1" >> /etc/sysctl.conf"

Leave a Reply