From patchwork Wed Feb 22 10:14:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 9586529 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 80D666057F 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 78470288EA for ; Wed, 22 Feb 2017 10:14:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6CFF328909; 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 F1F3D288FD for ; Wed, 22 Feb 2017 10:14:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932179AbdBVKOr (ORCPT ); Wed, 22 Feb 2017 05:14:47 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:36625 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932129AbdBVKO3 (ORCPT ); Wed, 22 Feb 2017 05:14:29 -0500 Received: by mail-pg0-f66.google.com with SMTP id z128so1669538pgb.3; Wed, 22 Feb 2017 02:14:28 -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=z7/COvIJ0UJPaOauoz4D2yOvNolzdImfR8qgV8lrrFE=; b=T/wkrFYk+TSvZpjbQ/ZXOEXfsfMu+xLlPKiN/oe7T8nsgDjbuZxYVuOHUPFetrXLk/ C3fvPIosPCrhISyI5NZXNHby+ccL4g80CyRRnoNS+UyE+xbcZXNe8feWjwGfx67CaFJn 48+DNOTba3Q7Q+37AaqHa4Mo/Hb6QjcvkmRqQH4X5fclHEtdVe0b5NM0/SHCwWTEtMGx TmZgHVyudjfAdvx8OzM8dy1Pw4parPM/ZZwu7EFQt5BiwPkIsjMciRUiCJZGak29bo9S AlmZLzeie/8AV1h5DNXUAFfebis0QDTGUMgtKM/Yd/6Dv115nDiQBeCaXSxPrNOQJET/ fKuQ== 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=z7/COvIJ0UJPaOauoz4D2yOvNolzdImfR8qgV8lrrFE=; b=JIgEPUtKbKJbllqHPzDoZvWe23rmGUKBO/OHWdRuOtTD92BuwapvPpPe0AEDuKEuSr Or+sIds6Cu6OxJ/7Ya/pON6Bo8MeiUI3iyITsFtDF3JjcICCGXrQRAA7WKuMfBC45XWi LZyeX6IgAI0x+B99BRPMCRVpT+Y9XNGL0AuXnQQMxOIPpXhaVaFV2f318gan7RjBbn13 inKfoJqnjpfVz1fz5fmqXbo+Y5Lc5mN1iedXdXhmvoPHWzkeXjGOwl4l3D8F4ZC8oLY8 ddKmyYM5cMzPdbAMuvPB8uixdSF/AFuGkdUuNWfcoNQCJ86hBfip7PudoEQxTXOdrBNh kQFw== X-Gm-Message-State: AMke39mnc1AQljyAdm8ttDeznbRGlFJ4QV/247v6ZkKjLGAnVojP245cMuwHLqkw0A9MPQ== X-Received: by 10.84.174.197 with SMTP id r63mr47161312plb.14.1487758468076; Wed, 22 Feb 2017 02:14:28 -0800 (PST) Received: from localhost ([45.35.47.137]) by smtp.gmail.com with ESMTPSA id z27sm2656414pfg.38.2017.02.22.02.14.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Feb 2017 02:14:27 -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 3/4] blk-mq: make lifetime consistent between hctx and its kobject Date: Wed, 22 Feb 2017 18:14:01 +0800 Message-Id: <1487758442-5855-4-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 This patch removes kobject_put() over hctx in __blk_mq_unregister_dev(), and trys to keep lifetime consistent between hctx and hctx's kobject. Now blk_mq_sysfs_register() and blk_mq_sysfs_unregister() become totally symmetrical, and kobject's refcounter drops to zero just when the hctx is freed. Signed-off-by: Ming Lei --- block/blk-mq-sysfs.c | 15 ++++++++++----- block/blk-mq.c | 5 +---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/block/blk-mq-sysfs.c b/block/blk-mq-sysfs.c index 77fb238af2be..cb19ec16a7fc 100644 --- a/block/blk-mq-sysfs.c +++ b/block/blk-mq-sysfs.c @@ -17,6 +17,14 @@ static void blk_mq_sysfs_release(struct kobject *kobj) { } +static void blk_mq_hw_sysfs_release(struct kobject *kobj) +{ + struct blk_mq_hw_ctx *hctx = container_of(kobj, struct blk_mq_hw_ctx, + kobj); + kfree(hctx->ctxs); + kfree(hctx); +} + struct blk_mq_ctx_sysfs_entry { struct attribute attr; ssize_t (*show)(struct blk_mq_ctx *, char *); @@ -200,7 +208,7 @@ static struct kobj_type blk_mq_ctx_ktype = { static struct kobj_type blk_mq_hw_ktype = { .sysfs_ops = &blk_mq_hw_sysfs_ops, .default_attrs = default_hw_ctx_attrs, - .release = blk_mq_sysfs_release, + .release = blk_mq_hw_sysfs_release, }; static void blk_mq_unregister_hctx(struct blk_mq_hw_ctx *hctx) @@ -244,12 +252,9 @@ static void __blk_mq_unregister_dev(struct device *dev, struct request_queue *q) struct blk_mq_hw_ctx *hctx; int i; - queue_for_each_hw_ctx(q, hctx, i) { + queue_for_each_hw_ctx(q, hctx, i) blk_mq_unregister_hctx(hctx); - kobject_put(&hctx->kobj); - } - blk_mq_debugfs_unregister_hctxs(q); kobject_uevent(&q->mq_kobj, KOBJ_REMOVE); diff --git a/block/blk-mq.c b/block/blk-mq.c index bc45736d70ba..993bb4d4d909 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2152,8 +2152,7 @@ void blk_mq_release(struct request_queue *q) queue_for_each_hw_ctx(q, hctx, i) { if (!hctx) continue; - kfree(hctx->ctxs); - kfree(hctx); + kobject_put(&hctx->kobj); } q->mq_map = NULL; @@ -2232,8 +2231,6 @@ static void blk_mq_realloc_hw_ctxs(struct blk_mq_tag_set *set, blk_mq_exit_hctx(q, set, hctx, j); free_cpumask_var(hctx->cpumask); kobject_put(&hctx->kobj); - kfree(hctx->ctxs); - kfree(hctx); hctxs[j] = NULL; }