swap problems

Jordon Bedwell jordon at envygeeks.com
Wed Jun 8 14:09:31 UTC 2011


On 6/8/2011 7:36 AM, Joep L. Blom wrote:
> My system (AMD Phenom II 4-core with 4 Gb memory) uses gradually more 

This is typical of any computer.

> Moreover my free memory is also decreasing (must be logical?). when I 
> start I have approx. 2Gb free and now it's barely 700 Mb.

Yes this is logical.  This is how memory and swap work (at basic):

Active: Go to memory unless real memory OOM. Then use SWAP.

Sleeping:
Stay in memory until another program needs it.
Move to swap if needed to free up memory for an active program.

Cache: Stay in memory until a program needs memory, then move to SWAP.

> Has anybody an idea how to see what programs are so sloppy written that 
> they don't release memory when they exit, or, which processes refuse to 
> disappear and why the swap space isn't released.

Generally on any optimised operating system remnants will remain cached,
this is typical of Windows, OS X, Linux, and even your computers
processor. Doing this helps make applications more responsive.  Compare
the first time you open up Firefox on cold boot to the second time you
open up Firefox and you will see what I mean.  Normally these parts will
stay in the memory until another program needs that memory and then move
to SWAP and theoretically even using SWAP should be better than a cold
application start.

You can use valgrind to profile, monitor and spot memory leaks in
applications. Some applications (well actually quite a lot) you can top
spot memory leaks, for example, Firefox, you can literally spot a memory
leak like many computer "newbs" have.

> When I try swapoff it can't perform as it doesn't have enough memory 
> which I think is logical as > 4 Gb cannot be stored in memory. But why 
> doesn't swapoff simply remove all garbage, except the space used by 
> running processes.

If this is happening then this might mean you truly do have a real
memory OOM situation that is pushing active applications to the SWAP and
you really are using all of your real memory, which means you need to
evaluate what programs are using up all your memory:

ps -eo pmem,pcpu,user,args | sort -k 1 -r
free -m; sync; echo 3 > /proc/sys/vm/drop_caches; free -m

Post those two lines back to us using Ubuntu paste or whatever tool.

> I know, the most simple solution is to restart but IMHO it is M$ 
> practice to program sloppy but I expected Open Source programs to behave 
> better.

Please, do hesitate from making ignorant, misinformed and incorrect
statements.  While I like to help, it's statements like this that make
me wonder how much people actually know and whether or not it's just
about spreading FUD through lies to get new users instead of showing how
awesome Linux is.  That is not the Microsoft way, and please try to show
a little respect to a company even if you do dislike them.  It's
Microsoft not M$.

If I may add too, on the clusters we design for clients using Debian,
when they are heavy traffic HA-clusters, we would rather the server OOM
and crash out and the server remove itself from the cluster until it's
back up (by automatic restart) then to SWAP at all, even a little.  This
is especially important on our MySQL clusters, there is already enough
overhead without it flowing into overhead added on by heavy SWAP.  I
guess that means our servers do it the Microsoft way right?




More information about the ubuntu-users mailing list