/* * Generic infrastructure for lifetime debugging of objects. * * Started by Thomas Gleixner * * Copyright (C) 2008, Thomas Gleixner <tglx@linutronix.de> * * For licencing details see kernel-base/COPYING */#define pr_fmt(fmt) "ODEBUG: " fmt#include<linux/debugobjects.h>#include<linux/interrupt.h>#include<linux/sched.h>#include<linux/sched/task_stack.h>#include<linux/seq_file.h>#include<linux/debugfs.h>#include<linux/slab.h>#include<linux/hash.h>#include<linux/kmemleak.h>#define ODEBUG_HASH_BITS 14#define ODEBUG_HASH_SIZE (1 << ODEBUG_HASH_BITS)#define ODEBUG_POOL_SIZE 1024#define ODEBUG_POOL_MIN_LEVEL 256#define ODEBUG_POOL_PERCPU_SIZE 64#define ODEBUG_BATCH_SIZE 16#define ODEBUG_CHUNK_SHIFT PAGE_SHIFT#define ODEBUG_CHUNK_SIZE (1 << ODEBUG_CHUNK_SHIFT)#define ODEBUG_CHUNK_MASK (~(ODEBUG_CHUNK_SIZE - 1))/* * We limit the freeing of debug objects via workqueue at a maximum * frequency of 10Hz and about 1024 objects for each freeing operation. * So it is freeing at most 10k debug objects per second. */#define ODEBUG_FREE_WORK_MAX 1024#define ODEBUG_FREE_WORK_DELAY DIV_ROUND_UP(HZ, 10)structdebug_bucket{structhlist_headlist;raw_spinlock_tlock;};/* * Debug object percpu free list * Access is protected by disabling irq */structdebug_percpu_free{structhlist_headfree_objs;intobj_free;};staticDEFINE_PER_CPU(structdebug_percpu_free,percpu_obj_pool);staticstructdebug_bucketobj_hash[ODEBUG_HASH_SIZE];staticstructdebug_objobj_static_pool[ODEBUG_POOL_SIZE]__initdata;staticDEFINE_RAW_SPINLOCK(pool_lock);staticHLIST_HEAD(obj_pool);staticHLIST_HEAD(obj_to_free);/* * Because of the presence of percpu free pools, obj_pool_free will * under-count those in the percpu free pools. Similarly, obj_pool_used * will over-count those in the percpu free pools. Adjustments will be * made at debug_stats_show(). Both obj_pool_min_free and obj_pool_max_used * can be off. */staticintobj_pool_min_free=ODEBUG_POOL_SIZE;staticintobj_pool_free=ODEBUG_POOL_SIZE;staticintobj_pool_used;staticintobj_pool_max_used;staticboolobj_freeing;/* The number of objs on the global free list */staticintobj_nr_tofree;staticintdebug_objects_maxchain__read_mostly;staticint__maybe_unuseddebug_objects_maxchecked__read_mostly;staticintdebug_objects_fixups__read_mostly;staticintdebug_objects_warnings__read_mostly;staticintdebug_objects_enabled__read_mostly=CONFIG_DEBUG_OBJECTS_ENABLE_DEFAULT;staticintdebug_objects_pool_size__read_mostly=ODEBUG_POOL_SIZE;staticintdebug_objects_pool_min_level__read_mostly=ODEBUG_POOL_MIN_LEVEL;staticstructdebug_obj_descr*descr_test__read_mostly;staticstructkmem_cache*obj_cache__read_mostly;/* * Track numbers of kmem_cache_alloc()/free() calls done. */staticintdebug_objects_allocated;staticintdebug_objects_freed;staticvoidfree_obj_work(structwork_struct*work);staticDECLARE_DELAYED_WORK(debug_obj_work,free_obj_work);staticint