* [PATCH] cgroup: rstat: force flush on css exit
@ 2025-12-04 21:06 Shakeel Butt
0 siblings, 0 replies; only message in thread
From: Shakeel Butt @ 2025-12-04 21:06 UTC (permalink / raw)
To: Tejun Heo
Cc: Johannes Weiner, Michal Koutný,
Paul E . McKenney, JP Kobryn, linux-mm, cgroups, linux-kernel,
Meta kernel team
Cuurently the rstat update side is lockless and transfers the css of
cgroup whose stats has been updated through lockless list (llist). There
is an expected race where rstat updater skips adding css to the llist
because it was already in the list but the flusher might not see those
updates done by the skipped updater.
Usually the subsequent updater will take care of such situation but what
if the skipped updater was the last updater before the cgroup is removed
by the user. In that case stat updates by the skipped updater will be
lost. To avoid that let's always flush the stats of the offlined cgroup.
Signed-off-by: Shakeel Butt <shakeel.butt@linux.dev>
Fixes: 36df6e3dbd7e ("cgroup: make css_rstat_updated nmi safe")
---
kernel/cgroup/rstat.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c
index a198e40c799b..91b34ebd5370 100644
--- a/kernel/cgroup/rstat.c
+++ b/kernel/cgroup/rstat.c
@@ -283,6 +283,16 @@ static struct cgroup_subsys_state *css_rstat_updated_list(
css_process_update_tree(root->ss, cpu);
+ /*
+ * We allow race between rstat updater and flusher which can cause a
+ * scenario where the updater skips adding the css to the list but the
+ * flusher might not see updater's updates. Usually the subsequent
+ * updater would take care of that but what if that was the last updater
+ * on that CPU before getting removed. Handle that scenario here.
+ */
+ if (!css_is_online(root))
+ __css_process_update_tree(root, cpu);
+
/* Return NULL if this subtree is not on-list */
if (!rstatc->updated_next)
return NULL;
--
2.47.3
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2025-12-04 21:06 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-04 21:06 [PATCH] cgroup: rstat: force flush on css exit Shakeel Butt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox