// SPDX-License-Identifier: GPL-2.0/* * Generic infrastructure for lifetime debugging of objects. * * Copyright (C) 2008, Thomas Gleixner <tglx@linutronix.de> */#define pr_fmt(fmt) "ODEBUG: " fmt#include<linux/cpu.h>#include<linux/debugobjects.h>#include<linux/debugfs.h>#include<linux/hash.h>#include<linux/kmemleak.h>#include<linux/sched.h>#include<linux/sched/loadavg.h>#include<linux/sched/task_stack.h>#include<linux/seq_file.h>#include<linux/slab.h>#include<linux/static_key.h>#define ODEBUG_HASH_BITS 14#define ODEBUG_HASH_SIZE (1 << ODEBUG_HASH_BITS)/* Must be power of two */#define ODEBUG_BATCH_SIZE 16/* Initial values. Must all be a multiple of batch size */#define ODEBUG_POOL_SIZE (64 * ODEBUG_BATCH_SIZE)#define ODEBUG_POOL_MIN_LEVEL (ODEBUG_POOL_SIZE / 4)#define ODEBUG_POOL_PERCPU_SIZE (8 * ODEBUG_BATCH_SIZE)#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 / ODEBUG_BATCH_SIZE)#define ODEBUG_FREE_WORK_DELAY DIV_ROUND_UP(HZ, 10)structdebug_bucket{structhlist_headlist;raw_spinlock_tlock;};structpool_stats{unsignedintcur_used;unsignedintmax_used;unsignedintmin_fill;};structobj_pool{structhlist_head