Skip to contentSkip to conversation

make BLK_DEF_MAX_SECTORS less confusing

PATCH New Christoph Hellwig 2 participants 6 messages Dec 27, 2023

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

Hi Jens,

this series removes a few abuses of BLK_DEF_MAX_SECTORS and then renames and documents that constant to make it's use clear.

Diffstat:

 block/blk-settings.c          |    2 +-
 block/blk-sysfs.c             |    2 +-
 drivers/block/aoe/aoeblk.c    |    3 ++-
 drivers/block/loop.c          |    3 ++-
 drivers/block/null_blk/main.c |   12 ++----------
 drivers/scsi/sd.c             |    2 +-
 include/linux/blkdev.h        |    9 ++++++++-
 7 files changed, 17 insertions(+), 16 deletions(-)
#1 lore raw

PATCH 1/4 null_blk: don't cap max_hw_sectors to BLK_DEF_MAX_SECTORS

null_blk has some rather odd capping of the max_hw_sectors value to BLK_DEF_MAX_SECTORS, which doesn't make sense - max_hw_sector is the hardware limit, and BLK_DEF_MAX_SECTORS despite the confusing name is the default cap for the max_sectors field used for normal file system I/O.

Remove all the capping, and simply leave it to the block layer or user to take up or not all of that for file system I/O.

Fixes ea17fd354ca8 ("null_blk: Allow controlling max_hw_sectors limit")
---
 drivers/block/null_blk/main.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)
drivers/block/null_blk/main.c +2 -10
index 3021d58ca51c1f..13ed446b5e198e 100644
@@ -2186,10 +2186,8 @@ static int null_add_dev(struct nullb_device *dev)
 
 	blk_queue_logical_block_size(nullb->q, dev->blocksize);
 	blk_queue_physical_block_size(nullb->q, dev->blocksize);
-	if (!dev->max_sectors)
-		dev->max_sectors = queue_max_hw_sectors(nullb->q);
-	dev->max_sectors = min(dev->max_sectors, BLK_DEF_MAX_SECTORS);
-	blk_queue_max_hw_sectors(nullb->q, dev->max_sectors);
+	if (dev->max_sectors)
+		blk_queue_max_hw_sectors(nullb->q, dev->max_sectors);
 
 	if (dev->virt_boundary)
 		blk_queue_virt_boundary(nullb->q, PAGE_SIZE - 1);
@@ -2289,12 +2287,6 @@ static int __init null_init(void)
 		g_bs = PAGE_SIZE;
 	}
 
-	if (g_max_sectors > BLK_DEF_MAX_SECTORS) {
-		pr_warn("invalid max sectors\n");
-		pr_warn("defaults max sectors to %u\n", BLK_DEF_MAX_SECTORS);
-		g_max_sectors = BLK_DEF_MAX_SECTORS;
-	}
-
 	if (g_home_node != NUMA_NO_NODE && g_home_node >= nr_online_nodes) {
 		pr_err("invalid home_node value\n");
 		g_home_node = NUMA_NO_NODE;
Signature · 1 line
2.39.2
#2 lore raw

PATCH 2/4 aoe: don't abuse BLK_DEF_MAX_SECTORS

In reply to Christoph Hellwig

BLK_DEF_MAX_SECTORS despite the confusing name is the default cap for the max_sectors limits. Don't use it to initialize max_hw_setors, which is a hardware / driver capacility.

---
 drivers/block/aoe/aoeblk.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/block/aoe/aoeblk.c +2 -1
index cf6883756155a3..d2dbf8aaccb5b1 100644
@@ -383,7 +383,8 @@ aoeblk_gdalloc(void *vp)
 	WARN_ON(d->flags & DEVFL_TKILL);
 	WARN_ON(d->gd);
 	WARN_ON(d->flags & DEVFL_UP);
-	blk_queue_max_hw_sectors(gd->queue, BLK_DEF_MAX_SECTORS);
+	/* random number picked from the history block max_sectors cap */
+	blk_queue_max_hw_sectors(gd->queue, 2560u);
 	blk_queue_io_opt(gd->queue, SZ_2M);
 	d->bufpool = mp;
 	d->blkq = gd->queue;
Signature · 1 line
2.39.2
#3 lore raw

PATCH 3/4 loop: don't abuse BLK_DEF_MAX_SECTORS

In reply to Christoph Hellwig

BLK_DEF_MAX_SECTORS despite the confusing name is the default cap for the max_sectors limits. Don't use it to initialize max_hw_setors, which is a hardware / driver capacility.

---
 drivers/block/loop.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/block/loop.c +2 -1
index 9f2d412fc560e1..6106303fcc4677 100644
@@ -2038,7 +2038,8 @@ static int loop_add(int i)
 	}
 	lo->lo_queue = lo->lo_disk->queue;
 
-	blk_queue_max_hw_sectors(lo->lo_queue, BLK_DEF_MAX_SECTORS);
+	/* random number picked from the history block max_sectors cap */
+	blk_queue_max_hw_sectors(lo->lo_queue, 2560u);
 
 	/*
 	 * By default, we do buffer IO, so it doesn't make sense to enable
Signature · 1 line
2.39.2
#4 lore raw

PATCH 4/4 block: rename and document BLK_DEF_MAX_SECTORS

In reply to Christoph Hellwig

Give BLK_DEF_MAX_SECTORS a _CAP postfix and document what it is used for.

---
 block/blk-settings.c   | 2 +-
 block/blk-sysfs.c      | 2 +-
 drivers/scsi/sd.c      | 2 +-
 include/linux/blkdev.h | 9 ++++++++-
 4 files changed, 11 insertions(+), 4 deletions(-)
block/blk-settings.c +1 -1
index 33b3f767b81e24..ba6e0e97118c08 100644
@@ -139,7 +139,7 @@ void blk_queue_max_hw_sectors(struct request_queue *q, unsigned int max_hw_secto
 	if (limits->max_user_sectors)
 		max_sectors = min(max_sectors, limits->max_user_sectors);
 	else
-		max_sectors = min(max_sectors, BLK_DEF_MAX_SECTORS);
+		max_sectors = min(max_sectors, BLK_DEF_MAX_SECTORS_CAP);
 
 	max_sectors = round_down(max_sectors,
 				 limits->logical_block_size >> SECTOR_SHIFT);
block/blk-sysfs.c +1 -1
index d5e669a401b0cc..40bab5975c5612 100644
@@ -241,7 +241,7 @@ queue_max_sectors_store(struct request_queue *q, const char *page, size_t count)
 	if (max_sectors_kb == 0) {
 		q->limits.max_user_sectors = 0;
 		max_sectors_kb = min(max_hw_sectors_kb,
-				     BLK_DEF_MAX_SECTORS >> 1);
+				     BLK_DEF_MAX_SECTORS_CAP >> 1);
 	} else {
 		if (max_sectors_kb > max_hw_sectors_kb ||
 		    max_sectors_kb < page_kb)
drivers/scsi/sd.c +1 -1
index 8c8ac5cd1833b4..6bedd2d5298f6d 100644
@@ -3500,7 +3500,7 @@ static int sd_revalidate_disk(struct gendisk *disk)
 	} else {
 		q->limits.io_opt = 0;
 		rw_max = min_not_zero(logical_to_sectors(sdp, dev_max),
-				      (sector_t)BLK_DEF_MAX_SECTORS);
+				      (sector_t)BLK_DEF_MAX_SECTORS_CAP);
 	}
 
 	/*
include/linux/blkdev.h +8 -1
index ce1ab712552e3c..9f9fbc22c4b037 100644
@@ -1056,7 +1056,14 @@ enum blk_default_limits {
 	BLK_SEG_BOUNDARY_MASK	= 0xFFFFFFFFUL,
 };
 
-#define BLK_DEF_MAX_SECTORS 2560u
+/*
+ * Default upper limit for the software max_sectors limit used for
+ * regular file system I/O.  This can be increased through sysfs.
+ *
+ * Not to be confused with the max_hw_sector limit that is entirely
+ * controlled by the driver, usually based on hardware limits.
+ */
+#define BLK_DEF_MAX_SECTORS_CAP	2560u
 
 static inline unsigned long queue_segment_boundary(const struct request_queue *q)
 {
Signature · 1 line
2.39.2
maintainer Applied
#5 lore raw
In reply to Christoph Hellwig
Quoted 13 lines · Christoph Hellwig

this series removes a few abuses of BLK_DEF_MAX_SECTORS and then renames and documents that constant to make it's use clear.

Diffstat:

 block/blk-settings.c          |    2 +-
 block/blk-sysfs.c             |    2 +-
 drivers/block/aoe/aoeblk.c    |    3 ++-
 drivers/block/loop.c          |    3 ++-
 drivers/block/null_blk/main.c |   12 ++----------
 drivers/scsi/sd.c             |    2 +-
 include/linux/blkdev.h        |    9 ++++++++-
 7 files changed, 17 insertions(+), 16 deletions(-)
Quoted 1 line

[...]

Applied, thanks!

[1/4] null_blk: don't cap max_hw_sectors to BLK_DEF_MAX_SECTORS

      commit: 9a9525de865410047fa962867b4fcd33943b206f
[2/4] aoe: don't abuse BLK_DEF_MAX_SECTORS
      commit: 3888b2ee6262616dbcbf902bc171963fe345da87
[3/4] loop: don't abuse BLK_DEF_MAX_SECTORS
      commit: 3d77976c3a8586ab1fb6845e2061588b7d04934f
[4/4] block: rename and document BLK_DEF_MAX_SECTORS
      commit: d6b9f4e6f7fb589d8024a31cc4883d15d0c8def4

Best regards,

Signature · 1 line
Jens Axboe