diff mbox series

[PATCHv3,10/10] blk-merge: properly account for integrity segments

Message ID 20240904152605.4055570-11-kbusch@meta.com (mailing list archive)
State Superseded
Headers show
Series block integrity merging and counting | expand

Commit Message

Keith Busch Sept. 4, 2024, 3:26 p.m. UTC
From: Keith Busch <kbusch@kernel.org>

Merging two requests wasn't accounting for the new segment count, so add
the "next" segement count to the first on a successful merge.

Merging a bio into an existing request was double counting the bio's
segments, even if the merge failed later on. Move the segment accounting
to the end when the merge is successful.

Signed-off-by: Keith Busch <kbusch@kernel.org>
---
 block/blk-integrity.c | 2 --
 block/blk-merge.c     | 7 +++++++
 2 files changed, 7 insertions(+), 2 deletions(-)

Comments

Anuj Gupta Sept. 6, 2024, 11:28 a.m. UTC | #1
On 04/09/24 08:26AM, Keith Busch wrote:
>From: Keith Busch <kbusch@kernel.org>
>
>Merging two requests wasn't accounting for the new segment count, so add
>the "next" segement count to the first on a successful merge.

Nit: s/segement/segment
Christoph Hellwig Sept. 10, 2024, 3:49 p.m. UTC | #2
Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>
diff mbox series

Patch

diff --git a/block/blk-integrity.c b/block/blk-integrity.c
index 985de64409cf5..4222c78eab18f 100644
--- a/block/blk-integrity.c
+++ b/block/blk-integrity.c
@@ -107,8 +107,6 @@  bool blk_integrity_merge_bio(struct request_queue *q, struct request *req,
 	    q->limits.max_integrity_segments)
 		return false;
 
-	req->nr_integrity_segments += nr_integrity_segs;
-
 	return true;
 }
 
diff --git a/block/blk-merge.c b/block/blk-merge.c
index 43ab1ce09de65..734e6e22a6d22 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -639,6 +639,10 @@  static inline int ll_new_hw_segment(struct request *req, struct bio *bio,
 	 * counters.
 	 */
 	req->nr_phys_segments += nr_phys_segs;
+#if defined(CONFIG_BLK_DEV_INTEGRITY)
+	if (bio->bi_opf & REQ_INTEGRITY)
+		req->nr_integrity_segments += blk_rq_count_integrity_segs(bio);
+#endif
 	return 1;
 
 no_merge:
@@ -725,6 +729,9 @@  static int ll_merge_requests_fn(struct request_queue *q, struct request *req,
 
 	/* Merge is OK... */
 	req->nr_phys_segments = total_phys_segments;
+#if defined(CONFIG_BLK_DEV_INTEGRITY)
+	req->nr_integrity_segments += next->nr_integrity_segments;
+#endif
 	return 1;
 }