From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1076CC433EF for ; Thu, 21 Oct 2021 12:45:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BA38360F02 for ; Thu, 21 Oct 2021 12:45:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org BA38360F02 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id DCD16900002; Thu, 21 Oct 2021 08:45:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D7FDD940007; Thu, 21 Oct 2021 08:45:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B8149900005; Thu, 21 Oct 2021 08:45:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0185.hostedemail.com [216.40.44.185]) by kanga.kvack.org (Postfix) with ESMTP id A9F1B900002 for ; Thu, 21 Oct 2021 08:45:04 -0400 (EDT) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 6075D2C6AF for ; Thu, 21 Oct 2021 12:45:04 +0000 (UTC) X-FDA: 78720414528.31.26CAB31 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf26.hostedemail.com (Postfix) with ESMTP id 03D4520019C4 for ; Thu, 21 Oct 2021 12:45:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=OdstAJJ/aNxAfiq3+i1crM5pZ57n3VavG4zixG5t6MY=; b=pcHEnwMXx537KKcW7aTqEKyhWh /+zcUhPuTBrY7E8EEIhV9YJDk+OtDP4J91xvJpoT0cJThFOmVVtsbn5Jci1Jik6BWAeE0/tmyYK3C RVo8Q8whjQYbu0UpH463xncgxbnL2rcB1ugWOZ+B44yaNFVMfUeX0GZS7hq4Z5cYfUREZunllDZVZ R9jMQ6tOwXQitYBib19oALNXB0tISM4c1hQwVEsu3IqO9LZXsTJPHW/poGNsGKCle5NXXO1w/2Bsz OQaVxlq0QpWXkBWNzF2RDuA5eXQdJcVsdI8EXxksma1BojPeL/lMzqGKA6w0QS42iyLgakLJTdNd9 ddJRG4cw==; Received: from [2001:4bb8:180:8777:dd70:8011:36d9:4c23] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mdXRL-007X1k-GZ; Thu, 21 Oct 2021 12:44:59 +0000 From: Christoph Hellwig To: Andrew Morton Cc: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Jan Kara , linux-mtd@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 5/5] mm: simplify bdi refcounting Date: Thu, 21 Oct 2021 14:44:41 +0200 Message-Id: <20211021124441.668816-6-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211021124441.668816-1-hch@lst.de> References: <20211021124441.668816-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 03D4520019C4 X-Stat-Signature: yrku1remuemiiythzk6hjhkgb4hrfwzj Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=pcHEnwMX; dmarc=none; spf=none (imf26.hostedemail.com: domain of BATV+f538400d2eeb65ed2b85+6633+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+f538400d2eeb65ed2b85+6633+infradead.org+hch@bombadil.srs.infradead.org X-HE-Tag: 1634820304-659289 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Move grabbing and releasing the bdi refcount out of the common wb_init/wb_exit helpers into code that is only used for the non-default memcg driven bdi_writeback structures. Signed-off-by: Christoph Hellwig --- mm/backing-dev.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/mm/backing-dev.c b/mm/backing-dev.c index 768e9ae489f66..5ccb250898083 100644 --- a/mm/backing-dev.c +++ b/mm/backing-dev.c @@ -291,8 +291,6 @@ static int wb_init(struct bdi_writeback *wb, struct b= acking_dev_info *bdi, =20 memset(wb, 0, sizeof(*wb)); =20 - if (wb !=3D &bdi->wb) - bdi_get(bdi); wb->bdi =3D bdi; wb->last_old_flush =3D jiffies; INIT_LIST_HEAD(&wb->b_dirty); @@ -316,7 +314,7 @@ static int wb_init(struct bdi_writeback *wb, struct b= acking_dev_info *bdi, =20 err =3D fprop_local_init_percpu(&wb->completions, gfp); if (err) - goto out_put_bdi; + return err; =20 for (i =3D 0; i < NR_WB_STAT_ITEMS; i++) { err =3D percpu_counter_init(&wb->stat[i], 0, gfp); @@ -330,9 +328,6 @@ static int wb_init(struct bdi_writeback *wb, struct b= acking_dev_info *bdi, while (i--) percpu_counter_destroy(&wb->stat[i]); fprop_local_destroy_percpu(&wb->completions); -out_put_bdi: - if (wb !=3D &bdi->wb) - bdi_put(bdi); return err; } =20 @@ -373,8 +368,6 @@ static void wb_exit(struct bdi_writeback *wb) percpu_counter_destroy(&wb->stat[i]); =20 fprop_local_destroy_percpu(&wb->completions); - if (wb !=3D &wb->bdi->wb) - bdi_put(wb->bdi); } =20 #ifdef CONFIG_CGROUP_WRITEBACK @@ -397,6 +390,7 @@ static void cgwb_release_workfn(struct work_struct *w= ork) struct bdi_writeback *wb =3D container_of(work, struct bdi_writeback, release_work); struct blkcg *blkcg =3D css_to_blkcg(wb->blkcg_css); + struct backing_dev_info *bdi =3D wb->bdi; =20 mutex_lock(&wb->bdi->cgwb_release_mutex); wb_shutdown(wb); @@ -416,6 +410,7 @@ static void cgwb_release_workfn(struct work_struct *w= ork) =20 percpu_ref_exit(&wb->refcnt); wb_exit(wb); + bdi_put(bdi); WARN_ON_ONCE(!list_empty(&wb->b_attached)); kfree_rcu(wb, rcu); } @@ -497,6 +492,7 @@ static int cgwb_create(struct backing_dev_info *bdi, INIT_LIST_HEAD(&wb->b_attached); INIT_WORK(&wb->release_work, cgwb_release_workfn); set_bit(WB_registered, &wb->state); + bdi_get(bdi); =20 /* * The root wb determines the registered state of the whole bdi and @@ -528,6 +524,7 @@ static int cgwb_create(struct backing_dev_info *bdi, goto out_put; =20 err_fprop_exit: + bdi_put(bdi); fprop_local_destroy_percpu(&wb->memcg_completions); err_ref_exit: percpu_ref_exit(&wb->refcnt); --=20 2.30.2