Repost: could ia32 mmap() allocations grow downward?
Quoted 6 lines · Wayne Whitney
Quoted 2 lines
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 [email protected]
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.
Quoted 3 lines · Petr Vandrovec
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.
OK, that makes sense for the glibc2 subthread of this discussion. Would you mind submitting the bug report, as you have a better command of the issues than I do? Or if you want, I can do it and just quote you. :-)
Quoted 3 lines
P.S.: I did some testing, and about 95% ofmremap()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.
Ah, so this is important data. It shows that the mmap() grows downward strategy will hurt the common case. I don't have any handle on the magnitude of this effect, but if it is significant, then I would have to agree that supporting the legacy brk() apps is not as important as keeping mremap() of the last VMA cheap. How expensive is moving a VMA, and how often do programs mremap()?
How about the idea of modifying brk() (or adding an alternative) to move VMAs out of the way as necessary? This way the negative impact (of moving VMAs) is only borne by the legacy brk() using app. Or is there some other downside that I am missing?
Wayne