stack_depot_save_flags(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’Ύ 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_ALLOC is set in depot_flags, then stack depot can replenish the stack pools in case no space is left β€” and it allocates using the GFP flags of alloc_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_GET is set in depot_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 use STACK_DEPOT_FLAG_GET, you must also call stack_depot_put when 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:


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