What is swappiness and how to change

linux, swappiness

In Linux it is very easy to configure the use of virtual memory used by the kernel. Swappiness controls the tendency of the linux kernel to move a process out of physical memory and start using swap. Disk is slower than RAM and thus can lead to a slower response time for the application itself, therefore swappiness controls how often processes are moved into the swap cache.

For example, if swappiness is set to 0, the kernel will avoid moving processes into the swap cache.

If swappiness is set to 100, the kernel will regularly use the swap cache.

By default, this setting is normally held at 60.

On a virtualised node, a good swappiness parameter to use is 010, that is because a VM has shared disk IO and it is important for the overall system to use less disk utilization.

How to change?

Find out how much swappiness is being used by running : cat /proc/sys/vm/swappiness
Adjust the parameter by changing/adding this parameter (vm.swappiness = 0) and save in: /etc/sysctl.conf
To get the change live without a restart or sysctl reload, you can run this: echo 0 > /proc/sys/vm/swappiness