Super User is a question and answer site for computer enthusiasts and power users. 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'm running Ubuntu 10.04 and I do some dev with it. As I open FF, Chrome, Eclipse (Zend Studio 7.2), etc. and do some work, then leave, screen saver goes on, and when I come back a few hours later (the computer has been running for about 1 day in total), the SWAP gets used intensively. I have 4GB of RAM and if I list all the process, I calculated about 2.8GB of RAM used by all the processes, but yet Ubuntu states that 3.8GB is used + 1.2GB of SWAP. I want to understand how this is so? Is there some memory fragmentation, leaks? Is it possible to clean this up to speed up the system again?

share|improve this question
up vote 4 down vote accepted

This might not have to do with the overall memory usage, but with how memory manager in Linux behaves. If processes are just idling, kernel might decide to swap them in order to gain more disk cache.

How eagerly Linux decides to swap inactive processes in order to get more disk cache can be tuned. By default Ubuntu has vm.swappiness=60.

You might want to try a different value. Try command sudo sysctl -w vm.swappiness=10 and just continue using your computer as usual. If the situation improved due this trick, you might add a line

vm.swappiness = 10

to your /etc/sysctl.conf file to make this change permanent across reboots.

share|improve this answer
thanks for this answer! I'll surely test that one out. This is great that you can actually tune SWAP usage :) – Yanick Rochon Aug 5 '10 at 17:31

This happens to me only if the computer goes into hibernation. Ubuntu will put all the Memory into the swap partition, and upon reloading the machine, I have about 10%-25% of the swap partition used up. Is your computer set to auto-hibernate?

A way to force the swap memory into RAM is to run

$sudo swapoff -a
$sudo swapon -a

I'm not sure if this is by design, or if its worth bringing up to the Ubuntu devs.

share|improve this answer
my computer does not go into hibernation, no. But I did put it once, and in fact the swap was used quite heavily. However, I believe that this is a default, normal behavior so I don't worry about that. Thanks though – Yanick Rochon Aug 5 '10 at 17:25

Its probably from the way Linux handle's memory. In short, SWAP is only used when absolutely necessary. Well Firefox is huge and has a well-known memory leak, I'm assuming Eclipse is huge as well, Chrome just eats RAM, etc.

Whats happening is that when you leave your computer alone, the memory leaks slowly eat up your physical RAM. So Linux simply swaps what isn't needed, the UI features. So when you return, it has to pull those out of swap. But then it needs to swap other background things, and as your mashing around with the Windows its probably having to load/swap many different things.

You can solve this by not leaving at least Firefox and Chrome up and using their saved tabs feature instead. I'm a Netbeans guy, so I'm not sure about Eclipse's memory footprint, but does it need to be up?

share|improve this answer
watch out for banshee too! It really chews up the memory. – Jonathan Aug 5 '10 at 16:38
"SWAP is only used when absolutely necessary." - sorry, no, that's not the case: – Ludwig Weinzierl Aug 5 '10 at 16:46
@Ludwig Exactly where in your article does it mention that Linux swaps when ever it wants? Linux swapping only when necessary is one of the core differences between Linux and Windows virtual memory handling. – TheLQ Aug 5 '10 at 17:08
The gist of it is that Linux may send some data out of memory and into swap space, even without the memory being completely full, if the swappiness setting is set greater than zero. The reason for this is that memory must be shared between programs and the disk cache, and sometimes it is best to reduce memory available to programs if it means the disk cache can be made larger. One way to make more memory available is by using the swap space. – Kevin Panko Aug 5 '10 at 22:39

You must log in to answer this question.

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