Align non-fixed MAP_SHARED file mmap to 2 MiB#98
Open
jserv wants to merge 1 commit into
Open
Conversation
Non-fixed MAP_SHARED file-backed mmap allocations whose result landed
mid 2 MiB block forced hvf_apply_file_overlay_quiesced to split the
containing HVF stage-2 segment at both ends. Back-to-back memfd-style
allocations burned segments at roughly two per mmap and could approach
GUEST_MAX_HVF_SEGMENTS (256). The earlier multi-segment overlay fix
handles correctness; this change reduces the segment-table churn.
find_free_gap and find_free_gap_inner gain a per-call alignment
argument. sys_mmap passes BLOCK_2MIB when the allocation actually
qualifies for the host overlay fast path (MAP_SHARED, host-page-aligned
offset, writable backer) and host_page_size_cached() otherwise. The
backing fd is now opened before the gap finder so overlay_fd_writable
can gate the alignment decision; every failure path closes the ref.
Alignment is a best-effort placement preference, not a Linux-visible
constraint:
- The cached gap hint advances by host-page granularity so a small
MAP_PRIVATE 4 KiB allocation can still occupy the trailing slack of
the 2 MiB block.
- When no 2 MiB-aligned gap is available, sys_mmap retries with
host-page alignment instead of returning -ENOMEM.
- For non-zero addr hints the path probes the exact host-page-aligned
hint window first, falls back to 2 MiB alignment in the wider hint
range, then to host-page alignment. A guest that pinpoints a free
address still gets the address it asked for.
mremap stays at host-page alignment because the destination does not
reinstall a file overlay.
Close #94
Contributor
Author
|
@doanbaotrung , Please validate this PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Non-fixed MAP_SHARED file-backed mmap allocations whose result landed mid 2 MiB block forced hvf_apply_file_overlay_quiesced to split the containing HVF stage-2 segment at both ends. Back-to-back memfd-style allocations burned segments at roughly two per mmap and could approach GUEST_MAX_HVF_SEGMENTS (256). The earlier multi-segment overlay fix handles correctness; this change reduces the segment-table churn.
find_free_gap and find_free_gap_inner gain a per-call alignment argument. sys_mmap passes BLOCK_2MIB when the allocation actually qualifies for the host overlay fast path (MAP_SHARED, host-page-aligned offset, writable backer) and host_page_size_cached() otherwise. The backing fd is now opened before the gap finder so overlay_fd_writable can gate the alignment decision; every failure path closes the ref.
Alignment is a best-effort placement preference, not a Linux-visible constraint:
mremap stays at host-page alignment because the destination does not reinstall a file overlay.
Close #94
Summary by cubic
Aligns non-fixed MAP_SHARED file-backed mmap to 2 MiB when eligible to reduce HVF stage-2 segment fragmentation and avoid segment exhaustion. Falls back to host-page alignment when needed and preserves exact hints; resolves #94.
Written for commit d8b8952. Summary will update on new commits.