public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] block: consider discard merge last
@ 2025-11-14 18:31 Keith Busch
  2025-11-16  3:20 ` Chaitanya Kulkarni
  2025-11-17 16:42 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Keith Busch @ 2025-11-14 18:31 UTC (permalink / raw)
  To: linux-block, axboe; +Cc: Keith Busch

From: Keith Busch <kbusch@kernel.org>

If the next discard range is contiguous with the current range being
considered, it's cheaper to expand the current range than to append an
additional bio.

Signed-off-by: Keith Busch <kbusch@kernel.org>
---
 block/blk-merge.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/block/blk-merge.c b/block/blk-merge.c
index d3115d7469df0..db08bc9060916 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -712,10 +712,10 @@ static void blk_account_io_merge_request(struct request *req)
 static enum elv_merge blk_try_req_merge(struct request *req,
 					struct request *next)
 {
-	if (blk_discard_mergable(req))
-		return ELEVATOR_DISCARD_MERGE;
-	else if (blk_rq_pos(req) + blk_rq_sectors(req) == blk_rq_pos(next))
+	if (blk_rq_pos(req) + blk_rq_sectors(req) == blk_rq_pos(next))
 		return ELEVATOR_BACK_MERGE;
+	else if (blk_discard_mergable(req))
+		return ELEVATOR_DISCARD_MERGE;
 
 	return ELEVATOR_NO_MERGE;
 }
@@ -903,12 +903,12 @@ bool blk_rq_merge_ok(struct request *rq, struct bio *bio)
 
 enum elv_merge blk_try_merge(struct request *rq, struct bio *bio)
 {
-	if (blk_discard_mergable(rq))
-		return ELEVATOR_DISCARD_MERGE;
-	else if (blk_rq_pos(rq) + blk_rq_sectors(rq) == bio->bi_iter.bi_sector)
+	if (blk_rq_pos(rq) + blk_rq_sectors(rq) == bio->bi_iter.bi_sector)
 		return ELEVATOR_BACK_MERGE;
 	else if (blk_rq_pos(rq) - bio_sectors(bio) == bio->bi_iter.bi_sector)
 		return ELEVATOR_FRONT_MERGE;
+	else if (blk_discard_mergable(rq))
+		return ELEVATOR_DISCARD_MERGE;
 	return ELEVATOR_NO_MERGE;
 }
 
-- 
2.47.3


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

* Re: [PATCH] block: consider discard merge last
  2025-11-14 18:31 [PATCH] block: consider discard merge last Keith Busch
@ 2025-11-16  3:20 ` Chaitanya Kulkarni
  2025-11-17 16:42 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Chaitanya Kulkarni @ 2025-11-16  3:20 UTC (permalink / raw)
  To: Keith Busch; +Cc: Keith Busch, linux-block@vger.kernel.org, axboe@kernel.dk

On 11/14/25 10:31, Keith Busch wrote:
> From: Keith Busch<kbusch@kernel.org>
>
> If the next discard range is contiguous with the current range being
> considered, it's cheaper to expand the current range than to append an
> additional bio.
>
> Signed-off-by: Keith Busch<kbusch@kernel.org>

Looks good.

Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>

-ck



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

* Re: [PATCH] block: consider discard merge last
  2025-11-14 18:31 [PATCH] block: consider discard merge last Keith Busch
  2025-11-16  3:20 ` Chaitanya Kulkarni
@ 2025-11-17 16:42 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2025-11-17 16:42 UTC (permalink / raw)
  To: linux-block, Keith Busch; +Cc: Keith Busch


On Fri, 14 Nov 2025 10:31:45 -0800, Keith Busch wrote:
> If the next discard range is contiguous with the current range being
> considered, it's cheaper to expand the current range than to append an
> additional bio.
> 
> 

Applied, thanks!

[1/1] block: consider discard merge last
      commit: 2516c246d01c23a5f5310e9ac78d9f8aad9b1d0e

Best regards,
-- 
Jens Axboe




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

end of thread, other threads:[~2025-11-17 16:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-14 18:31 [PATCH] block: consider discard merge last Keith Busch
2025-11-16  3:20 ` Chaitanya Kulkarni
2025-11-17 16:42 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox