Skip to content

Commit b9779ab

Browse files
Vijayanand Jittasfrothwell
authored andcommitted
lib: stackdepot: add support to disable stack depot
Add a kernel parameter stack_depot_disable to disable stack depot. So that stack hash table doesn't consume any memory when stack depot is disabled. The use case is CONFIG_PAGE_OWNER without page_owner=on. Without this patch, stackdepot will consume the memory for the hashtable. By default, it's 8M which is never trivial. With this option, in CONFIG_PAGE_OWNER configured system, page_owner=off, stack_depot_disable in kernel command line, we could save the wasted memory for the hashtable. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Vinayak Menon <[email protected]> Signed-off-by: Vijayanand Jitta <[email protected]> Cc: Alexander Potapenko <[email protected]> Cc: Minchan Kim <[email protected]> Cc: Yogesh Lal <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Stephen Rothwell <[email protected]>
1 parent 626ee2c commit b9779ab

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5132,6 +5132,12 @@
51325132
growing up) the main stack are reserved for no other
51335133
mapping. Default value is 256 pages.
51345134

5135+
stack_depot_disable= [KNL]
5136+
Setting this to true through kernel command line will
5137+
disable the stack depot thereby saving the static memory
5138+
consumed by the stack hash table. By default this is set
5139+
to false.
5140+
51355141
stacktrace [FTRACE]
51365142
Enabled the stack tracer on boot up.
51375143

include/linux/stackdepot.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle,
2121

2222
unsigned int filter_irq_stacks(unsigned long *entries, unsigned int nr_entries);
2323

24+
int stack_depot_init(void);
2425
#endif

init/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
#include <linux/mem_encrypt.h>
9999
#include <linux/kcsan.h>
100100
#include <linux/init_syscalls.h>
101+
#include <linux/stackdepot.h>
101102

102103
#include <asm/io.h>
103104
#include <asm/bugs.h>
@@ -828,6 +829,7 @@ static void __init mm_init(void)
828829
init_mem_debugging_and_hardening();
829830
kfence_alloc_pool();
830831
report_meminit();
832+
stack_depot_init();
831833
mem_init();
832834
/* page_owner must be initialized after buddy is ready */
833835
page_ext_init_flatmem_late();

lib/stackdepot.c

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <linux/stackdepot.h>
3232
#include <linux/string.h>
3333
#include <linux/types.h>
34+
#include <linux/memblock.h>
3435

3536
#define DEPOT_STACK_BITS (sizeof(depot_stack_handle_t) * 8)
3637

@@ -145,9 +146,32 @@ static struct stack_record *depot_alloc_stack(unsigned long *entries, int size,
145146
#define STACK_HASH_MASK (STACK_HASH_SIZE - 1)
146147
#define STACK_HASH_SEED 0x9747b28c
147148

148-
static struct stack_record *stack_table[STACK_HASH_SIZE] = {
149-
[0 ... STACK_HASH_SIZE - 1] = NULL
150-
};
149+
static bool stack_depot_disable;
150+
static struct stack_record **stack_table;
151+
152+
static int __init is_stack_depot_disabled(char *str)
153+
{
154+
kstrtobool(str, &stack_depot_disable);
155+
if (stack_depot_disable) {
156+
pr_info("Stack Depot is disabled\n");
157+
stack_table = NULL;
158+
}
159+
return 0;
160+
}
161+
early_param("stack_depot_disable", is_stack_depot_disabled);
162+
163+
int __init stack_depot_init(void)
164+
{
165+
if (!stack_depot_disable) {
166+
size_t size = (STACK_HASH_SIZE * sizeof(struct stack_record *));
167+
int i;
168+
169+
stack_table = memblock_alloc(size, size);
170+
for (i = 0; i < STACK_HASH_SIZE; i++)
171+
stack_table[i] = NULL;
172+
}
173+
return 0;
174+
}
151175

152176
/* Calculate hash for a stack */
153177
static inline u32 hash_stack(unsigned long *entries, unsigned int size)
@@ -241,7 +265,7 @@ depot_stack_handle_t stack_depot_save(unsigned long *entries,
241265
unsigned long flags;
242266
u32 hash;
243267

244-
if (unlikely(nr_entries == 0))
268+
if (unlikely(nr_entries == 0) || stack_depot_disable)
245269
goto fast_exit;
246270

247271
hash = hash_stack(entries, nr_entries);

0 commit comments

Comments
 (0)