Skip to contentSkip to conversation

ublk: reduce stack usage in __ublk_shmem_remove_ranges

PATCH In review Arnd Bergmann 2 participants 2 messages Sep 15 – Sep 16

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ublk: reduce stack usage in __ublk_shmem_remove_ranges

From: Arnd Bergmann <[email protected]>

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")

---
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(-)
drivers/block/ublk_drv.c +1 -1
index 66eb55e7162e..6fe85aba32ce 100644
@@ -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
 
 struct ublk_unpin_range {
 	unsigned long base_pfn;
Signature · 1 line
2.53.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 29 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

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")

---
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(-)
drivers/block/ublk_drv.c +0 -0
index 66eb55e7162e..6fe85aba32ce 100644

drivers/block/ublk_drv.c static void ublk_unpin_range_pages(unsigned long base_pfn, · line 5534

Quoted 5 lines
drivers/block/ublk_drv.c +1 -1
@@ -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

Thanks,
Ming Lei