Skip to content

How to Change the Kernel Swappiness Value in Linux

Category
Linux
Covers
Swap
Versions & support
About Linux kernel →
On this page

Swappiness is a Linux kernel parameter that controls the balance between swapping out idle processes and using available RAM memory. The default swappiness value in most Linux distributions is 60, which means the system starts swapping out processes when the available memory falls below 40%. However, this default value might not be suitable for all situations, and changing the swappiness value can improve system performance.

In this article, we will discuss how to change the swappiness value in Linux. We will cover different methods to change the swappiness value temporarily and permanently.

Temporary Change Swappiness Value

To change the swappiness value temporarily, you can use the sysctl command. This command allows you to modify the kernel parameters at runtime.

Here are the steps to change the swappiness value temporarily:

  1. Check the current swappiness value
  2. Before changing the swappiness value, you can check the current value by using the following command:

    cat /proc/sys/vm/swappiness 
    

    The output will be a number between 0 and 100, indicating the current swappiness value.

  3. Change the swappiness value
  4. To change the swappiness value temporarily, you can use the following command:

    sudo sysctl vm.swappiness=<value> 
    

    Replace <value> with the desired swappiness value. For example, if you want to set the swappiness value to 10, you can use the following command:

    sudo sysctl vm.swappiness=10 
    

    This will set the swappiness value to 10, which means the system will start swapping out processes when the available memory falls below 90%.

  5. Verify the new swappiness value
  6. You can verify the new swappiness value by using the cat command:

    cat /proc/sys/vm/swappiness 
    

    The output should be the new swappiness value that you set.

Permanent Change Swappiness Value

To make the swappiness value permanent across reboots, you can modify the sysctl.conf file. This file is used to set kernel parameters at boot time.

Here are the steps to make the swappiness value permanent:

  1. Edit the sysctl.conf file
  2. You can open the sysctl.conf file using a text editor. For example, you can use the nano editor:

    sudo nano /etc/sysctl.conf 
    

  3. Add the swappiness value
  4. Add the following line at the end of the file:

    
    vm.swappiness=<value>
    
    

    Replace <value> with the desired swappiness value. For example, if you want to set the swappiness value to 10, you can add the following line:

    
    vm.swappiness=10
    
    

    After adding the swappiness value, save and close the file.

  5. Apply the changes
  6. To apply the changes, run the following command:

    sudo sysctl -p 
    

    This will load the new swappiness value from the sysctl.conf file.

  7. Verify the new swappiness value
  8. You can verify the new swappiness value by using the cat command:

    cat /proc/sys/vm/swappiness 
    

    The output should be the new swappiness value that you set.

Conclusion

Changing the swappiness value in Linux can improve system performance in certain situations. In this article, we discussed how to change the swappiness value temporarily and permanently. By following the steps outlined above, you can set the swappiness value to a value that best suits your needs.

Rahul

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top