From patchwork Sat Apr 20 09:38:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiu Jianfeng X-Patchwork-Id: 13637107 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 22E7BC4345F for ; Sat, 20 Apr 2024 09:45:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 428BF6B0083; Sat, 20 Apr 2024 05:45:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3D9246B0087; Sat, 20 Apr 2024 05:45:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2A12F6B0088; Sat, 20 Apr 2024 05:45:14 -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 0DC826B0083 for ; Sat, 20 Apr 2024 05:45:14 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 98BEDC04E6 for ; Sat, 20 Apr 2024 09:45:13 +0000 (UTC) X-FDA: 82029426906.21.7BFAFE3 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf28.hostedemail.com (Postfix) with ESMTP id 03CFAC0013 for ; Sat, 20 Apr 2024 09:45:09 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf28.hostedemail.com: domain of xiujianfeng@huawei.com designates 45.249.212.255 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=1713606311; 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=cs/LCb+DhGRXWBVtPu+MqPOy2jUImrSLv4Ze2iaGZZ6JGdkbTkvV/gTiypLng95uGSWJ6r bGYEgRJm4IM4uUfHf3BrzXogEjzQFa00XmJxNE+48p1m5smn/8tmdEdgHgqXnVJzXapPC7 jL8X3WLgUe5SQjA4ie1Vy31SOCKpAUU= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf28.hostedemail.com: domain of xiujianfeng@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=xiujianfeng@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713606311; a=rsa-sha256; cv=none; b=ujySLsI5TbtTs2Jig4vPYE0Rrsvm0gtSHEzpuIZv0qnLFRRPpNQF9QH/wB0vau1WCDgLEb mVH3EzGUQz5NQkwMRbCZaWaVC6yV/CrMvU3KiUxfX0SZzs/wLj40EuNShJwiv17UyYkFi1 DDlTrnUrmPpbYVa2EgcXQHpFmRLSgeI= Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4VM64138TJz1R8j7; Sat, 20 Apr 2024 17:42:09 +0800 (CST) Received: from dggpeml500023.china.huawei.com (unknown [7.185.36.114]) by mail.maildlp.com (Postfix) with ESMTPS id AB5F5140132; Sat, 20 Apr 2024 17:45:05 +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:45:05 +0800 From: Xiu Jianfeng To: , , , , , , , , , , CC: , , , Subject: [PATCH] cgroup: Introduce css_is_online() helper Date: Sat, 20 Apr 2024 09:38:37 +0000 Message-ID: <20240420093837.1028410-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: 03CFAC0013 X-Stat-Signature: a5impa459c6qhcwi4bicf56uqarc7aeg X-HE-Tag: 1713606309-656385 X-HE-Meta: U2FsdGVkX19pkL0r9vBC0i/J3cbNWur4EY/BTnDwext0EZTzii2FQYYlfwuQrrAgLj7c1w9Bi3Nd0CHqnrmw+JLtN+HoqnXwEBzxcdCciB+YNu+7aa00oNvYDrUu935T3OsFO6NmyxxjU2bPUjPcOCSQsYdXbULgbWjOekiCe0U0BtKAsZY7iVwNerFfvQpfHRxPFyXyGDcvpEGVhqCCDSngbTlx25HIZMh809h2oT+hdjidHk9M5P2YsCBOPu/29Y08MM7f28lrncee1OHyGeXwWzPndqdg9BeGwN72+aNJrPwKltE37iIoDb/LTBKU3C3V+tYh8riOID116a1za5/Ime6f8Vh/HvS0QLWLfx8oGt3DGrc9dswb6Iz6KPcN6aAOZ5ePUiW+7HlOTkQYjSZRh5HObrqawd/Uh7KT5aHcY012zpxx3t7lZUudndmHYD4mZSXOyQHAmC/rnIXSusF5O/yH2WfO0lX+c++hPL/7uSlJolmbFrju16Nhphozy8JrLrexil9Hpn6DvVKwcCmRgiUp8ucgx5Y2g4pyyn3/A84SnYeECnUb0OGIR61hI9Nl+eddd9M2v8PlXxAEnvw65QVOoGV4mHG9x0HsP7h3lBPUy9W8PgKOShDfsuyHwlSax0dzucEW3q6lbfiYqpH2aIRQvr6q12GTRQiwvlV+4gqYHIhYTJR9Nex+xid+9H5HDRKiMp8xA978RglAFWD3SSvPf8eMRStgjfe9u10rGXWMIr1HdYZFMiLpcB/Fnct5wlGbdmzmm3WLAlvJtKNjvicrPmmc7LV7X4LCVegsSVLm2LhUaiPq2Cibz2p+XEWJDHwKcItaY/0hDLe6Pncm1W6VjPi7y1TNnAewOL5dlax+FcvhIOlHjm3ReBBw2K07yYuDjNfSICZtItljfiW11EMn8RMkvfGWP1faWOIwUec3DjwiV30oy/xQ9sYvhlQgYI5BIddfuMa0ZJm fsBZdVxL FSRMOfVQkalnW23JE7j6QIw0k/NN1EEygFmefmiYKZ+lkv3H/vheAyN6UC3JOP3WqkUgLXkd5Sctn3sxFtiG2soqPaAUDnP1tIbpJKiDpRr3ewZSVyIHPRqurZM1zGlfd/SNfMsXkLFrjkDNaLGSUAMdwzRgCiAxWzsk8d8+7stIQB+6HaT+S1Hhr++ehWvUBMheg 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 --- 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",