The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: "Michal Koutný" <mkoutny@suse.com>
To: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: "Michal Koutný" <mkoutny@suse.com>,
	"Waiman Long" <longman@redhat.com>, "Tejun Heo" <tj@kernel.org>,
	"Johannes Weiner" <hannes@cmpxchg.org>
Subject: [PATCH v2 04/11] cgroup: Print message when /proc/cgroups is read on v2-only system
Date: Tue, 11 Mar 2025 13:36:21 +0100	[thread overview]
Message-ID: <20250311123640.530377-5-mkoutny@suse.com> (raw)
In-Reply-To: <20250311123640.530377-1-mkoutny@suse.com>

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 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ý <mkoutny@suse.com>
Acked-by: Waiman Long <longman@redhat.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(-)

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..11ea8d24ac727 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_info_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;
-- 
2.48.1


  parent reply	other threads:[~2025-03-11 12:37 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-11 12:36 [PATCH v2 00/11] cgroup v1 deprecation messages Michal Koutný
2025-03-11 12:36 ` [PATCH v2 01/11] cgroup/cpuset-v1: Add deprecation messages to sched_load_balance and memory_pressure_enabled Michal Koutný
2025-03-11 14:02   ` Waiman Long
2025-03-11 12:36 ` [PATCH v2 02/11] cgroup/cpuset-v1: Add deprecation messages to memory_spread_page and memory_spread_slab Michal Koutný
2025-03-11 15:07   ` Waiman Long
2025-03-11 12:36 ` [PATCH v2 03/11] cgroup/blkio: Add deprecation messages to reset_stats Michal Koutný
2025-03-11 12:36 ` Michal Koutný [this message]
2025-03-11 12:36 ` [PATCH v2 05/11] cgroup/cpuset-v1: Add deprecation messages to mem_exclusive and mem_hardwall Michal Koutný
2025-03-11 15:08   ` Waiman Long
2025-03-11 12:36 ` [PATCH v2 06/11] cgroup/cpuset-v1: Add deprecation messages to memory_migrate Michal Koutný
2025-03-11 15:09   ` Waiman Long
2025-03-11 12:36 ` [PATCH v2 07/11] RFC cgroup/cpuset-v1: Add deprecation messages to sched_relax_domain_level Michal Koutný
2025-03-11 15:10   ` Waiman Long
2025-03-11 15:10   ` Waiman Long
2025-03-11 12:36 ` [PATCH v2 08/11] mm: Add transformation message for per-memcg swappiness Michal Koutný
2025-03-11 12:36 ` [PATCH v2 09/11] cgroup: Add deprecation message to legacy freezer controller Michal Koutný
2025-03-11 12:36 ` [PATCH v2 10/11] cgroup: Update file naming comment Michal Koutný
2025-03-11 12:36 ` [PATCH v2 11/11] blk-cgroup: Simplify policy files registration Michal Koutný
2025-03-11 18:56 ` [PATCH v2 00/11] cgroup v1 deprecation messages Jens Axboe
2025-03-11 19:23 ` Tejun Heo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250311123640.530377-5-mkoutny@suse.com \
    --to=mkoutny@suse.com \
    --cc=cgroups@vger.kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox