vm.swappiness tweaks

First lets revise the basics.

In terms of performance, small storage devices are faster e.g. registers are faster than ram, RAM is faster than hard disk. And Swap is a dedicated partition to be used as paging alternate to RAM when there is not much RAM available.

Now how linux decides when to use swap or not? There is a sysctl parameter called vm.swappiness that is used by linux to decide. vm.swappiness is the kernel parameter that controls how kernel favors swap over RAM. By default its value is 60. So as you guess as value of 0 in the parameter would tell linux to never use Swap. What good is this use for?

This laptop has 4G RAM, and considering my day to day activities thats more than enough. So i rarely need swap. Why should i care to lower vm.swappiness value? Because the lower the value, the faster my system gets (in my case) because RAM is suffcient and i dont want to see any page faults and disk read/write for paging to slow down system.

You can change this value two way:

Permanent method is to edit /etc/sysctl.conf and put it there OR create a new file and place it under /etc/sysctl.conf.d/. If you do this changes will be put into action either by restart or by running

sysctl -p

Other method, which only lasts one restart is using commandline to temporarily adjust the value like
sysctl vm.swappiness=30
(This will mean when RAM is 70% full, then kernel will consider swap)

For details google vm.swappiness and you will come across very nice articles like:

http://lwn.net/Articles/83588/
http://www.linuxvox.com/linux-articles/kernel-tuning/1-what-is-the-linux-kernel-parameter-vm-swappiness

Tags: , , , , , , , , , , ,

Leave a Comment