All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: Keith Busch <keith.busch@intel.com>
Cc: Jens Axboe <axboe@kernel.dk>,
	linux-nvme@lists.infradead.org, linux-block@vger.kernel.org,
	Christoph Hellwig <hch@lst.de>,
	Bart Van Assche <bart.vanassche@wdc.com>
Subject: Re: [RFC PATCH 1/3] blk-mq: Reference count request usage
Date: Tue, 22 May 2018 10:27:11 +0800	[thread overview]
Message-ID: <20180522022710.GB20430@ming.t460p> (raw)
In-Reply-To: <20180521231131.6685-2-keith.busch@intel.com>

On Mon, May 21, 2018 at 05:11:29PM -0600, Keith Busch wrote:
> This patch adds a struct kref to struct request so that request users
> can be sure they're operating on the same request without it changing
> while they're processing it. The request's tag won't be released for
> reuse until the last user is done with it.
> 
> Signed-off-by: Keith Busch <keith.busch@intel.com>
> ---
>  block/blk-mq.c         | 30 +++++++++++++++++++++++-------
>  include/linux/blkdev.h |  2 ++
>  2 files changed, 25 insertions(+), 7 deletions(-)
> 
> diff --git a/block/blk-mq.c b/block/blk-mq.c
> index 4cbfd784e837..8b370ed75605 100644
> --- a/block/blk-mq.c
> +++ b/block/blk-mq.c
> @@ -332,6 +332,7 @@ static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data,
>  #endif
>  
>  	data->ctx->rq_dispatched[op_is_sync(op)]++;
> +	kref_init(&rq->ref);
>  	return rq;
>  }
>  
> @@ -465,13 +466,33 @@ struct request *blk_mq_alloc_request_hctx(struct request_queue *q,
>  }
>  EXPORT_SYMBOL_GPL(blk_mq_alloc_request_hctx);
>  
> +static void blk_mq_exit_request(struct kref *ref)
> +{
> +	struct request *rq = container_of(ref, struct request, ref);
> +	struct request_queue *q = rq->q;
> +	struct blk_mq_ctx *ctx = rq->mq_ctx;
> +	struct blk_mq_hw_ctx *hctx = blk_mq_map_queue(q, ctx->cpu);
> +	const int sched_tag = rq->internal_tag;
> +
> +	if (rq->tag != -1)
> +		blk_mq_put_tag(hctx, hctx->tags, ctx, rq->tag);
> +	if (sched_tag != -1)
> +		blk_mq_put_tag(hctx, hctx->sched_tags, ctx, sched_tag);
> +	blk_mq_sched_restart(hctx);
> +	blk_queue_exit(q);
> +}
> +
> +static void blk_mq_put_request(struct request *rq)
> +{
> +       kref_put(&rq->ref, blk_mq_exit_request);
> +}
> +
>  void blk_mq_free_request(struct request *rq)
>  {
>  	struct request_queue *q = rq->q;
>  	struct elevator_queue *e = q->elevator;
>  	struct blk_mq_ctx *ctx = rq->mq_ctx;
>  	struct blk_mq_hw_ctx *hctx = blk_mq_map_queue(q, ctx->cpu);
> -	const int sched_tag = rq->internal_tag;
>  
>  	if (rq->rq_flags & RQF_ELVPRIV) {
>  		if (e && e->type->ops.mq.finish_request)
> @@ -495,12 +516,7 @@ void blk_mq_free_request(struct request *rq)
>  		blk_put_rl(blk_rq_rl(rq));
>  
>  	blk_mq_rq_update_state(rq, MQ_RQ_IDLE);
> -	if (rq->tag != -1)
> -		blk_mq_put_tag(hctx, hctx->tags, ctx, rq->tag);
> -	if (sched_tag != -1)
> -		blk_mq_put_tag(hctx, hctx->sched_tags, ctx, sched_tag);
> -	blk_mq_sched_restart(hctx);
> -	blk_queue_exit(q);
> +	blk_mq_put_request(rq);

Both the above line(atomic_try_cmpxchg_release is implied) and kref_init()
in blk_mq_rq_ctx_init() are run from fast path, and may introduce some cost,
you may have to run some benchmark to show if there is effect.

Also given the cost isn't free, could you describe a bit in comment log
what we can get with the cost?

Thanks,
Ming

WARNING: multiple messages have this Message-ID (diff)
From: ming.lei@redhat.com (Ming Lei)
Subject: [RFC PATCH 1/3] blk-mq: Reference count request usage
Date: Tue, 22 May 2018 10:27:11 +0800	[thread overview]
Message-ID: <20180522022710.GB20430@ming.t460p> (raw)
In-Reply-To: <20180521231131.6685-2-keith.busch@intel.com>

On Mon, May 21, 2018@05:11:29PM -0600, Keith Busch wrote:
> This patch adds a struct kref to struct request so that request users
> can be sure they're operating on the same request without it changing
> while they're processing it. The request's tag won't be released for
> reuse until the last user is done with it.
> 
> Signed-off-by: Keith Busch <keith.busch at intel.com>
> ---
>  block/blk-mq.c         | 30 +++++++++++++++++++++++-------
>  include/linux/blkdev.h |  2 ++
>  2 files changed, 25 insertions(+), 7 deletions(-)
> 
> diff --git a/block/blk-mq.c b/block/blk-mq.c
> index 4cbfd784e837..8b370ed75605 100644
> --- a/block/blk-mq.c
> +++ b/block/blk-mq.c
> @@ -332,6 +332,7 @@ static struct request *blk_mq_rq_ctx_init(struct blk_mq_alloc_data *data,
>  #endif
>  
>  	data->ctx->rq_dispatched[op_is_sync(op)]++;
> +	kref_init(&rq->ref);
>  	return rq;
>  }
>  
> @@ -465,13 +466,33 @@ struct request *blk_mq_alloc_request_hctx(struct request_queue *q,
>  }
>  EXPORT_SYMBOL_GPL(blk_mq_alloc_request_hctx);
>  
> +static void blk_mq_exit_request(struct kref *ref)
> +{
> +	struct request *rq = container_of(ref, struct request, ref);
> +	struct request_queue *q = rq->q;
> +	struct blk_mq_ctx *ctx = rq->mq_ctx;
> +	struct blk_mq_hw_ctx *hctx = blk_mq_map_queue(q, ctx->cpu);
> +	const int sched_tag = rq->internal_tag;
> +
> +	if (rq->tag != -1)
> +		blk_mq_put_tag(hctx, hctx->tags, ctx, rq->tag);
> +	if (sched_tag != -1)
> +		blk_mq_put_tag(hctx, hctx->sched_tags, ctx, sched_tag);
> +	blk_mq_sched_restart(hctx);
> +	blk_queue_exit(q);
> +}
> +
> +static void blk_mq_put_request(struct request *rq)
> +{
> +       kref_put(&rq->ref, blk_mq_exit_request);
> +}
> +
>  void blk_mq_free_request(struct request *rq)
>  {
>  	struct request_queue *q = rq->q;
>  	struct elevator_queue *e = q->elevator;
>  	struct blk_mq_ctx *ctx = rq->mq_ctx;
>  	struct blk_mq_hw_ctx *hctx = blk_mq_map_queue(q, ctx->cpu);
> -	const int sched_tag = rq->internal_tag;
>  
>  	if (rq->rq_flags & RQF_ELVPRIV) {
>  		if (e && e->type->ops.mq.finish_request)
> @@ -495,12 +516,7 @@ void blk_mq_free_request(struct request *rq)
>  		blk_put_rl(blk_rq_rl(rq));
>  
>  	blk_mq_rq_update_state(rq, MQ_RQ_IDLE);
> -	if (rq->tag != -1)
> -		blk_mq_put_tag(hctx, hctx->tags, ctx, rq->tag);
> -	if (sched_tag != -1)
> -		blk_mq_put_tag(hctx, hctx->sched_tags, ctx, sched_tag);
> -	blk_mq_sched_restart(hctx);
> -	blk_queue_exit(q);
> +	blk_mq_put_request(rq);

Both the above line(atomic_try_cmpxchg_release is implied) and kref_init()
in blk_mq_rq_ctx_init() are run from fast path, and may introduce some cost,
you may have to run some benchmark to show if there is effect.

Also given the cost isn't free, could you describe a bit in comment log
what we can get with the cost?

Thanks,
Ming

  reply	other threads:[~2018-05-22  2:27 UTC|newest]

Thread overview: 128+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-21 23:11 [RFC PATCH 0/3] blk-mq: Timeout rework Keith Busch
2018-05-21 23:11 ` Keith Busch
2018-05-21 23:11 ` [RFC PATCH 1/3] blk-mq: Reference count request usage Keith Busch
2018-05-21 23:11   ` Keith Busch
2018-05-22  2:27   ` Ming Lei [this message]
2018-05-22  2:27     ` Ming Lei
2018-05-22 15:19   ` Christoph Hellwig
2018-05-22 15:19     ` Christoph Hellwig
2018-05-21 23:11 ` [RFC PATCH 2/3] blk-mq: Fix timeout and state order Keith Busch
2018-05-21 23:11   ` Keith Busch
2018-05-22  2:28   ` Ming Lei
2018-05-22  2:28     ` Ming Lei
2018-05-22 15:24   ` Christoph Hellwig
2018-05-22 15:24     ` Christoph Hellwig
2018-05-22 16:27     ` Bart Van Assche
2018-05-22 16:27       ` Bart Van Assche
2018-05-21 23:11 ` [RFC PATCH 3/3] blk-mq: Remove generation seqeunce Keith Busch
2018-05-21 23:11   ` Keith Busch
2018-05-21 23:29   ` Bart Van Assche
2018-05-21 23:29     ` Bart Van Assche
2018-05-22 14:15     ` Keith Busch
2018-05-22 14:15       ` Keith Busch
2018-05-22 16:29       ` Bart Van Assche
2018-05-22 16:29         ` Bart Van Assche
2018-05-22 16:34         ` Keith Busch
2018-05-22 16:34           ` Keith Busch
2018-05-22 16:48           ` Bart Van Assche
2018-05-22 16:48             ` Bart Van Assche
2018-05-22  2:49   ` Ming Lei
2018-05-22  2:49     ` Ming Lei
2018-05-22  3:16     ` Jens Axboe
2018-05-22  3:16       ` Jens Axboe
2018-05-22  3:47       ` Ming Lei
2018-05-22  3:47         ` Ming Lei
2018-05-22  3:51         ` Jens Axboe
2018-05-22  3:51           ` Jens Axboe
2018-05-22  8:51           ` Ming Lei
2018-05-22  8:51             ` Ming Lei
2018-05-22 14:35             ` Jens Axboe
2018-05-22 14:35               ` Jens Axboe
2018-05-22 14:20     ` Keith Busch
2018-05-22 14:20       ` Keith Busch
2018-05-22 14:37       ` Ming Lei
2018-05-22 14:37         ` Ming Lei
2018-05-22 14:46         ` Keith Busch
2018-05-22 14:46           ` Keith Busch
2018-05-22 14:57           ` Ming Lei
2018-05-22 14:57             ` Ming Lei
2018-05-22 15:01             ` Keith Busch
2018-05-22 15:01               ` Keith Busch
2018-05-22 15:07               ` Ming Lei
2018-05-22 15:07                 ` Ming Lei
2018-05-22 15:17                 ` Keith Busch
2018-05-22 15:17                   ` Keith Busch
2018-05-22 15:23                   ` Ming Lei
2018-05-22 15:23                     ` Ming Lei
2018-05-22 16:17   ` Christoph Hellwig
2018-05-22 16:17     ` Christoph Hellwig
2018-05-23  0:34     ` Ming Lei
2018-05-23  0:34       ` Ming Lei
2018-05-23 14:35       ` Keith Busch
2018-05-23 14:35         ` Keith Busch
2018-05-24  1:52         ` Ming Lei
2018-05-24  1:52           ` Ming Lei
2018-05-23  5:48     ` Hannes Reinecke
2018-05-23  5:48       ` Hannes Reinecke
2018-07-12 18:16   ` Bart Van Assche
2018-07-12 18:16     ` Bart Van Assche
2018-07-12 19:24     ` Keith Busch
2018-07-12 19:24       ` Keith Busch
2018-07-12 22:24       ` Bart Van Assche
2018-07-12 22:24         ` Bart Van Assche
2018-07-13  1:12         ` jianchao.wang
2018-07-13  1:12           ` jianchao.wang
2018-07-13  2:40         ` jianchao.wang
2018-07-13  2:40           ` jianchao.wang
2018-07-13 15:43         ` Keith Busch
2018-07-13 15:43           ` Keith Busch
2018-07-13 15:52           ` Bart Van Assche
2018-07-13 15:52             ` Bart Van Assche
2018-07-13 18:47             ` Keith Busch
2018-07-13 18:47               ` Keith Busch
2018-07-13 23:03               ` Bart Van Assche
2018-07-13 23:03                 ` Bart Van Assche
2018-07-13 23:58                 ` Keith Busch
2018-07-13 23:58                   ` Keith Busch
2018-07-18 19:56                   ` hch
2018-07-18 19:56                     ` hch
2018-07-18 20:39                     ` hch
2018-07-18 20:39                       ` hch
2018-07-18 21:05                       ` Bart Van Assche
2018-07-18 21:05                         ` Bart Van Assche
2018-07-18 22:53                       ` Keith Busch
2018-07-18 22:53                         ` Keith Busch
2018-07-18 20:53                     ` Keith Busch
2018-07-18 20:53                       ` Keith Busch
2018-07-18 20:58                       ` Bart Van Assche
2018-07-18 20:58                         ` Bart Van Assche
2018-07-18 21:17                         ` Keith Busch
2018-07-18 21:17                           ` Keith Busch
2018-07-18 21:30                           ` Bart Van Assche
2018-07-18 21:30                             ` Bart Van Assche
2018-07-18 21:33                             ` Keith Busch
2018-07-18 21:33                               ` Keith Busch
2018-07-19 13:19                           ` hch
2018-07-19 13:19                             ` hch
2018-07-19 14:59                             ` Keith Busch
2018-07-19 14:59                               ` Keith Busch
2018-07-19 15:56                               ` Keith Busch
2018-07-19 15:56                                 ` Keith Busch
2018-07-19 16:04                                 ` Bart Van Assche
2018-07-19 16:04                                   ` Bart Van Assche
2018-07-19 16:22                                   ` Keith Busch
2018-07-19 16:22                                     ` Keith Busch
2018-07-19 16:29                                     ` hch
2018-07-19 16:29                                       ` hch
2018-07-19 20:18                                       ` Keith Busch
2018-07-19 20:18                                         ` Keith Busch
2018-07-19 13:22                       ` hch
2018-07-19 13:22                         ` hch
2018-05-21 23:29 ` [RFC PATCH 0/3] blk-mq: Timeout rework Bart Van Assche
2018-05-21 23:29   ` Bart Van Assche
2018-05-22 14:06   ` Keith Busch
2018-05-22 14:06     ` Keith Busch
2018-05-22 16:30     ` Bart Van Assche
2018-05-22 16:30       ` Bart Van Assche
2018-05-22 16:44       ` Keith Busch
2018-05-22 16:44         ` Keith Busch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180522022710.GB20430@ming.t460p \
    --to=ming.lei@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=bart.vanassche@wdc.com \
    --cc=hch@lst.de \
    --cc=keith.busch@intel.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.