Re: [PATCH] slab: allow sheaves for SLAB_NOLEAKTRACE caches
From: Catalin Marinas
Date: Thu Nov 12 2026 - 12:03:44 EST
On Thu, Nov 12, 2026 at 02:04:18AM -0800, Breno Leitao wrote:
> This is a patch that makes kmemleak cheaper to run, by letting
> kmemleak's own metadata cache use a _new_ sheaves type. The flag only
> makes that possible without recursion.
>
> The cost today:
> * every allocation kmemleak tracks needs one kmemleak_object from
> object_cache. An RCU callback frees it later.
>
> Why that's slow:
> * object_cache has no sheaves, so each of those allocations and frees
> goes to the shared slab lists under n->list_lock.
> - On meta's fleet kmemleak kernels, list_lock is the second most
> contended lock, after kmemleak_lock.
> - About 88% of that wait is RCU callbacks freeing kmemleak objects.
>
> Why sheaves aren't allowed:
> * a sheaf is a kmalloc object. Tracking it makes kmemleak allocate
> another kmemleak_object, which needs a sheaf, and so on.
>
> When I reported the recursion in [1], I suggested keeping
> SLAB_NOLEAKTRACE caches away from sheaves, and commit e47c897a2949
> ("slab: add sheaves to most caches") did that. It stopped the
> recursion, but it took the sheaves away from the whole cache, although
> only the kmemleak tracking of the sheaf itself recursed.
>
> Commit 17c38c88294d ("slab: remove cpu (partial) slabs usage from
> allocation paths"), from the same series, then left these caches with
> no per-CPU caching at all.
>
> In hindsight, skipping kmemleak only for the
> sheaf itself, as the new SLAB_ALLOC_NO_LEAKTRACE does, would have been
> the better fix.
>
> Link: https://lore.kernel.org/all/aW_NK2NXVgtuzCVH@xxxxxxxxx/ [1]
> Cc: Catalin Marinas <catalin.marinas@xxxxxxx>
> Signed-off-by: Breno Leitao <leitao@xxxxxxxxxx>
Reviewed-by: Catalin Marinas <catalin.marinas@xxxxxxx>