RE: [PATCH v5 1/5] mm: move mirrored memory overlap checking to the outer loop
From: Liu, Yuan1
Date: Fri Jun 26 2026 - 04:35:33 EST
> -----Original Message-----
> From: David Hildenbrand (Arm) <david@xxxxxxxxxx>
> Sent: Thursday, June 25, 2026 8:05 PM
> To: Liu, Yuan1 <yuan1.liu@xxxxxxxxx>; Oscar Salvador <osalvador@xxxxxxx>;
> Mike Rapoport <rppt@xxxxxxxxxx>; Wei Yang <richard.weiyang@xxxxxxxxx>
> Cc: linux-mm@xxxxxxxxx; Hu, Yong <yong.hu@xxxxxxxxx>; Zou, Nanhai
> <nanhai.zou@xxxxxxxxx>; Tim Chen <tim.c.chen@xxxxxxxxxxxxxxx>; Zhuo, Qiuxu
> <qiuxu.zhuo@xxxxxxxxx>; Chen, Yu C <yu.c.chen@xxxxxxxxx>; Deng, Pan
> <pan.deng@xxxxxxxxx>; Li, Tianyou <tianyou.li@xxxxxxxxx>; Chen Zhang
> <zhangchen.kidd@xxxxxx>; Zeng, Jason <jason.zeng@xxxxxxxxx>; linux-
> kernel@xxxxxxxxxxxxxxx
> Subject: Re: [PATCH v5 1/5] mm: move mirrored memory overlap checking to
> the outer loop
>
> On 5/20/26 11:34, Yuan Liu wrote:
> > Move the overlap memmap initialization check from memmap_init_range()
> > to memmap_init(), and replace the per-PFN check with a memblock-based
> > check.
> >
> > Reviewed-by: Wei Yang <richard.weiyang@xxxxxxxxx>
> > Reviewed-by: Jason Zeng <jason.zeng@xxxxxxxxx>
> > Signed-off-by: Yuan Liu <yuan1.liu@xxxxxxxxx>
> > ---
>
> IIRC, with the patch from Mike+Wei this patch here should no longer be
> required,
> right?
>
> https://lore.kernel.org/r/20260625073941.145014-1-rppt@xxxxxxxxxx
Hi David
Yes, we don't need the overlap-related patch anymore. The zone contiguity optimization will build on top of Mike's and Wei's changes, and I'll update the patches accordingly.
These days I've been revisiting the issue where pages_with_online_memmap overcounts subsection hole pages in early sections.
We previously attempted to address this with a patch [1], but I think the concern raised by Sashiko [2] is valid, so we may not be able to use patch [1].
I can think of the following alternative approach, which can avoid changing semantics of pfn_valid() or first_valid_pfn():
Basically we calculate pages_with_online_memmap by iterating over subsections in each zone during memmap_init(), to see pfn_to_online_page(start_pfn) is true or not.
If it is true, then the whole subsection will be counted into pages_with_online_memmap.
Here is the patch looks like:
+static void __init update_zone_online_memmap_pages(struct zone *zone)
+{
+ unsigned long pfn, end_pfn, sub_end;
+ unsigned long nr_pages = 0;
+
+ pfn = zone->zone_start_pfn;
+ end_pfn = zone_end_pfn(zone);
+
+ while (pfn < end_pfn) {
+ /* Advance to the next subsection boundary */
+ sub_end = ALIGN(pfn + 1, PAGES_PER_SUBSECTION);
+ if (sub_end > end_pfn)
+ sub_end = end_pfn;
+
+ if (pfn_to_online_page(pfn))
+ nr_pages += sub_end - pfn;
+
+ pfn = sub_end;
+ }
+
+ zone->pages_with_online_memmap = nr_pages;
+}
static void __init memmap_init(void)
{
unsigned long start_pfn, end_pfn;
unsigned long hole_pfn = 0;
+ struct zone *zone;
int i, j, zone_id = 0, nid;
for_each_mem_pfn_range(i, MAX_NUMNODES, &start_pfn, &end_pfn, &nid) {
@@ -985,6 +1019,9 @@ static void __init memmap_init(void)
#endif
if (hole_pfn < end_pfn)
init_unavailable_range(hole_pfn, end_pfn, zone_id, nid);
+
+ for_each_populated_zone(zone)
+ update_zone_online_memmap_pages(zone);
}
[1]https://lore.kernel.org/linux-mm/20260520093457.3719960-4-yuan1.liu@xxxxxxxxx/
[2]https://sashiko.dev/#/patchset/20260520093457.3719960-3-yuan1.liu@xxxxxxxxx
I'm not sure this is the right approach, so I'd really appreciate your thoughts.
> --
> Cheers,
>
> David