9

A value of swappiness=10 is recommended in Ubuntu's SwapFaq.

Why is a value of 10 is recommended rather than swappiness=0?

Are there any pros of 10 or cons of zero?

3
  • possible duplicate of Why most people recommend to reduce swappiness to 10-20?
    – Mitch
    Apr 2, 2013 at 5:25
  • 3
    @Mitch That question is about why people recommend to reduce swappiness. This question is different; it is asking why swappiness should be above zero at all. So this is not asking why people recommend for it to be so low; it's asking why the recommendation is as high as it is. Because the answer there (quite rationally) disagrees with the argument to reduce swappiness this far, there is some overlap with my answer here, but ultimately I think these are separate (albeit related) questions with separate answers. Apr 2, 2013 at 5:26
  • @EliahKagan touché :)
    – Mitch
    Apr 2, 2013 at 5:39

1 Answer 1

10

swappiness=0 will wait to swap until it is absolutely necessary. Setting a moderate value like swappiness=10 will cause pages to be swapped from memory to disk somewhat more readily. This can prevent the need to swap a lot at once; such a need can introduce annoying delays.

In addition, often a process runs but does nothing for an extended time. Many daemons (background services) behave this way. You may have a background application that is left unused for a while. And these days some applications are implemented as multiple processes, like Chromium and Google Chrome, where each tab has a separate process behind it (not a separate thread, but a separate process). Setting swappiness to a value like 10 makes it so these background tasks that are not being actively used are swapped to memory even when they could remain crammed in RAM. Then when a more actively used process needs to allocate more RAM, it can do so more quickly.

In conclusion, allowing processes to be swapped from RAM to disk earlier than necessary often confers a performance benefit and lower latencies when a process allocates memory. This is at the expense of the time it takes to swap the processes back. But this is usually done much less frequently than a process in active use allocates and releases memory, so the trade-off is often worthwhile.

1
  • You should also take into account your drive's buffer. If you have a SSD with a buffer of 512 MB and 4 GB of RAM. you can probably leave this at 10 without worrying about any performance issues because any program will be able to almost instantly allocate about 1 GB of RAM. I have a SSD with 256 MB buffer and 8 GB of RAM, so I also leave it at 10 because it also guarantees a quick allocation of about 1 GB which I rarely need.
    – stackount
    Dec 16, 2013 at 10:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .