From patchwork Sat Apr 20 09:44:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiu Jianfeng X-Patchwork-Id: 13637109 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 7B0B1C4345F for ; Sat, 20 Apr 2024 09:51:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1442A6B0083; Sat, 20 Apr 2024 05:51:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0F4316B0087; Sat, 20 Apr 2024 05:51:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F25806B008A; Sat, 20 Apr 2024 05:51:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id D27226B0083 for ; Sat, 20 Apr 2024 05:51:05 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 5482B8165C for ; Sat, 20 Apr 2024 09:51:05 +0000 (UTC) X-FDA: 82029441690.06.8F16D83 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf12.hostedemail.com (Postfix) with ESMTP id D0E2C4000F for ; Sat, 20 Apr 2024 09:51:02 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf12.hostedemail.com: domain of xiujianfeng@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=xiujianfeng@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713606663; 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=bgADTa3waPsssl8RL+ZRALLOXiA6HQ0uj3XdK1RV6Ho=; b=sAncPzsdMZlbl0/b8X8739TJcxpHeaArLzZEVvhzeg5s/yOQwFgtrs3v+iUXC6/3DZaOfS 7PKDVaCyOZR882s2RfiLwMSctkguwHMtxlRCioRhZOVsuEH3NhTbk8vUhxsL2jW1NiwD2R da8KnV7REy1jM7+IjQ7DxEdknD6+DzU= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf12.hostedemail.com: domain of xiujianfeng@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=xiujianfeng@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713606663; a=rsa-sha256; cv=none; b=Gy+C4TGyH6Fx+qYD/oM/Eh3FNMyoq/1VYgZYDR7XQFYJKFcziX59RHY4MnZBTRPizjgbZX 9oy+pku+wjGxIqCvawN7A2E2T2C7peF5jramejIEDNF26hU32OCGubMydFYp3Bzz84cJPE V3ryuBjCXWRF+BUSoOLves9H8xucd/s= Received: from mail.maildlp.com (unknown [172.19.163.252]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4VM6Dy22B2zShvC; Sat, 20 Apr 2024 17:49:54 +0800 (CST) Received: from dggpeml500023.china.huawei.com (unknown [7.185.36.114]) by mail.maildlp.com (Postfix) with ESMTPS id 07D1818007D; Sat, 20 Apr 2024 17:50:57 +0800 (CST) Received: from hulk-vt.huawei.com (10.67.174.26) by dggpeml500023.china.huawei.com (7.185.36.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Sat, 20 Apr 2024 17:50:56 +0800 From: Xiu Jianfeng To: , , , , , , , , , , CC: , , , Subject: [PATCH -next] cgroup: Introduce css_is_online() helper Date: Sat, 20 Apr 2024 09:44:28 +0000 Message-ID: <20240420094428.1028477-1-xiujianfeng@huawei.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Originating-IP: [10.67.174.26] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpeml500023.china.huawei.com (7.185.36.114) X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: D0E2C4000F X-Stat-Signature: 89b48kwktuhbyw7y9rg44b8oe8knwbqz X-HE-Tag: 1713606662-33086 X-HE-Meta: U2FsdGVkX19sTLZE8vmQCmuNtO58GxZvqwbsjHRM/6Y8MRfiROmM+7ldCgHK2bCm9O/Ui7qkH/w9ZgpzrJi0fidW0saWVR9Gk66EX9184TJ4eznYZRuAUcdrYdCehLEY1dsCkMoGk1ltA3ewParTxodQV2/XoSUUdWAvCrdhTi0/XdeKarNE4FHK+J/a/jTqYG/0Ml2T4B5j/j0TAAxPva+HBkaXyO1eRjvIgyJP14aAr7RVTrOvM+PvN1MlJjgm2/eIqHFozuHuPnKGIHWC70SvZndA4bJFCD3e8IJwcgt1HrPgdFdTcsEhtF57FoVdRZXoFhLCt6DiBX7c2CVNcnbR+hFP6IWHCaCvGBSpdZdvmbCQzpvo3BowcsoX6s2bYDdKdPPIUv0mNggGie5Gr4O4CBeACCGtzLl/Nuv3OHXaW0cST7OtP8eYSOrqQNKAFo9V/uXaWfQmYt6ZFEj4dxwPUWGyC9DCq8RE1caoTbu/PoN5XxORriKUMaX6NFpGwS5HJGChbmMuxbrOMSomNbAxBiUWmpKv94WTrTj9a14B7wYvIR0T1sovidYrjh+2P+bJiZz9xmiT59Mi5Z1mgV1G46luZUEIPzy/537BZHrzoFDbcikpvkxLmMMSpSMzcURGy7obhTqgOqhthkayn6p2X+HRZ2lf6GmRvQrp9QaMiohMu01dAoD0of76ews69FoL6VkWCGz05tE6Hp6hYUg+2EjcWwTlRmvT0ZzN39URFEAnCNgq7Sr5GCt5Ts2DCF5CrDSX+hiqYwkvJHY9lNd9WzSvun6Dpcq/EOjBUZSpQ0djH71lVj7vjbfQLRph3IXQViAdRvic1BNS+mICB9Crjh0ZUBaI4eWDwRoAclUHhtWyyE8KQb0jbTtl2UOSNccNYtKdbbq46QNp+/iQOHfwPC1AY05ASF/cpq3KRYhMKTDGd0cX7I6aZmSSnuG8fRun7Os0NguMwuXdYTC UHHY0i18 4nYlIJvz/nBO4Iszx4OP0IPVvntZZifd84a5PMoB0GeNWaHRjFqLYfFqWFQR0RuGez7ueirCKXzMO4e4bs+xEs800yJupQayjKwMFPoNFYYyPcQNotW1zcbCxWZr5v0snG7I1YXj/YX3ckI8gioKbB4I+T+RidxyQCM5cC9HIFh+9Ct8gVZfqzenOkbleIbmJl6cH 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: Introduce css_is_online() helper to test if whether the specified css is online, avoid testing css.flags with CSS_ONLINE directly outside of cgroup.c. Signed-off-by: Xiu Jianfeng Reviewed-by: Jan Kara --- fs/fs-writeback.c | 2 +- include/linux/cgroup.h | 9 +++++++++ include/linux/memcontrol.h | 2 +- kernel/cgroup/cgroup-internal.h | 2 +- mm/memcontrol.c | 2 +- mm/page_owner.c | 2 +- 6 files changed, 14 insertions(+), 5 deletions(-) diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c index 92a5b8283528..bb84c6a2fa8e 100644 --- a/fs/fs-writeback.c +++ b/fs/fs-writeback.c @@ -916,7 +916,7 @@ void wbc_account_cgroup_owner(struct writeback_control *wbc, struct page *page, folio = page_folio(page); css = mem_cgroup_css_from_folio(folio); /* dead cgroups shouldn't contribute to inode ownership arbitration */ - if (!(css->flags & CSS_ONLINE)) + if (!css_is_online(css)) return; id = css->id; diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index 2150ca60394b..e6b6f3418da8 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h @@ -346,6 +346,15 @@ static inline bool css_is_dying(struct cgroup_subsys_state *css) return !(css->flags & CSS_NO_REF) && percpu_ref_is_dying(&css->refcnt); } +/* + * css_is_online - test whether the specified css is online + * @css: target css + */ +static inline bool css_is_online(struct cgroup_subsys_state *css) +{ + return !!(css->flags & CSS_ONLINE); +} + static inline void cgroup_get(struct cgroup *cgrp) { css_get(&cgrp->self); diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 8f332b4ae84c..cd6b3bfd070f 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -939,7 +939,7 @@ static inline bool mem_cgroup_online(struct mem_cgroup *memcg) { if (mem_cgroup_disabled()) return true; - return !!(memcg->css.flags & CSS_ONLINE); + return css_is_online(&memcg->css); } void mem_cgroup_update_lru_size(struct lruvec *lruvec, enum lru_list lru, diff --git a/kernel/cgroup/cgroup-internal.h b/kernel/cgroup/cgroup-internal.h index 520b90dd97ec..feeaf172844d 100644 --- a/kernel/cgroup/cgroup-internal.h +++ b/kernel/cgroup/cgroup-internal.h @@ -183,7 +183,7 @@ extern struct list_head cgroup_roots; static inline bool cgroup_is_dead(const struct cgroup *cgrp) { - return !(cgrp->self.flags & CSS_ONLINE); + return !css_is_online(&cgrp->self); } static inline bool notify_on_release(const struct cgroup *cgrp) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 7703ced535a3..e77e9e1911e6 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -405,7 +405,7 @@ ino_t page_cgroup_ino(struct page *page) /* page_folio() is racy here, but the entire function is racy anyway */ memcg = folio_memcg_check(page_folio(page)); - while (memcg && !(memcg->css.flags & CSS_ONLINE)) + while (memcg && !css_is_online(&memcg->css)) memcg = parent_mem_cgroup(memcg); if (memcg) ino = cgroup_ino(memcg->css.cgroup); diff --git a/mm/page_owner.c b/mm/page_owner.c index 75c23302868a..7accb25e6fe6 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -523,7 +523,7 @@ static inline int print_page_owner_memcg(char *kbuf, size_t count, int ret, if (!memcg) goto out_unlock; - online = (memcg->css.flags & CSS_ONLINE); + online = css_is_online(&memcg->css); cgroup_name(memcg->css.cgroup, name, sizeof(name)); ret += scnprintf(kbuf + ret, count - ret, "Charged %sto %smemcg %s\n",