Skip to contentSkip to conversation

rbd: set max_segments to USHRT_MAX

PATCH In review Ilya Dryomov 2 participants 3 messages Jan 8, 2018 – Jan 9, 2018

Subsystems (2)
lore
Share & tools
lore

Ilya Dryomov

author maintainer
#0 lore raw

PATCH 1/1 rbd: set max_segments to USHRT_MAX

Commit d3834fefcfe5 ("rbd: bump queue_max_segments") bumped max_segments (unsigned short) to max_hw_sectors (unsigned int). max_hw_sectors is set to the number of 512-byte sectors in an object and overflows unsigned short for 32M (largest possible) objects, making the block layer resort to handing us single segment (i.e. single page or even smaller) bios in that case.

Fixes d3834fefcfe5 ("rbd: bump queue_max_segments")
---
 drivers/block/rbd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/rbd.c +1 -1
index f40050c97bb3..0bda823a90ca 100644
@@ -4381,7 +4381,7 @@ static int rbd_init_disk(struct rbd_device *rbd_dev)
 	segment_size = rbd_obj_bytes(&rbd_dev->header);
 	blk_queue_max_hw_sectors(q, segment_size / SECTOR_SIZE);
 	q->limits.max_sectors = queue_max_hw_sectors(q);
-	blk_queue_max_segments(q, segment_size / SECTOR_SIZE);
+	blk_queue_max_segments(q, USHRT_MAX);
 	blk_queue_max_segment_size(q, segment_size);
 	blk_queue_io_min(q, segment_size);
 	blk_queue_io_opt(q, segment_size);
Signature · 1 line
2.4.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Ilya Dryomov

Commit d3834fefcfe5 ("rbd: bump queue_max_segments") bumped max_segments (unsigned short) to max_hw_sectors (unsigned int). max_hw_sectors is set to the number of 512-byte sectors in an object and overflows unsigned short for 32M (largest possible) objects, making the block layer resort to handing us single segment (i.e. single page or even smaller) bios in that case.

Fixes d3834fefcfe5 ("rbd: bump queue_max_segments")

Is it OK for max_segments to be bigger than max_hw_sectors?

I didn't investigate but the question occurred to me, since you're fixing max_segments regardless of segment size, but not doing that to the other limits being set.

If that is not a problem:

Quoted 18 lines
---
 drivers/block/rbd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/rbd.c +1 -1
index f40050c97bb3..0bda823a90ca 100644
@@ -4381,7 +4381,7 @@ static int rbd_init_disk(struct rbd_device *rbd_dev)
 	segment_size = rbd_obj_bytes(&rbd_dev->header);
 	blk_queue_max_hw_sectors(q, segment_size / SECTOR_SIZE);
 	q->limits.max_sectors = queue_max_hw_sectors(q);
-	blk_queue_max_segments(q, segment_size / SECTOR_SIZE);
+	blk_queue_max_segments(q, USHRT_MAX);
 	blk_queue_max_segment_size(q, segment_size);
 	blk_queue_io_min(q, segment_size);
 	blk_queue_io_opt(q, segment_size);
author maintainer
#2 lore raw
Quoted 8 lines · Alex Elder
Quoted 7 lines · Ilya Dryomov

Commit d3834fefcfe5 ("rbd: bump queue_max_segments") bumped max_segments (unsigned short) to max_hw_sectors (unsigned int). max_hw_sectors is set to the number of 512-byte sectors in an object and overflows unsigned short for 32M (largest possible) objects, making the block layer resort to handing us single segment (i.e. single page or even smaller) bios in that case.

Quoted 5 lines
Quoted 3 lines
Fixes d3834fefcfe5 ("rbd: bump queue_max_segments")

Is it OK for max_segments to be bigger than max_hw_sectors?

I think so. max_hw_sectors (or rather max_sectors -- a soft limit capped by max_hw_sectors hard limit) limits the size of the request. max_segments limits the number of segments (~ bvecs) and rbd is fine with any number.

Quoted 4 lines

I didn't investigate but the question occurred to me, since you're fixing max_segments regardless of segment size, but not doing that to the other limits being set.

Yeah, queue_max_segment_size could be UINT_MAX and we could probably disable SG merging (BLK_MQ_F_SG_MERGE) which we don't benefit from. This is a small fix intended for stable though.

Thanks for the review!

Ilya