Skip to contentSkip to conversation

fix stacking of sd-imposed max_sectors

PATCH In review Christoph Hellwig 3 participants 7 messages May 23, 2024 – May 28, 2024

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

Hi Jens,

this series fixes a regression in 6.10-rc report by Mike when using device mapper multipath on top of SCSI disks. It is due the sd driver not only setting the hard max_dev_sectors limit but also pre-setting a potentially lower max_sectors value.

Diffstat:

 block/blk-settings.c |    2 ++
 drivers/scsi/sd.c    |    4 +++-
 2 files changed, 5 insertions(+), 1 deletion(-)
#1 lore raw

PATCH 1/2 sd: also set max_user_sectors when setting max_sectors

sd can set a max_sectors value that is lower than the max_hw_sectors
limit based on the block limits VPD page. While this is rather unusual,
it used to work until the max_user_sectors field was split out to cleanly deal with conflicting hardware and user limits when the hardware limit changes. Also set max_user_sectors to ensure the limit can properly be stacked.

Fixes 4f563a64732d ("block: add a max_user_discard_sectors queue limit")
---
 drivers/scsi/sd.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/scsi/sd.c +3 -1
index 332eb9dac22d91..f6c822c9cbd2d3 100644
@@ -3700,8 +3700,10 @@ static int sd_revalidate_disk(struct gendisk *disk)
 	 */
 	if (sdkp->first_scan ||
 	    q->limits.max_sectors > q->limits.max_dev_sectors ||
-	    q->limits.max_sectors > q->limits.max_hw_sectors)
+	    q->limits.max_sectors > q->limits.max_hw_sectors) {
 		q->limits.max_sectors = rw_max;
+		q->limits.max_user_sectors = rw_max;
+	}
 
 	sdkp->first_scan = 0;
 
Signature · 1 line
2.43.0
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] sd: also set max_user_sectors when setting max_sectors

Christoph,

Quoted 3 lines

sd can set a max_sectors value that is lower than the max_hw_sectors
limit based on the block limits VPD page. While this is rather
unusual,

It's not particularly unusual. Virtually all arrays have a much smaller stripe or cache line size than what the average HBA can handle in one transfer. Using the device's preferred I/O size to configure max_sectors made a substantial difference performance-wise.

Quoted 4 lines

it used to work until the max_user_sectors field was split out to cleanly deal with conflicting hardware and user limits when the hardware limit changes. Also set max_user_sectors to ensure the limit can properly be stacked.

Fine for a quick fix.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#3 lore raw

Re: [PATCH 1/2] sd: also set max_user_sectors when setting max_sectors

Quoted 11 lines · Martin K. Petersen

Christoph,

Quoted 3 lines

sd can set a max_sectors value that is lower than the max_hw_sectors
limit based on the block limits VPD page. While this is rather
unusual,

It's not particularly unusual. Virtually all arrays have a much smaller stripe or cache line size than what the average HBA can handle in one transfer. Using the device's preferred I/O size to configure max_sectors made a substantial difference performance-wise.

Well, in terms of Linux it is weird in that drivers weren't ever supposed to set max_sectors directly but only provide max_hw_sectors (although nbd also decreases it and rbd increases it in odd ways). Especially as we already have an opt_in limit for the optimal size.

I'll find a way to sort it out and build a grand unified and somewhat coherent theory out of it..

#4 lore raw

PATCH 2/2 block: stack max_user_sectors

In reply to Christoph Hellwig

The max_user_sectors is one of the three factors determining the actual max_sectors limit for READ/WRITE requests. Because of that it needs to be stacked at least for the device mapper multi-path case where requests are directly inserted on the lower device. For SCSI disks this is important because the sd driver actually sets it's own advisory limit that is lower than max_hw_sectors based on the block limits VPD page. While this is a bit odd an unusual, the same effect can happen if a user or udev script tweaks the value manually.

Fixes 4f563a64732d ("block: add a max_user_discard_sectors queue limit")
---
 block/blk-settings.c | 2 ++
 1 file changed, 2 insertions(+)
block/blk-settings.c +2 -0
index a7fe8e90240a6e..7a672021daee6a 100644
@@ -611,6 +611,8 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
 	unsigned int top, bottom, alignment, ret = 0;
 
 	t->max_sectors = min_not_zero(t->max_sectors, b->max_sectors);
+	t->max_user_sectors = min_not_zero(t->max_user_sectors,
+			b->max_user_sectors);
 	t->max_hw_sectors = min_not_zero(t->max_hw_sectors, b->max_hw_sectors);
 	t->max_dev_sectors = min_not_zero(t->max_dev_sectors, b->max_dev_sectors);
 	t->max_write_zeroes_sectors = min(t->max_write_zeroes_sectors,
Signature · 1 line
2.43.0
Reviewed-by on v1 2/2
#5 lore raw

Re: [PATCH 2/2] block: stack max_user_sectors

Christoph,

Quoted 4 lines

The max_user_sectors is one of the three factors determining the actual max_sectors limit for READ/WRITE requests. Because of that it needs to be stacked at least for the device mapper multi-path case where requests are directly inserted on the lower device.

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
maintainer Applied
#6 lore raw
In reply to Christoph Hellwig
Quoted 11 lines · Christoph Hellwig

this series fixes a regression in 6.10-rc report by Mike when using device mapper multipath on top of SCSI disks. It is due the sd driver not only setting the hard max_dev_sectors limit but also pre-setting a potentially lower max_sectors value.

Diffstat:

 block/blk-settings.c |    2 ++
 drivers/scsi/sd.c    |    4 +++-
 2 files changed, 5 insertions(+), 1 deletion(-)

[...]

Applied, thanks!

[1/2] sd: also set max_user_sectors when setting max_sectors

      commit: bafea1c58b24be594d97841ced1b7ae0347bf6e3
[2/2] block: stack max_user_sectors
      commit: e528bede6f4e6822afdf0fa80be46ea9199f0911

Best regards,

Signature · 1 line
Jens Axboe