[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: OT: free cmd is lying to me



At 1007344595s since epoch (12/02/01 14:56:35 -0500 UTC), Holger Rauch wrote:
> That said, the free cmd should report that approx. 1.4 GB of main memory
> should still be available. However, what I get is:
> 
>              total       used       free     shared    buffers     cached
> Mem:       2096664    2093416       3248          0      87172    1783556
> -/+ buffers/cache:     222688    1873976
> Swap:      4194272          0    4194272

Looks right to me.  According to free, your system has 2GB of memory,
most of which is 'used'.  However, looking at the next line, you'll
see that 1.8GB of that is actually free for use, as the memory
reported as being in use on the first line is mostly going towards
buffers and cache (87172 for buffers, 1783556 for cache).  In fact,
only 222,688 K are being used by actual processes on the system.

Search this list archive for other e-mails on the free command; you'll
find that the fact that Linux 'uses' all available memory for caching
and buffers tends to confuse people.

> In order to find out whether this is right, I wrote a small test
> program that continuously does a malloc() for 10 MB every 5 secs until the
> system runs out of memory. Strangely enough, it didn't. 

How long did you run it for?  To use up 1.8GB of available RAM would
take 15 minutes at the rate you described.  To exhaust all system
memory (including the 4GB of swap) would take a total of 48 minutes.
Did you wait that long?  Also, did you run the program as a normal
user?  The default ulimit probably would have clobbered the process
before it could hog that much memory.

> 1. What could be the cause that size of used mem doesn't increase
> accordingly when I malloc() 10 MB?

Because the system dumps cache in favor of your running process.
Linux counts its cache memory as 'in use', so when it drops cache to
provide memory to processes, the memory is still reported as 'in
use'.  The second line of 'free' output, however, should change when
you start new processes.

> 2. Why does "free" leave the impression on me that no swap space is
     used?

probably because none is  =) .  2GB of physical RAM is a lot to exhaust...

Hope this helps.   If I've misread your question about free (i.e., you
know about the buffer/cache thing), then maybe I'm missing something
about what's wrong with the system.

Jason

--
Jason Healy    |    jhealy@logn.net    |   http://www.logn.net/



Reply to: