+3 votes
in Operating Systems by (60.2k points)
I have 16GB RAM and 4GB swap memory on my machine. I am seeing a weird issue. Despite free RAM, the system tries to use swap memory. I am using Ubuntu operating system. Is there any way to stop this behavior of the OS?

1 Answer

+2 votes
by (355k points)
selected by
 
Best answer

By setting the value of swappiness, you can change the behavior of the OS. The value of swappiness ranges from 0 to 100.

swappiness = 0 means avoid swap memory

swappiness = 100 means use swap memory to its fullest.

Both Ubuntu and Debian OS come with 60 as the default value of swappiness. That's why your system is using swap memory even if RAM is available.

Run the following command to check the value of swappiness on your system.

cat /proc/sys/vm/swappiness

You can change the value of swappiness by updating /etc/sysctl.conf.

Open /etc/sysctl.conf as root and change or add this line to the file:

vm.swappiness = 10

To apply the change, run the following command or reboot the system.

sysctl -p

Now, your system will use swap memory when RAM is only 10% free.


...