[PATCH 01/12] mm/sparse: move mem_section init to sparse_extreme_init()

From: David Hildenbrand (Arm)

Date: Wed Sep 09 2026 - 10:36:26 EST


Let's just avoid another pair of ifdef inside a function. While at it,
switch to INTERNODE_CACHE_BYTES by just defining a fallback in cache.h
as well, given that the x86 variant already provides one.

Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
---
include/linux/cache.h | 1 +
mm/sparse.c | 19 ++++++++++++-------
2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/include/linux/cache.h b/include/linux/cache.h
index e69768f50d532..b6e857b985bca 100644
--- a/include/linux/cache.h
+++ b/include/linux/cache.h
@@ -89,6 +89,7 @@
*/
#ifndef INTERNODE_CACHE_SHIFT
#define INTERNODE_CACHE_SHIFT L1_CACHE_SHIFT
+#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
#endif

#if !defined(____cacheline_internodealigned_in_smp)
diff --git a/mm/sparse.c b/mm/sparse.c
index 9349ed6326c01..6a6d258862904 100644
--- a/mm/sparse.c
+++ b/mm/sparse.c
@@ -103,11 +103,22 @@ int __meminit sparse_index_init(unsigned long section_nr, int nid)

return 0;
}
+
+static void __init sparse_extreme_init(void)
+{
+ const unsigned long size = sizeof(struct mem_section *) * NR_SECTION_ROOTS;
+
+ mem_section = memblock_alloc_or_panic(size, INTERNODE_CACHE_BYTES);
+}
#else /* !SPARSEMEM_EXTREME */
int __meminit sparse_index_init(unsigned long section_nr, int nid)
{
return 0;
}
+
+static void __init sparse_extreme_init(void)
+{
+}
#endif

/*
@@ -197,13 +208,7 @@ void __init sparse_sections_init(void)
unsigned long start, end;
int i, nid;

-#ifdef CONFIG_SPARSEMEM_EXTREME
- unsigned long size, align;
-
- size = sizeof(struct mem_section *) * NR_SECTION_ROOTS;
- align = 1 << (INTERNODE_CACHE_SHIFT);
- mem_section = memblock_alloc_or_panic(size, align);
-#endif
+ sparse_extreme_init();

for_each_mem_pfn_range(i, MAX_NUMNODES, &start, &end, &nid)
memory_present(nid, start, end);

--
2.43.0