How to change Swappiness in Linux

Share on Social Media

In this article, you will learn how to change swappiness in Linux distributions.

What is Swappiness?

The Linux kernel’s swappiness setting defines how aggressively it will swap memory pages versus dropping pages from the page cache.

A higher value increases swap aggressiveness, while a lower value tells the Linux kernel to swap as little as possible to disk and favor RAM.

The swappiness range is from 0 to 100, and most Linux distributions have swappiness set to 60 by default.

Some database servers managed cache to use RAM, and is capable of managing what should be in RAM and what shouldn’t be. Allowing the Linux operating system to have too much control over what memory pages are in RAM is likely to lower your database performance. Therefore, it is recommended that swappiness should be set to 0.

Check Current Swappiness Setting:

Check current setting of swappiness.

# cat /proc/sys/vm/swappiness

Change Swappiness in Linux:

Set the swappiness setting to 0 for the running system.

# sysctl -w vm.swappiness=0
vm.swappiness = 0

Verify the current setting of swappiness again.

# cat /proc/sys/vm/swappiness

To make swappiness setting persistent, you have to add it in Kernel parameter file.

# echo 'vm.swappiness=0' >> /etc/sysctl.d/99-swappiness.conf

You have successfully change the swappiness for your Linux distribution.

Video to Change Swappiness in Linux:

YouTube player


In this article, you have learned how to change swappiness in Linux.