stackdepot: Make max number of pools boot-time configurable
Subsystems (2)
PATCH 1/1 stackdepot: Make max number of pools boot-time configurable
From: Matt Fleming <[email protected]>
We're hitting the WARN in depot_init_pool() about reaching the stack depot limit because we have long stacks that don't dedup very well.
Introduce a new start-up parameter to allow users to set the number of maximum stack depot pools.
--- .../admin-guide/kernel-parameters.txt | 5 ++ lib/stackdepot.c | 55 +++++++++++++++++-- 2 files changed, 56 insertions(+), 4 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +5 -0
@@ -6542,6 +6542,11 @@ consumed by the stack hash table. By default this is set to false. + stack_depot_max_pools= [KNL,EARLY] + Specify the maximum number of pools to use for storing + stack traces. Pools are allocated on-demand up to this + limit. Default value is 8191 pools. + stacktrace [FTRACE] Enabled the stack tracer on boot up.
lib/stackdepot.c +51 -4
98 lines not on this page · raw message
Signature · 1 line
2.34.1
Quoted 11 lines · Matt Fleming
From: Matt Fleming <[email protected]>
We're hitting the WARN in
depot_init_pool()about reaching the stack depot limit because we have long stacks that don't dedup very well.Introduce a new start-up parameter to allow users to set the number of maximum stack depot pools.
Signed-off-by Matt Fleming <[email protected]>---
Sorry, this is technically a v3 patch (even if it's very different to v1 and v2) so I should've included a list of changes:
Changes in v3:
- Switch from build-time to boot-time parameter
Changes in v2:
- Replace BUILD_BUG_ON with static_assert()
- Hide STACKDEPOT_MAX_POOLS behind EXPERT
Quoted 9 lines
.../admin-guide/kernel-parameters.txt | 5 ++ lib/stackdepot.c | 55 +++++++++++++++++-- 2 files changed, 56 insertions(+), 4 deletions(-)Documentation/admin-guide/kernel-parameters.txt +0
-0
Documentation/admin-guide/kernel-parameters.txt line 6549
Quoted 8 lines
Documentation/admin-guide/kernel-parameters.txt +5
-0@@ -6542,6 +6542,11 @@ consumed by the stack hash table. By default this is set to false. + stack_depot_max_pools= [KNL,EARLY] + Specify the maximum number of pools to use for storing + stack traces. Pools are allocated on-demand up to this + limit. Default value is 8191 pools. +
The default value is usually 8192 pools unless you're on arm64 with 64K pages in which case it's 8191. If this discrepancy is too confusing I'm fine just deleting this final sentence from the help text.
Andrew Morton
maintainerQuoted 13 lines · On Mon, 14 Jul 2025 15:33:32 +0100 Matt Fleming <[email protected]> wrote:
From: Matt Fleming <[email protected]>
We're hitting the WARN in
depot_init_pool()about reaching the stack depot limit because we have long stacks that don't dedup very well.Introduce a new start-up parameter to allow users to set the number of maximum stack depot pools.
...
lib/stackdepot.c line 45
Quoted 4 lines
lib/stackdepot.c +1
-0@@ -42,6 +42,8 @@ (((1LL << (DEPOT_POOL_INDEX_BITS )) -1 <DEPOT_POOLS_CAP ) ? \ (1LL << (DEPOT_POOL_INDEX_BITS)) - 1 : DEPOT_POOLS_CAP) +static unsigned int stack_max_pools =DEPOT_MAX_POOLS ;
Geeze that was all quite the mouthful. Can't we just do this?
lib/stackdepot.c renamed from lib/stackdepot.c~a +5 -7
@@ -36,13 +36,11 @@#include <linux/memblock.h> #include <linux/kasan-enabled.h> -#define DEPOT_POOLS_CAP 8192 -/* The pool_index is offset by 1 so the first record does not have a 0 handle. */ -#define DEPOT_MAX_POOLS \ - (((1LL << (DEPOT_POOL_INDEX_BITS)) - 1 < DEPOT_POOLS_CAP) ? \ - (1LL << (DEPOT_POOL_INDEX_BITS)) - 1 : DEPOT_POOLS_CAP) - -static unsigned int stack_max_pools =DEPOT_MAX_POOLS ; +/* +* The pool_index is offset by 1 so the first record does not have a 0 handle. +*/ +static unsigned int stack_max_pools__read_mostly = +MIN ((1LL <<DEPOT_POOL_INDEX_BITS ) -1 ,8192 );static bool stack_depot_disabled;static bool __stack_depot_early_init_requested__initdata =IS_ENABLED (CONFIG_STACKDEPOT_ALWAYS_INIT );
_
(please add this to the next version)
(but why do we do this min() at all? Why not simply use (1<<DEPOT_POOL_INDEX_BITS)?)
(shouldn't that 8192 be 8191? Seems oddly inconsistent)
lib/stackdepot.c static int __init disable_stack_depot(char *str) · line 108
Quoted 7 lines
lib/stackdepot.c +3
-0@@ -101,6 +103,33 @@ static int __init disable_stack_depot(char *str) }early_param ("stack_depot_disable" , disable_stack_depot); +static int __init parse_max_pools (char *str) +{ +const long long limit = (1LL << (DEPOT_POOL_INDEX_BITS )) -1 ;
Expands to
limit = (1LL << (((sizeof(depot_stack_handle_t) * 8) - (2 + 12 - 4) - 5))) - 1; which is 131071.
This seems a reasonable limit. If we are to have any limit at all. Why do we have a limit?
Quoted 4 lines
lib/stackdepot.c +4
-0+unsigned int max_pools; +int rv; + + rv =kstrtouint (str,0 , &max_pools);
lib/stackdepot.c static int __init disable_stack_depot(char *str) · line 122
Quoted 10 lines
lib/stackdepot.c +10
-0+if (rv) +return rv; + +if (max_pools <1024 ) { +pr_err ("stack_depot_max_pools too low, using default\n" ); + goto out; + } + +if (max_pools > limit) { +pr_err ("stack_depot_max_pools too high, using default\n" );
If user hits this they're going to tear hair figuring out the actual limit. So how about "stack_depot_max_pools exceeds %d, using default of %d".
Quoted 27 lines · Andrew Morton
Geeze that was all quite the mouthful. Can't we just do this?
lib/stackdepot.c renamed from lib/stackdepot.c~a +5
-7@@ -36,13 +36,11 @@#include <linux/memblock.h> #include <linux/kasan-enabled.h> -#define DEPOT_POOLS_CAP 8192 -/* The pool_index is offset by 1 so the first record does not have a 0 handle. */ -#define DEPOT_MAX_POOLS \ - (((1LL << (DEPOT_POOL_INDEX_BITS)) - 1 < DEPOT_POOLS_CAP) ? \ - (1LL << (DEPOT_POOL_INDEX_BITS)) - 1 : DEPOT_POOLS_CAP) - -static unsigned int stack_max_pools =DEPOT_MAX_POOLS ; +/* +* The pool_index is offset by 1 so the first record does not have a 0 handle. +*/ +static unsigned int stack_max_pools__read_mostly = +MIN ((1LL <<DEPOT_POOL_INDEX_BITS ) -1 ,8192 );static bool stack_depot_disabled;static bool __stack_depot_early_init_requested__initdata =IS_ENABLED (CONFIG_STACKDEPOT_ALWAYS_INIT );_
Quoted 1 line
(please add this to the next version)
Nice. Will do.
Quoted 3 lines
(but why do we do this
min()at all? Why not simply use (1<<DEPOT_POOL_INDEX_BITS)?)(shouldn't that 8192 be 8191? Seems oddly inconsistent)
Yeah, I don't have a good answer here. I was hoping Marco or Alexander would chime in.
Quoted 3 lines
If user hits this they're going to tear hair figuring out the actual limit. So how about "
stack_depot_max_poolsexceeds %d, using default of %d".
Good point. Will fix.