[ale] Can someone help me understand memory usage?

Ben Coleman oloryn at benshome.net
Thu Apr 25 23:36:17 EDT 2002


On Thu, 25 Apr 2002 20:06:20 -0400, Chris Fowler wrote:

>A friend just installed 384 megs of memory in his Linux box.  It is still
>swapping to disk.

Is he actually seeing thrashing (the computer runs slow because it is
constantly having to move stuff into and out of swap), or is he just
looking at the output of 'free' and seeing a non-zero value in the
'used' column for swap?  If it's the latter, he may have nothing to
worry about.

>1) What is cached memory?

Someone correct me if I don't quite have this correct, but to my
understanding the 'cache/buffer' memory is free memory that Linux uses,
essentially, for block device I/O purposes.  It's said that 'unused RAM
is wasted RAM', so Linux puts this otherwise free memory to use.

2) What would there be memory in cache and the box be using swap?

On any Linux box there will be some amount of code running that is
actually rarely scheduled for CPU time:  daemons running for services
that aren't actually used (or are rarely used - e.g. lpd on a machine
that rarely prints anything), 'initialization' code that gets run when
a program begins and afterwards is just baggage taking up memory, etc).
 Because Linux uses a 'least-recently-used' algorithm to decide what
gets swapped out, these tend to be the first memory pages to be put in
swap.  And because they *are* rarely actually executed, they tend to
*stay* in swap once they're there - Linux won't pull them back into RAM
until they actually need to run, even if there is plenty of free RAM
available.  Thus once you've got enough running to require the use of
swap, you tend to see *some* swap 'in use'  (e.g. in the output of
'free') afterwards, even if current memory use would fit in RAM.

E.g., on my Linux workstation, I currently see:

nj8j at frodo:~$ free
             total    used    free  shared buffers  cached
Mem:        255444  209432   46012       0   88132   86284
-/+ buffers/cache:   35016  220428
Swap:       124956   14076  110880

At some point in the last 54 days, I've used enough memory to push it
into swap(easy enough to do on a KDE workstation).  And despite the
fact that even by the top line I show more than enough 'free' memory to
cover what's in swap, 14MB is still 'in use' in swap.  Evidently I have
that much idle code ('in memory', but not actually using the CPU) lying
around.

OTOH, there's my mail/database server:

oloryn at erebor:~$ free
             total    used    free  shared buffers  cached
Mem:        255524  163896   91628       0   56292   51080
-/+ buffers/cache:   56524  199000
Swap:       248968       0  248968

It's been running 5 days and evidently has never had to put anything
into swap.

On the gripping hand, there's my dinky little 486 box:

oloryn at shire:~$ free
             total    used    free  shared buffers  cached
Mem:         14016   12996    1020       0    1468    4004
-/+ buffers/cache:    7524    6492
Swap:        32092   10836   21256

By any measure, this is definitely 'running in swap'.

Note that for evaluating memory use, the middle line (counting
buffer/cache memory as 'free', rather than 'used') is probably more
useful.  This took me a bit to catch on to, too.

Ben

-- 
Ben Coleman oloryn at benshome.net      | The attempt to legislatively
http://oloryn.home.mindspring.com/   | micromanage equality results, at
Amateur Radio NJ8J                   | best, in equal misery for all.



---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be 
sent to listmaster at ale dot org.






More information about the Ale mailing list