filprofiler
filprofiler copied to clipboard
Implement mremap()
Implementation notes:
Preventing re-occurence of #175:
- As with
free()orrealloc(), we would want to remove tracking information before runningmremap()to ensure thread-safety (another thread may grab the address with anothermmap()in parallel, and tracking info could be modified in wrong order). However,mremap()may fail. So options are:- Live with race condition.
- Live with situations where
mremap()fails and we lose tracking info. This is whatrealloc()does, but failedrealloc()results in us hitting the OOM handler, whereasmremap()default behavior is much more likely to fail because it's not "do we have memory" it's "do we have enough memory without moving". - Restore tracking if
mremap()fails. This shouldn't result in any race condition. - Special handling for
MREMAP_MAYMOVEwhich is more likerealloc(), where failure means OOM. - Implement resize logic inside rangemap that returns information needed to undo it.
- Split logic between shrinking (won't fail, but needs metadata first) and increasing (might fail, but metadata can happen later).*
OOM handling:
- Failed
mremap()is only an OOM condition ifMREMAP_MAYMOVEis specified butMREMAP_FIXEDis not. This is likely to be a common usage pattern.
MREMAP_DONTUNMAP needs to be handled specially, since it doesn't actually remove any memory from the tracking area, it just adds some.
Given more complex logic, this also seems like good to start moving away from C code for the external API and have be in Rust like the commercial production version, and might even allow reusing the same logic. Probably would need to make it generic over some sort of reentrancy-acquisition-and-should-I-record API.