cgroup: use separate rstat trees for each subsystem
authorJP Kobryn <inwardvessel@gmail.com>
Thu, 15 May 2025 00:19:34 +0000 (17:19 -0700)
committerTejun Heo <tj@kernel.org>
Mon, 19 May 2025 20:28:59 +0000 (10:28 -1000)
commit5da3bfa029d6809e192d112f39fca4dbe0137aaf
treeeecf6a790edcfc794b7d6cb464d1eb2f5a0e3715
parent541a4219bd66bef56d93dbd306dc64a4d70ae99e
cgroup: use separate rstat trees for each subsystem

Different subsystems may call cgroup_rstat_updated() within the same
cgroup, resulting in a tree of pending updates from multiple subsystems.
When one of these subsystems is flushed via cgroup_rstat_flushed(), all
other subsystems with pending updates on the tree will also be flushed.

Change the paradigm of having a single rstat tree for all subsystems to
having separate trees for each subsystem. This separation allows for
subsystems to perform flushes without the side effects of other subsystems.
As an example, flushing the cpu stats will no longer cause the memory stats
to be flushed and vice versa.

In order to achieve subsystem-specific trees, change the tree node type
from cgroup to cgroup_subsys_state pointer. Then remove those pointers from
the cgroup and instead place them on the css. Finally, change update/flush
functions to make use of the different node type (css). These changes allow
a specific subsystem to be associated with an update or flush. Separate
rstat trees will now exist for each unique subsystem.

Since updating/flushing will now be done at the subsystem level, there is
no longer a need to keep track of updated css nodes at the cgroup level.
The list management of these nodes done within the cgroup (rstat_css_list
and related) has been removed accordingly.

Conditional guards for checking validity of a given css were placed within
css_rstat_updated/flush() to prevent undefined behavior occuring from kfunc
usage in bpf programs. Guards were also placed within css_rstat_init/exit()
in order to help consolidate calls to them. At call sites for all four
functions, the existing guards were removed.

Signed-off-by: JP Kobryn <inwardvessel@gmail.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
include/linux/cgroup-defs.h
kernel/cgroup/cgroup.c
kernel/cgroup/rstat.c
tools/testing/selftests/bpf/progs/btf_type_tag_percpu.c