Linux cgroups development
 help / color / mirror / Atom feed
* [PATCH] mm/memcg: check kzalloc_node() return in memcg1_init()
@ 2026-07-21 10:09 Hongfu Li
  2026-07-22  0:13 ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Hongfu Li @ 2026-07-21 10:09 UTC (permalink / raw)
  To: hannes, mhocko, roman.gushchin, shakeel.butt, muchun.song, akpm
  Cc: cgroups, linux-mm, linux-kernel, hongfu.li, Hongfu Li

From: Hongfu Li <lihongfu@kylinos.cn>

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.

Signed-off-by: Hongfu Li <lihongfu@kylinos.cn>
---
 mm/memcontrol-v1.c | 2 +++++
 1 file changed, 2 insertions(+)

diff --git a/mm/memcontrol-v1.c b/mm/memcontrol-v1.c
index 2dc599484d00..33ea693c9281 100644
--- a/mm/memcontrol-v1.c
+++ b/mm/memcontrol-v1.c
@@ -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;
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm/memcg: check kzalloc_node() return in memcg1_init()
  2026-07-21 10:09 [PATCH] mm/memcg: check kzalloc_node() return in memcg1_init() Hongfu Li
@ 2026-07-22  0:13 ` Andrew Morton
  2026-07-22  6:18   ` Hongfu Li
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2026-07-22  0:13 UTC (permalink / raw)
  To: Hongfu Li
  Cc: hannes, mhocko, roman.gushchin, shakeel.butt, muchun.song,
	cgroups, linux-mm, linux-kernel, Hongfu Li

On Tue, 21 Jul 2026 18:09:16 +0800 Hongfu Li <hongfu.li@linux.dev> wrote:

> From: Hongfu Li <lihongfu@kylinos.cn>
> 
> 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.
> 
> ...
>
> --- a/mm/memcontrol-v1.c
> +++ b/mm/memcontrol-v1.c
> @@ -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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm/memcg: check kzalloc_node() return in memcg1_init()
  2026-07-22  0:13 ` Andrew Morton
@ 2026-07-22  6:18   ` Hongfu Li
  0 siblings, 0 replies; 3+ messages in thread
From: Hongfu Li @ 2026-07-22  6:18 UTC (permalink / raw)
  To: akpm
  Cc: cgroups, hannes, hongfu.li, lihongfu, linux-kernel, linux-mm,
	mhocko, muchun.song, roman.gushchin, shakeel.butt

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-07-22  6:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-21 10:09 [PATCH] mm/memcg: check kzalloc_node() return in memcg1_init() Hongfu Li
2026-07-22  0:13 ` Andrew Morton
2026-07-22  6:18   ` Hongfu Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox