From 7acbce0bf43dd711bec7c440f8e87687b3717b7c Mon Sep 17 00:00:00 2001 From: Marco Elver Date: Tue, 13 Jul 2021 13:34:14 +0800 Subject: [PATCH] BACKPORT: FROMLIST: mm: move helper to check slub_debug_enabled Move the helper to check slub_debug_enabled, so that we can confine the use of #ifdef outside slub.c as well. Link: https://lore.kernel.org/lkml/20210705103229.8505-2-yee.lee@mediatek.com/ Signed-off-by: Marco Elver Signed-off-by: Yee Lee Suggested-by: Matthew Wilcox Cc: Alexander Potapenko Cc: Andrey Konovalov Cc: Andrey Ryabinin Cc: Chinwen Chang Cc: Dmitry Vyukov Cc: Kuan-Ying Lee Cc: Nicholas Tang Signed-off-by: Andrew Morton Bug: 193482732 Change-Id: If264d6e72224910e541e18e8d47ce5eb505f4abf Signed-off-by: Yee Lee --- mm/slab.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/mm/slab.h b/mm/slab.h index 29300d7f042e..5274d6af7e58 100644 --- a/mm/slab.h +++ b/mm/slab.h @@ -242,10 +242,18 @@ extern unsigned long get_each_object_track(struct kmem_cache *s, int (*fn)(const struct kmem_cache *, const void *, const struct track *, void *), void *private); extern slab_flags_t slub_debug; +static inline bool __slub_debug_enabled(void) +{ + return static_branch_unlikely(&slub_debug_enabled); +} #else static inline void print_tracking(struct kmem_cache *s, void *object) { } +static inline bool __slub_debug_enabled(void) +{ + return false; +} #ifdef CONFIG_SLUB static inline unsigned long get_each_object_track(struct kmem_cache *s, struct page *page, enum track_item alloc, @@ -264,11 +272,10 @@ static inline unsigned long get_each_object_track(struct kmem_cache *s, */ static inline bool kmem_cache_debug_flags(struct kmem_cache *s, slab_flags_t flags) { -#ifdef CONFIG_SLUB_DEBUG - VM_WARN_ON_ONCE(!(flags & SLAB_DEBUG_FLAGS)); - if (static_branch_unlikely(&slub_debug_enabled)) + if (IS_ENABLED(CONFIG_SLUB_DEBUG)) + VM_WARN_ON_ONCE(!(flags & SLAB_DEBUG_FLAGS)); + if (__slub_debug_enabled()) return s->flags & flags; -#endif return false; }