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 :
You can temporarily set a value (10 in the example) by running the following as root :
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
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 !!