From patchwork Mon Mar 25 03:56:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 13601125 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id F373DC54E64 for ; Mon, 25 Mar 2024 03:30:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4C4156B0088; Sun, 24 Mar 2024 23:30:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 44CE26B0089; Sun, 24 Mar 2024 23:30:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2ED4E6B008A; Sun, 24 Mar 2024 23:30:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 1C26A6B0088 for ; Sun, 24 Mar 2024 23:30:15 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E45191A07BF for ; Mon, 25 Mar 2024 03:30:14 +0000 (UTC) X-FDA: 81934133148.17.7A61511 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf15.hostedemail.com (Postfix) with ESMTP id D3878A0005 for ; Mon, 25 Mar 2024 03:30:11 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; spf=pass (imf15.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711337413; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=Dg8G9zfCokzF65Lxxu58n6KJDVSu6SoXcMyzdHVTBfg=; b=pS67wmJOLs1G88ktE0l1tJZGOp2Uj2MB/WLMtoECJwuOuTc7exnvsHamUlX0UZdi/vaGp8 Q2br4KqWEfl/YW/+zVGZJWAy/JokfhDraSbesU8esOpF5Tg2eEDwHOr/SqJSttZHI8yxWc 9zxct9HK36DVnbw3rwI5fMddTsFf4EQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711337413; a=rsa-sha256; cv=none; b=aHttEaLyo7X0fjnkxyhF/wXMPacq0G4gp42z04ypvm9Vv/HIaSfEKv8B1wBH2499LJAPvC kY8ceXcke79lf9+5DoAu/1pr/6C68q9J08ZASvKuil6CMWaxd3CO6Uy7fLtF5TaAydZZwn aUDZkyVeWJKba9GGrPntik9fk5NRrYM= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; spf=pass (imf15.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4V2yzb54dHzXjgG; Mon, 25 Mar 2024 11:27:23 +0800 (CST) Received: from dggpemm100001.china.huawei.com (unknown [7.185.36.93]) by mail.maildlp.com (Postfix) with ESMTPS id 58E70140258; Mon, 25 Mar 2024 11:30:07 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm100001.china.huawei.com (7.185.36.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Mon, 25 Mar 2024 11:30:06 +0800 From: Kefeng Wang To: Andrew Morton , Dennis Zhou CC: , Kefeng Wang Subject: [PATCH] mm: backing-dev: use group allocation/free of per-cpu counters API Date: Mon, 25 Mar 2024 11:56:35 +0800 Message-ID: <20240325035635.49342-1-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm100001.china.huawei.com (7.185.36.93) X-Rspamd-Queue-Id: D3878A0005 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: qci9tkkpeytek4xoff9utemtb96igqkz X-HE-Tag: 1711337411-953015 X-HE-Meta: U2FsdGVkX18Y5ILQTWw8w8CqBVJbotgwFZVfolFaOOcs//Ouh+ZFbOBrYs/fd/bgR9iUU4ehV1MNzSmXXb8C0ILdObYn1Qf9a+/4BVZxS8pwfWCAU+2JjACdhi8kILkrApMgE3voHGTTeP69LjFEhTpZkWRKCAnERzAXZ6jYTf2x9A6yuRPTefjRuxPuqrMrQsmmlLgfAfFMsWxVJZEwOVa1RZqhfEWfjHC4V40Wbx79IVvWzrm9pB9sJsM2rTHXGBn2JcIR4yhUvOy8ntCs6pMwQBvkcFRHI7vY1A1R/V5o/lnL3T0YYA8E/rtMBxusYsiG4NzByZHR4Zyi8Jc/e3seCRKtgl6dp0zrK5AW39spAMqxQsDvTwQwjBmea2fUF5StNmgRZKBktEs0ZlQrilcu4k0JfWNkrr+AbkfTKMp9V0PfwTXisnE7onMs0RlaztdU02Phrp1+k5U6UnzNbDj8hwnc74vlFW86ZcRLsBINu2Bs+yxQs07CDlBMxJXlomYEBM58JpBKyqbWQJUvrdWE3JlOQshmMHlcYAU4HawNTnjhqV7lF4goCyezmgwxSFcTlTMx/07uYF0tqdj3Wlsoi9+1GkSTx+//eTefdNx5WdpBAJaj/fOq0uvUgSDKx9cxO2cxIYrlShbTPnUKcdm9h+KFfTbsHNwdllR1LnkTvcFiIe9qZe5YjkuBfPcsIkEo7vOqW7I5vqqo/p5GxFp4LhSjruPwhUcAwGKzN4xFAflNeRUdMrbRY64Heffhrgd0ilsOpQXYef3gmK4687lmZxK1PGzCchJWfuiTrMtavkCFqswpoEuJx494RIxJmfzaaOayjWE3xtBNjqGFFnk/kmDanf4FmhrqZcJCCl9VZ6pUgYxuLVeSvCJrVfYvjJwYfMNkrX9GlJPLuelJe7Ikp3KZ3W4jsISXXMdM+icOsjJ7KxOMz7IRz7BqmPV7b4UDGTS+ZdlufTcZ0QH zOgewilj AQc9hyoMTHcYh2ZJ5pkxx7lDPDqmU7Nse1PdE51fducty5ncSwwXi14iTbYIcYZCdjMqvrRevYhrkJLFPZ/5sUIVm4Td6qN9LYtiQ8XaPPUPaoZkrp/s4rIwpL/g/VUvbwiTP1fgtzJzENwDpyPazZpZqiz6dykxSrExI/JFhLBeVF/B9rxeGBvA6TQ== 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: List-Subscribe: List-Unsubscribe: Use group allocation/free of per-cpu counters api to accelerate wb_init/exit() and simplify code. Signed-off-by: Kefeng Wang --- mm/backing-dev.c | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/mm/backing-dev.c b/mm/backing-dev.c index 5f2be8c8df11..5fa3666356f9 100644 --- a/mm/backing-dev.c +++ b/mm/backing-dev.c @@ -388,7 +388,7 @@ static void wb_update_bandwidth_workfn(struct work_struct *work) static int wb_init(struct bdi_writeback *wb, struct backing_dev_info *bdi, gfp_t gfp) { - int i, err; + int err; memset(wb, 0, sizeof(*wb)); @@ -416,18 +416,10 @@ static int wb_init(struct bdi_writeback *wb, struct backing_dev_info *bdi, if (err) return err; - for (i = 0; i < NR_WB_STAT_ITEMS; i++) { - err = percpu_counter_init(&wb->stat[i], 0, gfp); - if (err) - goto out_destroy_stat; - } - - return 0; + err = percpu_counter_init_many(wb->stat, 0, gfp, NR_WB_STAT_ITEMS); + if (err) + fprop_local_destroy_percpu(&wb->completions); -out_destroy_stat: - while (i--) - percpu_counter_destroy(&wb->stat[i]); - fprop_local_destroy_percpu(&wb->completions); return err; } @@ -460,13 +452,8 @@ static void wb_shutdown(struct bdi_writeback *wb) static void wb_exit(struct bdi_writeback *wb) { - int i; - WARN_ON(delayed_work_pending(&wb->dwork)); - - for (i = 0; i < NR_WB_STAT_ITEMS; i++) - percpu_counter_destroy(&wb->stat[i]); - + percpu_counter_destroy_many(wb->stat, NR_WB_STAT_ITEMS); fprop_local_destroy_percpu(&wb->completions); }