Adjust Your swappiness!

By | 2010/06/23

What is swappiness and why the heck should I change it?

swappiness is a value between 1 and 100 which controls the priority of your system using ram vs. swap.

Making this change will greatly increase the performance of your box! Especially if you have a recent system with lots of ram.

A swappiness value of 1 means avoid swap as much as possible and only use ram.

A swappiness value of 100 means avoid ram as much as possible and only use swap.

By default, Ubuntu is set for swappiness of 60.

For desktop users I recommend changing swappiness to a value of 10.

For most servers I suggest setting it to a value of 25.

If you have 4, 8, or more GB of ram, consider setting your swappiness to 1.

Ok, so how to I check my swappiness?

Do this command to check your current swappiness value:

cat /proc/sys/vm/swappiness

You can temporarily change it by issuing:

sudo sysctl vm.swappiness=10

To set the value permanently on your box, edit this file:

sudo nano /etc/sysctl.conf

And put in the value you desire, such as:


8 thoughts on “Adjust Your swappiness!

  1. James Watt

    Really appreciate this info. Setting up a headless linux server (CentOS) with 32GB of physical RAM. It took longer for me to write this than it did to follow your guide. Thanks again.

    1. Scott Miller Post author

      Thanks! Ram is getting so cheap these days and it’s good to change this setting.

  2. twitter

    Thank you for info. I copy pasted and it worked.
    swappiness 60 :))

  3. Frank

    Never set your swappiness to 0 set it to 1, crashes and core dumps if no swap can be written when enabled.

    1. Scott Miller Post author

      Thanks! I have updated the post.

  4. lucious

    I am trying to permanently change my swappiness level, i’ve seen this answer posted in a few places and everyone greateful, saying it works. But it isn’t for me…

    After entering:
    sudo nano /etc/sysctl.conf

    i get a list come up saying various things all with a hashtags in front of each line….

    Where exactly do i add “vm.swappiness=10”??
    do i add a hashtag in front of it too like everything else in the file?
    I added it to the very top of the file and saved, rebooted, hasnt changed anything.
    I also added it to the bottom and saved, rebooted…..still hasn’t changed. my swappiness is still 60.

    Could someone please be a bit more specific?


    1. zsh


      The best practice is to add it at the end of the file that way you can easily find what you changed. And on the # symbol it means that what follows is a comment and tells the script not to parse it (not execute it as a command). They are there on each setting because those are the default settings, there is no reason for the shell to parse a default setting. If you were to change a preexisting setting you would remove the hashtag off of the updated command so the shell will parse it.
      If you added a hash tag and set the swappiness to 10 as in “#vm.swappiness=10” the shell wouldn’t execute it leaving the swappiness at 60.
      Let me give you an example from one of my /etc/sysctrl.conf files (it’s on a local router providing NAT for a subnet that I want segregated from the rest of my network)

      # Accept ICMP redirects only for gateways listed in our default
      # gateway list (enabled by default)
      # net.ipv4.conf.all.secure_redirects = 1
      # Do not accept IP source route packets (we are not a router)
      ## Set to 1 because we are a router
      net.ipv4.conf.all.accept_source_route = 1
      net.ipv6.conf.all.accept_source_route = 1
      # Turn off TCP Timestamps
      net.ipv4.tcp_timestamps = 0
      # Set Swappiness (default 60)


Leave a Reply

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

Notify me of followup comments via e-mail. You can also subscribe without commenting.