From: Vlastimil Babka <vbabka@suse.cz>
To: Matt Fleming <matt@readmodwrite.com>,
Andrew Morton <akpm@linux-foundation.org>
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>,
Matt Fleming <mfleming@cloudflare.com>
Subject: Re: [PATCH v4] stackdepot: Make max number of pools boot-time configurable
Date: Mon, 21 Jul 2025 16:45:43 +0200 [thread overview]
Message-ID: <8d6ab730-985e-4ac1-bd3b-0eb240f9eaff@suse.cz> (raw)
In-Reply-To: <20250718153928.94229-1-matt@readmodwrite.com>
On 7/18/25 17:39, Matt Fleming 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.
>
> Signed-off-by: Matt Fleming <mfleming@cloudflare.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
> --- a/lib/stackdepot.c
> +++ b/lib/stackdepot.c
> @@ -36,11 +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)
> +/*
> + * 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);
> @@ -62,7 +62,7 @@ static unsigned int stack_bucket_number_order;
> static unsigned int stack_hash_mask;
>
> /* Array of memory regions that store stack records. */
> -static void *stack_pools[DEPOT_MAX_POOLS];
> +static void **stack_pools;
Also nice that (AFAIU) we now save this previously statically allocated
array's memory if stackdepot is built-in but not used by anything.
> /* Newly allocated pool that is not yet added to stack_pools. */
> static void *new_pool;
> /* Number of pools in stack_pools. */
> @@ -101,6 +101,34 @@ 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;
> + 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 below 1024, using default of %u\n",
> + stack_max_pools);
> + goto out;
> + }
> +
> + if (max_pools > limit) {
> + pr_err("stack_depot_max_pools exceeds %lld, using default of %u\n",
> + limit, stack_max_pools);
> + goto out;
> + }
Maybe we could bound the requested value to between 1024 and limit instead
of falling back to the default and completely ignoring it when it's out of
the range?
> + stack_max_pools = max_pools;
> +out:
> + return 0;
> +}
> +early_param("stack_depot_max_pools", parse_max_pools);
> +
prev parent reply other threads:[~2025-07-21 14:45 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-18 15:39 Matt Fleming
2025-07-21 10:26 ` Marco Elver
2025-07-21 14:45 ` Vlastimil Babka [this message]
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=8d6ab730-985e-4ac1-bd3b-0eb240f9eaff@suse.cz \
--to=vbabka@suse.cz \
--cc=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 \
/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®