From: Andrew Morton <akpm@linux-foundation.org>
To: Matt Fleming <matt@readmodwrite.com>
Cc: linux-kernel@vger.kernel.org, kernel-team@cloudflare.com,
Marco Elver <elver@google.com>,
Alexander Potapenko <glider@google.com>,
Andrey Konovalov <andreyknvl@gmail.com>,
Dmitry Vyukov <dvyukov@google.com>,
Oscar Salvador <osalvador@suse.de>,
Vlastimil Babka <vbabka@suse.cz>,
Matt Fleming <mfleming@cloudflare.com>
Subject: Re: [PATCH] stackdepot: Make max number of pools boot-time configurable
Date: Mon, 14 Jul 2025 16:38:50 -0700 [thread overview]
Message-ID: <20250714163850.e58dd109d4c9e0d191995405@linux-foundation.org> (raw)
In-Reply-To: <20250714143332.264997-1-matt@readmodwrite.com>
On Mon, 14 Jul 2025 15:33:32 +0100 Matt Fleming <matt@readmodwrite.com> wrote:
> From: Matt Fleming <mfleming@cloudflare.com>
>
> 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.
>
> ...
>
> --- a/lib/stackdepot.c
> +++ b/lib/stackdepot.c
> @@ -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?
--- a/lib/stackdepot.c~a
+++ a/lib/stackdepot.c
@@ -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)
> @@ -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?
> + unsigned int max_pools;
> + int rv;
> +
> + rv = kstrtouint(str, 0, &max_pools);
> + 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".
next prev parent reply other threads:[~2025-07-14 23:38 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-14 14:33 Matt Fleming
2025-07-14 17:07 ` Matt Fleming
2025-07-14 23:38 ` Andrew Morton [this message]
2025-07-18 15:39 ` Matt Fleming
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250714163850.e58dd109d4c9e0d191995405@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=andreyknvl@gmail.com \
--cc=dvyukov@google.com \
--cc=elver@google.com \
--cc=glider@google.com \
--cc=kernel-team@cloudflare.com \
--cc=linux-kernel@vger.kernel.org \
--cc=matt@readmodwrite.com \
--cc=mfleming@cloudflare.com \
--cc=osalvador@suse.de \
--cc=vbabka@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®