All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RESEND] block: fix discard request merge
@ 2021-06-28  2:33 Ming Lei
  2021-06-29 13:41 ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Ming Lei @ 2021-06-28  2:33 UTC (permalink / raw
  To: Jens Axboe; +Cc: linux-block, Ming Lei, Christoph Hellwig, Wang Shanker

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.

Cc: Christoph Hellwig <hch@lst.de>
Reported-by: Wang Shanker <shankerwangmiao@gmail.com>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 block/blk-merge.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/block/blk-merge.c b/block/blk-merge.c
index 5c9d2a4ece86..a4afa488298e 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -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;
 
 	/*
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH RESEND] block: fix discard request merge
  2021-06-28  2:33 [PATCH RESEND] block: fix discard request merge Ming Lei
@ 2021-06-29 13:41 ` Jens Axboe
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2021-06-29 13:41 UTC (permalink / raw
  To: Ming Lei; +Cc: linux-block, Christoph Hellwig, Wang Shanker

On 6/27/21 8:33 PM, Ming Lei wrote:
> 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.

Applied, thanks.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-06-29 13:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-06-28  2:33 [PATCH RESEND] block: fix discard request merge Ming Lei
2021-06-29 13:41 ` Jens Axboe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.