Skip to contentSkip to conversation

mm/memcg: check kzalloc_node() return in memcg1_init()

PATCH In review Hongfu Li 2 participants 3 messages Jul 21 – Jul 22

Subsystems (3)
lore
Share & tools
lore

Hongfu Li

author
#0 lore raw

PATCH 1/1 mm/memcg: check kzalloc_node() return in memcg1_init()

From: Hongfu Li <[email protected]>

Add NULL check for per-node kzalloc_node() allocations in memcg1_init().

Skip the NUMA node when allocation fails. All users of soft_limit_tree.rb_tree_per_node[] safely handle NULL entries, only losing soft-limit tracking for that node.

---
 mm/memcontrol-v1.c | 2 +++++
 1 file changed, 2 insertions(+)
mm/memcontrol-v1.c +2 -0
index 2dc599484d00..33ea693c9281 100644
@@ -2566,6 +2566,8 @@ static int __init memcg1_init(void)
 		struct mem_cgroup_tree_per_node *rtpn;
 
 		rtpn = kzalloc_node(sizeof(*rtpn), GFP_KERNEL, node);
+		if (!rtpn)
+			continue;
 
 		rtpn->rb_root = RB_ROOT;
 		rtpn->rb_rightmost = NULL;
Signature · 1 line
2.54.0
maintainer
#1 lore raw
Quoted 13 lines · On Tue, 21 Jul 2026 18:09:16 +0800 Hongfu Li <[email protected]> wrote:

From: Hongfu Li <[email protected]>

Add NULL check for per-node kzalloc_node() allocations in memcg1_init().

Skip the NUMA node when allocation fails. All users of soft_limit_tree.rb_tree_per_node[] safely handle NULL entries, only losing soft-limit tracking for that node.

...

mm/memcontrol-v1.c static int __init memcg1_init(void) · line 2573

Quoted 8 lines
mm/memcontrol-v1.c +2 -0
@@ -2566,6 +2566,8 @@ static int __init memcg1_init(void)
 		struct mem_cgroup_tree_per_node *rtpn;
 
 		rtpn = kzalloc_node(sizeof(*rtpn), GFP_KERNEL, node);
+		if (!rtpn)
+			continue;
 
 		rtpn->rb_root = RB_ROOT;
 		rtpn->rb_rightmost = NULL;

Thanks. We assume that mamory allocations cannot fail within __init code. Because if they do, the kernel has some ghastly problem and it cannot possibly run.

author
#2 lore raw
Quoted 10 lines

mm/memcontrol-v1.c static int __init memcg1_init(void) · line 2573

Quoted 6 lines
mm/memcontrol-v1.c +2 -0
 		rtpn = kzalloc_node(sizeof(*rtpn), GFP_KERNEL, node);
+		if (!rtpn)
+			continue;
 
 		rtpn->rb_root = RB_ROOT;
 		rtpn->rb_rightmost = NULL;

Thanks. We assume that mamory allocations cannot fail within __init code. Because if they do, the kernel has some ghastly problem and it cannot possibly run.

Understood, thanks for the clarification. I'll drop this patch.

Best regards,
Hongfu