mm/memory hotplug: Fix zone->contiguous always false when hotplug
Subsystems (2)
PATCH 1/1 mm/memory hotplug: Fix zone->contiguous always false when hotplug
From: Yuan Liu <[email protected]>
set_zone_contiguous() uses __pageblock_pfn_to_page() to detect pageblocks that either do not exist (hole) or that do not belong to the same zone.
__pageblock_pfn_to_page(), however, relies on pfn_to_online_page(), effectively always returning NULL for memory ranges that were not onlined yet. So when called on a range-to-be-onlined, it indicates a memory hole to set_zone_contiguous().
Consequently, the set_zone_contiguous() call in move_pfn_range_to_zone(), which happens early during memory onlining, will never detect a zone as being contiguous. Bad: the fast path relies on the zone contiguous state may skipped.
To fix the issue, move the set_zone_contiguous() call to a later stage in memory onlining, where pfn_to_online_page() will succeed:
after we mark the memory sections to be online.
---
Separated from: https://lore.kernel.org/linux-mm/[email protected]/
mm/memory_hotplug.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
mm/memory_hotplug.c +7 -2
@@ -782,8 +782,6 @@ void move_pfn_range_to_zone(struct zone *zone, unsigned long start_pfn,memmap_init_range (nr_pages, nid,zone_idx (zone), start_pfn,0 ,MEMINIT_HOTPLUG , altmap, migratetype, isolate_pageblock); - -set_zone_contiguous (zone); }struct auto_movable_stats {
@@ -1205,6 +1203,13 @@ int online_pages(unsigned long pfn, unsigned long nr_pages, }online_pages_range (pfn, nr_pages); + +/* +* Now that the ranges are indicated as online, check whether the whole +* zone is contiguous. +*/ +set_zone_contiguous (zone); +adjust_present_page_count (pfn_to_page (pfn), group, nr_pages);if (node_arg.nid >=0 )
Signature · 1 line
2.47.1
Quoted 1 line · Tianyou Li
From: Yuan Liu <[email protected]>
Nit: subject should start with "mm/memory_hotplug:"
Quoted 19 lines
set_zone_contiguous()uses__pageblock_pfn_to_page()to detect pageblocks that either do not exist (hole) or that do not belong to the same zone.
__pageblock_pfn_to_page(), however, relies onpfn_to_online_page(), effectively always returning NULL for memory ranges that were not onlined yet. So when called on a range-to-be-onlined, it indicates a memory hole toset_zone_contiguous().Consequently, the
set_zone_contiguous()call inmove_pfn_range_to_zone(), which happens early during memory onlining, will never detect a zone as being contiguous. Bad: the fast path relies on the zone contiguous state may skipped.To fix the issue, move the
set_zone_contiguous()call to a later stage in memory onlining, wherepfn_to_online_page()will succeed:
after we mark the memory sections to be online.
Quoted 6 lines
Fixes 2d070eab2e82 ("mm: consider zone which is not fully populated to have holes")Cc Michal Hocko <[email protected]>Reviewed-by Nanhai Zou <[email protected]>Signed-off-by Yuan Liu <[email protected]>Signed-off-by Tianyou Li <[email protected]>
How was Yuan Liu involved? If he is a co-author there is a
missing.
Likely there is no resend required if you tell Andrew what to do, so he can just fixup when applying.
Signature · 3 lines
Cheers, David
On 2/6/2026 9:03 PM, David Hildenbrand (Arm) wrote
Quoted 5 lines · Tianyou Li
Quoted 1 line
From: Yuan Liu <[email protected]>
Nit: subject should start with "
mm/memory_hotplug:"
Got it. My bad, will pay attention next time. Thanks David.
Quoted 26 lines
Quoted 19 lines
set_zone_contiguous()uses__pageblock_pfn_to_page()to detect pageblocks that either do not exist (hole) or that do not belong to the same zone.
__pageblock_pfn_to_page(), however, relies onpfn_to_online_page(), effectively always returning NULL for memory ranges that were not onlined yet. So when called on a range-to-be-onlined, it indicates a memory hole toset_zone_contiguous().Consequently, the
set_zone_contiguous()call inmove_pfn_range_to_zone(), which happens early during memory onlining, will never detect a zone as being contiguous. Bad: the fast path relies on the zone contiguous state may skipped.To fix the issue, move the
set_zone_contiguous()call to a later stage in memory onlining, wherepfn_to_online_page()will succeed:
after we mark the memory sections to be online.Quoted 6 lines
Fixes 2d070eab2e82 ("mm: consider zone which is not fully populated to have holes")Cc Michal Hocko <[email protected]>Reviewed-by Nanhai Zou <[email protected]>Signed-off-by Yuan Liu <[email protected]>Signed-off-by Tianyou Li <[email protected]>
Quoted 6 lines
How was Yuan Liu involved? If he is a co-author there is a
Co-developed-by Yuan Liu <[email protected]>missing.
Yes, Yuan Liu co-author the patch. Thanks and I will pay attention next time. Appreciated.
Quoted 5 lines
Likely there is no resend required if you tell Andrew what to do, so he can just fixup when applying.
+ Andrew Morton for awareness.
Hi Andrew,
Please kindly let me know if resend required or you are willing to kindly fixup the titile and Co-developed-by tag for me. Appreciated in advance for any additional burden that costs.
Regards,
Tianyou