Re: [PATCH 2/3] mm/page_ext: support early allocation for SPARSEMEM

From: Mike Rapoport

Date: Sun Nov 15 2026 - 02:32:00 EST


Hi Muchun,

> Moving KMSAN's per-page metadata into page_ext requires page extensions
> to be available when kmsan_init_shadow() runs, before memblock is freed.
> FLATMEM page extensions are available by then, but SPARSEMEM normally
> allocates them later from the page or vmalloc allocators.
>
> Add need_early so clients can request SPARSEMEM section backing from
> memblock during page_ext_init_early().

Can't we just always allocate page_ext for early sections from memblock?

> Use page_ext_init() as the common late path for client callbacks.
> KMSAN starts requesting early page extensions in the following patch.
>
> Signed-off-by: Muchun Song <songmuchun@xxxxxxxxxxxxx>
> ---
> include/linux/page_ext.h | 26 +++--------
> mm/mm_init.c | 11 +----
> mm/page_ext.c | 99 ++++++++++++++++++++++++++++++----------
> 3 files changed, 82 insertions(+), 54 deletions(-)
>
> +static __ref void *alloc_page_ext(size_t size, int nid)
> {
> gfp_t flags = GFP_KERNEL | __GFP_ZERO | __GFP_NOWARN;
> void *addr = NULL;
>
> + if (!slab_is_available()) {
> + addr = memblock_alloc_try_nid(size, PAGE_SIZE, 0,
> + MEMBLOCK_ALLOC_ACCESSIBLE, nid);
> + if (addr)
> + memmap_boot_pages_add(size / PAGE_SIZE);
> + return addr;
> + }
> +
> addr = alloc_pages_exact_nid(nid, size, flags);

And unrelated to this patch, do we really need to try an allocation from
buddy rather than always use vmalloc?

--
Sincerely yours,
Mike.