7

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 2

5

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.

5
  • 1
    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. :) Jan 26, 2012 at 19:03
  • 1
    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. Jan 26, 2012 at 21:04
  • 1
    You 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
  • That's why I said I agree in principle. Jan 27, 2012 at 7:23
4

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.

2
  • I can empty swap manually by using the "swapoff -a" command. No need to reboot in this case.
    – HXH
    Jan 27, 2012 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.
    – HXH
    Jan 27, 2012 at 10:11

You must log in to answer this question.

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