2008 / 01 / 24


With the introduction of version 2.6, the new variable "swappiness" was added in the Linux kernel memory management subsystem and a tunable was created for it. Six months later a debate between Linux kernel developers was reported on KernelTrap, followed by a long discussion on Slashdot.

High value of swappiness will make the kernel page out application text in favour of another application or even file-system cache. The default value is 60 (see mm/vmscan.c):

1   /*
2    *  linux/mm/vmscan.c
3    *
4    *  Copyright (C) 1991, 1992, 1993, 1994  Linus Torvalds
5    *


103 /*
104  * From 0 .. 100.  Higher means more swappy.
105  */
106 int vm_swappiness = 60;
107 long vm_total_pages;    /* The total number of pages which the VM controls */
Even now, in January 2008, most Linux distributions do not change this value.

Linux sluggish performance

My experience is that with the default value for swappiness, Linux becomes sluggish, typical examples are a workstation pausing when switching from one application to another even though there is more than enough memory to accommodate both, or a webserver needing time to wake up before serving pages. Another symptom of a high value of swappiness is the disk being constantly activated regardless of its load, chug, chug, chug...

I have run both servers and workstations without any problem, and actually better performance with "swappiness = 0". Of course you should read more and make your own informed decision before changing the value, and specifically the comment at the top of this patch.

How to change swappiness

In order to change its value after reboot, add the following line:

vm.swappiness = 0
in the file /etc/sysctl.conf. You can then update the system with these values by running:

sysctl -w vm.swappiness=0
echo 0 >/proc/sys/vm/swappiness

To check the current value on a running system:

sysctl vm.swappiness
cat /proc/sys/vm/swappiness