Adjust Linux Swappiness

Try it in our public cloud & Get $5 Credit

Linux swap is a quick way to boost a machine’s resources. With a swap file or partition in place, a server will function as if it has additional RAM at its disposal. While adding swap will lessen the likelihood of out-of-memory errors, it comes at a performance cost as normally fast RAM is replaced by filesystem access. Should swap ever cause a noticeable performance hit, swappiness can be adjusted to increase this. Swappiness is a value that determines how aggressively the kernel attempts to use swap space. This change is especially significant on newer systems where RAM is cheap and plentiful.

Getting Started

To complete this guide, you will need the following:
• 1 Node (Cloud Server or Dedicated Server) with any Linux distribution installed.


Start by checking your current swappiness setting so you have a baseline. The default on CentOS and Ubuntu is 60. Here is how to check your current value:

cat /proc/sys/vm/swappiness

Let’s temporarily change the value to see how it affects performance. Here we’ll set the value to 10. We won’t save it permanently until we see how it works.

sysctl vm.swappiness=10

When you’ve found your ideal value, edit /etc/sysctl.conf. Set vm.swappiness=10, or whatever value you ultimately choose. This will make the change permanent.

nano /etc/sysctl.conf

Then add "vm.swappiness=10" at the end of the file, were 10 is the desired value.


You now have a means of tweaking system performance should you ever require more swap, but find performance lacking once that space is used. If this guide was helpful to you, kindly share it with others who may also be interested.