Re: [PATCH RFC v2 01/11] stackdepot: stop preallocating after the final pool
From: Marco Elver
Date: Fri Oct 16 2026 - 13:01:53 EST
On Tue, 8 Sept 2026 at 15:13, Caleb Kan <calebkan1106@xxxxxxxxx> wrote:
>
> From: Caleb Kan <ckan@xxxxxxxxxxxxxx>
>
> depot_init_pool() decides whether another pool is needed before it
> increments pools_num. When it registers the last allowed pool, pools_num
> is still one below stack_max_pools, so the existing comparison clears
> new_pool.
>
> With new_pool cleared, stack_depot_save_flags() can allocate another
> order-2 pool after a lookup miss. depot_keep_new_pool() retains its pointer
> in the global new_pool, so the allocation is not lost. However, pools_num
> has already reached stack_max_pools, and depot_init_pool() rejects every
> attempt to register the pool. It remains allocated and unusable until
> reboot. The non-NULL pointer prevents later saves from allocating more
> spare pools.
>
> Account for the pool being registered in the limit check so registering
> the final pool installs STACK_DEPOT_POISON and prevents the extra
> allocation.
>
> Fixes: 31639fd6cebd ("stackdepot: use variable size records for non-evictable entries")
> Signed-off-by: Caleb Kan <ckan@xxxxxxxxxxxxxx>
Reviewed-by: Marco Elver <elver@xxxxxxxxxx>
Please send this separately. I hope to find time next week to comment
on the rest of the series.
> ---
> lib/stackdepot.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/stackdepot.c b/lib/stackdepot.c
> index dd2717ff94bf..90c52f2e0d3f 100644
> --- a/lib/stackdepot.c
> +++ b/lib/stackdepot.c
> @@ -323,7 +323,7 @@ static bool depot_init_pool(void **prealloc)
> * NULL; do not reset to NULL if we have reached the maximum number of
> * pools.
> */
> - if (pools_num < stack_max_pools)
> + if (pools_num + 1 < stack_max_pools)
> WRITE_ONCE(new_pool, NULL);
> else
> WRITE_ONCE(new_pool, STACK_DEPOT_POISON);
>
> --
> Git-155)
>