Hi, all Please check the patch below. Thanks:) No need to check validity for every pfn in [spfn, epfn). --- mm/page_alloc.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 174c849ba9f2..212460c9fe0f 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -6936,11 +6936,19 @@ void __init free_area_init_memoryless_node(int nid) */ static u64 __init init_unavailable_range(unsigned long spfn, unsigned long epfn) { - unsigned long pfn; + unsigned long pfn, block_pfn; u64 pgcnt = 0; + bool in_block = 0; + + block_pfn = ALIGN_DOWN(spfn, pageblock_nr_pages); for (pfn = spfn; pfn < epfn; pfn++) { - if (!pfn_valid(ALIGN_DOWN(pfn, pageblock_nr_pages))) { + if (block_pfn != ALIGN_DOWN(pfn, pageblock_nr_pages)) { + block_pfn = ALIGN_DOWN(pfn, pageblock_nr_pages); + in_block = 0; + } + + if (!in_block && !pfn_valid(ALIGN_DOWN(pfn, pageblock_nr_pages))) { pfn = ALIGN_DOWN(pfn, pageblock_nr_pages) + pageblock_nr_pages - 1; continue; @@ -6953,6 +6961,7 @@ static u64 __init init_unavailable_range(unsigned long spfn, unsigned long epfn) __init_single_page(pfn_to_page(pfn), pfn, 0, 0); __SetPageReserved(pfn_to_page(pfn)); pgcnt++; + in_block = 1; } return pgcnt; -- 2.17.1