Linux block layer
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: Bart Van Assche <bart.vanassche@sandisk.com>
Cc: Jens Axboe <axboe@kernel.dk>,
	linux-block@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
	Hannes Reinecke <hare@suse.com>, Omar Sandoval <osandov@fb.com>
Subject: Re: [PATCH v3 01/12] blk-mq: Reduce blk_mq_hw_ctx size
Date: Mon, 19 Jun 2017 10:26:36 +0800	[thread overview]
Message-ID: <20170619022631.GB11219@ming.t460p> (raw)
In-Reply-To: <20170608173355.25898-2-bart.vanassche@sandisk.com>

On Thu, Jun 08, 2017 at 10:33:44AM -0700, Bart Van Assche wrote:
> Since the srcu structure is rather large (184 bytes on an x86-64
> system with kernel debugging disabled), only allocate it if needed.
> 
> Reported-by: Ming Lei <ming.lei@redhat.com>
> Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> Cc: Hannes Reinecke <hare@suse.com>
> Cc: Omar Sandoval <osandov@fb.com>
> Cc: Ming Lei <ming.lei@redhat.com>
> ---
>  block/blk-mq.c         | 30 ++++++++++++++++++++++--------
>  include/linux/blk-mq.h |  5 +++--
>  2 files changed, 25 insertions(+), 10 deletions(-)
> 
> diff --git a/block/blk-mq.c b/block/blk-mq.c
> index 4e8b1bc87274..ef64a3ea4e83 100644
> --- a/block/blk-mq.c
> +++ b/block/blk-mq.c
> @@ -172,7 +172,7 @@ void blk_mq_quiesce_queue(struct request_queue *q)
>  
>  	queue_for_each_hw_ctx(q, hctx, i) {
>  		if (hctx->flags & BLK_MQ_F_BLOCKING)
> -			synchronize_srcu(&hctx->queue_rq_srcu);
> +			synchronize_srcu(hctx->queue_rq_srcu);
>  		else
>  			rcu = true;
>  	}
> @@ -1056,9 +1056,9 @@ static void __blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx)
>  	} else {
>  		might_sleep();
>  
> -		srcu_idx = srcu_read_lock(&hctx->queue_rq_srcu);
> +		srcu_idx = srcu_read_lock(hctx->queue_rq_srcu);
>  		blk_mq_sched_dispatch_requests(hctx);
> -		srcu_read_unlock(&hctx->queue_rq_srcu, srcu_idx);
> +		srcu_read_unlock(hctx->queue_rq_srcu, srcu_idx);
>  	}
>  }
>  
> @@ -1460,9 +1460,9 @@ static void blk_mq_try_issue_directly(struct blk_mq_hw_ctx *hctx,
>  
>  		might_sleep();
>  
> -		srcu_idx = srcu_read_lock(&hctx->queue_rq_srcu);
> +		srcu_idx = srcu_read_lock(hctx->queue_rq_srcu);
>  		__blk_mq_try_issue_directly(hctx, rq, cookie, true);
> -		srcu_read_unlock(&hctx->queue_rq_srcu, srcu_idx);
> +		srcu_read_unlock(hctx->queue_rq_srcu, srcu_idx);
>  	}
>  }
>  
> @@ -1806,7 +1806,7 @@ static void blk_mq_exit_hctx(struct request_queue *q,
>  		set->ops->exit_hctx(hctx, hctx_idx);
>  
>  	if (hctx->flags & BLK_MQ_F_BLOCKING)
> -		cleanup_srcu_struct(&hctx->queue_rq_srcu);
> +		cleanup_srcu_struct(hctx->queue_rq_srcu);
>  
>  	blk_mq_remove_cpuhp(hctx);
>  	blk_free_flush_queue(hctx->fq);
> @@ -1879,7 +1879,7 @@ static int blk_mq_init_hctx(struct request_queue *q,
>  		goto free_fq;
>  
>  	if (hctx->flags & BLK_MQ_F_BLOCKING)
> -		init_srcu_struct(&hctx->queue_rq_srcu);
> +		init_srcu_struct(hctx->queue_rq_srcu);
>  
>  	blk_mq_debugfs_register_hctx(q, hctx);
>  
> @@ -2154,6 +2154,20 @@ struct request_queue *blk_mq_init_queue(struct blk_mq_tag_set *set)
>  }
>  EXPORT_SYMBOL(blk_mq_init_queue);
>  
> +static int blk_mq_hw_ctx_size(struct blk_mq_tag_set *tag_set)
> +{
> +	int hw_ctx_size = sizeof(struct blk_mq_hw_ctx);
> +
> +	BUILD_BUG_ON(ALIGN(offsetof(struct blk_mq_hw_ctx, queue_rq_srcu),
> +			   __alignof__(struct blk_mq_hw_ctx)) !=
> +		     sizeof(struct blk_mq_hw_ctx));
> +
> +	if (tag_set->flags & BLK_MQ_F_BLOCKING)
> +		hw_ctx_size += sizeof(struct srcu_struct);
> +
> +	return hw_ctx_size;
> +}
> +
>  static void blk_mq_realloc_hw_ctxs(struct blk_mq_tag_set *set,
>  						struct request_queue *q)
>  {
> @@ -2168,7 +2182,7 @@ static void blk_mq_realloc_hw_ctxs(struct blk_mq_tag_set *set,
>  			continue;
>  
>  		node = blk_mq_hw_queue_to_node(q->mq_map, i);
> -		hctxs[i] = kzalloc_node(sizeof(struct blk_mq_hw_ctx),
> +		hctxs[i] = kzalloc_node(blk_mq_hw_ctx_size(set),
>  					GFP_KERNEL, node);
>  		if (!hctxs[i])
>  			break;
> diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h
> index fcd641032f8d..c534ec64e214 100644
> --- a/include/linux/blk-mq.h
> +++ b/include/linux/blk-mq.h
> @@ -39,8 +39,6 @@ struct blk_mq_hw_ctx {
>  	struct blk_mq_tags	*tags;
>  	struct blk_mq_tags	*sched_tags;
>  
> -	struct srcu_struct	queue_rq_srcu;
> -
>  	unsigned long		queued;
>  	unsigned long		run;
>  #define BLK_MQ_MAX_DISPATCH_ORDER	7
> @@ -62,6 +60,9 @@ struct blk_mq_hw_ctx {
>  	struct dentry		*debugfs_dir;
>  	struct dentry		*sched_debugfs_dir;
>  #endif
> +
> +	/* Must be the last member - see also blk_mq_hw_ctx_size(). */
> +	struct srcu_struct	queue_rq_srcu[0];
>  };
>  
>  struct blk_mq_tag_set {
> -- 
> 2.12.2
> 

Reviewed-by: Ming Lei <ming.lei@redhat.com>

Thanks,
Ming

  reply	other threads:[~2017-06-19  2:26 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-08 17:33 [PATCH v3 00/12] More patches for kernel v4.13 Bart Van Assche
2017-06-08 17:33 ` [PATCH v3 01/12] blk-mq: Reduce blk_mq_hw_ctx size Bart Van Assche
2017-06-19  2:26   ` Ming Lei [this message]
2017-06-08 17:33 ` [PATCH v3 02/12] block: Make request operation type argument declarations consistent Bart Van Assche
2017-06-08 17:33 ` [PATCH v3 03/12] block: Introduce request_queue.initialize_rq_fn() Bart Van Assche
2017-06-08 17:33 ` [PATCH v3 04/12] block: Make most scsi_req_init() calls implicit Bart Van Assche
2017-06-08 17:33 ` [PATCH v3 05/12] block: Change argument type of scsi_req_init() Bart Van Assche
2017-06-08 17:33 ` [PATCH v3 06/12] blk-mq: Initialize a request before assigning a tag Bart Van Assche
2017-06-08 17:33 ` [PATCH v3 07/12] block: Add a comment above queue_lockdep_assert_held() Bart Van Assche
2017-06-08 17:33 ` [PATCH v3 08/12] block: Check locking assumptions at runtime Bart Van Assche
2017-06-08 17:33 ` [PATCH v3 09/12] block: Document what queue type each function is intended for Bart Van Assche
2017-06-08 17:33 ` [PATCH v3 10/12] blk-mq: Document locking assumptions Bart Van Assche
2017-06-08 17:33 ` [PATCH v3 11/12] block: Constify disk_type Bart Van Assche
2017-06-08 17:33 ` [PATCH v3 12/12] blk-mq: Warn when attempting to run a hardware queue that is not mapped Bart Van Assche
2017-06-19  2:55 ` [PATCH v3 00/12] More patches for kernel v4.13 Jens Axboe
2017-06-19 18:35   ` Bart Van Assche

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=20170619022631.GB11219@ming.t460p \
    --to=ming.lei@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=bart.vanassche@sandisk.com \
    --cc=hare@suse.com \
    --cc=hch@lst.de \
    --cc=linux-block@vger.kernel.org \
    --cc=osandov@fb.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox