Re: [PATCH v2 5/7] mm/page_ext: allocate page extensions early for SPARSEMEM
From: Muchun Song
Date: Wed Nov 18 2026 - 10:38:34 EST
On 2026/11/18 22:17, Mike Rapoport wrote:
On Tue, Nov 17, 2026 at 11:00:06PM -0800, Chris Down wrote:
Hi Muchun,I think so :)
Muchun Song writes:
Mike's suggestion considerably simplifies the code, and early page_ext isYou're probably right.
only needed by optional debugging and instrumentation users. I would prefer
to keep this approach.
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? :-)... with zone extents known we could take it even further :)
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);
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().
Agreed. Using memmap_alloc() for early page_ext allocations and
teaching it to avoid ZONE_MOVABLE sounds cleaner. I'll keep this
series as is and handle that in a separate series.
Thanks!
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