Re: [PATCH 0/2] mm: introduce MAP_FIXED_SAFE
From: Florian Weimer
Date: Fri Dec 08 2017 - 15:47:40 EST
On 12/08/2017 03:27 PM, Pavel Machek wrote:
On Fri 2017-12-08 22:08:07, Michael Ellerman wrote:
If we had a time machine, the right set of flags would be:
- MAP_FIXED: don't treat addr as a hint, fail if addr is not free
- MAP_REPLACE: replace an existing mapping (or force or clobber)
Actually, if we had a time machine... would we even provide
MAP_REPLACE functionality?
Probably yes. ELF loading needs to construct a complex set of mappings
from a single file. munmap (to create a hole) followed by mmap would be
racy because another thread could have reused the gap in the meantime.
The only alternative to overriding existing mappings would be mremap
with MREMAP_FIXED, and that doesn't look like an improvement API-wise.
(The glibc dynamic linker uses an mmap call with an increased length to
reserve address space and then loads additional segments with MAP_FIXED
at the offsets specified in the program header.)
Thanks,
Florian