It has been quite a bit of time since a Linux “How To”. So here we are with quite a useful tweak to any Linux system to increase system responsiveness.
A little background
It is often experienced that after performing quite a “humongous” task your computer might seem sluggish. For example, extracting a huge file. During and for some time after extracting files, your system is quite irresponsive. Why is this ?
Linux has a tendency to “swap off” stuff from RAM to the hard disk when it runs short of memory. This causes the sluggishness as read/write to the hard disk is way slower than that to RAM. This tendancy can be customized in our favour i.e decrease the tendancy in this case, because we need as much possible process memory on our RAM than on the hard disk.
It is also often seen that after/during performing a memory consuming task, file browsing goes slow. This is because pagecache and swapcache are retained at the expense of dentries and inodes (which kindof keeps track of the filesystem). This too can be controlled manually in Linux.
So how to do it?
The balance between “Swapping off to hard disk” and “Retaining in RAM” is maintained by an integer stored in the file /proc/sys/vm/swappiness. A value of 100 means that kernel will aggressively swap off application memory to hard disk. A value closer to 0 will rather retain application memory in RAM and hence system becomes more responsive. But remember that pursuing this might cause your system to run out of RAM. Hence default value is set as 60 in most distributions. You can check the current value using :
cat /proc/sys/vm/swappiness
You can temporarily set a value (10 in the example) by running the following as root :
echo 10>/proc/sys/vm/swappiness
The change can be made permanent by adding vm.swappiness=10 on your /etc/sysctl.conf file.
Similarly the coice between retaining swapcache and dentries and inodes is monitored by an integer in /proc/sys/vm/vfs_cache_pressure. The default value is 100. Any value less than 100 will tend to make file browsing faster as dentries and inodes are retained in cache actively. You can temporarily change the value using
echo 50>/proc/sys/vm/vfs_cache_pressure
Again the change can be made permenant by adding the line vm.vfs_cache_pressure=50 to your /etc/sysctl.conf file.
You can experiment with different values and choose a value which seems to suite you. Hope this helps !!




This should have little effect on today’s machines with huge memories. If the memory is low enough that this is a problem the zram kernel module may help. (memory-CPU tradeoff). It mounts a part of ram as the swap space and keeps it compressed. The CPU will be used more but hard disk activity will be minimized. Here’s a nice little script to initialize zram. (http://weirdfellow.wordpress.com/2011/05/04/compressed-ram-with-zram/) . Also it is always preferable to use the sysctl tool.
I’ve been doing this for years and it’s a good tweak to use alongside setting noatime for the filesystem.
Fantastic article on linux, very needful and useful to follow as I new to this….