Re: [PATCH] ublk: reduce stack usage in __ublk_shmem_remove_ranges

From: Ming Lei

Date: Tue Sep 15 2026 - 20:37:58 EST


On Tue, Sep 15, 2026 at 3:01 PM Arnd Bergmann <arnd@xxxxxxxxxx> wrote:
>
> From: Arnd Bergmann <arnd@xxxxxxxx>
>
> The array in __ublk_shmem_remove_ranges() is one kilobyte long,
> which is really too much for an on-stack allocation, as can be
> seen with a frame warning limit of 1.25kb that otherwise produces
> a clean build on my test system:
>
> drivers/block/ublk_drv.c: In function '__ublk_shmem_remove_ranges':
> drivers/block/ublk_drv.c:5573:1: error: the frame size of 1392 bytes is larger than 1280 bytes [-Werror=frame-larger-than=]
>
> Maybe half the size is good enough here, so try 32 entries.
> If 64 entries are really required, the array could be dynamically
> allocated, but that would risk an allocation failure.
>
> Fixes: 309e02dccf64 ("ublk: avoid unpinning pages under maple tree spinlock")
> Signed-off-by: Arnd Bergmann <arnd@xxxxxxxx>
> ---
> I have really no idea if the 64 number was significant or just chosen
> to fit within usual stack frames.
> ---
> drivers/block/ublk_drv.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
> index 66eb55e7162e..6fe85aba32ce 100644
> --- a/drivers/block/ublk_drv.c
> +++ b/drivers/block/ublk_drv.c
> @@ -5531,7 +5531,7 @@ static void ublk_unpin_range_pages(unsigned long base_pfn,
> *
> * Returns true if the tree walk completed, false if more ranges remain.
> */
> -#define UBLK_REMOVE_BATCH 64
> +#define UBLK_REMOVE_BATCH 32

Reviewed-by: Ming Lei <tom.leiming@xxxxxxxxx>

Thanks,
Ming Lei