When physical memory starts to fill up then, all the inactive pages in the RAM shift to Swap space. This ensures that the processes function as intended, unless a process require resources beyond the capabilities of our system. How fast the Kernel moves inactive pages from Physical memory (i.e RAM) to Swap space can be seen from Swappiness parameter. So, a low Swappiness value would indicate that such pages are being moved out not so fast. But, it shows the opposite for higher values.
The Swappiness values can range between 0 and 100. So, a 0 Swappiness value would push the Kernel to not move out inactive pages. While a 100 shows that inactive pages are moving out aggressively. Apart from that, we also need to consider while setting a higher Swappiness value that, Physical disks are comparatively slower than RAM. So, a higher Swappiness doesn’t always mean better System performance.
Default value of Swappiness?
Default value of Swappiness in Ubuntu is 60, which can be seen through following command –
Note: Following operations require superuser privileges. In case you don’t have one then, we advise you to contact your System Administrator for assistance.
Change Swappiness value in Ubuntu
To temporarily change Swappiness value, issue the following command –
sudo sysctl vm.swappiness=20
But, for making permanent changes, which aren’t lost on reboot – we need to edit the following configuration file –
sudo nano /etc/sysctl.conf
And, add the following text to it –
Save and exit.
To view the changes made, again use the cat command-line utility –
This time it should show the Swappiness value we have set. If it doesn’t then, we perhaps already have
vm.swappiness= entry in the configuration file. So, don’t add a new entry, just edit the previous one.
In conclusion, we have covered how to change Swappiness value in Ubuntu. The Swappiness value should be set neither too high nor too low.