Re: [PATCH v7 1/2] mm/memory_hotplug: make shrink_zone_span() more robust
"David Hildenbrand (Arm)" <[email protected]>
| Newsgroups | org.kvack.linux-mm,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
On 8/21/26 05:14, Wei Yang wrote: > On Tue, Aug 18, 2026 at 04:57:01AM -0400, Yuan Liu wrote: >> From: "David Hildenbrand (Arm)" <[email protected]> >> >> Let's make shrink_zone_span() more robust by checking in >> find_smallest_section_pfn() / find_biggest_section_pfn() that the >> start and end PFNs of the subsection are within the zone. >> >> While at it, clean up the function by factoring the core check out >> into subsection_overlaps_zone(). >> >> There likely is no need to check the nid first. We require >> SPARSEMEM_VMEMMAP_ENABLE, where pfn_to_page() is cheap, and >> pfn_to_nid() on CONFIG_NUMA would call pfn_to_page() either way. >> So let's just drop that for now. >> >> Signed-off-by: David Hildenbrand (Arm) <[email protected]> >> Tested-by: Yuan Liu <[email protected]> >> Signed-off-by: Yuan Liu <[email protected]> >> --- >> mm/memory_hotplug.c | 59 ++++++++++++++++++--------------------------- >> 1 file changed, 24 insertions(+), 35 deletions(-) >> >> diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c >> index 7ac19fab2263..cd82e79f0782 100644 >> --- a/mm/memory_hotplug.c >> +++ b/mm/memory_hotplug.c >> @@ -422,49 +422,39 @@ int __add_pages(int nid, unsigned long pfn, unsigned long nr_pages, >> return err; >> } >> >> -/* find the smallest valid pfn in the range [start_pfn, end_pfn) */ >> -static unsigned long find_smallest_section_pfn(int nid, struct zone *zone, >> - unsigned long start_pfn, >> - unsigned long end_pfn) >> +static bool subsection_overlaps_zone(unsigned long pfn, struct zone *zone) >> { >> - for (; start_pfn < end_pfn; start_pfn += PAGES_PER_SUBSECTION) { >> - if (unlikely(!pfn_to_online_page(start_pfn))) >> - continue; >> + const unsigned long start_pfn = ALIGN_DOWN(pfn, PAGES_PER_SUBSECTION); >> + const unsigned long end_pfn = start_pfn + PAGES_PER_SUBSECTION - 1; >> >> - if (unlikely(pfn_to_nid(start_pfn) != nid)) >> - continue; > > Would we have a memory layout with node interleave? I think core-mm is not prepared for actual overlapping zone ranges during boot. -- Cheers, David