stack_depot_save_flags(9)
πΎ stack_depot_save_flags β kernel API manual, bestie edition πΎ
okay so this is stack_depot_save_flags(9) from the Kernel API Manual, and we're about to save some stack traces to the stack depot. it's giving "filing cabinet for stack traces" energy and honestly? iconic. ποΈβ¨
β¨ NAME β¨
stack_depot_save_flags β save a stack trace to stack depot π
πΈ SYNOPSIS πΈ
depot_stack_handle_t stack_depot_save_flags (unsigned long *entries ,
unsigned int nr_entries , gfp_t alloc_flags , depot_flags_t depot_flags
);
like, that's the whole vibe. four args, one handle back. periodt. π
π¦ ARGUMENTS π¦
entriesβ pointer to the stack trace. yes, the actual stack trace. this is the main character. πnr_entriesβ how many frames are in the stack, bestie. count them. π’alloc_flagsβ the allocation GFP flags. these are the rules for how memory gets grabbed. π§depot_flagsβ stack depot flags. these change the whole personality of the call. π«
π DESCRIPTION π
so what it does: it saves a stack trace from the entries array of size nr_entries. that's it. that's the job. lowkey simple, highkey important. π
now the fun part β the flags, because they matter:
- if
STACK_DEPOT_FLAG_CAN_ALLOCis set indepot_flags, then stack depot can replenish the stack pools in case no space is left β and it allocates using the GFP flags ofalloc_flags. so it's allowed to go shopping for more space. ποΈ - otherwise (no
STACK_DEPOT_FLAG_CAN_ALLOC), stack depot avoids any allocations and fails if there's no space left to store the stack trace. no space, no save, no drama. π - if
STACK_DEPOT_FLAG_GETis set indepot_flags, stack depot will increment the refcount on the saved stack trace if it already exists in stack depot. so if your trace is already famous, it just gets more famous. β
β οΈ bestie, listen β if you useSTACK_DEPOT_FLAG_GET, you must also callstack_depot_putwhen keeping the stack trace is no longer required. otherwise the refcount overflows. and not in a cute way. π
one more thing: if the stack trace you provided comes from the interrupt context, only the part up to the interrupt entry is saved. we don't save the whole thing, just up to the interrupt. that's the cut. βοΈ
π CONTEXT π
any context! π but β and this is the big but β unsetting STACK_DEPOT_FLAG_CAN_ALLOC is required if alloc_pages cannot be used from the current context.
currently that's the case for contexts where neither GFP_ATOMIC nor GFP_NOWAIT can be used β specifically NMI and raw_spin_lock. so like, know where you are before you call this, fr fr. π§
π₯ RETURN π₯
handle of the stack struct stored in depot β and 0 on failure. that's the whole return situation. zero means nope. π
ββοΈ
π SEE ALSO π
kernel file ./include/linux/stackdepot.h, plus the whole squad:
stack_depot_save(9)__stack_depot_get_stack_record(9)stack_depot_fetch(9)stack_depot_print(9)stack_depot_snprint(9)stack_depot_put(9)stack_depot_set_extra_bits(9)stack_depot_get_extra_bits(9)
okay that's the whole page!! π«Ά this one ships out of ./include/linux, dated October 2026, and it's the stack_depot_save_flags(9) era of the Kernel API Manual. go save some stacks, you absolute legend. ππ
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms