Introduction

Swappiness is a Linux kernel parameter that determines how often the system swaps data from RAM to the swap space on the hard disk. By default, Linux systems have a swappiness value of 60, which means that the system will start swapping data when RAM usage exceeds 40%. In this guide, we'll walk you through the step-by-step process of changing the swappiness of your Linux system to optimize performance.

Prerequisites

Before you begin, make sure you have the following:

  • A Linux system (e.g., Ubuntu, CentOS, Debian)
  • Root or sudo access to the system

Step 1: Check Current Swappiness

Open a terminal on your Linux system and run the following command to check the current swappiness value:

cat /proc/sys/vm/swappiness

Step 2: Temporary Swappiness Change

To temporarily change the swappiness value, you can use the sysctl command. For example, to set the swappiness value to 10, run:

sudo sysctl vm.swappiness=10

This change will take effect immediately, but it's only temporary and will be reset when you reboot your system.

Step 3: Permanent Swappiness Change

To make the swappiness change permanent, you need to modify the /etc/sysctl.conf configuration file. Open the file in a text editor:

sudo nano /etc/sysctl.conf

Add the following line at the end of the file to set the swappiness value:

vm.swappiness=10

Save and close the file. Then, apply the changes by running:

sudo sysctl -p

Step 4: Verify Swappiness Change

Run the following command to verify that the swappiness value has been changed:

cat /proc/sys/vm/swappiness

Conclusion

Congratulations! You've successfully changed the swappiness of your Linux system to optimize performance. Adjusting the swappiness value can help improve responsiveness and reduce disk I/O, especially on systems with limited RAM.

Thank you for reading our guide on how to change the swappiness of your Linux system. We hope you found it helpful!

Was this answer helpful? 0 Users Found This Useful (0 Votes)