History

lib/stackdepot: introduce __stack_depot_save()

Add __stack_depot_save(), which provides more fine-grained control over stackdepot's memory allocation behaviour, in case stackdepot runs out of "stack slabs". Normally stackdepot uses alloc_pages() in case it runs out of space; passing can_alloc==false to __stack_depot_save() prohibits this, at the cost of more likely failure to record a stack trace.

Marco Elver committed 5 years ago

Commit 11ac25c1 parent 7f2b8812 files · +41 −6Browse files

Unified · Split

2 files
  1. include/linux/stackdepot.h +4 −0
  2. lib/stackdepot.c +37 −6
include/linux/stackdepot.h+4−0
@@ -15,6 +15,10 @@ · 14 unmodified lines
15 15
16typedef u32 depot_stack_handle_t;16typedef u32 depot_stack_handle_t;
17 17
18depot_stack_handle_t __stack_depot_save(unsigned long *entries,
19 unsigned int nr_entries,
20 gfp_t gfp_flags, bool can_alloc);
21
18depot_stack_handle_t stack_depot_save(unsigned long *entries,22depot_stack_handle_t stack_depot_save(unsigned long *entries,
19 unsigned int nr_entries, gfp_t gfp_flags);23 unsigned int nr_entries, gfp_t gfp_flags);
20 24
lib/stackdepot.c+37−6
@@ -248,17 +248,28 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle, · 247 unmodified lines
248EXPORT_SYMBOL_GPL(stack_depot_fetch);248EXPORT_SYMBOL_GPL(stack_depot_fetch);
249 249
250/**250/**
251 * stack_depot_save - Save a stack trace from an array251 * __stack_depot_save - Save a stack trace from an array
252 *252 *
253 * @entries: Pointer to storage array253 * @entries: Pointer to storage array
254 * @nr_entries: Size of the storage array254 * @nr_entries: Size of the storage array
255 * @alloc_flags: Allocation gfp flags255 * @alloc_flags: Allocation gfp flags
256 * @can_alloc: Allocate stack slabs (increased chance of failure if false)
257 *
258 * Saves a stack trace from @entries array of size @nr_entries. If @can_alloc is
259 * %true, is allowed to replenish the stack slab pool in case no space is left
260 * (allocates using GFP flags of @alloc_flags). If @can_alloc is %false, avoids
261 * any allocations and will fail if no space is left to store the stack trace.
262 *
263 * Context: Any context, but setting @can_alloc to %false is required if
264 * alloc_pages() cannot be used from the current context. Currently
265 * this is the case from contexts where neither %GFP_ATOMIC nor
266 * %GFP_NOWAIT can be used (NMI, raw_spin_lock).
256 *267 *
257 * Return: The handle of the stack struct stored in depot268 * Return: The handle of the stack struct stored in depot, 0 on failure.
258 */269 */
259depot_stack_handle_t stack_depot_save(unsigned long *entries,270depot_stack_handle_t __stack_depot_save(unsigned long *entries,
260 unsigned int nr_entries,271 unsigned int nr_entries,
261 gfp_t alloc_flags)272 gfp_t alloc_flags, bool can_alloc)
262{273{
263 struct stack_record *found = NULL, **bucket;274 struct stack_record *found = NULL, **bucket;
264 depot_stack_handle_t retval = 0;275 depot_stack_handle_t retval = 0;
@@ -291,7 +302,7 @@ depot_stack_handle_t stack_depot_save(unsigned long *entries, · 26 unmodified lines
291 * The smp_load_acquire() here pairs with smp_store_release() to302 * The smp_load_acquire() here pairs with smp_store_release() to
292 * |next_slab_inited| in depot_alloc_stack() and init_stack_slab().303 * |next_slab_inited| in depot_alloc_stack() and init_stack_slab().
293 */304 */
294 if (unlikely(!smp_load_acquire(&next_slab_inited))) {305 if (unlikely(can_alloc && !smp_load_acquire(&next_slab_inited))) {
295 /*306 /*
296 * Zero out zone modifiers, as we don't have specific zone307 * Zero out zone modifiers, as we don't have specific zone
297 * requirements. Keep the flags related to allocation in atomic308 * requirements. Keep the flags related to allocation in atomic
@@ -339,6 +350,26 @@ exit: · 41 unmodified lines
339fast_exit:350fast_exit:
340 return retval;351 return retval;
341}352}
353EXPORT_SYMBOL_GPL(__stack_depot_save);
354
355/**
356 * stack_depot_save - Save a stack trace from an array
357 *
358 * @entries: Pointer to storage array
359 * @nr_entries: Size of the storage array
360 * @alloc_flags: Allocation gfp flags
361 *
362 * Context: Contexts where allocations via alloc_pages() are allowed.
363 * See __stack_depot_save() for more details.
364 *
365 * Return: The handle of the stack struct stored in depot, 0 on failure.
366 */
367depot_stack_handle_t stack_depot_save(unsigned long *entries,
368 unsigned int nr_entries,
369 gfp_t alloc_flags)
370{
371 return __stack_depot_save(entries, nr_entries, alloc_flags, true);
372}
342EXPORT_SYMBOL_GPL(stack_depot_save);373EXPORT_SYMBOL_GPL(stack_depot_save);
343 374
344static inline int in_irqentry_text(unsigned long ptr)375static inline int in_irqentry_text(unsigned long ptr)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t