Tweaking Linux Server Swappiness for Increased Performance

Swappiness might sound silly, but it is actually a very useful parameter in the Linux kernel that determines how aggressively the kernel will use the swap partition. Linux is usually already well-optimized to use very little swap when physical memory is available. With the swappiness setting, you can increase or decrease this usage.

The default setting on most Linux distributions is 60 out of 100. Most things are still not swapped with this setting. When memory starts to get a little low, however, Linux will start to use swap to ensure that the system does not run out of memory. If a system has no swap, it will invoke the out-of-memory-killer and start killing processes that are taking up valuable memory.

To view your system’s current swappiness setting, type this from the command line:

cat /proc/sys/vm/swappiness

The output should look something like this:

vm.swappiness = 10

Remember, the lower the swappiness, the less aggressive Linux will be. With a setting of 10, Linux will only resort to swap when absolutely necessary. At “0”, Linux will only swap to avoid the out-of-memory state.

To change the swap value, type:

echo 10 > /proc/sys/vm/swappiness

Replace “10” with whatever setting you want. For more information about swappiness and swap in general, see this online tutorial.