mm/mm_init: remove unnecessary initialization of pgdat->per_cpu_nodestats
PATCH 1/1 mm/mm_init: remove unnecessary initialization of pgdat->per_cpu_nodestats
free_area_init_node() sets pgdat->per_cpu_nodestats to NULL and later calls free_area_init_core(), which unconditionally overwrites it with &boot_nodestats. Nothing reads the field in between, so the store has no effect.
Remove unnecessary initialization. No functional change.
--- mm/mm_init.c | 1 - 1 file changed, 1 deletion(-)
mm/mm_init.c +0 -1
@@ -1722,7 +1722,6 @@ static void __init free_area_init_node(int nid) pgdat->node_id = nid; pgdat->node_start_pfn = start_pfn; - pgdat->per_cpu_nodestats =NULL ;if (start_pfn != end_pfn) { pr_info("Initmem setup node %d [mem %#018Lx-%#018Lx]\n", nid,
Signature · 1 line
2.43.0
Andrew Morton
maintainerQuoted 12 lines · On Thu, 30 Jul 2026 00:51:15 +0900 Sang-Heon Jeon <[email protected]> wrote:
free_area_init_node()setspgdat->per_cpu_nodestatsto NULL and later callsfree_area_init_core(), which unconditionally overwrites it with&boot_nodestats. Nothing reads the field in between, so the store has no effect.Remove unnecessary initialization. No functional change.
...
mm/mm_init.c static void __init free_area_init_node(int nid) · line 1727
Quoted 7 lines
mm/mm_init.c +0
-1@@ -1722,7 +1722,6 @@ static void __init free_area_init_node(int nid) pgdat->node_id = nid; pgdat->node_start_pfn = start_pfn; - pgdat->per_cpu_nodestats =NULL ;if (start_pfn != end_pfn) { pr_info("Initmem setup node %d [mem %#018Lx-%#018Lx]\n", nid,
Looks OK, thanks. Although this statement is "free" in __init code and its removal does make the code that bit harder to follow.
Possibly *pgdat was zeroed out anyway, I got bored figuring that out. The memblock_alloc_range_nid() kerneldoc is silent on the state of the returned memory but I spy a kzalloc_node() in there.
Mike Rapoport
maintainerQuoted 19 lines · Andrew Morton
Quoted 17 lines · On Thu, 30 Jul 2026 00:51:15 +0900 Sang-Heon Jeon <[email protected]> wrote:
free_area_init_node()setspgdat->per_cpu_nodestatsto NULL and later callsfree_area_init_core(), which unconditionally overwrites it with&boot_nodestats. Nothing reads the field in between, so the store has no effect.Remove unnecessary initialization. No functional change.
...
mm/mm_init.c +0
-1@@ -1722,7 +1722,6 @@ static void __init free_area_init_node(int nid) pgdat->node_id = nid; pgdat->node_start_pfn = start_pfn; - pgdat->per_cpu_nodestats =NULL ;
Quoted 5 lines
mm/mm_init.c static void __init free_area_init_node(int nid) · line 1727
Quoted 2 lines
mm/mm_init.c +0
-0if (start_pfn != end_pfn) { pr_info("Initmem setup node %d [mem %#018Lx-%#018Lx]\n", nid,Looks OK, thanks. Although this statement is "free" in
__initcode and its removal does make the code that bit harder to follow.
Heh, it's already not that easy to follow :)
We initialize a few fields in pgdat, then setup node and its zone sizes, then return to initialization of the rest of pgdat internals.
It feels like we need a larger cleanup there, and this patch wouldn't really move a needle.
Quoted 3 lines
Possibly *pgdat was zeroed out anyway, I got bored figuring that out. The
memblock_alloc_range_nid()kerneldoc is silent on the state of the returned memory but I spy akzalloc_node()in there.
memblock_alloc_range_nid() does not zero the memory, unless inappropriately called after slab_is_available(). But alloc_node_data() that allocates pgdat's does :)
Signature · 2 lines
Sincerely yours, Mike.
Quoted 1 line · Sang-Heon Jeon
mm/mm_init: remove unnecessary initialization ofpgdat->per_cpu_nodestats
Applied to misc branch of memblock.git tree, thanks!
[1/1] mm/mm_init: remove unnecessary initialization of pgdat->per_cpu_nodestats
commit: 78fac571b06490654af45c902c7ab5f651fe7067
tree: https://git.kernel.org/pub/scm/linux/kernel/git/rppt/memblock
branch: misc
--
Sincerely yours,
Mike.