mmap MAP_FIXED behavior for adjacent page mappings
09:00 17 Sep 2026

When allocating memory using mmap with the `MAP_FIXED_NOREPLACE` flag, to attempt to extend a mapping obtained earlier, I got an address lower than the specified address. I found out that the address I got is the one I mmap-ed already before, so the memory ranges of both calls are next to each other, specifically I got for example:

memory range 1:
    requested NULL with size 0x100000
    I got 0x4a8d000
memory range 2: 
    requested 0x4b8d000 (fixed) with size 0x100000
    I got 0x4a8d000 again

The linux man page only states: "mmap() returns a pointer to the mapped area", which could mean the whole segment, which is what I am observing? However POSIX states: "When MAP_FIXED is set in the flags argument, the implementation is informed that the value of pa shall be addr, exactly."

Is this behavior a linux specific thing? I am using linux version 7.0.0-31-generic with glibc 2.39.

c linux memory-management posix