Re: [PATCH v2 5/7] mm/page_ext: allocate page extensions early for SPARSEMEM
From: Mike Rapoport
Date: Wed Nov 18 2026 - 09:18:12 EST
On Tue, Nov 17, 2026 at 11:00:06PM -0800, Chris Down wrote:
> Hi Muchun,
>
> Muchun Song writes:
> > Mike's suggestion considerably simplifies the code, and early page_ext is
> > only needed by optional debugging and instrumentation users. I would prefer
> > to keep this approach.
>
> You're probably right.
I think so :)
The memap_alloc() that essentially allocates the memory map does
memblock_alloc_try_nid_raw(size, align, min_addr,
MEMBLOCK_ALLOC_NOLEAKTRACE, nid);
so we anyway may end up with reserved memory in ZONE_MOVABLE.
Until recently we had memory map allocation before the zones were setup, so
there wasn't much we could do about it, but ...
> But can I cheekily suggest something in the middle perhaps? :-)
>
> Given the zones are already set up before page_ext_alloc() runs, perhaps
> you can pass the start of the node's ZONE_MOVABLE as max_addr to
> memblock_alloc_try_nid() when the node has one. The general idea is:
>
> struct zone *movable = &NODE_DATA(nid)->node_zones[ZONE_MOVABLE];
> phys_addr_t max_addr = MEMBLOCK_ALLOC_ACCESSIBLE;
>
> if (!zone_is_empty(movable))
> max_addr = PFN_PHYS(movable->zone_start_pfn);
> addr = memblock_alloc_try_nid(size, PAGE_SIZE, __pa(MAX_DMA_ADDRESS),
> max_addr, nid);
> if (!addr && max_addr != MEMBLOCK_ALLOC_ACCESSIBLE)
> addr = memblock_alloc_try_nid(size, PAGE_SIZE,
> __pa(MAX_DMA_ADDRESS),
> MEMBLOCK_ALLOC_ACCESSIBLE, nid);
... with zone extents known we could take it even further :)
page_ext is treated as the memory map in many ways, so we can allocate the
early page_ext sections with memmap_alloc().
And since the latter always runs after zones are set up it could include
this change.
But I think this should come as a separate series that also could move
memmap_boot_pages_add to memmap_alloc().
> I briefly tried that and it seems to work quite nicely.
>
> But I don't object to it even without that, so feel free to add either way:
>
> Reviewed-by: Chris Down <chris@xxxxxxxxxxxxxx>
>
> Thanks!
>
> Chris
--
Sincerely yours,
Mike.