This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Re: memory allocation magic numbers in glibc
- To: steve at turbolinux dot co dot jp
- Subject: Re: memory allocation magic numbers in glibc
- From: Wolfram Gloger <Wolfram dot Gloger at dent dot med dot uni-muenchen dot de>
- Date: Mon, 4 Sep 2000 12:22:00 +0200 (MDT)
- CC: libc-alpha at sourceware dot cygnus dot com
- References: <m2snrkgv9h.fsf@dejima.jp.tlan>
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.