Friday 12 June 2009

Swappiness

There is something that has a powerful effect on your computer speed and that is the memory.
In this kind-of-old (hope it doesn't get angry) computer I have 250 Mb of physical memory. That is pretty little if you want to run some heavy apps.

Fortunately, Linux relies on a partition of your disk called "swap". There, all the memory pages that go to idle state are stored until they are needed again. This is very useful since it lets your physical memory concentrate on what is in use.

Unfortunately, there is a problem. You can use some resource once and then leave it and then use it again and so. This makes the system swap this resource and then take it back to memory and swap it again and so making your applications go slower.

There is a fix to this since you can modify the swappiness of the system (this is, how much memory you want to swap). Swappiness could have a value from 0 (no swap) to 100 (swap a lot). Default is 60. You can modify this by editing the file /proc/sys/vm/swappiness. If you want to store this behaviour permanently, you then need to add a line to your /etc/sysctl.conf:
vm.swappiness = value
Then, restart or run:
sysctl -w vm.swappiness=value

For me, the value that works best is 50 but I am thinking about changing it to 40 and see what happens. If you want to find out yours, you can try and start those apps you use frequently, run htop and see how much memory is the system using. If there is a lot of memory being used, it'll be better to have a large swappiness value. If not, you are free to set a lower value.

No comments:

Post a Comment