Re: [PATCH v2 5/7] mm/page_ext: allocate page extensions early for SPARSEMEM

From: Mike Rapoport

Date: Wed Nov 18 2026 - 14:04:09 EST


On Wed, Nov 18, 2026 at 11:13:29PM +0800, Muchun Song wrote:
>
>
> On 2026/11/18 22:22, Mike Rapoport wrote:
> > 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>
>
> Thanks for reviewing.
>
> >
> > 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().
>
> size is currently page-aligned by init_section_page_ext(), so both forms are
> equivalent here. Is the suggestion to avoid relying on this caller-side
> invariant and make it more robust? If so, I'll use DIV_ROUND_UP() for both
> accounting calls.

Yeah, keeping it here does not cost much and whatever
init_section_page_ext() does we still count the pages right.

Especially if we move the whole thingy to memmap_alloc().

> Thanks,
> Muchun
>
> >
> > > + 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.