Skip to content

Commit a0ab145

Browse files
Werkovhtejun
authored andcommitted
cgroup: Print message when /proc/cgroups is read on v2-only system
As a followup to commits 6c29209 ("cgroup: replace unified-hierarchy.txt with a proper cgroup v2 documentation") and ab03125 ("cgroup: Show # of subsystem CSSes in cgroup.stat"), add a runtime message to users who read status of controllers in /proc/cgroups on v2-only system. The detection is based on a) no controllers are attached to v1, b) default hierarchy is mounted (the latter is for setups that never mount v2 but read /proc/cgroups upon boot when controllers default to v2, so that this code may be backported to older kernels). Signed-off-by: Michal Koutný <[email protected]> Acked-by: Waiman Long <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent 77bbb25 commit a0ab145

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

kernel/cgroup/cgroup-internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ struct cgroup_mgctx {
168168

169169
extern struct cgroup_subsys *cgroup_subsys[];
170170
extern struct list_head cgroup_roots;
171+
extern bool cgrp_dfl_visible;
171172

172173
/* iterate across the hierarchies */
173174
#define for_each_root(root) \

kernel/cgroup/cgroup-v1.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,7 @@ struct cftype cgroup1_base_files[] = {
673673
int proc_cgroupstats_show(struct seq_file *m, void *v)
674674
{
675675
struct cgroup_subsys *ss;
676+
bool cgrp_v1_visible = false;
676677
int i;
677678

678679
seq_puts(m, "#subsys_name\thierarchy\tnum_cgroups\tenabled\n");
@@ -684,12 +685,18 @@ int proc_cgroupstats_show(struct seq_file *m, void *v)
684685
for_each_subsys(ss, i) {
685686
if (cgroup1_subsys_absent(ss))
686687
continue;
688+
cgrp_v1_visible |= ss->root != &cgrp_dfl_root;
689+
687690
seq_printf(m, "%s\t%d\t%d\t%d\n",
688691
ss->legacy_name, ss->root->hierarchy_id,
689692
atomic_read(&ss->root->nr_cgrps),
690693
cgroup_ssid_enabled(i));
691694
}
692695

696+
if (cgrp_dfl_visible && !cgrp_v1_visible)
697+
pr_info_once("/proc/cgroups lists only v1 controllers, use cgroup.controllers of root cgroup for v2 info\n");
698+
699+
693700
return 0;
694701
}
695702

kernel/cgroup/cgroup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ EXPORT_SYMBOL_GPL(cgrp_dfl_root);
171171
* The default hierarchy always exists but is hidden until mounted for the
172172
* first time. This is for backward compatibility.
173173
*/
174-
static bool cgrp_dfl_visible;
174+
bool cgrp_dfl_visible;
175175

176176
/* some controllers are not supported in the default hierarchy */
177177
static u16 cgrp_dfl_inhibit_ss_mask;

0 commit comments

Comments
 (0)