Signup/Sign In

How to Change the Swappiness Value in Linux

Posted in Programming   JANUARY 7, 2022

    How to Change the Swappiness Value  in Linux

    Memory is a vital aspect of every system. The Linux kernel recognizes this and works to guarantee there’s enough RAM at the system’s disposal. The Kernel maintains memory by employing a swap mechanism to produce more memory space.

    In this article, we will talk about what a swap is, how it works, and lastly, how to tune the swappiness of your Linux system.

    What Is Swap?

    A Swap system is described as space allocated on the disk by the operating system and utilized when RAM is inadequate. In Linux, the Swap system may be a partitioned disk area that operates as a swap or a swap file. The swap system may also mix both swap partition and swap files.

    When a system is out of physical memory, the Kernel swaps inactive pages from the main memory into the swap system. That frees up some space in the main memory for usage by other programs.

    Although you may get away without a swap system, if you have a system with less than 4 GB of RAM or a system with essential performance needs, a swap can come in extremely handy—and is recommended. Otherwise, if your system demands more memory than the system can offer, the system can crash, which might have fatal effects.

    Note: Do not think that a swap system is a substitute or an alternative to extra memory. A Swap system is nothing more than a partition or a file saved on the disk; it cannot wholly act as physical memory. If your system is continually running out of adequate memory, try adding extra physical memory since raising your swap system size won’t help much.

    What is Swappiness?

    Swappiness is a kernel setting that enables system administrators to change how frequently the system employs the swap system. Swappiness establishes the connection between switching out inactive pages from the RAM to the swap system.

    The swappiness feature was initially debuted in Linux kernel version 2.6; it spans from 0 to 100. The greater the swappiness number, the more the inactive pages are switched from the main memory to the swap area. Lower values will lead to static pages staying in the main memory.

    How to Change the Swappiness Value

    The default swappiness setting is typically the fair value for most use scenarios. However, you may wish to modify this number for numerous reasons.

    There is no ideal or suggested swappiness value. However, you may use several programs like free to monitor how your system memory operates and alter the swappiness setting until you discover your system’s best number.

    We may alter the swappiness value by changing the configuration file. This approach keeps the swappiness value even after a reboot.

    To achieve this, open the file /etc/sysctl.conf using your text editor and modify the value of the following item vm.swappiness to your desired value. (Add the entry if it does not exist).

    How to Change the Swappiness Value

    To adjust your system’s swappiness setting during runtime, use the sysctl command as shown: Change the swappiness value to meet your best deal.

    sudo sysctl vm.swappiness=10

    How to Change the Swappiness Value

    Note: Accessing swap space is substantially slower than accessing physical memory. Therefore, raising your swappiness value to 100 will not ensure a boost in performance.

    Conclusion

    In this article, we explored what swap is and how it works. Using this approach, you may optimize your system space requirements to match your use demands.

    About the author:
    Adarsh Kumar Singh is a technology writer with a passion for coding and programming. With years of experience in the technical field, he has established a reputation as a knowledgeable and insightful writer on a range of technical topics.
    Tags:linuxhowtoubuntu
    IF YOU LIKE IT, THEN SHARE IT

    Want to learn coding and don't know where to start?

    Try out our Interactive Courses for Free 🥳 😯 🤩
    learn to code footer Ad
     

    RELATED POSTS