Linux – Unnecessary Swapping in Linux

linuxswap

It seems that sometimes, my computer will start swapping unnecessarily (memory usuage is ~25%), and I can't figure out why.

It seems to happen most often when running Perl scripts, but these aren't intensive scripts, and I can't find any thing saying that Perl can only see a certain amount of memory. The swap usage persists after the scripts finish, and even after closing Firefox, Banshee, etc. Restarting X will sometimes solve the problem, but other times, a full restart is required.

This becomes a big problem for me because as soon as whatever-it-is starts swapping, everything else seems to as well. Basic things like closing program or switching viewpoints take longer and longer. If left unchecked, this swap usage will eventually force my computer into indefinite thrashing, unable to even respond to keystrokes!

I'm running Ubuntu 9.04, 2.6.28-15 kernel, I've got 4GB of RAM, and am usually sitting at ~25% usage.

I've also tried lowering the "swappiness," with no luck.

Best Answer

My suggestion is setting your swappiness to 0.

Setting your swappiness to a "lower number" may reduce the "frequency" of using swap, but setting it to 0 will force the kernel down a different code path, forcing all memory allocation to first use up all available memory and cache before using swap space.

You can set swappiness to zero by issuing the following:

echo 0 > /proc/sys/vm/swappiness

Related Question