]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
mm/sparse: remove unnecessary NULL check before allocating mem_section
authorSang-Heon Jeon <ekffu200098@gmail.com>
Sun, 19 Apr 2026 14:42:25 +0000 (23:42 +0900)
committerAndrew Morton <akpm@linux-foundation.org>
Fri, 29 May 2026 04:04:47 +0000 (21:04 -0700)
Commit 850ed20539a4 ("mm: move array mem_section init code out of
memory_present()") moved mem_section allocation logic into
memblocks_present().

Before that move, memory_present() could be called multiple times, so
unlikely() matched the common case, where most calls found mem_section
already allocated.

After that move, memblocks_present() is called exactly once from
sparse_init().  Under CONFIG_SPARSEMEM_EXTREME, mem_section is always NULL
when it is called.

So remove unnecessary NULL check before allocating mem_section.  No
functional change.

Link: https://lore.kernel.org/20260419144225.2875654-1-ekffu200098@gmail.com
Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com>
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Reviewed by: Donet Tom <donettom@linux.ibm.com>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Cc: Liam Howlett <liam@infradead.org>
Cc: Lorenzo Stoakes <ljs@kernel.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/sparse.c

index effdac6b0ab13c8f905bed6ff257267f51bfbe0f..e13f9f5fa0909244c34d6c686245d16b09e61419 100644 (file)
@@ -201,13 +201,11 @@ static void __init memblocks_present(void)
        int i, nid;
 
 #ifdef CONFIG_SPARSEMEM_EXTREME
-       if (unlikely(!mem_section)) {
-               unsigned long size, align;
+       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);
-       }
+       size = sizeof(struct mem_section *) * NR_SECTION_ROOTS;
+       align = 1 << (INTERNODE_CACHE_SHIFT);
+       mem_section = memblock_alloc_or_panic(size, align);
 #endif
 
        for_each_mem_pfn_range(i, MAX_NUMNODES, &start, &end, &nid)