On Mon, Apr 29, 2019 at 08:05:30AM +0200, Hannes Reinecke wrote: > On 4/28/19 10:14 AM, Ming Lei wrote: > > Split blk_mq_alloc_and_init_hctx into two parts, and one is > > blk_mq_alloc_hctx() for allocating all hctx resources, another > > is blk_mq_init_hctx() for initializing hctx, which serves as > > counter-part of blk_mq_exit_hctx(). > > > > Cc: Dongli Zhang <dongli.zhang@xxxxxxxxxx> > > Cc: James Smart <james.smart@xxxxxxxxxxxx> > > Cc: Bart Van Assche <bart.vanassche@xxxxxxx> > > Cc: linux-scsi@xxxxxxxxxxxxxxx, > > Cc: Martin K . Petersen <martin.petersen@xxxxxxxxxx>, > > Cc: Christoph Hellwig <hch@xxxxxx>, > > Cc: James E . J . Bottomley <jejb@xxxxxxxxxxxxxxxxxx>, > > Reviewed-by: Hannes Reinecke <hare@xxxxxxxx> > > Tested-by: James Smart <james.smart@xxxxxxxxxxxx> > > Signed-off-by: Ming Lei <ming.lei@xxxxxxxxxx> > > --- > > block/blk-mq.c | 138 ++++++++++++++++++++++++++++++++------------------------- > > 1 file changed, 77 insertions(+), 61 deletions(-) > > > > diff --git a/block/blk-mq.c b/block/blk-mq.c > > index d98cb9614dfa..44ecca6b0cac 100644 > > --- a/block/blk-mq.c > > +++ b/block/blk-mq.c > > @@ -2284,15 +2284,70 @@ static void blk_mq_exit_hw_queues(struct request_queue *q, > > } > > } > > +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, 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 int blk_mq_init_hctx(struct request_queue *q, > > struct blk_mq_tag_set *set, > > struct blk_mq_hw_ctx *hctx, unsigned hctx_idx) > > { > > - int node; > > + hctx->queue_num = hctx_idx; > > - node = hctx->numa_node; > > + cpuhp_state_add_instance_nocalls(CPUHP_BLK_MQ_DEAD, &hctx->cpuhp_dead); > > + > > + hctx->tags = set->tags[hctx_idx]; > > + > > + if (set->ops->init_hctx && > > + set->ops->init_hctx(hctx, set->driver_data, hctx_idx)) > > + goto unregister_cpu_notifier; > > + > > + if (blk_mq_init_request(set, hctx->fq->flush_rq, hctx_idx, > > + hctx->numa_node)) > > + goto exit_hctx; > > + return 0; > > + > > + exit_hctx: > > + if (set->ops->exit_hctx) > > + set->ops->exit_hctx(hctx, hctx_idx); > > + unregister_cpu_notifier: > > + blk_mq_remove_cpuhp(hctx); > > + return -1; > > +} > > + > > +static struct blk_mq_hw_ctx * > > +blk_mq_alloc_hctx(struct request_queue *q, > > + struct blk_mq_tag_set *set, > > + unsigned hctx_idx, int node) > > +{ > > + struct blk_mq_hw_ctx *hctx; > > + > > + hctx = kzalloc_node(blk_mq_hw_ctx_size(set), > > + GFP_NOIO | __GFP_NOWARN | __GFP_NORETRY, > > + node); > > + if (!hctx) > > + goto fail_alloc_hctx; > > + > > + if (!zalloc_cpumask_var_node(&hctx->cpumask, > > + GFP_NOIO | __GFP_NOWARN | __GFP_NORETRY, > > + node)) > > + goto free_hctx; > > + > > + atomic_set(&hctx->nr_active, 0); > > + hctx->numa_node = node; > > if (node == NUMA_NO_NODE) > > - node = hctx->numa_node = set->numa_node; > > + hctx->numa_node = set->numa_node; > > + node = hctx->numa_node; > > INIT_DELAYED_WORK(&hctx->run_work, blk_mq_run_work_fn); > > spin_lock_init(&hctx->lock); > The 'hctx_idx' argument is now unused, and should be removed from the > function definition. OK, will do it in V9. Thanks, Ming