Skip to content

Commit 1f0723a

Browse files
tehcastertorvalds
authored andcommitted
mm, slub: enable slub_debug static key when creating cache with explicit debug flags
Commit ca0cab6 ("mm, slub: introduce static key for slub_debug()") introduced a static key to optimize the case where no debugging is enabled for any cache. The static key is enabled when slub_debug boot parameter is passed, or CONFIG_SLUB_DEBUG_ON enabled. However, some caches might be created with one or more debugging flags explicitly passed to kmem_cache_create(), and the commit missed this. Thus the debugging functionality would not be actually performed for these caches unless the static key gets enabled by boot param or config. This patch fixes it by checking for debugging flags passed to kmem_cache_create() and enabling the static key accordingly. Note such explicit debugging flags should not be used outside of debugging and testing as they will now enable the static key globally. btrfs_init_cachep() creates a cache with SLAB_RED_ZONE but that's a mistake that's being corrected [1]. rcu_torture_stats() creates a cache with SLAB_STORE_USER, but that is a testing module so it's OK and will start working as intended after this patch. Also note that in case of backports to kernels before v5.12 that don't have 59450bb ("mm, slab, slub: stop taking cpu hotplug lock"), static_branch_enable_cpuslocked() should be used. [1] https://lore.kernel.org/linux-btrfs/[email protected]/ Link: https://lkml.kernel.org/r/[email protected] Fixes: ca0cab6 ("mm, slub: introduce static key for slub_debug()") Signed-off-by: Vlastimil Babka <[email protected]> Reported-by: Oliver Glitta <[email protected]> Acked-by: David Rientjes <[email protected]> Cc: Christoph Lameter <[email protected]> Cc: Pekka Enberg <[email protected]> Cc: Joonsoo Kim <[email protected]> Cc: "Paul E. McKenney" <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 82edd9d commit 1f0723a

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

mm/slub.c

+9
Original file line numberDiff line numberDiff line change
@@ -3828,6 +3828,15 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
38283828

38293829
static int kmem_cache_open(struct kmem_cache *s, slab_flags_t flags)
38303830
{
3831+
#ifdef CONFIG_SLUB_DEBUG
3832+
/*
3833+
* If no slub_debug was enabled globally, the static key is not yet
3834+
* enabled by setup_slub_debug(). Enable it if the cache is being
3835+
* created with any of the debugging flags passed explicitly.
3836+
*/
3837+
if (flags & SLAB_DEBUG_FLAGS)
3838+
static_branch_enable(&slub_debug_enabled);
3839+
#endif
38313840
s->flags = kmem_cache_flags(s->size, flags, s->name);
38323841
#ifdef CONFIG_SLAB_FREELIST_HARDENED
38333842
s->random = get_random_long();

0 commit comments

Comments
 (0)