Scyld: memory leak or just caching?

Sean Dilda agrajag at scyld.com
Wed Jun 27 15:51:04 PDT 2001


On Wed, 27 Jun 2001, Mike Weller wrote:

> Sean wrote:
> > Sounds like just caching to me.  However, if you want to double check,
> > write a simple program that malloc()'s about 100M, bpsh it over there
> > and see what happens.
> 
> Ok, I wrote a program to allocate 100M of RAM.  "ps -leaf" reports
> 100M used by the program (taking SZ * 4096k/page).  However, "free"
> reports an increase of only 100k, and no swap was used.  Does the
> kernel preallocate more RAM than it needs, and then gives it to
> processes that need it?  How can I learn more about kernel memory?
> "ps" is uninformative.
> 
> Below is some of the info I captured :
> 
> [root at beowulf ~]# cat /home/malloc.c
> #include <malloc.h>
> #define NUM_MALLOCS 1
> int main( )
> {
> 	int x;
> 	for( x = 0; x < NUM_MALLOCS; ++x )
> 			malloc( 1024 * 1024 * 100 );
> 	sleep( 100000 );
> 	return( 0 );
> }

I just ran some tests on my laptop, apparently the kernel is to smart
for us.  It appears that it doesn't actually register the memory as
being used until you change it.  So, try changing:

>       int x;
>       for( x = 0; x < NUM_MALLOCS; ++x )
>                       malloc( 1024 * 1024 * 100 );

to:

        calloc(NUM_MALLOCS, 1024 * 1024 * 100 ); 


calloc() actually zero's the memory as it allocates it, so this will
cause the kernel to actually pay attention to the memory.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
URL: <http://www.beowulf.org/pipermail/beowulf/attachments/20010627/5ab634cf/attachment.sig>


More information about the Beowulf mailing list