linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Move blk_mq_submit_bio() error handling
@ 2024-12-16 20:18 Bart Van Assche
  2024-12-16 20:19 ` [PATCH 1/2] block: Optimize blk_mq_submit_bio() for the cache hit scenario Bart Van Assche
  2024-12-16 20:19 ` [PATCH 2/2] blk-mq: Move more error handling into blk_mq_submit_bio() Bart Van Assche
  0 siblings, 2 replies; 11+ messages in thread
From: Bart Van Assche @ 2024-12-16 20:18 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-block, Christoph Hellwig, Damien Le Moal, Bart Van Assche

Hi Jens,

Some of the blk_mq_submit_bio() error handling occurs in that function itself
while the remaining error handling code occurs in functions called by
blk_mq_submit_bio(). This patch series makes blk_mq_submit_bio() easier to
understand by moving all error handling code into blk_mq_submit_bio(). No
functionality has been changed.

Please consider this patch series for the next merge window.

Thanks,

Bart.

Bart Van Assche (2):
  block: Optimize blk_mq_submit_bio() for the cache hit scenario
  blk-mq: Move more error handling into blk_mq_submit_bio()

 block/blk-mq.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)


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

* [PATCH 1/2] block: Optimize blk_mq_submit_bio() for the cache hit scenario
  2024-12-16 20:18 [PATCH 0/2] Move blk_mq_submit_bio() error handling Bart Van Assche
@ 2024-12-16 20:19 ` Bart Van Assche
  2024-12-17  4:16   ` Christoph Hellwig
  2024-12-16 20:19 ` [PATCH 2/2] blk-mq: Move more error handling into blk_mq_submit_bio() Bart Van Assche
  1 sibling, 1 reply; 11+ messages in thread
From: Bart Van Assche @ 2024-12-16 20:19 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-block, Christoph Hellwig, Damien Le Moal, Bart Van Assche

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

Cc: Damien Le Moal <dlemoal@kernel.org>
Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 block/blk-mq.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 7ee21346a41e..8d2aab4d9ba9 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -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);

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

* [PATCH 2/2] blk-mq: Move more error handling into blk_mq_submit_bio()
  2024-12-16 20:18 [PATCH 0/2] Move blk_mq_submit_bio() error handling Bart Van Assche
  2024-12-16 20:19 ` [PATCH 1/2] block: Optimize blk_mq_submit_bio() for the cache hit scenario Bart Van Assche
@ 2024-12-16 20:19 ` Bart Van Assche
  2024-12-17  4:18   ` Christoph Hellwig
  1 sibling, 1 reply; 11+ messages in thread
From: Bart Van Assche @ 2024-12-16 20:19 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-block, Christoph Hellwig, Damien Le Moal, 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 <dlemoal@kernel.org>
Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 block/blk-mq.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 8d2aab4d9ba9..80eb91296142 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -2971,8 +2971,6 @@ static struct request *blk_mq_get_new_requests(struct request_queue *q,
 	if (rq)
 		return rq;
 	rq_qos_cleanup(q, bio);
-	if (bio->bi_opf & REQ_NOWAIT)
-		bio_wouldblock_error(bio);
 	return NULL;
 }
 
@@ -3106,8 +3104,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);

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

* Re: [PATCH 1/2] block: Optimize blk_mq_submit_bio() for the cache hit scenario
  2024-12-16 20:19 ` [PATCH 1/2] block: Optimize blk_mq_submit_bio() for the cache hit scenario Bart Van Assche
@ 2024-12-17  4:16   ` Christoph Hellwig
  2024-12-17 19:22     ` Bart Van Assche
  0 siblings, 1 reply; 11+ messages in thread
From: Christoph Hellwig @ 2024-12-17  4:16 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: Jens Axboe, linux-block, Christoph Hellwig, Damien Le Moal

On Mon, Dec 16, 2024 at 12:19:00PM -0800, Bart Van Assche wrote:
> Help the CPU branch predictor in case of a cache hit by handling the cache
> hit scenario first.

Numbers, please.


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

* Re: [PATCH 2/2] blk-mq: Move more error handling into blk_mq_submit_bio()
  2024-12-16 20:19 ` [PATCH 2/2] blk-mq: Move more error handling into blk_mq_submit_bio() Bart Van Assche
@ 2024-12-17  4:18   ` Christoph Hellwig
  2024-12-17 21:06     ` Bart Van Assche
  0 siblings, 1 reply; 11+ messages in thread
From: Christoph Hellwig @ 2024-12-17  4:18 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: Jens Axboe, linux-block, Christoph Hellwig, Damien Le Moal

On Mon, Dec 16, 2024 at 12:19:01PM -0800, Bart Van Assche wrote:
> diff --git a/block/blk-mq.c b/block/blk-mq.c
> index 8d2aab4d9ba9..80eb91296142 100644
> --- a/block/blk-mq.c
> +++ b/block/blk-mq.c
> @@ -2971,8 +2971,6 @@ static struct request *blk_mq_get_new_requests(struct request_queue *q,
>  	if (rq)
>  		return rq;
>  	rq_qos_cleanup(q, bio);
> -	if (bio->bi_opf & REQ_NOWAIT)
> -		bio_wouldblock_error(bio);
>  	return NULL;

Please turn this into:

	if (rq)
		rq_qos_cleanup(q, bio);
	return rq;

Otherwise this looks like a nice cleanup.


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

* Re: [PATCH 1/2] block: Optimize blk_mq_submit_bio() for the cache hit scenario
  2024-12-17  4:16   ` Christoph Hellwig
@ 2024-12-17 19:22     ` Bart Van Assche
  2024-12-17 21:15       ` Jens Axboe
  2024-12-18  6:59       ` Christoph Hellwig
  0 siblings, 2 replies; 11+ messages in thread
From: Bart Van Assche @ 2024-12-17 19:22 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Jens Axboe, linux-block, Damien Le Moal

On 12/16/24 8:16 PM, Christoph Hellwig wrote:
> On Mon, Dec 16, 2024 at 12:19:00PM -0800, Bart Van Assche wrote:
>> Help the CPU branch predictor in case of a cache hit by handling the cache
>> hit scenario first.
> 
> Numbers, please.

For a single CPU core and with the brd driver and fio and the io_uring
I/O engine, I see the following performance in a VM (three test runs for
each test case):

Without this patch:      1619K, 1641K, 1638K IOPS or 1633 K +/- 10 K.
With this patch applied: 1650K, 1633K, 1635K IOPS or 1639 K +/-  8 K.

So there is a small performance improvement but the improvement is
smaller than the measurement error. Is this sufficient data to proceed
with this patch?

Thanks,

Bart.


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

* Re: [PATCH 2/2] blk-mq: Move more error handling into blk_mq_submit_bio()
  2024-12-17  4:18   ` Christoph Hellwig
@ 2024-12-17 21:06     ` Bart Van Assche
  2024-12-18  7:00       ` Christoph Hellwig
  0 siblings, 1 reply; 11+ messages in thread
From: Bart Van Assche @ 2024-12-17 21:06 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Jens Axboe, linux-block, Damien Le Moal

On 12/16/24 8:18 PM, Christoph Hellwig wrote:
> On Mon, Dec 16, 2024 at 12:19:01PM -0800, Bart Van Assche wrote:
>> diff --git a/block/blk-mq.c b/block/blk-mq.c
>> index 8d2aab4d9ba9..80eb91296142 100644
>> --- a/block/blk-mq.c
>> +++ b/block/blk-mq.c
>> @@ -2971,8 +2971,6 @@ static struct request *blk_mq_get_new_requests(struct request_queue *q,
>>   	if (rq)
>>   		return rq;
>>   	rq_qos_cleanup(q, bio);
>> -	if (bio->bi_opf & REQ_NOWAIT)
>> -		bio_wouldblock_error(bio);
>>   	return NULL;
> 
> Please turn this into:
> 
> 	if (rq)
> 		rq_qos_cleanup(q, bio);
> 	return rq;
> 
> Otherwise this looks like a nice cleanup.

It seems to me that there is a typo in the above code? Unless if you 
tell me otherwise, I will assume that this is what you meant:

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 8d2aab4d9ba9..f4300e608ed8 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -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 (!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);



Thanks,

Bart.

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

* Re: [PATCH 1/2] block: Optimize blk_mq_submit_bio() for the cache hit scenario
  2024-12-17 19:22     ` Bart Van Assche
@ 2024-12-17 21:15       ` Jens Axboe
  2024-12-18  6:59       ` Christoph Hellwig
  1 sibling, 0 replies; 11+ messages in thread
From: Jens Axboe @ 2024-12-17 21:15 UTC (permalink / raw)
  To: Bart Van Assche, Christoph Hellwig; +Cc: linux-block, Damien Le Moal

On 12/17/24 12:22 PM, Bart Van Assche wrote:
> On 12/16/24 8:16 PM, Christoph Hellwig wrote:
>> On Mon, Dec 16, 2024 at 12:19:00PM -0800, Bart Van Assche wrote:
>>> Help the CPU branch predictor in case of a cache hit by handling the cache
>>> hit scenario first.
>>
>> Numbers, please.
> 
> For a single CPU core and with the brd driver and fio and the io_uring
> I/O engine, I see the following performance in a VM (three test runs for
> each test case):
> 
> Without this patch:      1619K, 1641K, 1638K IOPS or 1633 K +/- 10 K.
> With this patch applied: 1650K, 1633K, 1635K IOPS or 1639 K +/-  8 K.
> 
> So there is a small performance improvement but the improvement is
> smaller than the measurement error. Is this sufficient data to proceed
> with this patch?

I think it's fine, it's going to be very hard to reliably measure. I
tend to prefer the expected case to be the one checked for, eg:

rq = get_cached();
if (rq)
	...

anyway, as then the expected outcome is what you're reading next
anyway. Either that or

rq = get_cached();
if (unlikely(!rq))
	goto some_failure_path;

If you really wanted to measure it, you'd probably skip the IOPS
part and just look at branch misprediction in perf.

-- 
Jens Axboe


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

* Re: [PATCH 1/2] block: Optimize blk_mq_submit_bio() for the cache hit scenario
  2024-12-17 19:22     ` Bart Van Assche
  2024-12-17 21:15       ` Jens Axboe
@ 2024-12-18  6:59       ` Christoph Hellwig
  2024-12-18 18:22         ` Bart Van Assche
  1 sibling, 1 reply; 11+ messages in thread
From: Christoph Hellwig @ 2024-12-18  6:59 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: Christoph Hellwig, Jens Axboe, linux-block, Damien Le Moal

On Tue, Dec 17, 2024 at 11:22:47AM -0800, Bart Van Assche wrote:
> For a single CPU core and with the brd driver and fio and the io_uring
> I/O engine, I see the following performance in a VM (three test runs for
> each test case):
>
> Without this patch:      1619K, 1641K, 1638K IOPS or 1633 K +/- 10 K.
> With this patch applied: 1650K, 1633K, 1635K IOPS or 1639 K +/-  8 K.
>
> So there is a small performance improvement but the improvement is
> smaller than the measurement error. Is this sufficient data to proceed
> with this patch?

I think it's sufficient data that should not claim that it is an
optimizations.  The resulting code still looks nicer to me, but
arguing with optimizations feels like BS.


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

* Re: [PATCH 2/2] blk-mq: Move more error handling into blk_mq_submit_bio()
  2024-12-17 21:06     ` Bart Van Assche
@ 2024-12-18  7:00       ` Christoph Hellwig
  0 siblings, 0 replies; 11+ messages in thread
From: Christoph Hellwig @ 2024-12-18  7:00 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: Christoph Hellwig, Jens Axboe, linux-block, Damien Le Moal

On Tue, Dec 17, 2024 at 01:06:12PM -0800, Bart Van Assche wrote:
> It seems to me that there is a typo in the above code? Unless if you tell 
> me otherwise, I will assume that this is what you meant:

Yes.


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

* Re: [PATCH 1/2] block: Optimize blk_mq_submit_bio() for the cache hit scenario
  2024-12-18  6:59       ` Christoph Hellwig
@ 2024-12-18 18:22         ` Bart Van Assche
  0 siblings, 0 replies; 11+ messages in thread
From: Bart Van Assche @ 2024-12-18 18:22 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Jens Axboe, linux-block, Damien Le Moal

On 12/17/24 10:59 PM, Christoph Hellwig wrote:
> On Tue, Dec 17, 2024 at 11:22:47AM -0800, Bart Van Assche wrote:
>> For a single CPU core and with the brd driver and fio and the io_uring
>> I/O engine, I see the following performance in a VM (three test runs for
>> each test case):
>>
>> Without this patch:      1619K, 1641K, 1638K IOPS or 1633 K +/- 10 K.
>> With this patch applied: 1650K, 1633K, 1635K IOPS or 1639 K +/-  8 K.
>>
>> So there is a small performance improvement but the improvement is
>> smaller than the measurement error. Is this sufficient data to proceed
>> with this patch?
> 
> I think it's sufficient data that should not claim that it is an
> optimizations.  The resulting code still looks nicer to me, but
> arguing with optimizations feels like BS.

I will change the patch title.

Thanks,

Bart.



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

end of thread, other threads:[~2024-12-18 18:22 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-16 20:18 [PATCH 0/2] Move blk_mq_submit_bio() error handling Bart Van Assche
2024-12-16 20:19 ` [PATCH 1/2] block: Optimize blk_mq_submit_bio() for the cache hit scenario Bart Van Assche
2024-12-17  4:16   ` Christoph Hellwig
2024-12-17 19:22     ` Bart Van Assche
2024-12-17 21:15       ` Jens Axboe
2024-12-18  6:59       ` Christoph Hellwig
2024-12-18 18:22         ` Bart Van Assche
2024-12-16 20:19 ` [PATCH 2/2] blk-mq: Move more error handling into blk_mq_submit_bio() Bart Van Assche
2024-12-17  4:18   ` Christoph Hellwig
2024-12-17 21:06     ` Bart Van Assche
2024-12-18  7:00       ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).