> >> The proper solution would be to rewrite mmap.c to be smarter (perhaps > >> by looking at /proc/self/maps and reserving a lot of space with > >> PROT_NONE mappings at startup and then managing it itself), but so far > >> nobody's done that > > > > Yes they have. That's what -R does. > > -R doesn't happen by default, it requires you to specify how much you > want, and it insists that the space all be in one chunk.
I've covered the defaults elsewhere in this thread. If your 64-bit host can't find a contiguous 4G block of address space then you've much more serious issues. System policies preventing applications allocating that much address space are a different problem, and splitting the into chunks would not help. > > We used to try and parse /proc/self/maps. This caused more problems than > > it solved. It doesn't cover things like mmap_min_addr, and you have to > > re-parse it before every allocation in case the host libc allocated > > something new in between. > > If you've used a PROT_NONE mapping to claim the space at startup, host libc > doesn't override that mapping, does it? Ah, I see what you mean. If you're solving problems other than 32-on-64 then there's some argument for allowing discontiguous blocks. I'm not convinced there's much point parsing /proc/self/maps though. Just keep calling mmap for sensible sized blocks until you either have enough address space or it fails. In the latter case maybe free some back immediately to give the host libc room to work. The hard bit is coming up with heuristics for "sensibe size block" and "have enough". /proc/self/maps only tells you which areas of the host VM are currently mapped. What we really want to know is which areas are available to be mapped. On 32-bit hosts this may be this may be less than half of the gaps in /proc/self/maps. On 64-bit hosts it's many orders of magnitude smaller. For example x86-64 only has 47-bits of usable virtual address space. Nested qemu is also going to make a complete mess of /proc/self/maps, though I admit you're probably going to trip over other bugs first :-) Paul