How to configure swappiness in Linux Memory Management?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












10















The swappiness parameter controls the tendency of the kernel to move processes out of physical memory and onto the swap disk. What is the default setting and how to configure that to improve overall performance?










share|improve this question



















  • 2





    After changing swappiness, I found it useful to empty the swap with swapoff -a to start afresh. serverfault.com/a/354384/203035

    – Nemo
    Jul 1 '17 at 10:07















10















The swappiness parameter controls the tendency of the kernel to move processes out of physical memory and onto the swap disk. What is the default setting and how to configure that to improve overall performance?










share|improve this question



















  • 2





    After changing swappiness, I found it useful to empty the swap with swapoff -a to start afresh. serverfault.com/a/354384/203035

    – Nemo
    Jul 1 '17 at 10:07













10












10








10


6






The swappiness parameter controls the tendency of the kernel to move processes out of physical memory and onto the swap disk. What is the default setting and how to configure that to improve overall performance?










share|improve this question
















The swappiness parameter controls the tendency of the kernel to move processes out of physical memory and onto the swap disk. What is the default setting and how to configure that to improve overall performance?







linux performance swap






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 9 at 21:46









peterh

4,467113159




4,467113159










asked Feb 25 '16 at 11:58









GAD3RGAD3R

26.9k1757111




26.9k1757111







  • 2





    After changing swappiness, I found it useful to empty the swap with swapoff -a to start afresh. serverfault.com/a/354384/203035

    – Nemo
    Jul 1 '17 at 10:07












  • 2





    After changing swappiness, I found it useful to empty the swap with swapoff -a to start afresh. serverfault.com/a/354384/203035

    – Nemo
    Jul 1 '17 at 10:07







2




2





After changing swappiness, I found it useful to empty the swap with swapoff -a to start afresh. serverfault.com/a/354384/203035

– Nemo
Jul 1 '17 at 10:07





After changing swappiness, I found it useful to empty the swap with swapoff -a to start afresh. serverfault.com/a/354384/203035

– Nemo
Jul 1 '17 at 10:07










3 Answers
3






active

oldest

votes


















6














The Linux kernel provides a tweakable setting that controls swappiness



$ cat /proc/sys/vm/swappiness
60


open /etc/sysctl.conf as root. Then, change or add this line to the file:



vm.swappiness = 10


for changing the swappiness value temporarily try this command:



$ echo 50 > /proc/sys/vm/swappiness





share|improve this answer

























  • How does it answer "how to configure that to improve overall performance ?"

    – techraf
    Feb 25 '16 at 12:10











  • Swapping is needed when where your system is performence is slow because it happens at times when you are running out of usable RAM, which would have slowed your system down (maybe even crashed applications) even if you didn't have swap. So to simplify things, swapping happens because your system is becoming bogged down, rather than the other way around - and in some cases it can save the day.

    – Mongrel
    Feb 25 '16 at 12:22






  • 1





    Don't you also need to sudo sysctl -p /etc/sysctl.conf for changes to take effect?

    – pkaramol
    Jan 15 '18 at 11:31


















11














From Swappiness, Wikipedia



You could set this value in a virtual file /proc/sys/vm/swappiness
The mentioned value will be deciding how the swap space should be used, below are the values with their intents.



vm.swappiness = 0 # Swap is disabled. In earlier versions, this meant that the kernel would swap only to avoid an out of memory condition, but in later versions this is achieved by setting to 1.
vm.swappiness = 1 # Kernel version 3.5 and over, as well as kernel version 2.6.32-303 and over: Minimum amount of swapping without disabling it entirely.
vm.swappiness = 10 # This value is sometimes recommended to improve performance when sufficient memory exists in a system, this value *10* could be considered for the performance being expected.
vm.swappiness = 60 # The default value.
vm.swappiness = 100 # The kernel will swap aggressively.


Although it actually depends upon the need too, if the physical memory available is sufficient, there may not be a great need of swap space, in Layman's terms there won't be a need of changing the default value of 60.






share|improve this answer

























  • @techraf updated the answer.

    – Keyshov Borate
    Feb 25 '16 at 12:15






  • 1





    In VMs I do advise nonetheless changing it to 10 just in case.

    – Rui F Ribeiro
    Oct 30 '18 at 17:38


















2














In RedHat/CentOS the default value is 60.

"In order to improve performance" is very broad term.
What performance are you trying to improve?


Do you have issues with low memory?
Does your system SWAP when there's still free memory/cached memory?



In Linux free RAM = wasted RAM, so almost all free memory is used for disc caches.

There are cases with swappiness=60 where pages in memory are moved to SWAP if they haven't been accessed for extended time periods, no matter you have unallocated RAM.

Moving some memory pages to SWAP is not necessary a bad thing.



Please shed some more light on your issue for more detailed answer.






share|improve this answer






















    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f265713%2fhow-to-configure-swappiness-in-linux-memory-management%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    6














    The Linux kernel provides a tweakable setting that controls swappiness



    $ cat /proc/sys/vm/swappiness
    60


    open /etc/sysctl.conf as root. Then, change or add this line to the file:



    vm.swappiness = 10


    for changing the swappiness value temporarily try this command:



    $ echo 50 > /proc/sys/vm/swappiness





    share|improve this answer

























    • How does it answer "how to configure that to improve overall performance ?"

      – techraf
      Feb 25 '16 at 12:10











    • Swapping is needed when where your system is performence is slow because it happens at times when you are running out of usable RAM, which would have slowed your system down (maybe even crashed applications) even if you didn't have swap. So to simplify things, swapping happens because your system is becoming bogged down, rather than the other way around - and in some cases it can save the day.

      – Mongrel
      Feb 25 '16 at 12:22






    • 1





      Don't you also need to sudo sysctl -p /etc/sysctl.conf for changes to take effect?

      – pkaramol
      Jan 15 '18 at 11:31















    6














    The Linux kernel provides a tweakable setting that controls swappiness



    $ cat /proc/sys/vm/swappiness
    60


    open /etc/sysctl.conf as root. Then, change or add this line to the file:



    vm.swappiness = 10


    for changing the swappiness value temporarily try this command:



    $ echo 50 > /proc/sys/vm/swappiness





    share|improve this answer

























    • How does it answer "how to configure that to improve overall performance ?"

      – techraf
      Feb 25 '16 at 12:10











    • Swapping is needed when where your system is performence is slow because it happens at times when you are running out of usable RAM, which would have slowed your system down (maybe even crashed applications) even if you didn't have swap. So to simplify things, swapping happens because your system is becoming bogged down, rather than the other way around - and in some cases it can save the day.

      – Mongrel
      Feb 25 '16 at 12:22






    • 1





      Don't you also need to sudo sysctl -p /etc/sysctl.conf for changes to take effect?

      – pkaramol
      Jan 15 '18 at 11:31













    6












    6








    6







    The Linux kernel provides a tweakable setting that controls swappiness



    $ cat /proc/sys/vm/swappiness
    60


    open /etc/sysctl.conf as root. Then, change or add this line to the file:



    vm.swappiness = 10


    for changing the swappiness value temporarily try this command:



    $ echo 50 > /proc/sys/vm/swappiness





    share|improve this answer















    The Linux kernel provides a tweakable setting that controls swappiness



    $ cat /proc/sys/vm/swappiness
    60


    open /etc/sysctl.conf as root. Then, change or add this line to the file:



    vm.swappiness = 10


    for changing the swappiness value temporarily try this command:



    $ echo 50 > /proc/sys/vm/swappiness






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Feb 25 '16 at 12:21









    schaiba

    5,55912229




    5,55912229










    answered Feb 25 '16 at 12:02









    MongrelMongrel

    2,10331747




    2,10331747












    • How does it answer "how to configure that to improve overall performance ?"

      – techraf
      Feb 25 '16 at 12:10











    • Swapping is needed when where your system is performence is slow because it happens at times when you are running out of usable RAM, which would have slowed your system down (maybe even crashed applications) even if you didn't have swap. So to simplify things, swapping happens because your system is becoming bogged down, rather than the other way around - and in some cases it can save the day.

      – Mongrel
      Feb 25 '16 at 12:22






    • 1





      Don't you also need to sudo sysctl -p /etc/sysctl.conf for changes to take effect?

      – pkaramol
      Jan 15 '18 at 11:31

















    • How does it answer "how to configure that to improve overall performance ?"

      – techraf
      Feb 25 '16 at 12:10











    • Swapping is needed when where your system is performence is slow because it happens at times when you are running out of usable RAM, which would have slowed your system down (maybe even crashed applications) even if you didn't have swap. So to simplify things, swapping happens because your system is becoming bogged down, rather than the other way around - and in some cases it can save the day.

      – Mongrel
      Feb 25 '16 at 12:22






    • 1





      Don't you also need to sudo sysctl -p /etc/sysctl.conf for changes to take effect?

      – pkaramol
      Jan 15 '18 at 11:31
















    How does it answer "how to configure that to improve overall performance ?"

    – techraf
    Feb 25 '16 at 12:10





    How does it answer "how to configure that to improve overall performance ?"

    – techraf
    Feb 25 '16 at 12:10













    Swapping is needed when where your system is performence is slow because it happens at times when you are running out of usable RAM, which would have slowed your system down (maybe even crashed applications) even if you didn't have swap. So to simplify things, swapping happens because your system is becoming bogged down, rather than the other way around - and in some cases it can save the day.

    – Mongrel
    Feb 25 '16 at 12:22





    Swapping is needed when where your system is performence is slow because it happens at times when you are running out of usable RAM, which would have slowed your system down (maybe even crashed applications) even if you didn't have swap. So to simplify things, swapping happens because your system is becoming bogged down, rather than the other way around - and in some cases it can save the day.

    – Mongrel
    Feb 25 '16 at 12:22




    1




    1





    Don't you also need to sudo sysctl -p /etc/sysctl.conf for changes to take effect?

    – pkaramol
    Jan 15 '18 at 11:31





    Don't you also need to sudo sysctl -p /etc/sysctl.conf for changes to take effect?

    – pkaramol
    Jan 15 '18 at 11:31













    11














    From Swappiness, Wikipedia



    You could set this value in a virtual file /proc/sys/vm/swappiness
    The mentioned value will be deciding how the swap space should be used, below are the values with their intents.



    vm.swappiness = 0 # Swap is disabled. In earlier versions, this meant that the kernel would swap only to avoid an out of memory condition, but in later versions this is achieved by setting to 1.
    vm.swappiness = 1 # Kernel version 3.5 and over, as well as kernel version 2.6.32-303 and over: Minimum amount of swapping without disabling it entirely.
    vm.swappiness = 10 # This value is sometimes recommended to improve performance when sufficient memory exists in a system, this value *10* could be considered for the performance being expected.
    vm.swappiness = 60 # The default value.
    vm.swappiness = 100 # The kernel will swap aggressively.


    Although it actually depends upon the need too, if the physical memory available is sufficient, there may not be a great need of swap space, in Layman's terms there won't be a need of changing the default value of 60.






    share|improve this answer

























    • @techraf updated the answer.

      – Keyshov Borate
      Feb 25 '16 at 12:15






    • 1





      In VMs I do advise nonetheless changing it to 10 just in case.

      – Rui F Ribeiro
      Oct 30 '18 at 17:38















    11














    From Swappiness, Wikipedia



    You could set this value in a virtual file /proc/sys/vm/swappiness
    The mentioned value will be deciding how the swap space should be used, below are the values with their intents.



    vm.swappiness = 0 # Swap is disabled. In earlier versions, this meant that the kernel would swap only to avoid an out of memory condition, but in later versions this is achieved by setting to 1.
    vm.swappiness = 1 # Kernel version 3.5 and over, as well as kernel version 2.6.32-303 and over: Minimum amount of swapping without disabling it entirely.
    vm.swappiness = 10 # This value is sometimes recommended to improve performance when sufficient memory exists in a system, this value *10* could be considered for the performance being expected.
    vm.swappiness = 60 # The default value.
    vm.swappiness = 100 # The kernel will swap aggressively.


    Although it actually depends upon the need too, if the physical memory available is sufficient, there may not be a great need of swap space, in Layman's terms there won't be a need of changing the default value of 60.






    share|improve this answer

























    • @techraf updated the answer.

      – Keyshov Borate
      Feb 25 '16 at 12:15






    • 1





      In VMs I do advise nonetheless changing it to 10 just in case.

      – Rui F Ribeiro
      Oct 30 '18 at 17:38













    11












    11








    11







    From Swappiness, Wikipedia



    You could set this value in a virtual file /proc/sys/vm/swappiness
    The mentioned value will be deciding how the swap space should be used, below are the values with their intents.



    vm.swappiness = 0 # Swap is disabled. In earlier versions, this meant that the kernel would swap only to avoid an out of memory condition, but in later versions this is achieved by setting to 1.
    vm.swappiness = 1 # Kernel version 3.5 and over, as well as kernel version 2.6.32-303 and over: Minimum amount of swapping without disabling it entirely.
    vm.swappiness = 10 # This value is sometimes recommended to improve performance when sufficient memory exists in a system, this value *10* could be considered for the performance being expected.
    vm.swappiness = 60 # The default value.
    vm.swappiness = 100 # The kernel will swap aggressively.


    Although it actually depends upon the need too, if the physical memory available is sufficient, there may not be a great need of swap space, in Layman's terms there won't be a need of changing the default value of 60.






    share|improve this answer















    From Swappiness, Wikipedia



    You could set this value in a virtual file /proc/sys/vm/swappiness
    The mentioned value will be deciding how the swap space should be used, below are the values with their intents.



    vm.swappiness = 0 # Swap is disabled. In earlier versions, this meant that the kernel would swap only to avoid an out of memory condition, but in later versions this is achieved by setting to 1.
    vm.swappiness = 1 # Kernel version 3.5 and over, as well as kernel version 2.6.32-303 and over: Minimum amount of swapping without disabling it entirely.
    vm.swappiness = 10 # This value is sometimes recommended to improve performance when sufficient memory exists in a system, this value *10* could be considered for the performance being expected.
    vm.swappiness = 60 # The default value.
    vm.swappiness = 100 # The kernel will swap aggressively.


    Although it actually depends upon the need too, if the physical memory available is sufficient, there may not be a great need of swap space, in Layman's terms there won't be a need of changing the default value of 60.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jul 8 '18 at 1:27









    adatum

    10210




    10210










    answered Feb 25 '16 at 12:08









    Keyshov BorateKeyshov Borate

    72911225




    72911225












    • @techraf updated the answer.

      – Keyshov Borate
      Feb 25 '16 at 12:15






    • 1





      In VMs I do advise nonetheless changing it to 10 just in case.

      – Rui F Ribeiro
      Oct 30 '18 at 17:38

















    • @techraf updated the answer.

      – Keyshov Borate
      Feb 25 '16 at 12:15






    • 1





      In VMs I do advise nonetheless changing it to 10 just in case.

      – Rui F Ribeiro
      Oct 30 '18 at 17:38
















    @techraf updated the answer.

    – Keyshov Borate
    Feb 25 '16 at 12:15





    @techraf updated the answer.

    – Keyshov Borate
    Feb 25 '16 at 12:15




    1




    1





    In VMs I do advise nonetheless changing it to 10 just in case.

    – Rui F Ribeiro
    Oct 30 '18 at 17:38





    In VMs I do advise nonetheless changing it to 10 just in case.

    – Rui F Ribeiro
    Oct 30 '18 at 17:38











    2














    In RedHat/CentOS the default value is 60.

    "In order to improve performance" is very broad term.
    What performance are you trying to improve?


    Do you have issues with low memory?
    Does your system SWAP when there's still free memory/cached memory?



    In Linux free RAM = wasted RAM, so almost all free memory is used for disc caches.

    There are cases with swappiness=60 where pages in memory are moved to SWAP if they haven't been accessed for extended time periods, no matter you have unallocated RAM.

    Moving some memory pages to SWAP is not necessary a bad thing.



    Please shed some more light on your issue for more detailed answer.






    share|improve this answer



























      2














      In RedHat/CentOS the default value is 60.

      "In order to improve performance" is very broad term.
      What performance are you trying to improve?


      Do you have issues with low memory?
      Does your system SWAP when there's still free memory/cached memory?



      In Linux free RAM = wasted RAM, so almost all free memory is used for disc caches.

      There are cases with swappiness=60 where pages in memory are moved to SWAP if they haven't been accessed for extended time periods, no matter you have unallocated RAM.

      Moving some memory pages to SWAP is not necessary a bad thing.



      Please shed some more light on your issue for more detailed answer.






      share|improve this answer

























        2












        2








        2







        In RedHat/CentOS the default value is 60.

        "In order to improve performance" is very broad term.
        What performance are you trying to improve?


        Do you have issues with low memory?
        Does your system SWAP when there's still free memory/cached memory?



        In Linux free RAM = wasted RAM, so almost all free memory is used for disc caches.

        There are cases with swappiness=60 where pages in memory are moved to SWAP if they haven't been accessed for extended time periods, no matter you have unallocated RAM.

        Moving some memory pages to SWAP is not necessary a bad thing.



        Please shed some more light on your issue for more detailed answer.






        share|improve this answer













        In RedHat/CentOS the default value is 60.

        "In order to improve performance" is very broad term.
        What performance are you trying to improve?


        Do you have issues with low memory?
        Does your system SWAP when there's still free memory/cached memory?



        In Linux free RAM = wasted RAM, so almost all free memory is used for disc caches.

        There are cases with swappiness=60 where pages in memory are moved to SWAP if they haven't been accessed for extended time periods, no matter you have unallocated RAM.

        Moving some memory pages to SWAP is not necessary a bad thing.



        Please shed some more light on your issue for more detailed answer.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Feb 25 '16 at 12:21









        firetofireto

        713




        713



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f265713%2fhow-to-configure-swappiness-in-linux-memory-management%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown






            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?