cgroup: no need for cgroup_mutex for /proc/cgroups
authorShakeel Butt <shakeelb@google.com>
Mon, 25 Oct 2021 06:19:16 +0000 (23:19 -0700)
committerTejun Heo <tj@kernel.org>
Mon, 25 Oct 2021 17:26:00 +0000 (07:26 -1000)
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@google.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
kernel/cgroup/cgroup-v1.c

index fd14a60379c1031ef601e8793b4dd78ee8259de9..81c9e0685948ceb4c69b454fd4f7f0352eb5a3aa 100644 (file)
@@ -659,11 +659,9 @@ 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_each_subsys(ss, i)
                seq_printf(m, "%s\t%d\t%d\t%d\n",
@@ -671,7 +669,6 @@ int proc_cgroupstats_show(struct seq_file *m, void *v)
                           atomic_read(&ss->root->nr_cgrps),
                           cgroup_ssid_enabled(i));
 
-       mutex_unlock(&cgroup_mutex);
        return 0;
 }