Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

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.

share|improve this answer
While 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. :) – user unknown Jan 26 '12 at 19:03
I 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. – Jo-Erlend Schinstad Jan 26 '12 at 21:04
You could rewrite the critical code in the kernel. It's open source. – user unknown Jan 26 '12 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. – Jo-Erlend Schinstad Jan 27 '12 at 0:38
That's why I said I agree in principle. – user unknown Jan 27 '12 at 7:23

See the section titled "What is swappiness and how do I change it?" on this page:

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.

share|improve this answer
I can empty swap manually by using the "swapoff -a" command. No need to reboot in this case. – Ghassen Telmoudi Jan 27 '12 at 9:08
$ cat /proc/sys/vm/swappiness<br> $ 60 $ sudo sysctl vm.swappiness=10 $ sudo /etc/sysctl.conf There is no trace for vm.swappiness in this file. – Ghassen Telmoudi Jan 27 '12 at 10:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.