include/linux/stackdepot.h
Source file repositories/reference/linux-study-clean/include/linux/stackdepot.h
File Facts
- System
- Linux kernel
- Corpus path
include/linux/stackdepot.h- Extension
.h- Size
- 9165 bytes
- Lines
- 258
- Domain
- Core OS
- Bucket
- Core Kernel Interface
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/gfp.h
Detected Declarations
struct stack_recordfunction stack_depot_initfunction stack_depot_request_early_init
Annotated Snippet
struct stack_record {
struct list_head hash_list; /* Links in the hash table */
u32 hash; /* Hash in hash table */
u32 size; /* Number of stored frames */
union handle_parts handle; /* Constant after initialization */
refcount_t count;
union {
unsigned long entries[CONFIG_STACKDEPOT_MAX_FRAMES]; /* Frames */
struct {
/*
* An important invariant of the implementation is to
* only place a stack record onto the freelist iff its
* refcount is zero. Because stack records with a zero
* refcount are never considered as valid, it is safe to
* union @entries and freelist management state below.
* Conversely, as soon as an entry is off the freelist
* and its refcount becomes non-zero, the below must not
* be accessed until being placed back on the freelist.
*/
struct list_head free_list; /* Links in the freelist */
unsigned long rcu_state; /* RCU cookie */
};
};
};
#endif
typedef u32 depot_flags_t;
/*
* Flags that can be passed to stack_depot_save_flags(); see the comment next
* to its declaration for more details.
*/
#define STACK_DEPOT_FLAG_CAN_ALLOC ((depot_flags_t)0x0001)
#define STACK_DEPOT_FLAG_GET ((depot_flags_t)0x0002)
#define STACK_DEPOT_FLAGS_NUM 2
#define STACK_DEPOT_FLAGS_MASK ((depot_flags_t)((1 << STACK_DEPOT_FLAGS_NUM) - 1))
/*
* Using stack depot requires its initialization, which can be done in 3 ways:
*
* 1. Selecting CONFIG_STACKDEPOT_ALWAYS_INIT. This option is suitable in
* scenarios where it's known at compile time that stack depot will be used.
* Enabling this config makes the kernel initialize stack depot in mm_init().
*
* 2. Calling stack_depot_request_early_init() during early boot, before
* stack_depot_early_init() in mm_init() completes. For example, this can
* be done when evaluating kernel boot parameters.
*
* 3. Calling stack_depot_init(). Possible after boot is complete. This option
* is recommended for modules initialized later in the boot process, after
* mm_init() completes.
*
* stack_depot_init() and stack_depot_request_early_init() can be called
* regardless of whether CONFIG_STACKDEPOT is enabled and are no-op when this
* config is disabled. The save/fetch/print stack depot functions can only be
* called from the code that makes sure CONFIG_STACKDEPOT is enabled _and_
* initializes stack depot via one of the ways listed above.
*/
#ifdef CONFIG_STACKDEPOT
int stack_depot_init(void);
void __init stack_depot_request_early_init(void);
/* Must be only called from mm_init(). */
int __init stack_depot_early_init(void);
#else
static inline int stack_depot_init(void) { return 0; }
static inline void stack_depot_request_early_init(void) { }
static inline int stack_depot_early_init(void) { return 0; }
#endif
/**
* stack_depot_save_flags - Save a stack trace to stack depot
*
* @entries: Pointer to the stack trace
* @nr_entries: Number of frames in the stack
* @alloc_flags: Allocation GFP flags
* @depot_flags: Stack depot flags
*
* Saves a stack trace from @entries array of size @nr_entries.
*
* If STACK_DEPOT_FLAG_CAN_ALLOC is set in @depot_flags, stack depot can
* replenish the stack pools in case no space is left (allocates using GFP
* flags of @alloc_flags). Otherwise, stack depot avoids any allocations and
* fails if no space is left to store the stack trace.
*
* If STACK_DEPOT_FLAG_GET is set in @depot_flags, stack depot will increment
Annotation
- Immediate include surface: `linux/gfp.h`.
- Detected declarations: `struct stack_record`, `function stack_depot_init`, `function stack_depot_request_early_init`.
- Atlas domain: Core OS / Core Kernel Interface.
- Implementation status: source 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.