From patchwork Wed Feb 22 10:14:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 9586531 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 95AB160581 for ; Wed, 22 Feb 2017 10:14:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8CD48288EA for ; Wed, 22 Feb 2017 10:14:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 81D432891A; Wed, 22 Feb 2017 10:14:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 27AEE28911 for ; Wed, 22 Feb 2017 10:14:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932194AbdBVKOs (ORCPT ); Wed, 22 Feb 2017 05:14:48 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:33297 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932116AbdBVKO0 (ORCPT ); Wed, 22 Feb 2017 05:14:26 -0500 Received: by mail-pg0-f66.google.com with SMTP id 5so1700950pgj.0; Wed, 22 Feb 2017 02:14:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MGlSHT+Auy89pjM7bHstu9iBSrzpYltbmGZZveTzFNA=; b=ttY59Jbo03obkwxlqGDmW7vddOPocHF7cpUxeW5XNNKGmBvpZWCy6dsi4E1yYeGCIg 3Hif+iKThogVcmRU06524n3P8v/JbTu1Of1vi4XENy5OkrgHzcsCng0QM5cao44MsgLX 4rNYqhy/epzRuOdzd94boV/mp9pT88T2AG6i4PHivs2m4Tx1xIghia4mAlHUM7e6trO3 ppoWQz6AMZHVGF5ws+ZhFAn9yn2T1jTkrmBQJKm0TcUv+PqjlrvGRt8EKXTKOTBBFfVM nbtuSfwZHuZZQ49ReWpzABtBe0I1+r+YHcj0wOJpNStVFi/80/OZRHWIcXqrGkJqT0SZ Y39Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=MGlSHT+Auy89pjM7bHstu9iBSrzpYltbmGZZveTzFNA=; b=LgsCsbRxliKzTBPv7A5y3nWBX4DH7wKQTMy21LGDFH4Fm3tQwHU9gZ+UKYYW4gs478 UHe2ZnXgVhYzODB5ZJHd3+ga9nIIR4eK6zXXhAxRnkLrrPuVVh4kULuDX0Ztr9vk5lBL RZpiWQToOcw+Hutv5F+iKHUCJ3alahaelQWcxdUWX9zprIspcQkOGP9eGYG+PkpYN9Vn Yx97V5wNBlEKFGdJ9v91OsAN1VSdfVrocd10FMsivtwWfLVBsNXPaqMMxGPKCMUP3HUl Myz3aPNlfLIu9lDDOdoVhgdBxm4NfEYMyuPwJEAhbh7mNfhS2X/6asp8Mvn+KNhtlkPb xW8w== X-Gm-Message-State: AMke39m5F5UVtm1jRdnN55tDay5xocr+LslfQ98Qcl/XvzADos2jwA215uOCOEmJYxe20Q== X-Received: by 10.84.212.2 with SMTP id d2mr46852961pli.152.1487758464862; Wed, 22 Feb 2017 02:14:24 -0800 (PST) Received: from localhost ([45.35.47.137]) by smtp.gmail.com with ESMTPSA id f62sm2649563pfg.48.2017.02.22.02.14.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Feb 2017 02:14:24 -0800 (PST) From: Ming Lei To: Jens Axboe , linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, Christoph Hellwig , Omar Sandoval Cc: Ming Lei Subject: [PATCH 2/4] blk-mq: make lifetime consitent between q/ctx and its kobject Date: Wed, 22 Feb 2017 18:14:00 +0800 Message-Id: <1487758442-5855-3-git-send-email-tom.leiming@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487758442-5855-1-git-send-email-tom.leiming@gmail.com> References: <1487758442-5855-1-git-send-email-tom.leiming@gmail.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently from kobject view, both q->mq_kobj and ctx->kobj can be released during one cycle of blk_mq_register_dev() and blk_mq_unregister_dev(). Actually, sw queue's lifetime is same with its request queue's, which is covered by request_queue->kobj. So we don't need to call kobject_put() for the two kinds of kobject in __blk_mq_unregister_dev(), instead we do that in release handler of request queue. Signed-off-by: Ming Lei --- block/blk-mq-sysfs.c | 20 +++++++++++++------- block/blk-mq.c | 7 ++++++- block/blk-mq.h | 1 + 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/block/blk-mq-sysfs.c b/block/blk-mq-sysfs.c index 124305407c80..77fb238af2be 100644 --- a/block/blk-mq-sysfs.c +++ b/block/blk-mq-sysfs.c @@ -242,15 +242,11 @@ static int blk_mq_register_hctx(struct blk_mq_hw_ctx *hctx) static void __blk_mq_unregister_dev(struct device *dev, struct request_queue *q) { struct blk_mq_hw_ctx *hctx; - struct blk_mq_ctx *ctx; - int i, j; + int i; queue_for_each_hw_ctx(q, hctx, i) { blk_mq_unregister_hctx(hctx); - hctx_for_each_ctx(hctx, ctx, j) - kobject_put(&ctx->kobj); - kobject_put(&hctx->kobj); } @@ -258,8 +254,6 @@ static void __blk_mq_unregister_dev(struct device *dev, struct request_queue *q) kobject_uevent(&q->mq_kobj, KOBJ_REMOVE); kobject_del(&q->mq_kobj); - kobject_put(&q->mq_kobj); - kobject_put(&dev->kobj); q->mq_sysfs_init_done = false; @@ -277,6 +271,18 @@ void blk_mq_hctx_kobj_init(struct blk_mq_hw_ctx *hctx) kobject_init(&hctx->kobj, &blk_mq_hw_ktype); } +void blk_mq_sysfs_deinit(struct request_queue *q) +{ + struct blk_mq_ctx *ctx; + int cpu; + + for_each_possible_cpu(cpu) { + ctx = per_cpu_ptr(q->queue_ctx, cpu); + kobject_put(&ctx->kobj); + } + kobject_put(&q->mq_kobj); +} + void blk_mq_sysfs_init(struct request_queue *q) { struct blk_mq_ctx *ctx; diff --git a/block/blk-mq.c b/block/blk-mq.c index ade1d7cde37e..bc45736d70ba 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2160,7 +2160,12 @@ void blk_mq_release(struct request_queue *q) kfree(q->queue_hw_ctx); - /* ctx kobj stays in queue_ctx */ + /* + * release .mq_kobj and sw queue's kobject now because + * both share lifetime with request queue. + */ + blk_mq_sysfs_deinit(q); + free_percpu(q->queue_ctx); } diff --git a/block/blk-mq.h b/block/blk-mq.h index 445343425f6d..2cd73b762351 100644 --- a/block/blk-mq.h +++ b/block/blk-mq.h @@ -78,6 +78,7 @@ static inline struct blk_mq_hw_ctx *blk_mq_map_queue(struct request_queue *q, * sysfs helpers */ extern void blk_mq_sysfs_init(struct request_queue *q); +extern void blk_mq_sysfs_deinit(struct request_queue *q); extern int blk_mq_sysfs_register(struct request_queue *q); extern void blk_mq_sysfs_unregister(struct request_queue *q); extern void blk_mq_hctx_kobj_init(struct blk_mq_hw_ctx *hctx);