Subscribe to my RSS feed RSS
October 4, 2009

What Is the Linux Kernel Parameter vm.swappiness?

vm.swappiness is a tunable kernel parameter that controls how much the kernel favors swap over RAM. At the source code level, it’s also defined as the tendency to steal mapped memory. A high swappiness value means that the kernel will be more apt to unmap mapped pages. A low swappiness value means the opposite, the kernel will be less apt to unmap mapped pages. In other words, the higher the vm.swappiness value, the more the system will swap.

The default value I’ve seen on both enterprise level Red Hat and SLES servers is 60.

To find out what the default value is on a particular server, run:

sysctl vm.swappiness

The value is also located in /proc/sys/vm/swappiness.

What reason might there be to change the value of this parameter? Like all other tunable kernel parameters, there may not be a compelling reason to change the default value, but having a facility that allows one to manipulate how the linux kernel behaves without modifying source code is indispensable.

If there were reasons to change the vm.swappiness kernel parameter, one might be to decrease the parameter if swapping is undesirable. I’ve seen enterprise configurations where servers had a swap to RAM ratio of 1:125. It’s evident in this case that there is no interest in ever using anything but physical memory so why not make the kernel privy to this information. Whether the vm.swappiness parameter is set to 0, 20, 40, or any other value, the owner of the server should perform due diligence to see what affect this has on the server and applications. For an under-the-cover look on the effect of changing the parameter, one only needs to look at the vmscan.c source file and the swap_tendency algorithm.

swap tendency = mapped_ratio / 2 + distress + vm_swappiness;

On the flip side, one may consider increasing the vm.swappiness parameter greater than the default if a particular system has physical memory contraints.

“Systems with memory constraints that run batch jobs (processes that sleep for long time) might benefit from an aggressive swapping behavior.”

Andrew Morton sets his workstation vm.swappiness parameter to 100. “My point is that decreasing the tendency of the kernel to swap stuff out is wrong. You really don’t want hundreds of megabytes of BloatyApp’s untouched memory floating about in the machine. Get it out on the disk, use the memory for something useful.”

The following is an excerpt of a benchmark obtained using different vm.swappiness values while performing dd on a 2.6.5-7.97-default kernel (

vm.swappiness Total I/O Avg Swap
0 273.57 MB/s 0 MB
20 273.75 MB/s 0 MB
40 273.52 MB/s 0 MB
60 229.01 MB/s 23068 MB
80 195.63 MB/s 25587 MB
100 184.30 MB/s 26006 MB

To read more information on the vm.swappiness kernel tunable, you may find these links helpful.

swapping and the value of /proc/sys/vm/swappiness

Linux performance tuning – /proc/sys/vm/swappiness

Linux: Tuning Swappiness

Feed for this Entry | Trackback Address

2 comments already

  1. grok on 10.05.2010 at 12:03 am | permalink
  2. A valuable window into the system control of GNUnix kernels and systems. Thanx.

  3. Quora on 03.27.2012 at 8:13 pm | permalink
  4. Why does Linux swap out pages when I have many pages cached and vm.swappiness is set to 0? Shouldn’t cached pages get resized and no swapping should occur?…

    Awesome question. I dove into the inner workings of swap as part of a Linux kernel spelunking effort a few years back, so I can comment. Mostly it’s because vm.swappiness is a HINT to the kernel – it indicates your desire, but it is neither a limit no…

Leave a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>