[Devel] [PATCH RH7] cgroup: no need for cgroup_mutex for /proc/cgroups

Pavel Tikhomirov ptikhomirov at virtuozzo.com
Mon Apr 11 17:17:05 MSK 2022


From: Shakeel Butt <shakeelb at google.com>

On the real systems, the cgroups hierarchies are setup early and just
once by the node controller, so, other than number of cgroups, all
information in /proc/cgroups remain same for the system uptime. Let's
remove the cgroup_mutex usage on reading /proc/cgroups. There is a
chance of inconsistent number of cgroups for co-mounted cgroups while
printing the information from /proc/cgroups but that is not a big
issue. In addition /proc/cgroups is a v1 specific interface, so the
dependency on it should reduce over time.

The main motivation for removing the cgroup_mutex from /proc/cgroups is
to reduce the avenues of its contention. On our fleet, we have observed
buggy application hammering on /proc/cgroups and drastically slowing
down the node controller on the system which have many negative
consequences on other workloads running on the system.

Signed-off-by: Shakeel Butt <shakeelb at google.com>
Signed-off-by: Tejun Heo <tj at kernel.org>

https://jira.sw.ru/browse/PSBM-139206
(cherry picked from commit 822bc9bac9e9a2f76a772a34f745962dfc223353)
Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
 kernel/cgroup.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 846e22644474..64f4227b2305 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -5620,11 +5620,9 @@ static int proc_cgroupstats_show(struct seq_file *m, void *v)
 
 	seq_puts(m, "#subsys_name\thierarchy\tnum_cgroups\tenabled\n");
 	/*
-	 * ideally we don't want subsystems moving around while we do this.
-	 * cgroup_mutex is also necessary to guarantee an atomic snapshot of
-	 * subsys/hierarchy state.
+	 * Grab the subsystems state racily. No need to add avenue to
+	 * cgroup_mutex contention.
 	 */
-	mutex_lock(&cgroup_mutex);
 	for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) {
 		struct cgroup_subsys *ss = subsys[i];
 		int num;
@@ -5639,7 +5637,6 @@ static int proc_cgroupstats_show(struct seq_file *m, void *v)
 			   ss->name, ss->root->hierarchy_id,
 			   num, !ss->disabled);
 	}
-	mutex_unlock(&cgroup_mutex);
 	return 0;
 }
 
-- 
2.35.1



More information about the Devel mailing list