Message ID | 20250304153801.597907-5-mkoutny@suse.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | cgroup v1 deprecation warnings | expand |
Context | Check | Description |
---|---|---|
shin/vmtest-linus-master-PR | success | PR summary |
shin/vmtest-linus-master-VM_Test-0 | success | Logs for build-kernel |
On Tue, Mar 04, 2025 at 04:37:56PM +0100, Michal Koutný wrote: > As a followup to commits 6c2920926b10e ("cgroup: replace > unified-hierarchy.txt with a proper cgroup v2 documentation") and > ab03125268679 ("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 neven mount v2 but read /proc/cgroups upon > boot when controllers default to v2). I'm hoping that we could deprecate /proc/cgroups entirely. Maybe we can just warn whenever the file is accessed? Thanks.
On Tue, Mar 04, 2025 at 06:55:02AM -1000, Tejun Heo <tj@kernel.org> wrote: > I'm hoping that we could deprecate /proc/cgroups entirely. Maybe we can just > warn whenever the file is accessed? I added the guard with legacy systems (i.e. make this backportable) in mind which start with no cgroupfs mounted at all and until they decide to continue either v1 or v2 way, looking at /proc/cgroups is fine. It should warn users that look at /proc/cgroups in cases when it bears no valid information. Michal
On 3/5/25 5:17 AM, Michal Koutný wrote: > On Tue, Mar 04, 2025 at 06:55:02AM -1000, Tejun Heo <tj@kernel.org> wrote: >> I'm hoping that we could deprecate /proc/cgroups entirely. Maybe we can just >> warn whenever the file is accessed? > I added the guard with legacy systems (i.e. make this backportable) in > mind which start with no cgroupfs mounted at all and until they decide > to continue either v1 or v2 way, looking at /proc/cgroups is fine. > It should warn users that look at /proc/cgroups in cases when it bears > no valid information. I like the idea of warning users about using /etc/cgroups if no v1 filesystem is mounted. It makes sense to make it backportable to older kernel. We can always add a follow-up patch later to always warn about it. Acked-by: Waiman Long <longman@redhat.com>
diff --git a/kernel/cgroup/cgroup-internal.h b/kernel/cgroup/cgroup-internal.h index c964dd7ff967a..95ab39e1ec8f0 100644 --- a/kernel/cgroup/cgroup-internal.h +++ b/kernel/cgroup/cgroup-internal.h @@ -168,6 +168,7 @@ struct cgroup_mgctx { extern struct cgroup_subsys *cgroup_subsys[]; extern struct list_head cgroup_roots; +extern bool cgrp_dfl_visible; /* iterate across the hierarchies */ #define for_each_root(root) \ diff --git a/kernel/cgroup/cgroup-v1.c b/kernel/cgroup/cgroup-v1.c index e28d5f0d20ed0..5c59b01024019 100644 --- a/kernel/cgroup/cgroup-v1.c +++ b/kernel/cgroup/cgroup-v1.c @@ -673,6 +673,7 @@ struct cftype cgroup1_base_files[] = { int proc_cgroupstats_show(struct seq_file *m, void *v) { struct cgroup_subsys *ss; + bool cgrp_v1_visible = false; int i; seq_puts(m, "#subsys_name\thierarchy\tnum_cgroups\tenabled\n"); @@ -684,12 +685,18 @@ int proc_cgroupstats_show(struct seq_file *m, void *v) for_each_subsys(ss, i) { if (cgroup1_subsys_absent(ss)) continue; + cgrp_v1_visible |= ss->root != &cgrp_dfl_root; + seq_printf(m, "%s\t%d\t%d\t%d\n", ss->legacy_name, ss->root->hierarchy_id, atomic_read(&ss->root->nr_cgrps), cgroup_ssid_enabled(i)); } + if (cgrp_dfl_visible && !cgrp_v1_visible) + pr_warn_once("/proc/cgroups lists only v1 controllers, use cgroup.controllers of root cgroup for v2 info\n"); + + return 0; } diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index afc665b7b1fe5..3a5af0fc544a6 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -171,7 +171,7 @@ EXPORT_SYMBOL_GPL(cgrp_dfl_root); * The default hierarchy always exists but is hidden until mounted for the * first time. This is for backward compatibility. */ -static bool cgrp_dfl_visible; +bool cgrp_dfl_visible; /* some controllers are not supported in the default hierarchy */ static u16 cgrp_dfl_inhibit_ss_mask;
As a followup to commits 6c2920926b10e ("cgroup: replace unified-hierarchy.txt with a proper cgroup v2 documentation") and ab03125268679 ("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 neven mount v2 but read /proc/cgroups upon boot when controllers default to v2). Signed-off-by: Michal Koutný <mkoutny@suse.com> --- kernel/cgroup/cgroup-internal.h | 1 + kernel/cgroup/cgroup-v1.c | 7 +++++++ kernel/cgroup/cgroup.c | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-)