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

Re: OT: free cmd is lying to me



On Sun, 2001-12-02 at 14:28, Jason Healy wrote:

> > 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.

IIRC from the Understanding the Linux Kernel book by O'Reilly, linux
doesn't actually worry about memory until you actually use it.  I'm not
sure if a malloc counts as using it for storing data since I'm no C
programmer but unless you actually write to the memory linux doesn't
bother setting up the actual pages since it's a waste for the system to
make and tear down pages that are never accessed.

--mike

--mike




Reply to: