Skip to contentSkip to conversation

mm/mm_init: remove unnecessary initialization of pgdat->per_cpu_nodestats

PATCH Applied Sang-Heon Jeon 3 participants 4 messages Jul 29 – Jul 30

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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
index 711f821f7b3c..367b03623f89 100644
@@ -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
maintainer
#1 lore raw
Quoted 12 lines · On Thu, 30 Jul 2026 00:51:15 +0900 Sang-Heon Jeon <[email protected]> wrote:

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 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.

maintainer
#2 lore raw
Quoted 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() 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 +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 -0
 	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.

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 a kzalloc_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.