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?
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
to your /etc/sysctl.conf file to make this change permanent across reboots.
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
I'm not sure if this is by design, or if its worth bringing up to the Ubuntu devs.
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?