I always notice that Ubuntu start using swap, as soon as the RAM usage is around 60-70%. How to configure it so it should wait so RAM usage became 80-90%. And is there a way to empty the swap, as soon as the there is space available on the RAM, other than swapoff manually?
2 Answers
The answer to your question how, is "no". Linux is extremely good at memory management. You could never hope to compete with it. And you wouldn't want to unswap just because you had free RAM. Because Linux knows what parts of the memory is most useful. In other words; you'd reduce performance drastically by manually moving unused memory from the harddisk and into RAM.
-
1While I agree in principle, the absoluteness of
you could never compete with it
moves the kernel developers into a god-like position, which doesn't sound reasonable. :) Jan 26, 2012 at 19:03 -
1I was not talking about kernel developers. I was talking about the kernel. A human brain would never be able to analyze that kind of data as quickly as a computer can. Just remember that one byte is 256 combinations. Four bytes is 4.3 billion. Imagine a gigabyte. Jan 26, 2012 at 21:04
-
1You could rewrite the critical code in the kernel. It's open source. Jan 26, 2012 at 23:53
-
Sure you could, but now we've come full circle; the point is that the kernel is already very good at this. Jan 27, 2012 at 0:38
-
See the section titled "What is swappiness and how do I change it?" on this page:
https://help.ubuntu.com/community/SwapFaq
But, I also agree with Jo-Erlend Schinstad. If there is no urgent need to change the default behavior, it is best to leave it alone. However, I see that the article itself recommends a value of 10, while the default is 60. So, changing to the recommended value of 10 should take you the way you want to go (less swapping).
Also, part of your original question is, how to empty swap. swap is emptied every time you reboot.