Skip to contentSkip to conversation

block: fix discard request merge

PATCH RESEND Applied Ming Lei 2 participants 2 messages Jun 28, 2021 – Jun 29, 2021 Block layer

lore
Share & tools
lore

Ming Lei

author
#0 lore raw

PATCH RESEND 1/1 block: fix discard request merge

ll_new_hw_segment() is reached only in case of single range discard merge, and we don't have max discard segment size limit actually, so it is wrong to run the following check:

if (req->nr_phys_segments + nr_phys_segs > blk_rq_get_max_segments(req))

it may be always false since req->nr_phys_segments is initialized as one, and bio's segment count is still 1, blk_rq_get_max_segments(reg) is 1 too.

Fix the issue by not doing the check and bypassing the calculation of discard request's nr_phys_segments.

Based on analysis from Wang Shanker.

---
 block/blk-merge.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
block/blk-merge.c +6 -2
index 5c9d2a4ece86..a4afa488298e 100644
@@ -559,10 +559,14 @@ static inline unsigned int blk_rq_get_max_segments(struct request *rq)
 static inline int ll_new_hw_segment(struct request *req, struct bio *bio,
 		unsigned int nr_phys_segs)
 {
-	if (req->nr_phys_segments + nr_phys_segs > blk_rq_get_max_segments(req))
+	if (blk_integrity_merge_bio(req->q, req, bio) == false)
 		goto no_merge;
 
-	if (blk_integrity_merge_bio(req->q, req, bio) == false)
+	/* discard request merge won't add new segment */
+	if (req_op(req) == REQ_OP_DISCARD)
+		return 1;
+
+	if (req->nr_phys_segments + nr_phys_segs > blk_rq_get_max_segments(req))
 		goto no_merge;
 
 	/*
Signature · 1 line
2.31.1
maintainer Applied
#1 lore raw
Quoted 6 lines · Ming Lei

ll_new_hw_segment() is reached only in case of single range discard merge, and we don't have max discard segment size limit actually, so it is wrong to run the following check:

if (req->nr_phys_segments + nr_phys_segs > blk_rq_get_max_segments(req))

Quoted 8 lines

it may be always false since req->nr_phys_segments is initialized as one, and bio's segment count is still 1, blk_rq_get_max_segments(reg) is 1 too.

Fix the issue by not doing the check and bypassing the calculation of discard request's nr_phys_segments.

Based on analysis from Wang Shanker.

Applied, thanks.

Signature · 1 line
Jens Axboe