ext/opcache: drop the pre-emptive munmap before the huge page remap - #23574
Open
s2x wants to merge 1 commit into
Open
ext/opcache: drop the pre-emptive munmap before the huge page remap#23574s2x wants to merge 1 commit into
s2x wants to merge 1 commit into
Conversation
create_segments() reserved requested_size + huge_page_size, unmapped the whole reservation, and only then MAP_FIXED-mapped the huge pages at the aligned address inside it. That munmap is unnecessary: MAP_FIXED replaces the overlapped part of the reservation atomically. It also opens a window in which another thread can map something at that address before the remap runs. Keep the reservation, map the huge pages into it, and release only the head and the tail that are left over. Their sizes always add up to exactly huge_page_size, because the reservation is requested_size + huge_page_size and the mapping is requested_size. When the remap fails the whole reservation is released before falling back to normal pages: the kernel may already have discarded the overlapped part, so the reservation cannot be reused. Suggested by Arnaud Le Blanc in phpGH-23554.
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.
Follow-up to #23554, suggested by @arnaud-lb:
MAP_FIXEDalready replaces the overlapped part of the reservation, so themunmap()before it is unnecessary and only opens a window for another thread to take the address.This keeps the reservation, maps the huge pages into it, and releases only the head and the tail that are left over — they always add up to
huge_page_size. On failure the whole reservation is released, because a failedMAP_FIXEDcan leavea hole in it.
As with my last patch, please check this carefully. This part of the code is still new to me.