Skip to content

Commit 14077b9

Browse files
committed
debugobjects: Use static key for boot pool selection
Get rid of the conditional in the hot path. Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Zhen Lei <[email protected]> Link: https://lore.kernel.org/all/[email protected]
1 parent 9ce99c6 commit 14077b9

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

lib/debugobjects.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77

88
#define pr_fmt(fmt) "ODEBUG: " fmt
99

10+
#include <linux/cpu.h>
1011
#include <linux/debugobjects.h>
11-
#include <linux/interrupt.h>
12+
#include <linux/debugfs.h>
13+
#include <linux/hash.h>
14+
#include <linux/kmemleak.h>
1215
#include <linux/sched.h>
1316
#include <linux/sched/task_stack.h>
1417
#include <linux/seq_file.h>
15-
#include <linux/debugfs.h>
1618
#include <linux/slab.h>
17-
#include <linux/hash.h>
18-
#include <linux/kmemleak.h>
19-
#include <linux/cpu.h>
19+
#include <linux/static_key.h>
2020

2121
#define ODEBUG_HASH_BITS 14
2222
#define ODEBUG_HASH_SIZE (1 << ODEBUG_HASH_BITS)
@@ -103,6 +103,8 @@ static int __data_racy debug_objects_freed;
103103
static void free_obj_work(struct work_struct *work);
104104
static DECLARE_DELAYED_WORK(debug_obj_work, free_obj_work);
105105

106+
static DEFINE_STATIC_KEY_FALSE(obj_cache_enabled);
107+
106108
static int __init enable_object_debug(char *str)
107109
{
108110
debug_objects_enabled = true;
@@ -343,7 +345,7 @@ static struct debug_obj *alloc_object(void *addr, struct debug_bucket *b,
343345
{
344346
struct debug_obj *obj;
345347

346-
if (likely(obj_cache))
348+
if (static_branch_likely(&obj_cache_enabled))
347349
obj = pcpu_alloc();
348350
else
349351
obj = __alloc_object(&pool_boot);
@@ -393,7 +395,7 @@ static void free_obj_work(struct work_struct *work)
393395
static void __free_object(struct debug_obj *obj)
394396
{
395397
guard(irqsave)();
396-
if (likely(obj_cache))
398+
if (static_branch_likely(&obj_cache_enabled))
397399
pcpu_free(obj);
398400
else
399401
hlist_add_head(&obj->node, &pool_boot);
@@ -572,7 +574,7 @@ static struct debug_obj *lookup_object_or_alloc(void *addr, struct debug_bucket
572574

573575
static void debug_objects_fill_pool(void)
574576
{
575-
if (unlikely(!obj_cache))
577+
if (!static_branch_likely(&obj_cache_enabled))
576578
return;
577579

578580
if (likely(!pool_should_refill(&pool_global)))
@@ -1378,6 +1380,7 @@ void __init debug_objects_mem_init(void)
13781380

13791381
/* Everything worked. Expose the cache */
13801382
obj_cache = cache;
1383+
static_branch_enable(&obj_cache_enabled);
13811384

13821385
#ifdef CONFIG_HOTPLUG_CPU
13831386
cpuhp_setup_state_nocalls(CPUHP_DEBUG_OBJ_DEAD, "object:offline", NULL,

0 commit comments

Comments
 (0)