Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp552149imm; Fri, 17 Aug 2018 02:35:48 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzzP+8CEM2kiG6v4Og5dTq8Je/Vc2/bwIF2ktY0vM/sK4IHmtHIvFT/EhI8UWxMSTXqxFm7 X-Received: by 2002:a63:de4c:: with SMTP id y12-v6mr32081102pgi.435.1534498547959; Fri, 17 Aug 2018 02:35:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534498547; cv=none; d=google.com; s=arc-20160816; b=BHppN3IKF59ogvDsDPRyt2IBMnt53IkgKW7gnqmQzhPBGUtvIO3cZ7KVmSlY6CraGL m44Ko9Z0Nx0xB9JFIRn+A7b5HNHTuPdzQwBYEbF/0HfJ/xy5rdaXDu62cPl11CnT7uIv haPFSvHbaKQS5RrNfHuC16rU42VcmHIjv/Ou8hKKhDy4qN01uul7hj/8beWXxznbIFUW Jm/qz6k+NCZIJDu3VxCBO4XXytV3xdMM1Y6MEb+0aheHffS8TOwyuA80O3jsW6xiu8m/ sto7AsvasIontC7LYKosUA5Rr3v7EYOfVsXmDOE+T52mEk26O/TpZpOsyKdM41hApyhB v3Vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=p8qZSHsxSCEOIZZ2DpQ6bZwTTmUs5f5A/k0yL+06Hm4=; b=EfXkC0ETkNmdJa6uRdJKrEaa3LrsDRwNnT9u8Z3c5wB5LPSWLxGNdwA9pcl22PCKw1 w0T3LxAtdMHuGZslTUKMHKHnDp8qYQyG6GrSWlkmFAn2fr13GzzCZJMj5cVDrgL3hS/j r7E1h1rM57Ey5J+kLl+cGWzMrWEx8rQeZPD6KobdRUtsFAlCJjmjY3uWTvnAMRIoIyl8 qnTeND0X3jw3c2waLO7zg76w0n3D8DMrga28Em/RQuGJ3WgKLZiPwomMOUmVN4XobLnv SYdlWR44g3V+mFhfLTi2YYAgUj4EVu0qxyQZD5vNn5nqob/RCxLHflXmhy9f0QlUux+7 LaHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dOUywK3R; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q28-v6si1652674pgm.362.2018.08.17.02.35.32; Fri, 17 Aug 2018 02:35:47 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dOUywK3R; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726663AbeHQMge (ORCPT + 99 others); Fri, 17 Aug 2018 08:36:34 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:44316 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726319AbeHQMge (ORCPT ); Fri, 17 Aug 2018 08:36:34 -0400 Received: by mail-wr1-f65.google.com with SMTP id r16-v6so6506350wrt.11; Fri, 17 Aug 2018 02:33:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=p8qZSHsxSCEOIZZ2DpQ6bZwTTmUs5f5A/k0yL+06Hm4=; b=dOUywK3R4Tzm6szaeMbOBwfkbVd4meNX2FxSm0LETtiJRajWQO0xxrJOPMwAru9mEd QhtWD9EH7JfIDZxGkZBQV5QRHMAKO/LMtifBI4VEx5Wl44AlgkZQv0WToQe1DWsS02mA ugxxX7g/iqgX62EDjyED1FhBd7Qwle1LZPdbHN9lNjX8ZQ2oBMNW5lkNUGqtpd5+fICa UGYP9C8f7uAP/DBsrA1tZOg7GlKeKmxbwK4ZFifNHvHr8WcBrwfEmjMUvBWKppWZH5xF XR5a//Z2UnMFMKF1R6Dc1f30eVQwM/JsUvS51dqF0UpM1BQViVjMLt/sNeaGJeHiHBKW yoBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=p8qZSHsxSCEOIZZ2DpQ6bZwTTmUs5f5A/k0yL+06Hm4=; b=EiLSKP2s6ZqVXAj/pHtGtDSH9hl6+36U/dpLdDapcg3IcvwwuEgFEfJNaHLD6CukBF aYRYdFOWmJDY58y6qDH+VRJ42zbCOpyQmhXKT0ya3ndiYlgCgpHIey+8UYmXURpfnbpI XOMKlDVHHhE0HoXaSs8wwLl/585SHaQlUcI1TcO/eddII84Wlga+K4icJIz1zcdz7AQx rpujEpY1o0AUqDWcZRzMkeCLU2qs7fHPmwreENAdRltSy9BJkF+jtAX9z7SDYSfkQdBB LBAyjhS2RBWFGqSOmDfJ2OeWXzJqO/a6XQbtridvj2+baQx6yxImXufGv3T/gAd/sFqh PKPw== X-Gm-Message-State: APzg51BNKbBAYAp9TZDDE3kfEutaB/7nB0PgePvUdtiAvPWH0aR6vdc5 G5Gr8FySiuzw6vcIwBYeTq9M/reoyMijMuNJnHVpmbRlkEk= X-Received: by 2002:adf:ac38:: with SMTP id v53-v6mr949796wrc.142.1534498431819; Fri, 17 Aug 2018 02:33:51 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a1c:32c1:0:0:0:0:0 with HTTP; Fri, 17 Aug 2018 02:33:51 -0700 (PDT) In-Reply-To: <1534478043-7170-2-git-send-email-jianchao.w.wang@oracle.com> References: <1534478043-7170-1-git-send-email-jianchao.w.wang@oracle.com> <1534478043-7170-2-git-send-email-jianchao.w.wang@oracle.com> From: Ming Lei Date: Fri, 17 Aug 2018 17:33:51 +0800 Message-ID: Subject: Re: [PATCH V2 1/2] blk-mq: init hctx sched after update ctx and hctx mapping To: Jianchao Wang Cc: Jens Axboe , Bart Van Assche , Keith Busch , linux-block , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 17, 2018 at 11:54 AM, Jianchao Wang wrote: > Currently, when update nr_hw_queues, io scheduler's init_hctx will > be invoked before the mapping between ctx and hctx is adapted > correctly by blk_mq_map_swqueue. The io scheduler init_hctx (kyber) > may depend on this mapping and get wrong result and panic finally. > A simply way to fix this is switch the io scheduler to none before > update the nr_hw_queues, and then get it back after update nr_hw_queues. > To achieve this, we add a new member elv_type in request_queue to > save the original elevator and adapt and export elevator_switch_mq. > And also blk_mq_sched_init_/exit_hctx are removed due to nobody use > them any more. > > Signed-off-by: Jianchao Wang > --- > block/blk-mq-sched.c | 44 -------------------------------------------- > block/blk-mq-sched.h | 5 ----- > block/blk-mq.c | 36 ++++++++++++++++++++++++++++-------- > block/blk.h | 2 ++ > block/elevator.c | 20 ++++++++++++-------- > include/linux/blkdev.h | 3 +++ > 6 files changed, 45 insertions(+), 65 deletions(-) > > diff --git a/block/blk-mq-sched.c b/block/blk-mq-sched.c > index cf9c66c..29bfe80 100644 > --- a/block/blk-mq-sched.c > +++ b/block/blk-mq-sched.c > @@ -462,50 +462,6 @@ static void blk_mq_sched_tags_teardown(struct request_queue *q) > blk_mq_sched_free_tags(set, hctx, i); > } > > -int blk_mq_sched_init_hctx(struct request_queue *q, struct blk_mq_hw_ctx *hctx, > - unsigned int hctx_idx) > -{ > - struct elevator_queue *e = q->elevator; > - int ret; > - > - if (!e) > - return 0; > - > - ret = blk_mq_sched_alloc_tags(q, hctx, hctx_idx); > - if (ret) > - return ret; > - > - if (e->type->ops.mq.init_hctx) { > - ret = e->type->ops.mq.init_hctx(hctx, hctx_idx); > - if (ret) { > - blk_mq_sched_free_tags(q->tag_set, hctx, hctx_idx); > - return ret; > - } > - } > - > - blk_mq_debugfs_register_sched_hctx(q, hctx); > - > - return 0; > -} > - > -void blk_mq_sched_exit_hctx(struct request_queue *q, struct blk_mq_hw_ctx *hctx, > - unsigned int hctx_idx) > -{ > - struct elevator_queue *e = q->elevator; > - > - if (!e) > - return; > - > - blk_mq_debugfs_unregister_sched_hctx(hctx); > - > - if (e->type->ops.mq.exit_hctx && hctx->sched_data) { > - e->type->ops.mq.exit_hctx(hctx, hctx_idx); > - hctx->sched_data = NULL; > - } > - > - blk_mq_sched_free_tags(q->tag_set, hctx, hctx_idx); > -} > - > int blk_mq_init_sched(struct request_queue *q, struct elevator_type *e) > { > struct blk_mq_hw_ctx *hctx; > diff --git a/block/blk-mq-sched.h b/block/blk-mq-sched.h > index 0cb8f93..4e028ee 100644 > --- a/block/blk-mq-sched.h > +++ b/block/blk-mq-sched.h > @@ -28,11 +28,6 @@ void blk_mq_sched_dispatch_requests(struct blk_mq_hw_ctx *hctx); > int blk_mq_init_sched(struct request_queue *q, struct elevator_type *e); > void blk_mq_exit_sched(struct request_queue *q, struct elevator_queue *e); > > -int blk_mq_sched_init_hctx(struct request_queue *q, struct blk_mq_hw_ctx *hctx, > - unsigned int hctx_idx); > -void blk_mq_sched_exit_hctx(struct request_queue *q, struct blk_mq_hw_ctx *hctx, > - unsigned int hctx_idx); > - > static inline bool > blk_mq_sched_bio_merge(struct request_queue *q, struct bio *bio) > { > diff --git a/block/blk-mq.c b/block/blk-mq.c > index 5efd789..de7027f 100644 > --- a/block/blk-mq.c > +++ b/block/blk-mq.c > @@ -2147,8 +2147,6 @@ static void blk_mq_exit_hctx(struct request_queue *q, > if (set->ops->exit_request) > set->ops->exit_request(set, hctx->fq->flush_rq, hctx_idx); > > - blk_mq_sched_exit_hctx(q, hctx, hctx_idx); > - > if (set->ops->exit_hctx) > set->ops->exit_hctx(hctx, hctx_idx); > > @@ -2216,12 +2214,9 @@ static int blk_mq_init_hctx(struct request_queue *q, > set->ops->init_hctx(hctx, set->driver_data, hctx_idx)) > goto free_bitmap; > > - if (blk_mq_sched_init_hctx(q, hctx, hctx_idx)) > - goto exit_hctx; > - > hctx->fq = blk_alloc_flush_queue(q, hctx->numa_node, set->cmd_size); > if (!hctx->fq) > - goto sched_exit_hctx; > + goto exit_hctx; > > if (blk_mq_init_request(set, hctx->fq->flush_rq, hctx_idx, node)) > goto free_fq; > @@ -2235,8 +2230,6 @@ static int blk_mq_init_hctx(struct request_queue *q, > > free_fq: > kfree(hctx->fq); > - sched_exit_hctx: > - blk_mq_sched_exit_hctx(q, hctx, hctx_idx); > exit_hctx: > if (set->ops->exit_hctx) > set->ops->exit_hctx(hctx, hctx_idx); > @@ -2913,6 +2906,25 @@ static void __blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set, > list_for_each_entry(q, &set->tag_list, tag_set_list) > blk_mq_freeze_queue(q); > > + /* > + * switch io scheduler to NULL to clean up the data in it. > + * will get it back after update mapping between cpu and hw queues. > + */ > + list_for_each_entry(q, &set->tag_list, tag_set_list) { > + if (!q->elevator) { > + q->elv_type = NULL; > + continue; > + } > + q->elv_type = q->elevator->type; > + mutex_lock(&q->sysfs_lock); > + /* > + * elevator_release will put it. > + */ > + __module_get(q->elv_type->elevator_owner); I understand what elevator_release() frees is the 'ref-counter' got in elevator_get(), but who will be the counter-pair of the above __module_get()? Thanks, Ming Lei