Skip to contentSkip to conversation

blk-mq: set the nr_integrity_segments from bio

PATCH Superseded Keith Busch 3 participants 3 messages Sep 3, 2024 – Sep 4, 2024 Block layer

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 blk-mq: set the nr_integrity_segments from bio

From: Keith Busch <[email protected]>

This value is used for potential merging later.

---
v1->v2:

Check the bio actually has integrity before counting the segments. I previously tested v1 with additional experimental patches atop that addressed the problem differently and didn't notice the obvious API requirement.

 block/blk-mq.c | 4 ++++
 1 file changed, 4 insertions(+)
block/blk-mq.c +4 -0
index 36abbaefe3874..3ed5181c75610 100644
@@ -2546,6 +2546,10 @@ static void blk_mq_bio_to_request(struct request *rq, struct bio *bio,
 	rq->__sector = bio->bi_iter.bi_sector;
 	rq->write_hint = bio->bi_write_hint;
 	blk_rq_bio_prep(rq, bio, nr_segs);
+#if defined(CONFIG_BLK_DEV_INTEGRITY)
+	if (bio->bi_opf & REQ_INTEGRITY)
+		rq->nr_integrity_segments = blk_rq_count_integrity_sg(rq->q, bio);
+#endif
 
 	/* This can't fail, since GFP_NOIO includes __GFP_DIRECT_RECLAIM. */
 	err = blk_crypto_rq_bio_prep(rq, bio, GFP_NOIO);
Signature · 1 line
2.43.5
#1 lore raw
Quoted 21 lines · Keith Busch

From: Keith Busch <[email protected]>

This value is used for potential merging later.

---
v1->v2:

Check the bio actually has integrity before counting the segments. I previously tested v1 with additional experimental patches atop that addressed the problem differently and didn't notice the obvious API requirement.

 block/blk-mq.c | 4 ++++
 1 file changed, 4 insertions(+)
block/blk-mq.c +0 -0
index 36abbaefe3874..3ed5181c75610 100644

block/blk-mq.c static void blk_mq_bio_to_request(struct request *rq, struct bio *bio, · line 2551

Quoted 6 lines
block/blk-mq.c +3 -0
@@ -2546,6 +2546,10 @@ static void blk_mq_bio_to_request(struct request *rq, struct bio *bio,
 	rq->__sector = bio->bi_iter.bi_sector;
 	rq->write_hint = bio->bi_write_hint;
 	blk_rq_bio_prep(rq, bio, nr_segs);
+#if defined(CONFIG_BLK_DEV_INTEGRITY)
+	if (bio->bi_opf & REQ_INTEGRITY)
+		rq->nr_integrity_segments = blk_rq_count_integrity_sg(rq->q, bio);

Hmm. The current model is that drivers are supposed to clal this, which they should stop doing now that the block layer maintains this count. So I think this needs a bit more work, after which blk_rq_count_integrity_sg is also unexported, nad preferably also has a name that drops the incorrect _sg.

#2 lore raw
Quoted 16 lines · Christoph Hellwig

block/blk-mq.c static void blk_mq_bio_to_request(struct request *rq, struct bio *bio, · line 2551

Quoted 9 lines · Keith Busch
block/blk-mq.c +3 -0
@@ -2546,6 +2546,10 @@ static void blk_mq_bio_to_request(struct request *rq, struct bio *bio,
 	rq->__sector = bio->bi_iter.bi_sector;
 	rq->write_hint = bio->bi_write_hint;
 	blk_rq_bio_prep(rq, bio, nr_segs);
+#if defined(CONFIG_BLK_DEV_INTEGRITY)
+	if (bio->bi_opf & REQ_INTEGRITY)
+		rq->nr_integrity_segments = blk_rq_count_integrity_sg(rq->q, bio);

Hmm. The current model is that drivers are supposed to clal this, which they should stop doing now that the block layer maintains this count. So I think this needs a bit more work, after which blk_rq_count_integrity_sg is also unexported, nad preferably also has a name that drops the incorrect _sg.

Sure, I have a larger patch set in the works doing pretty much that. I wanted the request's existing field to be accurate first because inaccurate values break merging. But I can post the rest of series if you prefer to see drivers rely on the existing field instead of recounting the segments.