Skip to content

Commit 646faf3

Browse files
Werkovhtejun
authored andcommitted
cgroup: Add compatibility option for content of /proc/cgroups
/proc/cgroups lists only v1 controllers by default, however, this is only enforced since the commit af000ce ("cgroup: Do not report unavailable v1 controllers in /proc/cgroups") and there is software in the wild that uses content of /proc/cgroups to decide on availability of v2 (sic) controllers. Add a boottime param that can bring back the previous behavior for setups where the check in the software cannot be changed and it causes e.g. unintended OOMs. Also, this patch takes out cgrp_v1_visible from cgroup1_subsys_absent() guard since it's only important to check which hierarchy (v1 vs v2) the subsys is attached to. This has no effect on the printed message but the code is cleaner since cgrp_v1_visible is really about mounted hierarchies, not the content of /proc/cgroups. Link: https://lore.kernel.org/r/[email protected] Fixes: af000ce ("cgroup: Do not report unavailable v1 controllers in /proc/cgroups") Fixes: a0ab145 ("cgroup: Print message when /proc/cgroups is read on v2-only system") Signed-off-by: Michal Koutný <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent 954bacc commit 646faf3

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,14 @@
630630
named mounts. Specifying both "all" and "named" disables
631631
all v1 hierarchies.
632632

633+
cgroup_v1_proc= [KNL] Show also missing controllers in /proc/cgroups
634+
Format: { "true" | "false" }
635+
/proc/cgroups lists only v1 controllers by default.
636+
This compatibility option enables listing also v2
637+
controllers (whose v1 code is not compiled!), so that
638+
semi-legacy software can check this file to decide
639+
about usage of v2 (sic) controllers.
640+
633641
cgroup_favordynmods= [KNL] Enable or Disable favordynmods.
634642
Format: { "true" | "false" }
635643
Defaults to the value of CONFIG_CGROUP_FAVOR_DYNMODS.

kernel/cgroup/cgroup-v1.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ static u16 cgroup_no_v1_mask;
3232
/* disable named v1 mounts */
3333
static bool cgroup_no_v1_named;
3434

35+
/* Show unavailable controllers in /proc/cgroups */
36+
static bool proc_show_all;
37+
3538
/*
3639
* pidlist destructions need to be flushed on cgroup destruction. Use a
3740
* separate workqueue as flush domain.
@@ -683,10 +686,11 @@ int proc_cgroupstats_show(struct seq_file *m, void *v)
683686
*/
684687

685688
for_each_subsys(ss, i) {
686-
if (cgroup1_subsys_absent(ss))
687-
continue;
688689
cgrp_v1_visible |= ss->root != &cgrp_dfl_root;
689690

691+
if (!proc_show_all && cgroup1_subsys_absent(ss))
692+
continue;
693+
690694
seq_printf(m, "%s\t%d\t%d\t%d\n",
691695
ss->legacy_name, ss->root->hierarchy_id,
692696
atomic_read(&ss->root->nr_cgrps),
@@ -1359,3 +1363,9 @@ static int __init cgroup_no_v1(char *str)
13591363
return 1;
13601364
}
13611365
__setup("cgroup_no_v1=", cgroup_no_v1);
1366+
1367+
static int __init cgroup_v1_proc(char *str)
1368+
{
1369+
return (kstrtobool(str, &proc_show_all) == 0);
1370+
}
1371+
__setup("cgroup_v1_proc=", cgroup_v1_proc);

0 commit comments

Comments
 (0)