Re: [PATCH v2] mm/sparse: Remove sparse buffer pre-allocation mechanism
From: Mike Rapoport
Date: Sun Apr 12 2026 - 12:26:27 EST
On Fri, Apr 10, 2026 at 05:24:19PM +0800, Muchun Song wrote:
> Commit 9bdac9142407 ("sparsemem: Put mem map for one node together.")
> introduced a mechanism to pre-allocate a large memory block to hold all
> memmaps for a NUMA node upfront.
>
> However, the original commit message did not clearly state the actual
> benefits or the necessity of explicitly pre-allocating a single chunk
> for all memmap areas of a given node.
>
> One of the concerns about removing this pre-allocation is that the
> subsequent per-section memmap allocations could become scattered around,
> and might turn too many memory blocks/sections into an "un-offlinable"
> state. However, tests show that even without the explicit node-wide
> pre-allocation, memblock still allocates memory closely and
> back-to-back. When tracing vmemmap_set_pmd allocations, the physical
> chunks allocated by memblock are strictly adjacent to each other in a
> single contiguous physical range (mapped top-down). Because they are
> packed tightly together naturally, they will at most consume or pollute
> the exact same number of memory blocks as the explicit pre-allocation
> did.
>
> Another concern is the boot performance impact of calling memmap_alloc()
> multiple times compared to one large node-wide allocation. Tests on a
> 256GB VM showed that memmap allocation time increased from 199,555 ns
> to 741,292 ns. Even though it is 3.7x slower, on a 1TB machine, the
> entire memory allocation time would only take a few milliseconds. This
> boot performance difference is completely negligible.
>
> Since no negative impact on memory offlining behavior or noticeable
> boot performance regression was found, this patch proposes removing
> the explicit node-wide memmap pre-allocation mechanism to reduce the
> maintenance burden.
>
> Signed-off-by: Muchun Song <songmuchun@xxxxxxxxxxxxx>
Acked-by: Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx>
> ---
> Changes in v2:
> - Addressed David Hildenbrand's and Mike Rapoport's concerns from the
> v1 discussion by incorporating the detailed memblock contiguous
> allocation analysis and the boot performance measurements directly
> into the commit message.
> ---
> include/linux/mm.h | 1 -
> mm/sparse-vmemmap.c | 7 +-----
> mm/sparse.c | 58 +--------------------------------------------
> 3 files changed, 2 insertions(+), 64 deletions(-)
--
Sincerely yours,
Mike.