This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: memory allocation magic numbers in glibc


Hello,

> Why does the following program give two different numbers depending
> upon how it is invoked?
> 
> #include <stdio.h>
> main()
> {
> 	int i = 0;
> 	char *p;
> 
> 	while (i++ < 5000) {
> 		p = malloc(1024 * 1024);
> 		if (!p) break;
> 	}
> 
> 	printf("allocated %ld kbytes\n", (i-1)*1024L);
> }
> 
> 
> On Alpha I get:
> 
> # /tmp/mtest
> allocated 5120000 kbytes
> # /lib/ld-linux.so.2 /tmp/mtest
> allocated 1048576 kbytes
> 
> 
> On Intel I get:
> $ /tmp/mtest
> allocated 1965056 kbytes
> $ /lib/ld-linux.so.2 /tmp/mtest
> allocated 1048576 kbytes

The difference is due to the different memory layout, as explained by
others.

However, you're hitting the `1024 mmap'ed chunks' limit, which you
shouldn't hit with the latest malloc (glibc-2.1.91 and up).  I think
it's a bug in thread-m.h (patch forthcoming!), for now you can
hopefully work around the problem by linking with -lpthread (even
though you're not using threads).

You should be able to allocate at least 2GB, even with the traditional
sbrk()able heap `blocked' due to ld-linux.so.2 in this way.

Regards,
Wolfram.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]