mm: init hole_pfn from first memblock region instead of 0#641
Merged
Conversation
In memmap_init(), hole_pfn starts at 0 and is used to track the start of the next hole in init_unavailable_range(). When the first memblock memory region does not start at PFN 0 (e.g., LKL with MMU where memory starts at ARCH_PFN_OFFSET), hole_pfn = 0 causes init_unavailable_range(0, start_pfn, ...) to be called for PFNs that have no corresponding struct page allocated. Currently this is safe because pfn_valid() returns false for those PFNs and the pageblock-skip logic in init_unavailable_range() prevents pfn_to_page() from being called. However, it wastes boot time iterating through empty pageblocks. Fix by initializing hole_pfn to the start_pfn of the first memblock memory region. With this fix, unnecessary init_unavailable_range() call is skipped entirely. Signed-off-by: Cheng Lingfei <chenglingfei@foxmail.com>
tavip
approved these changes
Jul 8, 2026
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.
memmap_init() initializes hole_pfn to 0. On LKL with MMU, the first memblock memory range starts at ARCH_PFN_OFFSET, and PFNs below that offset have no corresponding struct pages in the FLATMEM memory map.
As a result, memmap_init_zone_range() calls init_unavailable_range() for [0, start_pfn). This is currently harmless because the pageblock validity check skips these PFNs before pfn_to_page() is called, but it unnecessarily scans all pageblocks below ARCH_PFN_OFFSET.
Initialize hole_pfn from the first memblock memory range so that the scan starts at the first PFN represented by the memory map.