|
7 | 7 |
|
8 | 8 | #define pr_fmt(fmt) "ODEBUG: " fmt
|
9 | 9 |
|
| 10 | +#include <linux/cpu.h> |
10 | 11 | #include <linux/debugobjects.h>
|
11 |
| -#include <linux/interrupt.h> |
| 12 | +#include <linux/debugfs.h> |
| 13 | +#include <linux/hash.h> |
| 14 | +#include <linux/kmemleak.h> |
12 | 15 | #include <linux/sched.h>
|
13 | 16 | #include <linux/sched/task_stack.h>
|
14 | 17 | #include <linux/seq_file.h>
|
15 |
| -#include <linux/debugfs.h> |
16 | 18 | #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> |
20 | 20 |
|
21 | 21 | #define ODEBUG_HASH_BITS 14
|
22 | 22 | #define ODEBUG_HASH_SIZE (1 << ODEBUG_HASH_BITS)
|
@@ -103,6 +103,8 @@ static int __data_racy debug_objects_freed;
|
103 | 103 | static void free_obj_work(struct work_struct *work);
|
104 | 104 | static DECLARE_DELAYED_WORK(debug_obj_work, free_obj_work);
|
105 | 105 |
|
| 106 | +static DEFINE_STATIC_KEY_FALSE(obj_cache_enabled); |
| 107 | + |
106 | 108 | static int __init enable_object_debug(char *str)
|
107 | 109 | {
|
108 | 110 | debug_objects_enabled = true;
|
@@ -343,7 +345,7 @@ static struct debug_obj *alloc_object(void *addr, struct debug_bucket *b,
|
343 | 345 | {
|
344 | 346 | struct debug_obj *obj;
|
345 | 347 |
|
346 |
| - if (likely(obj_cache)) |
| 348 | + if (static_branch_likely(&obj_cache_enabled)) |
347 | 349 | obj = pcpu_alloc();
|
348 | 350 | else
|
349 | 351 | obj = __alloc_object(&pool_boot);
|
@@ -393,7 +395,7 @@ static void free_obj_work(struct work_struct *work)
|
393 | 395 | static void __free_object(struct debug_obj *obj)
|
394 | 396 | {
|
395 | 397 | guard(irqsave)();
|
396 |
| - if (likely(obj_cache)) |
| 398 | + if (static_branch_likely(&obj_cache_enabled)) |
397 | 399 | pcpu_free(obj);
|
398 | 400 | else
|
399 | 401 | hlist_add_head(&obj->node, &pool_boot);
|
@@ -572,7 +574,7 @@ static struct debug_obj *lookup_object_or_alloc(void *addr, struct debug_bucket
|
572 | 574 |
|
573 | 575 | static void debug_objects_fill_pool(void)
|
574 | 576 | {
|
575 |
| - if (unlikely(!obj_cache)) |
| 577 | + if (!static_branch_likely(&obj_cache_enabled)) |
576 | 578 | return;
|
577 | 579 |
|
578 | 580 | if (likely(!pool_should_refill(&pool_global)))
|
@@ -1378,6 +1380,7 @@ void __init debug_objects_mem_init(void)
|
1378 | 1380 |
|
1379 | 1381 | /* Everything worked. Expose the cache */
|
1380 | 1382 | obj_cache = cache;
|
| 1383 | + static_branch_enable(&obj_cache_enabled); |
1381 | 1384 |
|
1382 | 1385 | #ifdef CONFIG_HOTPLUG_CPU
|
1383 | 1386 | cpuhp_setup_state_nocalls(CPUHP_DEBUG_OBJ_DEAD, "object:offline", NULL,
|
|
0 commit comments