Re: Repost: could ia32 mmap() allocations grow downward?

From: Petr Vandrovec (VANDROVE@vc.cvut.cz)
Date: Thu Dec 13 2001 - 12:38:47 EST


On 13 Dec 01 at 8:22, Wayne Whitney wrote:
> > So maybe MAGMA uses some API which it should not use under any
> > circumstances... Such as that you linked it with libc6 stdio.
>
> Indeed. How can I avoid the map at 0x40000000? Must I avoid using
> certain glibc2 functions, and then link the executable carefully to leave
> out their initialization routines? Or can I set some magic environment

It is caused by (I think that stupid...) code in
glibc-2.2.4/libio/libioP.h:ALLOC_BUF(), which unconditionally does
'mmap(0, ROUND_TO_PAGE(size), PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS,
-1, 0)' instead of 'malloc(size)' when it finds that underlying system
supports malloc.

If you linked Magma yourself, try adding:

---
#include <malloc.h>

void* malloc(size_t len) { return sbrk(len); } void* __mmap(void* start, size_t len, int prot, int flags, int fd, unsigned long offset) { if (start == 0 && fd == -1) { return malloc(len); } return NULL; } --- into your project. It forces my 'void main() { printf("X\n"); pause(); }' to use brk() instead of mmap() for stdio buffers. Maybe we should move to bug-glibc instead, as there is no way to force stdio to not ignore mallopt() parameters, it still insist on using mmap, and I think that it is a glibc2.2 bug. Petr Vandrovec vandrove@vc.cvut.cz

P.S.: I did some testing, and about 95% of mremap() allocations is targeted to last VMA, so no VMA move is needed for them. But no Java was part of picture, only c/c++ programs I use - gcc, mc, perl. - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sat Dec 15 2001 - 21:00:26 EST