Common/MemArena: Set MAP_NORESERVE in LazyMemoryRegion on Linux. #12177
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This came up during the discussion that led to the #12173 fixes.
In short: When
/proc/sys/vm/overcommit_memory
is 0 (which appears to be the default in the Linux kernel), Linux refusesmmap
requests of private anonymous memory that it knows cannot actually be fulfilled by the current amount of free RAM and swap. This causes the fast block lookup optimization to fail on low-memory (<= 4 GB) devices. This behavior makes sense (more or less) if you assume that all the allocated memory will actually be written to, but with our LazyMemoryRegion here, we assume that only a tiny amount will actually be touched before the memory will be reset or free'd. So the suggestion came up to just setMAP_NORESERVE
-- which supresses the check and allows the allocation anyway.I think this is reasonable and basically matches what Windows and Android do, so might as well. (For reference, on Android, the default of
/proc/sys/vm/overcommit_memory
is 1, so it never checks for anything and just allows the request to go through. We could setMAP_NORESERVE
there too but it wouldn't really change anything unless someone messed with that setting.)