From: JP Kobryn <inwardvessel@gmail.com>
To: tj@kernel.org, shakeel.butt@linux.dev, yosryahmed@google.com,
mkoutny@suse.com, hannes@cmpxchg.org, akpm@linux-foundation.org
Cc: linux-mm@kvack.org, cgroups@vger.kernel.org, kernel-team@meta.com
Subject: [PATCH v6 5/6] cgroup: helper for checking rstat participation of css
Date: Wed, 14 May 2025 17:19:36 -0700 [thread overview]
Message-ID: <20250515001937.219505-6-inwardvessel@gmail.com> (raw)
In-Reply-To: <20250515001937.219505-1-inwardvessel@gmail.com>
There are a few places where a conditional check is performed to validate a
given css on its rstat participation. This new helper tries to make the
code more readable where this check is performed.
Signed-off-by: JP Kobryn <inwardvessel@gmail.com>
---
kernel/cgroup/rstat.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c
index 0bb609e73bde..7dd396ae3c68 100644
--- a/kernel/cgroup/rstat.c
+++ b/kernel/cgroup/rstat.c
@@ -14,6 +14,17 @@ static DEFINE_PER_CPU(raw_spinlock_t, rstat_base_cpu_lock);
static void cgroup_base_stat_flush(struct cgroup *cgrp, int cpu);
+/*
+ * Determines whether a given css can participate in rstat.
+ * css's that are cgroup::self use rstat for base stats.
+ * Other css's associated with a subsystem use rstat only when
+ * they define the ss->css_rstat_flush callback.
+ */
+static inline bool css_uses_rstat(struct cgroup_subsys_state *css)
+{
+ return css_is_self(css) || css->ss->css_rstat_flush != NULL;
+}
+
static struct css_rstat_cpu *css_rstat_cpu(
struct cgroup_subsys_state *css, int cpu)
{
@@ -119,7 +130,7 @@ __bpf_kfunc void css_rstat_updated(struct cgroup_subsys_state *css, int cpu)
* Since bpf programs can call this function, prevent access to
* uninitialized rstat pointers.
*/
- if (!css_is_self(css) && css->ss->css_rstat_flush == NULL)
+ if (!css_uses_rstat(css))
return;
/*
@@ -390,7 +401,7 @@ __bpf_kfunc void css_rstat_flush(struct cgroup_subsys_state *css)
* Since bpf programs can call this function, prevent access to
* uninitialized rstat pointers.
*/
- if (!is_self && css->ss->css_rstat_flush == NULL)
+ if (!css_uses_rstat(css))
return;
might_sleep();
@@ -462,7 +473,7 @@ void css_rstat_exit(struct cgroup_subsys_state *css)
{
int cpu;
- if (!css_is_self(css) && css->ss->css_rstat_flush == NULL)
+ if (!css_uses_rstat(css))
return;
css_rstat_flush(css);
--
2.47.1
next prev parent reply other threads:[~2025-05-15 0:20 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-15 0:19 [PATCH v6 0/6] cgroup: separate rstat trees JP Kobryn
2025-05-15 0:19 ` [PATCH v6 1/6] cgroup: warn on rstat usage by early init subsystems JP Kobryn
2025-05-19 20:18 ` Tejun Heo
2025-05-19 20:20 ` Tejun Heo
2025-05-15 0:19 ` [PATCH v6 2/6] cgroup: compare css to cgroup::self in helper for distingushing css JP Kobryn
2025-05-19 20:21 ` Tejun Heo
2025-05-15 0:19 ` [PATCH v6 3/6] cgroup: use separate rstat trees for each subsystem JP Kobryn
2025-05-15 0:19 ` [PATCH v6 4/6] cgroup: use subsystem-specific rstat locks to avoid contention JP Kobryn
2025-05-15 0:19 ` JP Kobryn [this message]
2025-05-15 0:19 ` [PATCH v6 6/6] cgroup: document the rstat per-cpu initialization JP Kobryn
2025-05-19 20:28 ` Tejun Heo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250515001937.219505-6-inwardvessel@gmail.com \
--to=inwardvessel@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=kernel-team@meta.com \
--cc=linux-mm@kvack.org \
--cc=mkoutny@suse.com \
--cc=shakeel.butt@linux.dev \
--cc=tj@kernel.org \
--cc=yosryahmed@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox