Skip to contentSkip to conversation

Two blk_mq_submit_bio() patches

PATCH Applied Bart Van Assche 4 participants 8 messages Dec 18, 2024 – Jan 14, 2025 Block layer

lore
Share & tools
lore
#0 lore raw

v3 cover Two blk_mq_submit_bio() patches

Hi Jens,

This patch series includes two cleanup patches for blk_mq_submit_bio(). No functionality has been changed.

Please consider this patch series for the next merge window.

Thanks,

Bart.

Changes compared to v2 of this patch series:
- Changed the title of the first patch.
- Added unlikely() in the second patch.
- Dropped the patch that was added as the third patch.

Changes compared to v1 of this patch series:
- Addressed Christoph's comments on patch 2/3.
- Added patch 3/3 to this series.

Bart Van Assche (2):
block: Reorder the request allocation code in blk_mq_submit_bio()
blk-mq: Move more error handling into blk_mq_submit_bio()

 block/blk-mq.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
#1 lore raw

PATCH v3 1/2 block: Reorder the request allocation code in blk_mq_submit_bio()

Help the CPU branch predictor in case of a cache hit by handling the cache hit scenario first.

---
 block/blk-mq.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
block/blk-mq.c +3 -3
index 7ee21346a41e..8d2aab4d9ba9 100644
@@ -3102,12 +3102,12 @@ void blk_mq_submit_bio(struct bio *bio)
 		goto queue_exit;
 
 new_request:
-	if (!rq) {
+	if (rq) {
+		blk_mq_use_cached_rq(rq, plug, bio);
+	} else {
 		rq = blk_mq_get_new_requests(q, plug, bio, nr_segs);
 		if (unlikely(!rq))
 			goto queue_exit;
-	} else {
-		blk_mq_use_cached_rq(rq, plug, bio);
 	}
 
 	trace_block_getrq(bio);
Reviewed-by on v3 1/2
#3 lore raw

Re: [PATCH v3 1/2] block: Reorder the request allocation code in blk_mq_submit_bio()

In reply to Bart Van Assche
Quoted 6 lines · Bart Van Assche

Help the CPU branch predictor in case of a cache hit by handling the cache hit scenario first.

Looks good.

-ck

#4 lore raw

PATCH v3 2/2 blk-mq: Move more error handling into blk_mq_submit_bio()

In reply to Bart Van Assche

The error handling code in blk_mq_get_new_requests() cannot be understood without knowing that this function is only called by blk_mq_submit_bio(). Hence move the code for handling blk_mq_get_new_requests() failures into blk_mq_submit_bio().

Cc Damien Le Moal <[email protected]>
Cc Christoph Hellwig <[email protected]>
---
 block/blk-mq.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
block/blk-mq.c +7 -7
index 8d2aab4d9ba9..a83ec9368df6 100644
@@ -2968,12 +2968,9 @@ static struct request *blk_mq_get_new_requests(struct request_queue *q,
 	}
 
 	rq = __blk_mq_alloc_requests(&data);
-	if (rq)
-		return rq;
-	rq_qos_cleanup(q, bio);
-	if (bio->bi_opf & REQ_NOWAIT)
-		bio_wouldblock_error(bio);
-	return NULL;
+	if (unlikely(!rq))
+		rq_qos_cleanup(q, bio);
+	return rq;
 }
 
 /*
@@ -3106,8 +3103,11 @@ void blk_mq_submit_bio(struct bio *bio)
 		blk_mq_use_cached_rq(rq, plug, bio);
 	} else {
 		rq = blk_mq_get_new_requests(q, plug, bio, nr_segs);
-		if (unlikely(!rq))
+		if (unlikely(!rq)) {
+			if (bio->bi_opf & REQ_NOWAIT)
+				bio_wouldblock_error(bio);
 			goto queue_exit;
+		}
 	}
 
 	trace_block_getrq(bio);
Reviewed-by on v3 2/2
#6 lore raw

Re: [PATCH v3 2/2] blk-mq: Move more error handling into blk_mq_submit_bio()

In reply to Bart Van Assche
Quoted 9 lines · Bart Van Assche

The error handling code in blk_mq_get_new_requests() cannot be understood without knowing that this function is only called by blk_mq_submit_bio(). Hence move the code for handling blk_mq_get_new_requests() failures into blk_mq_submit_bio().

Cc Damien Le Moal<[email protected]>
Cc Christoph Hellwig<[email protected]>

---

Looks good.

-ck

maintainer Applied
#7 lore raw
In reply to Bart Van Assche
Quoted 8 lines · Bart Van Assche

This patch series includes two cleanup patches for blk_mq_submit_bio(). No functionality has been changed.

Please consider this patch series for the next merge window.

Thanks,

[...]

Applied, thanks!

[1/2] block: Reorder the request allocation code in blk_mq_submit_bio()

      commit: 44e41381591dc5b4ea67a9f170b4ec85c817586e
[2/2] blk-mq: Move more error handling into blk_mq_submit_bio()
      commit: 659381520a3b13403c3051516317adc02e48259b

Best regards,

Signature · 1 line
Jens Axboe