From nobody Mon Jun 15 00:11:42 2026 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 65F0516FF37 for ; Tue, 7 Apr 2026 08:40:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775551203; cv=none; b=ADkCHh9g6TI0OcxW4hJaCId6d8WnbcWjaOyRpNdyLYaYIaAwWSPVQwCLxdCvjifelXeY6C+daI6KoTL0TmHu7GejJ6FSkypf7ctuichw9vc4wOroo1qNbKC9HaZjRpsUE84/ABEoiKpX9df7qyTQAiUFhDaztP5Sv9Vo3LygGyM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775551203; c=relaxed/simple; bh=EHx2ckpEpMwwN/GbJ/FQgfXcaWhBCUmIQIoAMzrY/hY=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=DbDcbcjrPY6lNWLA9AhefBwNfuQjSEU0rcGDcgqc4QXqqDIjT5CNEFRUvrEXwsROLktar7C2Uu+0WR99cMxWk0SedyRudphACd4kCclJNKgXXJnbOlZO5hqMDkkZE84KJtRIJgypNlMmtnd+Ci14WWHbbwW8RnN/pD34Ln9LdV0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=MEn1Bz1z; arc=none smtp.client-ip=209.85.216.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="MEn1Bz1z" Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-35da9692ec3so4317881a91.1 for ; Tue, 07 Apr 2026 01:40:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1775551201; x=1776156001; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=O4bUAcw60BufFG8grCHM7B/gjvGCGM8MGOE43IA5CTQ=; b=MEn1Bz1zWPdEb7N3adhPQWfVPZlvPpzNpjaCLWG160j0Q10nCaY5CdeylM6IVYHcvv yp1PT6Kb55px2sX2rTxPcspOpX9tIT8K7XFGbqirDYthlp/Yu41g1PxDMnhnzg3VNnsC JarY3Vlqo5Pa4tN/J7/T27JeTuztLbsdgb4YWitza6EI0FMTSHd4J43dTZuJnKTQtl9N xVxIz1Pa8REkgY222FeNPDjfBXYIcYeQzoPruDb5Cj8gWuDM+y2NEwyCCoASLrIpk2ru QaWbtO511p8elpni5jjAQVt++pft6x/8FDCuKU2mMkXRUuVCMsRbSig/CN52cpvd6bUI JHfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775551201; x=1776156001; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=O4bUAcw60BufFG8grCHM7B/gjvGCGM8MGOE43IA5CTQ=; b=a2N5vK151kkoyqdvh59FeCPkCAC0WXzb2c2FB6GqhTjP091WwmLg/4IFKZScVAyYFU DVo1KfFGQDXY/MuTJn793LKAk+q+zOSRj9i/RSGP4PCYECtwfBViAD2ZCbA666TvMkpE 7oRNuq4hUPTw6SyYJSj4okmvUF+dl4BKSYuNBhsL6Obhy1RR/NJTAIy0TLFEtji4GGi9 lwLCcshdSx1hQLTgbArE+4LhfDebEa5NQXeZ27ZDDqzvXnO9xB/YQ2g8aVNTAJjRdaaE N5CpcIpMCwqqTrWdtRH0/tyy68nMUntFMIXdQCBQ1B95JngPOOHELI4MPhB7RXGRnISi 1A9A== X-Forwarded-Encrypted: i=1; AJvYcCWJlZiqStKAjaN/GFjeq4g79alnrp3Z73GALzySscAvQQ2+nqc3Llqhr+S9lV2MhNhvwH73x0JcHTAgKDc=@vger.kernel.org X-Gm-Message-State: AOJu0YwJ9ptAmleg38N46Nqe00Bil14w0mPWtY80OGbBm2clImN2lvW3 Xzg0I7E/esuhtH7vdae7EjyjUMTMgD5Q9UqKjQxerL3SmSmsNCAtBF/VUeKAltQHQLwJw8x01+Q 7O+Cg X-Gm-Gg: AeBDietJ+Mef4Kt3HEvOEoIlV6+UOozcdkMedwp6xuZ2EaE8BJBRHvNZYmrtLpcHMfU hDDdyjS+nwC41TIX2+0YE6DmD72oq21qXHbJ5Tgr4NT5zbFazNJd2RurWGzB2oXflhNZPeg707m 8QKX8QORo6CUr1tpY9cpJKEU59uQAj+ZxSkqTp00bDHVnR3doX0RIfPTFiJbUxfblLf2IOj7fMY N8evBb4w4Jktj8DJeHNW50EJGc+EIzEu5CXpFVS15dE0BZhXuFeO8iPIPluELl0irebVRtWAPfP p11dyMSTpiOP2wz4++vkR0A17UtCFESVsWbry9oNTKHHnm9fBIBaHxlu3zWEvW5eF7xOYh+XDbJ UsZmk366tmfBBYV/P9zRJu8krNghdqzdn3TkZbfYtnDLDllktyNVNPihnwPgE08O4JOCwKjydhf k7U57yUXOUZOI1VU+Q2AZqFFxpQerjcPrSNu4+h2YGwQoGkQZgnmn2zyE= X-Received: by 2002:a17:90b:314d:b0:359:f43d:4a6e with SMTP id 98e67ed59e1d1-35de662f67fmr15869369a91.0.1775551200600; Tue, 07 Apr 2026 01:40:00 -0700 (PDT) Received: from n232-176-004.byted.org ([36.110.163.103]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35de697b0c9sm4681861a91.7.2026.04.07.01.39.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2026 01:40:00 -0700 (PDT) From: Muchun Song To: Andrew Morton , David Hildenbrand Cc: yinghai@kernel.org, Muchun Song , Muchun Song , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH] mm/sparse: remove sparse_buffer Date: Tue, 7 Apr 2026 16:39:50 +0800 Message-Id: <20260407083951.2823915-1-songmuchun@bytedance.com> X-Mailer: git-send-email 2.20.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The sparse_buffer was originally introduced in commit 9bdac9142407 ("sparsemem: Put mem map for one node together.") to allocate a contiguous block of memory for all memmaps of a NUMA node. However, the original commit message did not clearly state the actual benefits or the necessity of keeping all memmap areas strictly contiguous for a given node. With the evolution of memory management over the years, the current code only requires a 2MB contiguous allocation to support huge page mappings for CONFIG_SPARSEMEM_VMEMMAP. Thus, it seems we no longer need such complex logic to keep all memmap allocations completely contiguous across the entire node. Since the original commit was merged 16 years ago and no additional context regarding its original intention could be found, this patch proposes removing this mechanism to reduce the maintenance burden. If anyone knows the historical background or if there are specific architectures (Note that the mechanism implemented in 9bdac9142407 was restricted to x86_64. Therefore, I doubt there are any functional dependencies for other architectures.) or edge cases that still rely on this, sharing that context would be highly appreciated. Signed-off-by: Muchun Song --- include/linux/mm.h | 1 - mm/sparse-vmemmap.c | 7 +----- mm/sparse.c | 58 +-------------------------------------------- 3 files changed, 2 insertions(+), 64 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 0b776907152e..1d676fef4303 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -4855,7 +4855,6 @@ static inline void print_vma_addr(char *prefix, unsig= ned long rip) } #endif =20 -void *sparse_buffer_alloc(unsigned long size); unsigned long section_map_size(void); struct page * __populate_section_memmap(unsigned long pfn, unsigned long nr_pages, int nid, struct vmem_altmap *altmap, diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c index 6eadb9d116e4..aca1b00e86dd 100644 --- a/mm/sparse-vmemmap.c +++ b/mm/sparse-vmemmap.c @@ -87,15 +87,10 @@ static void * __meminit altmap_alloc_block_buf(unsigned= long size, void * __meminit vmemmap_alloc_block_buf(unsigned long size, int node, struct vmem_altmap *altmap) { - void *ptr; - if (altmap) return altmap_alloc_block_buf(size, altmap); =20 - ptr =3D sparse_buffer_alloc(size); - if (!ptr) - ptr =3D vmemmap_alloc_block(size, node); - return ptr; + return vmemmap_alloc_block(size, node); } =20 static unsigned long __meminit vmem_altmap_next_pfn(struct vmem_altmap *al= tmap) diff --git a/mm/sparse.c b/mm/sparse.c index effdac6b0ab1..672e2ad396a8 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -241,12 +241,9 @@ struct page __init *__populate_section_memmap(unsigned= long pfn, struct dev_pagemap *pgmap) { unsigned long size =3D section_map_size(); - struct page *map =3D sparse_buffer_alloc(size); + struct page *map; phys_addr_t addr =3D __pa(MAX_DMA_ADDRESS); =20 - if (map) - return map; - map =3D memmap_alloc(size, size, addr, nid, false); if (!map) panic("%s: Failed to allocate %lu bytes align=3D0x%lx nid=3D%d from=3D%p= a\n", @@ -256,55 +253,6 @@ struct page __init *__populate_section_memmap(unsigned= long pfn, } #endif /* !CONFIG_SPARSEMEM_VMEMMAP */ =20 -static void *sparsemap_buf __meminitdata; -static void *sparsemap_buf_end __meminitdata; - -static inline void __meminit sparse_buffer_free(unsigned long size) -{ - WARN_ON(!sparsemap_buf || size =3D=3D 0); - memblock_free(sparsemap_buf, size); -} - -static void __init sparse_buffer_init(unsigned long size, int nid) -{ - phys_addr_t addr =3D __pa(MAX_DMA_ADDRESS); - WARN_ON(sparsemap_buf); /* forgot to call sparse_buffer_fini()? */ - /* - * Pre-allocated buffer is mainly used by __populate_section_memmap - * and we want it to be properly aligned to the section size - this is - * especially the case for VMEMMAP which maps memmap to PMDs - */ - sparsemap_buf =3D memmap_alloc(size, section_map_size(), addr, nid, true); - sparsemap_buf_end =3D sparsemap_buf + size; -} - -static void __init sparse_buffer_fini(void) -{ - unsigned long size =3D sparsemap_buf_end - sparsemap_buf; - - if (sparsemap_buf && size > 0) - sparse_buffer_free(size); - sparsemap_buf =3D NULL; -} - -void * __meminit sparse_buffer_alloc(unsigned long size) -{ - void *ptr =3D NULL; - - if (sparsemap_buf) { - ptr =3D (void *) roundup((unsigned long)sparsemap_buf, size); - if (ptr + size > sparsemap_buf_end) - ptr =3D NULL; - else { - /* Free redundant aligned space */ - if ((unsigned long)(ptr - sparsemap_buf) > 0) - sparse_buffer_free((unsigned long)(ptr - sparsemap_buf)); - sparsemap_buf =3D ptr + size; - } - } - return ptr; -} - void __weak __meminit vmemmap_populate_print_last(void) { } @@ -362,8 +310,6 @@ static void __init sparse_init_nid(int nid, unsigned lo= ng pnum_begin, goto failed; } =20 - sparse_buffer_init(map_count * section_map_size(), nid); - sparse_vmemmap_init_nid_early(nid); =20 for_each_present_section_nr(pnum_begin, pnum) { @@ -381,7 +327,6 @@ static void __init sparse_init_nid(int nid, unsigned lo= ng pnum_begin, __func__, nid); pnum_begin =3D pnum; sparse_usage_fini(); - sparse_buffer_fini(); goto failed; } memmap_boot_pages_add(DIV_ROUND_UP(PAGES_PER_SECTION * sizeof(struct pa= ge), @@ -390,7 +335,6 @@ static void __init sparse_init_nid(int nid, unsigned lo= ng pnum_begin, } } sparse_usage_fini(); - sparse_buffer_fini(); return; failed: /* --=20 2.20.1