Commit 961c949b authored by Andrey Konovalov's avatar Andrey Konovalov Committed by Andrew Morton

lib/stackdepot: rename slab to pool

Use "pool" instead of "slab" for naming memory regions stack depot
uses to store stack traces. Using "slab" is confusing, as stack depot
pools have nothing to do with the slab allocator.

Also give better names to pool-related global variables: change
"depot_" prefix to "pool_" to point out that these variables are
related to stack depot pools.

Also rename the slabindex (poolindex) field in handle_parts to pool_index
to align its name with the pool_index global variable.

No functional changes.

Link: https://lkml.kernel.org/r/923c507edb350c3b6ef85860f36be489dfc0ad21.1676063693.git.andreyknvl@google.comSigned-off-by: default avatarAndrey Konovalov <andreyknvl@google.com>
Acked-by: default avatarVlastimil Babka <vbabka@suse.cz>
Reviewed-by: default avatarAlexander Potapenko <glider@google.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 4c2e9a67
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
#define DEPOT_STACK_BITS (sizeof(depot_stack_handle_t) * 8) #define DEPOT_STACK_BITS (sizeof(depot_stack_handle_t) * 8)
#define STACK_ALLOC_NULL_PROTECTION_BITS 1 #define STACK_ALLOC_NULL_PROTECTION_BITS 1
#define STACK_ALLOC_ORDER 2 /* 'Slab' size order for stack depot, 4 pages */ #define STACK_ALLOC_ORDER 2 /* Pool size order for stack depot, 4 pages */
#define STACK_ALLOC_SIZE (1LL << (PAGE_SHIFT + STACK_ALLOC_ORDER)) #define STACK_ALLOC_SIZE (1LL << (PAGE_SHIFT + STACK_ALLOC_ORDER))
#define STACK_ALLOC_ALIGN 4 #define STACK_ALLOC_ALIGN 4
#define STACK_ALLOC_OFFSET_BITS (STACK_ALLOC_ORDER + PAGE_SHIFT - \ #define STACK_ALLOC_OFFSET_BITS (STACK_ALLOC_ORDER + PAGE_SHIFT - \
...@@ -47,16 +47,16 @@ ...@@ -47,16 +47,16 @@
#define STACK_ALLOC_INDEX_BITS (DEPOT_STACK_BITS - \ #define STACK_ALLOC_INDEX_BITS (DEPOT_STACK_BITS - \
STACK_ALLOC_NULL_PROTECTION_BITS - \ STACK_ALLOC_NULL_PROTECTION_BITS - \
STACK_ALLOC_OFFSET_BITS - STACK_DEPOT_EXTRA_BITS) STACK_ALLOC_OFFSET_BITS - STACK_DEPOT_EXTRA_BITS)
#define STACK_ALLOC_SLABS_CAP 8192 #define STACK_ALLOC_POOLS_CAP 8192
#define STACK_ALLOC_MAX_SLABS \ #define STACK_ALLOC_MAX_POOLS \
(((1LL << (STACK_ALLOC_INDEX_BITS)) < STACK_ALLOC_SLABS_CAP) ? \ (((1LL << (STACK_ALLOC_INDEX_BITS)) < STACK_ALLOC_POOLS_CAP) ? \
(1LL << (STACK_ALLOC_INDEX_BITS)) : STACK_ALLOC_SLABS_CAP) (1LL << (STACK_ALLOC_INDEX_BITS)) : STACK_ALLOC_POOLS_CAP)
/* The compact structure to store the reference to stacks. */ /* The compact structure to store the reference to stacks. */
union handle_parts { union handle_parts {
depot_stack_handle_t handle; depot_stack_handle_t handle;
struct { struct {
u32 slabindex : STACK_ALLOC_INDEX_BITS; u32 pool_index : STACK_ALLOC_INDEX_BITS;
u32 offset : STACK_ALLOC_OFFSET_BITS; u32 offset : STACK_ALLOC_OFFSET_BITS;
u32 valid : STACK_ALLOC_NULL_PROTECTION_BITS; u32 valid : STACK_ALLOC_NULL_PROTECTION_BITS;
u32 extra : STACK_DEPOT_EXTRA_BITS; u32 extra : STACK_DEPOT_EXTRA_BITS;
...@@ -91,15 +91,15 @@ static unsigned int stack_bucket_number_order; ...@@ -91,15 +91,15 @@ static unsigned int stack_bucket_number_order;
static unsigned int stack_hash_mask; static unsigned int stack_hash_mask;
/* Array of memory regions that store stack traces. */ /* Array of memory regions that store stack traces. */
static void *stack_slabs[STACK_ALLOC_MAX_SLABS]; static void *stack_pools[STACK_ALLOC_MAX_POOLS];
/* Currently used slab in stack_slabs. */ /* Currently used pool in stack_pools. */
static int depot_index; static int pool_index;
/* Offset to the unused space in the currently used slab. */ /* Offset to the unused space in the currently used pool. */
static size_t depot_offset; static size_t pool_offset;
/* Lock that protects the variables above. */ /* Lock that protects the variables above. */
static DEFINE_RAW_SPINLOCK(depot_lock); static DEFINE_RAW_SPINLOCK(pool_lock);
/* Whether the next slab is initialized. */ /* Whether the next pool is initialized. */
static int next_slab_inited; static int next_pool_inited;
static int __init disable_stack_depot(char *str) static int __init disable_stack_depot(char *str)
{ {
...@@ -220,30 +220,30 @@ int stack_depot_init(void) ...@@ -220,30 +220,30 @@ int stack_depot_init(void)
} }
EXPORT_SYMBOL_GPL(stack_depot_init); EXPORT_SYMBOL_GPL(stack_depot_init);
static bool init_stack_slab(void **prealloc) static bool init_stack_pool(void **prealloc)
{ {
if (!*prealloc) if (!*prealloc)
return false; return false;
/* /*
* This smp_load_acquire() pairs with smp_store_release() to * This smp_load_acquire() pairs with smp_store_release() to
* |next_slab_inited| below and in depot_alloc_stack(). * |next_pool_inited| below and in depot_alloc_stack().
*/ */
if (smp_load_acquire(&next_slab_inited)) if (smp_load_acquire(&next_pool_inited))
return true; return true;
if (stack_slabs[depot_index] == NULL) { if (stack_pools[pool_index] == NULL) {
stack_slabs[depot_index] = *prealloc; stack_pools[pool_index] = *prealloc;
*prealloc = NULL; *prealloc = NULL;
} else { } else {
/* If this is the last depot slab, do not touch the next one. */ /* If this is the last depot pool, do not touch the next one. */
if (depot_index + 1 < STACK_ALLOC_MAX_SLABS) { if (pool_index + 1 < STACK_ALLOC_MAX_POOLS) {
stack_slabs[depot_index + 1] = *prealloc; stack_pools[pool_index + 1] = *prealloc;
*prealloc = NULL; *prealloc = NULL;
} }
/* /*
* This smp_store_release pairs with smp_load_acquire() from * This smp_store_release pairs with smp_load_acquire() from
* |next_slab_inited| above and in stack_depot_save(). * |next_pool_inited| above and in stack_depot_save().
*/ */
smp_store_release(&next_slab_inited, 1); smp_store_release(&next_pool_inited, 1);
} }
return true; return true;
} }
...@@ -257,35 +257,35 @@ depot_alloc_stack(unsigned long *entries, int size, u32 hash, void **prealloc) ...@@ -257,35 +257,35 @@ depot_alloc_stack(unsigned long *entries, int size, u32 hash, void **prealloc)
required_size = ALIGN(required_size, 1 << STACK_ALLOC_ALIGN); required_size = ALIGN(required_size, 1 << STACK_ALLOC_ALIGN);
if (unlikely(depot_offset + required_size > STACK_ALLOC_SIZE)) { if (unlikely(pool_offset + required_size > STACK_ALLOC_SIZE)) {
if (unlikely(depot_index + 1 >= STACK_ALLOC_MAX_SLABS)) { if (unlikely(pool_index + 1 >= STACK_ALLOC_MAX_POOLS)) {
WARN_ONCE(1, "Stack depot reached limit capacity"); WARN_ONCE(1, "Stack depot reached limit capacity");
return NULL; return NULL;
} }
depot_index++; pool_index++;
depot_offset = 0; pool_offset = 0;
/* /*
* smp_store_release() here pairs with smp_load_acquire() from * smp_store_release() here pairs with smp_load_acquire() from
* |next_slab_inited| in stack_depot_save() and * |next_pool_inited| in stack_depot_save() and
* init_stack_slab(). * init_stack_pool().
*/ */
if (depot_index + 1 < STACK_ALLOC_MAX_SLABS) if (pool_index + 1 < STACK_ALLOC_MAX_POOLS)
smp_store_release(&next_slab_inited, 0); smp_store_release(&next_pool_inited, 0);
} }
init_stack_slab(prealloc); init_stack_pool(prealloc);
if (stack_slabs[depot_index] == NULL) if (stack_pools[pool_index] == NULL)
return NULL; return NULL;
stack = stack_slabs[depot_index] + depot_offset; stack = stack_pools[pool_index] + pool_offset;
stack->hash = hash; stack->hash = hash;
stack->size = size; stack->size = size;
stack->handle.slabindex = depot_index; stack->handle.pool_index = pool_index;
stack->handle.offset = depot_offset >> STACK_ALLOC_ALIGN; stack->handle.offset = pool_offset >> STACK_ALLOC_ALIGN;
stack->handle.valid = 1; stack->handle.valid = 1;
stack->handle.extra = 0; stack->handle.extra = 0;
memcpy(stack->entries, entries, flex_array_size(stack, entries, size)); memcpy(stack->entries, entries, flex_array_size(stack, entries, size));
depot_offset += required_size; pool_offset += required_size;
return stack; return stack;
} }
...@@ -336,10 +336,10 @@ static inline struct stack_record *find_stack(struct stack_record *bucket, ...@@ -336,10 +336,10 @@ static inline struct stack_record *find_stack(struct stack_record *bucket,
* @nr_entries: Size of the storage array * @nr_entries: Size of the storage array
* @extra_bits: Flags to store in unused bits of depot_stack_handle_t * @extra_bits: Flags to store in unused bits of depot_stack_handle_t
* @alloc_flags: Allocation gfp flags * @alloc_flags: Allocation gfp flags
* @can_alloc: Allocate stack slabs (increased chance of failure if false) * @can_alloc: Allocate stack pools (increased chance of failure if false)
* *
* Saves a stack trace from @entries array of size @nr_entries. If @can_alloc is * Saves a stack trace from @entries array of size @nr_entries. If @can_alloc is
* %true, is allowed to replenish the stack slab pool in case no space is left * %true, is allowed to replenish the stack pool in case no space is left
* (allocates using GFP flags of @alloc_flags). If @can_alloc is %false, avoids * (allocates using GFP flags of @alloc_flags). If @can_alloc is %false, avoids
* any allocations and will fail if no space is left to store the stack trace. * any allocations and will fail if no space is left to store the stack trace.
* *
...@@ -396,14 +396,14 @@ depot_stack_handle_t __stack_depot_save(unsigned long *entries, ...@@ -396,14 +396,14 @@ depot_stack_handle_t __stack_depot_save(unsigned long *entries,
goto exit; goto exit;
/* /*
* Check if the current or the next stack slab need to be initialized. * Check if the current or the next stack pool need to be initialized.
* If so, allocate the memory - we won't be able to do that under the * If so, allocate the memory - we won't be able to do that under the
* lock. * lock.
* *
* The smp_load_acquire() here pairs with smp_store_release() to * The smp_load_acquire() here pairs with smp_store_release() to
* |next_slab_inited| in depot_alloc_stack() and init_stack_slab(). * |next_pool_inited| in depot_alloc_stack() and init_stack_pool().
*/ */
if (unlikely(can_alloc && !smp_load_acquire(&next_slab_inited))) { if (unlikely(can_alloc && !smp_load_acquire(&next_pool_inited))) {
/* /*
* Zero out zone modifiers, as we don't have specific zone * Zero out zone modifiers, as we don't have specific zone
* requirements. Keep the flags related to allocation in atomic * requirements. Keep the flags related to allocation in atomic
...@@ -417,7 +417,7 @@ depot_stack_handle_t __stack_depot_save(unsigned long *entries, ...@@ -417,7 +417,7 @@ depot_stack_handle_t __stack_depot_save(unsigned long *entries,
prealloc = page_address(page); prealloc = page_address(page);
} }
raw_spin_lock_irqsave(&depot_lock, flags); raw_spin_lock_irqsave(&pool_lock, flags);
found = find_stack(*bucket, entries, nr_entries, hash); found = find_stack(*bucket, entries, nr_entries, hash);
if (!found) { if (!found) {
...@@ -437,10 +437,10 @@ depot_stack_handle_t __stack_depot_save(unsigned long *entries, ...@@ -437,10 +437,10 @@ depot_stack_handle_t __stack_depot_save(unsigned long *entries,
* We didn't need to store this stack trace, but let's keep * We didn't need to store this stack trace, but let's keep
* the preallocated memory for the future. * the preallocated memory for the future.
*/ */
WARN_ON(!init_stack_slab(&prealloc)); WARN_ON(!init_stack_pool(&prealloc));
} }
raw_spin_unlock_irqrestore(&depot_lock, flags); raw_spin_unlock_irqrestore(&pool_lock, flags);
exit: exit:
if (prealloc) { if (prealloc) {
/* Nobody used this memory, ok to free it. */ /* Nobody used this memory, ok to free it. */
...@@ -488,7 +488,7 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle, ...@@ -488,7 +488,7 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle,
unsigned long **entries) unsigned long **entries)
{ {
union handle_parts parts = { .handle = handle }; union handle_parts parts = { .handle = handle };
void *slab; void *pool;
size_t offset = parts.offset << STACK_ALLOC_ALIGN; size_t offset = parts.offset << STACK_ALLOC_ALIGN;
struct stack_record *stack; struct stack_record *stack;
...@@ -496,15 +496,15 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle, ...@@ -496,15 +496,15 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle,
if (!handle) if (!handle)
return 0; return 0;
if (parts.slabindex > depot_index) { if (parts.pool_index > pool_index) {
WARN(1, "slab index %d out of bounds (%d) for stack id %08x\n", WARN(1, "pool index %d out of bounds (%d) for stack id %08x\n",
parts.slabindex, depot_index, handle); parts.pool_index, pool_index, handle);
return 0; return 0;
} }
slab = stack_slabs[parts.slabindex]; pool = stack_pools[parts.pool_index];
if (!slab) if (!pool)
return 0; return 0;
stack = slab + offset; stack = pool + offset;
*entries = stack->entries; *entries = stack->entries;
return stack->size; return stack->size;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment