public inbox for cgroups@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cgroup: wait for css offline when rmdir
@ 2022-05-27  2:39 Hongchen Zhang
       [not found] ` <1653619158-27607-1-git-send-email-zhanghongchen-cXZgJK919ebM1kAEIRd3EQ@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Hongchen Zhang @ 2022-05-27  2:39 UTC (permalink / raw)
  To: Tejun Heo, Zefan Li, Johannes Weiner
  Cc: cgroups, linux-kernel, Hongchen Zhang

when remove a cgroup dir, make sure all the csses associated which
the cgroup are all offlined,so that we will be sure that the resources
allocated by the csses are all freed when rmdir exit successfully.

Signed-off-by: Hongchen Zhang <zhanghongchen@loongson.cn>
---
 kernel/cgroup/cgroup.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index adb820e..12d3a14 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -3020,6 +3020,31 @@ void cgroup_lock_and_drain_offline(struct cgroup *cgrp)
 	}
 }
 
+/* wait all cgrp's csses become offlined */
+void cgroup_wait_css_offline(struct cgroup *cgrp)
+{
+	struct cgroup_subsys *ss;
+	int ssid;
+
+	lockdep_assert_held(&cgroup_mutex);
+	for_each_subsys(ss, ssid) {
+		struct cgroup_subsys_state *css = cgroup_css(cgrp, ss);
+		DEFINE_WAIT(wait);
+
+		if (!css || !percpu_ref_is_dying(&css->refcnt))
+			continue;
+
+		prepare_to_wait(&cgrp->offline_waitq, &wait,
+				TASK_UNINTERRUPTIBLE);
+
+		mutex_unlock(&cgroup_mutex);
+		schedule();
+		finish_wait(&cgrp->offline_waitq, &wait);
+
+		mutex_lock(&cgroup_mutex);
+	}
+}
+
 /**
  * cgroup_save_control - save control masks and dom_cgrp of a subtree
  * @cgrp: root of the target subtree
@@ -5724,6 +5749,7 @@ int cgroup_rmdir(struct kernfs_node *kn)
 	if (!ret)
 		TRACE_CGROUP_PATH(rmdir, cgrp);
 
+	cgroup_wait_css_offline(cgrp);
 	cgroup_kn_unlock(kn);
 	return ret;
 }
-- 
1.8.3.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-05-31 17:22 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-27  2:39 [PATCH] cgroup: wait for css offline when rmdir Hongchen Zhang
     [not found] ` <1653619158-27607-1-git-send-email-zhanghongchen-cXZgJK919ebM1kAEIRd3EQ@public.gmane.org>
2022-05-27  8:46   ` kernel test robot
2022-05-27  8:48   ` Tejun Heo
2022-05-30  1:53     ` Hongchen Zhang
     [not found]       ` <e74e03f1-cb54-b158-a085-2965fd088d1d-cXZgJK919ebM1kAEIRd3EQ@public.gmane.org>
2022-05-31  1:01         ` Tejun Heo
     [not found]           ` <YpVo4XiIDu68w40Z-NiLfg/pYEd1N0TnZuCh8vA@public.gmane.org>
2022-05-31  3:49             ` Hongchen Zhang
     [not found]               ` <fbb820c5-dbcb-0f00-c365-d3c57ca27edf-cXZgJK919ebM1kAEIRd3EQ@public.gmane.org>
2022-05-31 17:19                 ` Tejun Heo
     [not found]                   ` <YpZOIz/CbQs+aWF6-NiLfg/pYEd1N0TnZuCh8vA@public.gmane.org>
2022-05-31 17:22                     ` Tejun Heo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox