Re: [PATCH] mm/slub: don't let kmemleak report rcu sheaves

From: Catalin Marinas

Date: Sat Dec 05 2026 - 07:06:30 EST


On Fri, Dec 04, 2026 at 01:04:42PM +0000, Harry Yoo wrote:
> On Fri, Dec 04, 2026 at 10:43:27AM +0000, Catalin Marinas wrote:
> > On Wed, Nov 25, 2026 at 02:10:45PM +0000, Harry Yoo wrote:
> > > On Wed, Nov 18, 2026 at 04:06:29PM +0000, Catalin Marinas wrote:
> > > > On Tue, Nov 17, 2026 at 11:05:28PM +0000, Catalin Marinas wrote:
> > > > > diff --git a/mm/slub.c b/mm/slub.c
> > > > > index 45e077c7526c..13b8e57d6dae 100644
> > > > > --- a/mm/slub.c
> > > > > +++ b/mm/slub.c
> > > > > @@ -6278,6 +6278,14 @@ bool __kfree_rcu_sheaf(struct kmem_cache *s, void *obj, unsigned int free_flags)
> > > > >
> > > > > local_unlock(&s->cpu_sheaves->lock);
> > > > >
> > > > > + /*
> > > > > + * A sheaf allocated with kmalloc_nolock() is not tracked by
> > > > > + * kmemleak, so neither its objects nor the rcu callback queued
> > > > > + * after it would be scanned. Fall back to defer_kfree_rcu().
> > > > > + */
> > > > > + if (IS_ENABLED(CONFIG_DEBUG_KMEMLEAK) && !allow_spin)
> > > > > + goto fail;
> > > > > +
> > > > > /* Don't wake up kswapd, it will cause deadlock under pi_lock */
> > > > > empty = alloc_empty_sheaf(s, __GFP_NOWARN, alloc_flags);
> > > > >
> > > >
> > > > For the objects queued in a sheaf, rather than the !allow_spin fallback
> > > > above, it's simpler to move the kmemleak_ignore() call in
> > > > kvfree_call_rcu() before kfree_rcu_sheaf(), so they are treated the same
> > > > as on the non-sheaf path.
> > >
> > > No strong opinion on this but kmemleak_not_leak() would let kmemleak
> > > track objects queued in a sheaf?

[...]

> I'm kinda debating whether v2 is ready to be queued to slab tree as
> it doesn't handle a sheaf allocated with !allow_spin and you suggested:
> > For the objects queued in a sheaf, rather than the !allow_spin
> > fallback above, it's simpler to move the kmemleak_ignore() call in
> > kvfree_call_rcu() before kfree_rcu_sheaf(), so they are treated the
> > same as on the non-sheaf path.
> https://lore.kernel.org/linux-mm/av3NBYxYXyYk_tjS@xxxxxxx

I think v2 is fine to queue. The remaining !allow_spin case only affects
objects queued in a sheaf allocated with kmalloc_nolock(). IIUC only the
slub kunit test_nolock() can create one. There is no other caller of
kfree_rcu_nolock() yet.

If we want to cover the kfree_rcu_nolock() case as well, I guess we can
do a separate patch with the !allow_spin fallback. Moving
kmemleak_ignore() wouldn't help since it can't be called on the nolock
path, so I dropped that suggestion.

--
Catalin