[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <8d6ab730-985e-4ac1-bd3b-0eb240f9eaff@suse.cz>
Date: Mon, 21 Jul 2025 16:45:43 +0200
From: Vlastimil Babka <vbabka@...e.cz>
To: Matt Fleming <matt@...dmodwrite.com>,
Andrew Morton <akpm@...ux-foundation.org>
Cc: linux-kernel@...r.kernel.org, kernel-team@...udflare.com,
Marco Elver <elver@...gle.com>, Alexander Potapenko <glider@...gle.com>,
Andrey Konovalov <andreyknvl@...il.com>, Dmitry Vyukov <dvyukov@...gle.com>,
Oscar Salvador <osalvador@...e.de>, Matt Fleming <mfleming@...udflare.com>
Subject: Re: [PATCH v4] stackdepot: Make max number of pools boot-time
configurable
On 7/18/25 17:39, Matt Fleming wrote:
> From: Matt Fleming <mfleming@...udflare.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@...udflare.com>
Acked-by: Vlastimil Babka <vbabka@...e.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);
> +
Powered by blists - more mailing lists