lib/debugobjects.c
Source file repositories/reference/linux-study-clean/lib/debugobjects.c
File Facts
- System
- Linux kernel
- Corpus path
lib/debugobjects.c- Extension
.c- Size
- 40228 bytes
- Lines
- 1569
- Domain
- Kernel Services
- Bucket
- lib
- Inferred role
- Kernel Services: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/cpu.hlinux/debugobjects.hlinux/debugfs.hlinux/hash.hlinux/kmemleak.hlinux/sched.hlinux/sched/loadavg.hlinux/sched/task_stack.hlinux/seq_file.hlinux/slab.hlinux/static_key.h
Detected Declarations
struct debug_bucketstruct pool_statsstruct obj_poolstruct self_testfunction enable_object_debugfunction disable_object_debugfunction pool_countfunction pool_should_refillfunction pool_must_refillfunction pool_move_batchfunction pool_push_batchfunction pool_pop_batchfunction pcpu_refill_statsfunction pcpu_freefunction pcpu_freefunction free_object_listfunction hlist_for_each_entry_safefunction fill_pool_from_freelistfunction kmem_alloc_batchfunction fill_poolfunction hlist_for_each_entryfunction calc_usagefunction free_obj_workfunction scoped_guardfunction __free_objectfunction free_objectfunction put_objectsfunction free_objectfunction object_cpu_offlinefunction debug_objects_oomfunction debug_print_objectfunction debug_object_fixupfunction debug_object_is_on_stackfunction debug_object_initfunction debug_objects_is_pi_blocked_onfunction can_fill_poolfunction debug_objects_fill_poolfunction __debug_object_initfunction debug_object_initfunction debug_object_init_on_stackfunction debug_object_activatefunction debug_object_deactivatefunction debug_object_destroyfunction debug_object_freefunction debug_object_assert_initfunction debug_object_active_statefunction __debug_check_no_obj_freedfunction hlist_for_each_entry_safe
Annotated Snippet
struct debug_bucket {
struct hlist_head list;
raw_spinlock_t lock;
};
struct pool_stats {
unsigned int cur_used;
unsigned int max_used;
unsigned int min_fill;
};
struct obj_pool {
struct hlist_head objects;
unsigned int cnt;
unsigned int min_cnt;
unsigned int max_cnt;
struct pool_stats stats;
} ____cacheline_aligned;
static DEFINE_PER_CPU_ALIGNED(struct obj_pool, pool_pcpu) = {
.max_cnt = ODEBUG_POOL_PERCPU_SIZE,
};
static struct debug_bucket obj_hash[ODEBUG_HASH_SIZE];
static struct debug_obj obj_static_pool[ODEBUG_POOL_SIZE] __initdata;
static DEFINE_RAW_SPINLOCK(pool_lock);
static struct obj_pool pool_global = {
.min_cnt = ODEBUG_POOL_MIN_LEVEL,
.max_cnt = ODEBUG_POOL_SIZE,
.stats = {
.min_fill = ODEBUG_POOL_SIZE,
},
};
static struct obj_pool pool_to_free = {
.max_cnt = UINT_MAX,
};
static HLIST_HEAD(pool_boot);
static unsigned long avg_usage;
static bool obj_freeing;
static int __data_racy debug_objects_maxchain __read_mostly;
static int __data_racy __maybe_unused debug_objects_maxchecked __read_mostly;
static int __data_racy debug_objects_fixups __read_mostly;
static int __data_racy debug_objects_warnings __read_mostly;
static bool __data_racy debug_objects_enabled __read_mostly
= CONFIG_DEBUG_OBJECTS_ENABLE_DEFAULT;
static const struct debug_obj_descr *descr_test __read_mostly;
static struct kmem_cache *obj_cache __ro_after_init;
/*
* Track numbers of kmem_cache_alloc()/free() calls done.
*/
static int __data_racy debug_objects_allocated;
static int __data_racy debug_objects_freed;
static void free_obj_work(struct work_struct *work);
static DECLARE_DELAYED_WORK(debug_obj_work, free_obj_work);
static DEFINE_STATIC_KEY_FALSE(obj_cache_enabled);
static int __init enable_object_debug(char *str)
{
debug_objects_enabled = true;
return 0;
}
early_param("debug_objects", enable_object_debug);
static int __init disable_object_debug(char *str)
{
debug_objects_enabled = false;
return 0;
}
early_param("no_debug_objects", disable_object_debug);
static const char *obj_states[ODEBUG_STATE_MAX] = {
[ODEBUG_STATE_NONE] = "none",
[ODEBUG_STATE_INIT] = "initialized",
[ODEBUG_STATE_INACTIVE] = "inactive",
[ODEBUG_STATE_ACTIVE] = "active",
[ODEBUG_STATE_DESTROYED] = "destroyed",
[ODEBUG_STATE_NOTAVAILABLE] = "not available",
};
Annotation
- Immediate include surface: `linux/cpu.h`, `linux/debugobjects.h`, `linux/debugfs.h`, `linux/hash.h`, `linux/kmemleak.h`, `linux/sched.h`, `linux/sched/loadavg.h`, `linux/sched/task_stack.h`.
- Detected declarations: `struct debug_bucket`, `struct pool_stats`, `struct obj_pool`, `struct self_test`, `function enable_object_debug`, `function disable_object_debug`, `function pool_count`, `function pool_should_refill`, `function pool_must_refill`, `function pool_move_batch`.
- Atlas domain: Kernel Services / lib.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.