Re: [PATCH v2 5/7] mm/page_ext: allocate page extensions early for SPARSEMEM
From: Mike Rapoport
Date: Wed Nov 18 2026 - 09:22:22 EST
On Tue, Nov 17, 2026 at 08:06:25PM +0800, Muchun Song wrote:
> KMSAN needs page extensions when kmsan_init_shadow() installs per-page
> metadata, before memblock_free_all() releases memory to the buddy
> allocator. FLATMEM makes page extensions available by this point,
> whereas SPARSEMEM initializes them later in boot.
>
> Allocate boot-time SPARSEMEM page extensions from memblock to match
> FLATMEM's initialization timing. This gives early clients the same
> page_ext availability guarantee across both memory models, while runtime
> memory hotplug continues to use vmalloc.
>
> Signed-off-by: Muchun Song <songmuchun@xxxxxxxxxxxxx>
Reviewed-by: Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx>
with a nit below
> ---
> v2:
> - Allocate all boot-time SPARSEMEM page extensions from memblock
> (suggested by Mike Rapoport)
> - Keep memblock allocations above DMA and suppress per-section free
> messages (suggested by Chris Down)
> ---
> include/linux/page_ext.h | 9 +--
> mm/mm_init.c | 4 --
> mm/page_ext.c | 119 +++++++++++++++++++--------------------
> 3 files changed, 60 insertions(+), 72 deletions(-)
>
> +static __ref void *alloc_page_ext(size_t size, int nid)
> {
> void *addr;
>
> + if (!slab_is_available()) {
> + addr = memblock_alloc_try_nid(size, PAGE_SIZE, __pa(MAX_DMA_ADDRESS),
> + MEMBLOCK_ALLOC_ACCESSIBLE, nid);
> + if (addr)
> + memmap_boot_pages_add(size / PAGE_SIZE);
I think it should be DIV_ROUND_UP().
> + return addr;
> + }
> +
> addr = vzalloc_node(size, nid);
> if (addr)
> - memmap_pages_add(DIV_ROUND_UP(size, PAGE_SIZE));
> + memmap_pages_add(size / PAGE_SIZE);
And here too.
>
> return addr;
> }
> @@ -304,7 +300,7 @@ static int __meminit init_section_page_ext(unsigned long pfn, int nid)
> if (section->page_ext)
> return 0;
>
> - table_size = page_ext_size * PAGES_PER_SECTION;
> + table_size = PAGE_ALIGN(page_ext_size * PAGES_PER_SECTION);
> base = alloc_page_ext(table_size, nid);
>
> /*
--
Sincerely yours,
Mike.