Linux Swappiness

Have you ever been upset by the Linux tendancy to swap… Especially when trying to allocate a large InnoDB buffer pool.. Look at the following output:

yves@yves-laptop:~$ free
total used free shared buffers cached
Mem: 2041888 1991096 50792 0 52 954592
-/+ buffers/cache: 1036452 1005436
Swap: 975200 1308 973892

There is still 50792 + 52 + 954592 = 1005436 of free memory and Linux starts to swap!!! The reason is hidden here:

yves@yves-laptop:~$ cat /proc/sys/vm/swappiness

The swappiness controls the Linux to swap for the File cache. For a file server or a web server or even MySQL with MyISAM tables, the file cache is interesting but for InnoDB or NDB Cluster it is close to useless. Only put a “0″ in that proc entry (echo 0 > /proc/sys/vm/swappiness) and add “vm.swappiness = 0″ to /etc/sysctl.conf to preserve the setting after reboot and the problem is gone.

About Yves Trudeau

I work as a senior consultant in the MySQL professional services team at Sun. My main areas of expertise are DRBD/Heartbeat and NDB Cluster. I am also involved in the WaffleGrid project.
This entry was posted in linux, mysql, NDB Cluster, performance, yves. Bookmark the permalink.

3 Responses to Linux Swappiness

  1. Marcin Pohl says:

    you dont have to reboot after you put the new setting in /etc/sysctl.conf. all you need to do is execute sysctl -p

  2. Ah, if only it were that simple. In many cases I have seen Linux “helpfully” allocate swap even with swappiness set to 0.

  3. Pingback: Big DBA Head! - Database Brain Power! » The 5 minute DBA: Default My.cnf File