Skip to content

mm: init hole_pfn from first memblock region instead of 0#641

Merged
tavip merged 1 commit into
lkl:masterfrom
clingfei:master
Jul 8, 2026
Merged

mm: init hole_pfn from first memblock region instead of 0#641
tavip merged 1 commit into
lkl:masterfrom
clingfei:master

Conversation

@clingfei

@clingfei clingfei commented Jul 5, 2026

Copy link
Copy Markdown

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.

@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown

Test Results

106 files  ±0  106 suites  ±0   11m 28s ⏱️ + 2m 43s
205 tests ±0  194 ✅ ±0  11 💤 ±0  0 ❌ ±0 
789 runs  ±0  733 ✅ ±0  56 💤 ±0  0 ❌ ±0 

Results for commit 9009517. ± Comparison against base commit e50792e.

♻️ This comment has been updated with latest results.

@tavip tavip left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the fix @clingfei! Minor comment inline.

Comment thread mm/mm_init.c Outdated
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 tavip left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you @clingfei !

@tavip tavip merged commit 6bce814 into lkl:master Jul 8, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants