[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <6lagtqkkxsnuphgmluwodah7nlhiuovw74fzdzr7xgq4nwdwup@eyfgwukzbynd>
Date: Fri, 9 Jan 2026 19:48:20 +0800
From: Hao Li <hao.li@...ux.dev>
To: Vlastimil Babka <vbabka@...e.cz>
Cc: Andrew Morton <akpm@...ux-foundation.org>,
Christoph Lameter <cl@...two.org>, David Rientjes <rientjes@...gle.com>,
Roman Gushchin <roman.gushchin@...ux.dev>, Harry Yoo <harry.yoo@...cle.com>,
Uladzislau Rezki <urezki@...il.com>, "Liam R. Howlett" <Liam.Howlett@...cle.com>,
Suren Baghdasaryan <surenb@...gle.com>, Sebastian Andrzej Siewior <bigeasy@...utronix.de>,
Alexei Starovoitov <ast@...nel.org>, linux-mm@...ck.org, linux-kernel@...r.kernel.org,
linux-rt-devel@...ts.linux.dev, bpf@...r.kernel.org, kasan-dev@...glegroups.com
Subject: Re: [PATCH RFC 14/19] slab: simplify kmalloc_nolock()
On Fri, Jan 09, 2026 at 11:11:26AM +0100, Vlastimil Babka wrote:
> On 12/16/25 03:35, Hao Li wrote:
> > On Thu, Oct 23, 2025 at 03:52:36PM +0200, Vlastimil Babka wrote:
> >> @@ -5214,27 +5144,13 @@ void *kmalloc_nolock_noprof(size_t size, gfp_t gfp_flags, int node)
> >> if (ret)
> >> goto success;
> >>
> >> - ret = ERR_PTR(-EBUSY);
> >> -
> >> /*
> >> * Do not call slab_alloc_node(), since trylock mode isn't
> >> * compatible with slab_pre_alloc_hook/should_failslab and
> >> * kfence_alloc. Hence call __slab_alloc_node() (at most twice)
> >> * and slab_post_alloc_hook() directly.
> >> - *
> >> - * In !PREEMPT_RT ___slab_alloc() manipulates (freelist,tid) pair
> >> - * in irq saved region. It assumes that the same cpu will not
> >> - * __update_cpu_freelist_fast() into the same (freelist,tid) pair.
> >> - * Therefore use in_nmi() to check whether particular bucket is in
> >> - * irq protected section.
> >> - *
> >> - * If in_nmi() && local_lock_is_locked(s->cpu_slab) then it means that
> >> - * this cpu was interrupted somewhere inside ___slab_alloc() after
> >> - * it did local_lock_irqsave(&s->cpu_slab->lock, flags).
> >> - * In this case fast path with __update_cpu_freelist_fast() is not safe.
> >> */
> >> - if (!in_nmi() || !local_lock_is_locked(&s->cpu_slab->lock))
> >> - ret = __slab_alloc_node(s, alloc_gfp, node, _RET_IP_, size);
> >> + ret = __slab_alloc_node(s, alloc_gfp, node, _RET_IP_, size);
> >>
> >> if (PTR_ERR(ret) == -EBUSY) {
> >
> > After Patch 10 is applied, the logic that returns `EBUSY` has been
> > removed along with the `s->cpu_slab` logic. As a result, it appears that
> > `__slab_alloc_node` will no longer return `EBUSY`.
>
> True, I missed that, thanks.
> Since we can still get failures due to the cpu_sheaves local lock held, I
> think we could just do the single retry with a larger bucket if ret is NULL.
Sounds good - this is a clean approach.
> Whlle it may be NULL for other reasons (being genuinely out of memory and
> the limited context not allowing reclaim etc), it wouldn't hurt, and it's
> better than to introduce returning EBUSY into various paths.
I agree - it seems cleaner for __slab_alloc_node() to return only NULL
or a valid pointer. If it could also return -EBUSY, the return semantics
would be a bit less clear.
--
Thanks,
Hao
>
> >> if (can_retry) {
> >> @@ -7250,10 +7166,6 @@ void __kmem_cache_release(struct kmem_cache *s)
> >> {
> >> cache_random_seq_destroy(s);
> >> pcs_destroy(s);
> >> -#ifdef CONFIG_PREEMPT_RT
> >> - if (s->cpu_slab)
> >> - lockdep_unregister_key(&s->lock_key);
> >> -#endif
> >> free_percpu(s->cpu_slab);
> >> free_kmem_cache_nodes(s);
> >> }
> >>
> >> --
> >> 2.51.1
> >>
>
Powered by blists - more mailing lists