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 <elver@google.com>
Signed-off-by: Yee Lee <yee.lee@mediatek.com>
Suggested-by: Matthew Wilcox <willy@infradead.org>
Cc: Alexander Potapenko <glider@google.com>
Cc: Andrey Konovalov <andreyknvl@gmail.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Chinwen Chang <chinwen.chang@mediatek.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Kuan-Ying Lee <Kuan-Ying.Lee@mediatek.com>
Cc: Nicholas Tang <nicholas.tang@mediatek.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Bug: 193482732
Change-Id: If264d6e72224910e541e18e8d47ce5eb505f4abf
Signed-off-by: Yee Lee <yee.lee@mediatek.com>
This commit is contained in:
Marco Elver
2021-07-13 13:34:14 +08:00
committed by Todd Kjos
parent d6eeae59b5
commit 7acbce0bf4

View File

@@ -242,10 +242,18 @@ extern unsigned long get_each_object_track(struct kmem_cache *s,
int (*fn)(const struct kmem_cache *, const void *, int (*fn)(const struct kmem_cache *, const void *,
const struct track *, void *), void *private); const struct track *, void *), void *private);
extern slab_flags_t slub_debug; extern slab_flags_t slub_debug;
static inline bool __slub_debug_enabled(void)
{
return static_branch_unlikely(&slub_debug_enabled);
}
#else #else
static inline void print_tracking(struct kmem_cache *s, void *object) static inline void print_tracking(struct kmem_cache *s, void *object)
{ {
} }
static inline bool __slub_debug_enabled(void)
{
return false;
}
#ifdef CONFIG_SLUB #ifdef CONFIG_SLUB
static inline unsigned long get_each_object_track(struct kmem_cache *s, static inline unsigned long get_each_object_track(struct kmem_cache *s,
struct page *page, enum track_item alloc, 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) static inline bool kmem_cache_debug_flags(struct kmem_cache *s, slab_flags_t flags)
{ {
#ifdef CONFIG_SLUB_DEBUG if (IS_ENABLED(CONFIG_SLUB_DEBUG))
VM_WARN_ON_ONCE(!(flags & SLAB_DEBUG_FLAGS)); VM_WARN_ON_ONCE(!(flags & SLAB_DEBUG_FLAGS));
if (static_branch_unlikely(&slub_debug_enabled)) if (__slub_debug_enabled())
return s->flags & flags; return s->flags & flags;
#endif
return false; return false;
} }