All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] blk-mq: don't grab rq's refcount in blk_mq_check_expired()
@ 2021-08-11 14:38 Ming Lei
  2021-08-11 14:55 ` Keith Busch
  0 siblings, 1 reply; 3+ messages in thread
From: Ming Lei @ 2021-08-11 14:38 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-block, Bart Van Assche, Christoph Hellwig, John Garry, Ming Lei

Inside blk_mq_queue_tag_busy_iter() we already grabbed request's
refcount before calling ->fn(), so needn't to grab it one more time
in blk_mq_check_expired().

Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 block/blk-mq.c | 25 +++++++------------------
 1 file changed, 7 insertions(+), 18 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index d2725f94491d..4d3457d2957f 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -917,6 +917,10 @@ void blk_mq_put_rq_ref(struct request *rq)
 		__blk_mq_free_request(rq);
 }
 
+/*
+ * This request won't be re-allocated because its refcount is held when
+ * calling this callback.
+ */
 static bool blk_mq_check_expired(struct blk_mq_hw_ctx *hctx,
 		struct request *rq, void *priv, bool reserved)
 {
@@ -930,27 +934,12 @@ static bool blk_mq_check_expired(struct blk_mq_hw_ctx *hctx,
 		return true;
 
 	/*
-	 * We have reason to believe the request may be expired. Take a
-	 * reference on the request to lock this request lifetime into its
-	 * currently allocated context to prevent it from being reallocated in
-	 * the event the completion by-passes this timeout handler.
-	 *
-	 * If the reference was already released, then the driver beat the
-	 * timeout handler to posting a natural completion.
-	 */
-	if (!refcount_inc_not_zero(&rq->ref))
-		return true;
-
-	/*
-	 * The request is now locked and cannot be reallocated underneath the
-	 * timeout handler's processing. Re-verify this exact request is truly
-	 * expired; if it is not expired, then the request was completed and
-	 * reallocated as a new request.
+	 * Re-verify this exact request is truly expired; if it is not expired,
+	 * then the request was completed and reallocated as a new request
+	 * after returning from blk_mq_check_expired().
 	 */
 	if (blk_mq_req_expired(rq, next))
 		blk_mq_rq_timed_out(rq, reserved);
-
-	blk_mq_put_rq_ref(rq);
 	return true;
 }
 
-- 
2.31.1


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

* Re: [PATCH] blk-mq: don't grab rq's refcount in blk_mq_check_expired()
  2021-08-11 14:38 [PATCH] blk-mq: don't grab rq's refcount in blk_mq_check_expired() Ming Lei
@ 2021-08-11 14:55 ` Keith Busch
  2021-08-11 15:10   ` Ming Lei
  0 siblings, 1 reply; 3+ messages in thread
From: Keith Busch @ 2021-08-11 14:55 UTC (permalink / raw)
  To: Ming Lei
  Cc: Jens Axboe, linux-block, Bart Van Assche, Christoph Hellwig, John Garry

On Wed, Aug 11, 2021 at 10:38:38PM +0800, Ming Lei wrote:
> Inside blk_mq_queue_tag_busy_iter() we already grabbed request's
> refcount before calling ->fn(), so needn't to grab it one more time
> in blk_mq_check_expired().
> 
> Signed-off-by: Ming Lei <ming.lei@redhat.com>
> ---
>  block/blk-mq.c | 25 +++++++------------------
>  1 file changed, 7 insertions(+), 18 deletions(-)
> 
> diff --git a/block/blk-mq.c b/block/blk-mq.c
> index d2725f94491d..4d3457d2957f 100644
> --- a/block/blk-mq.c
> +++ b/block/blk-mq.c
> @@ -917,6 +917,10 @@ void blk_mq_put_rq_ref(struct request *rq)
>  		__blk_mq_free_request(rq);
>  }
>  
> +/*
> + * This request won't be re-allocated because its refcount is held when
> + * calling this callback.
> + */
>  static bool blk_mq_check_expired(struct blk_mq_hw_ctx *hctx,
>  		struct request *rq, void *priv, bool reserved)
>  {
> @@ -930,27 +934,12 @@ static bool blk_mq_check_expired(struct blk_mq_hw_ctx *hctx,
>  		return true;
>  
>  	/*
> -	 * We have reason to believe the request may be expired. Take a
> -	 * reference on the request to lock this request lifetime into its
> -	 * currently allocated context to prevent it from being reallocated in
> -	 * the event the completion by-passes this timeout handler.
> -	 *
> -	 * If the reference was already released, then the driver beat the
> -	 * timeout handler to posting a natural completion.
> -	 */
> -	if (!refcount_inc_not_zero(&rq->ref))
> -		return true;
> -
> -	/*
> -	 * The request is now locked and cannot be reallocated underneath the
> -	 * timeout handler's processing. Re-verify this exact request is truly
> -	 * expired; if it is not expired, then the request was completed and
> -	 * reallocated as a new request.
> +	 * Re-verify this exact request is truly expired; if it is not expired,
> +	 * then the request was completed and reallocated as a new request
> +	 * after returning from blk_mq_check_expired().
>  	 */
>  	if (blk_mq_req_expired(rq, next))
>  		blk_mq_rq_timed_out(rq, reserved);

There's no need to check expired twice if the iterator is already taking a
reference. I had this double check because I didn't want to penalize normal IO
by preventing it from completing while the timeout handler is running, but it
looks like the current timeout iterator is going to do that anyway.

> -
> -	blk_mq_put_rq_ref(rq);
>  	return true;
>  }

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

* Re: [PATCH] blk-mq: don't grab rq's refcount in blk_mq_check_expired()
  2021-08-11 14:55 ` Keith Busch
@ 2021-08-11 15:10   ` Ming Lei
  0 siblings, 0 replies; 3+ messages in thread
From: Ming Lei @ 2021-08-11 15:10 UTC (permalink / raw)
  To: Keith Busch
  Cc: Jens Axboe, linux-block, Bart Van Assche, Christoph Hellwig, John Garry

On Wed, Aug 11, 2021 at 08:55:25AM -0600, Keith Busch wrote:
> On Wed, Aug 11, 2021 at 10:38:38PM +0800, Ming Lei wrote:
> > Inside blk_mq_queue_tag_busy_iter() we already grabbed request's
> > refcount before calling ->fn(), so needn't to grab it one more time
> > in blk_mq_check_expired().
> > 
> > Signed-off-by: Ming Lei <ming.lei@redhat.com>
> > ---
> >  block/blk-mq.c | 25 +++++++------------------
> >  1 file changed, 7 insertions(+), 18 deletions(-)
> > 
> > diff --git a/block/blk-mq.c b/block/blk-mq.c
> > index d2725f94491d..4d3457d2957f 100644
> > --- a/block/blk-mq.c
> > +++ b/block/blk-mq.c
> > @@ -917,6 +917,10 @@ void blk_mq_put_rq_ref(struct request *rq)
> >  		__blk_mq_free_request(rq);
> >  }
> >  
> > +/*
> > + * This request won't be re-allocated because its refcount is held when
> > + * calling this callback.
> > + */
> >  static bool blk_mq_check_expired(struct blk_mq_hw_ctx *hctx,
> >  		struct request *rq, void *priv, bool reserved)
> >  {
> > @@ -930,27 +934,12 @@ static bool blk_mq_check_expired(struct blk_mq_hw_ctx *hctx,
> >  		return true;
> >  
> >  	/*
> > -	 * We have reason to believe the request may be expired. Take a
> > -	 * reference on the request to lock this request lifetime into its
> > -	 * currently allocated context to prevent it from being reallocated in
> > -	 * the event the completion by-passes this timeout handler.
> > -	 *
> > -	 * If the reference was already released, then the driver beat the
> > -	 * timeout handler to posting a natural completion.
> > -	 */
> > -	if (!refcount_inc_not_zero(&rq->ref))
> > -		return true;
> > -
> > -	/*
> > -	 * The request is now locked and cannot be reallocated underneath the
> > -	 * timeout handler's processing. Re-verify this exact request is truly
> > -	 * expired; if it is not expired, then the request was completed and
> > -	 * reallocated as a new request.
> > +	 * Re-verify this exact request is truly expired; if it is not expired,
> > +	 * then the request was completed and reallocated as a new request
> > +	 * after returning from blk_mq_check_expired().
> >  	 */
> >  	if (blk_mq_req_expired(rq, next))
> >  		blk_mq_rq_timed_out(rq, reserved);
> 
> There's no need to check expired twice if the iterator is already taking a
> reference. I had this double check because I didn't want to penalize normal IO
> by preventing it from completing while the timeout handler is running, but it
> looks like the current timeout iterator is going to do that anyway.

Indeed, will clean that in V2.


Thanks,
Ming


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

end of thread, other threads:[~2021-08-11 15:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-11 14:38 [PATCH] blk-mq: don't grab rq's refcount in blk_mq_check_expired() Ming Lei
2021-08-11 14:55 ` Keith Busch
2021-08-11 15:10   ` Ming Lei

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.