Sunday, December 13, 2015

Changing Linux Swappiness

As the RAM price is going down very fast, most modern computers can be equipped with plenty of RAM, perhaps more than enough for most of people using RAM-efficient operating systems, such as Linux. I personally have 8GB of RAM installed, and I barely use even half of this unless I run virtual machines.

However, for whatever the reason, I still find some instances where my Linux system makes use of the swap space although I have plenty of RAM still unused. Here, I will show you how to minimize the use of the swap space. After all, accessing RAM should be incomparably faster than accessing the hard disk drive or solid state drive, so you probably want to minimize swap usage if your system has a plenty of RAM installed.

There is a variable called swappiness in Linux that determines the likelihood of swap to be used by the system. This value is saved in /proc/sys/vm/swappiness file. So, to check your system's swappiness value, simply run
$ cat /proc/sys/vm/swappiness

The default will be most likely 60. You may want to adjust this to 0 to minimize.
$ sudo echo 0 > /proc/sys/vm/swappiness

That's it!

No comments:

Post a Comment