linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cgroup: provide cgroup_nov1= to disable controllers in v1 mounts
@ 2016-02-10 22:59 Johannes Weiner
  2016-02-11 15:17 ` Tejun Heo
  0 siblings, 1 reply; 6+ messages in thread
From: Johannes Weiner @ 2016-02-10 22:59 UTC (permalink / raw)
  To: Tejun Heo; +Cc: cgroups, linux-kernel, kernel-team

Testing cgroup2 can be painful with system software automatically
mounting and populating all cgroup controllers in v1 mode. Sometimes
they can be unmounted from rc.local, sometimes even that is too late.

Provide a commandline option to disable certain controllers in v1
mounts, so that they remain available for cgroup2 mounts.

Example use:

cgroup_nov1=memory,cpu
cgroup_nov1=all

Disabling will be confirmed at boot-time as such:

[    0.013770] Disabling cpu control group subsystem in v1 mounts
[    0.016004] Disabling memory control group subsystem in v1 mounts

Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
---
 kernel/cgroup.c | 43 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)

diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index d27904c193da..44ff23a10235 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -180,6 +180,9 @@ EXPORT_SYMBOL_GPL(cgrp_dfl_root);
  */
 static bool cgrp_dfl_root_visible;
 
+/* Controllers blocked by the commandline in v1 */
+static unsigned long cgroup_nov1_mask;
+
 /* some controllers are not supported in the default hierarchy */
 static unsigned long cgrp_dfl_root_inhibit_ss_mask;
 
@@ -241,6 +244,11 @@ static bool cgroup_ssid_enabled(int ssid)
 	return static_key_enabled(cgroup_subsys_enabled_key[ssid]);
 }
 
+static bool cgroup_ssid_nov1(int ssid)
+{
+	return cgroup_nov1_mask & (1 << ssid);
+}
+
 /**
  * cgroup_on_dfl - test whether a cgroup is on the default hierarchy
  * @cgrp: the cgroup of interest
@@ -1678,6 +1686,8 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts)
 				continue;
 			if (!cgroup_ssid_enabled(i))
 				continue;
+			if (cgroup_ssid_nov1(i))
+				continue;
 
 			/* Mutually exclusive option 'all' + subsystem name */
 			if (all_ss)
@@ -1698,7 +1708,7 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts)
 	 */
 	if (all_ss || (!one_ss && !opts->none && !opts->name))
 		for_each_subsys(ss, i)
-			if (cgroup_ssid_enabled(i))
+			if (cgroup_ssid_enabled(i) && !cgroup_ssid_nov1(i))
 				opts->subsys_mask |= (1 << i);
 
 	/*
@@ -5324,6 +5334,10 @@ int __init cgroup_init(void)
 			continue;
 		}
 
+		if (cgroup_ssid_nov1(ssid))
+			printk(KERN_INFO "Disabling %s control group subsystem in v1 mounts\n",
+			       ss->name);
+
 		cgrp_dfl_root.subsys_mask |= 1 << ss->id;
 
 		if (!ss->dfl_cftypes)
@@ -5750,6 +5764,33 @@ static int __init cgroup_disable(char *str)
 }
 __setup("cgroup_disable=", cgroup_disable);
 
+static int __init cgroup_nov1(char *str)
+{
+	struct cgroup_subsys *ss;
+	char *token;
+	int i;
+
+	while ((token = strsep(&str, ",")) != NULL) {
+		if (!*token)
+			continue;
+
+		if (!strcmp(token, "all")) {
+			cgroup_nov1_mask = ~0UL;
+			break;
+		}
+
+		for_each_subsys(ss, i) {
+			if (strcmp(token, ss->name) &&
+			    strcmp(token, ss->legacy_name))
+				continue;
+
+			cgroup_nov1_mask |= 1 << i;
+		}
+	}
+	return 1;
+}
+__setup("cgroup_nov1=", cgroup_nov1);
+
 /**
  * css_tryget_online_from_dir - get corresponding css from a cgroup dentry
  * @dentry: directory dentry of interest
-- 
2.7.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] cgroup: provide cgroup_nov1= to disable controllers in v1 mounts
  2016-02-10 22:59 [PATCH] cgroup: provide cgroup_nov1= to disable controllers in v1 mounts Johannes Weiner
@ 2016-02-11 15:17 ` Tejun Heo
  2016-02-11 18:34   ` Johannes Weiner
  0 siblings, 1 reply; 6+ messages in thread
From: Tejun Heo @ 2016-02-11 15:17 UTC (permalink / raw)
  To: Johannes Weiner; +Cc: cgroups, linux-kernel, kernel-team

Hello,

On Wed, Feb 10, 2016 at 05:59:55PM -0500, Johannes Weiner wrote:
> cgroup_nov1=memory,cpu
> cgroup_nov1=all

It looks kinda confusing.  cgroup_no_v1?

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] cgroup: provide cgroup_nov1= to disable controllers in v1 mounts
  2016-02-11 15:17 ` Tejun Heo
@ 2016-02-11 18:34   ` Johannes Weiner
  2016-02-12 20:03     ` Tejun Heo
  0 siblings, 1 reply; 6+ messages in thread
From: Johannes Weiner @ 2016-02-11 18:34 UTC (permalink / raw)
  To: Tejun Heo; +Cc: cgroups, linux-kernel, kernel-team

On Thu, Feb 11, 2016 at 10:17:07AM -0500, Tejun Heo wrote:
> Hello,
> 
> On Wed, Feb 10, 2016 at 05:59:55PM -0500, Johannes Weiner wrote:
> > cgroup_nov1=memory,cpu
> > cgroup_nov1=all
> 
> It looks kinda confusing.  cgroup_no_v1?

What's ambiguous about November 1st mode?

>From 89e581ca54bdca37d6c464334d2217d14a229540 Mon Sep 17 00:00:00 2001
From: Johannes Weiner <hannes@cmpxchg.org>
Date: Wed, 10 Feb 2016 17:29:31 -0500
Subject: [PATCH] cgroup: provide cgroup_no_v1= to disable controllers in v1
 mounts

Testing cgroup2 can be painful with system software automatically
mounting and populating all cgroup controllers in v1 mode. Sometimes
they can be unmounted from rc.local, sometimes even that is too late.

Provide a commandline option to disable certain controllers in v1
mounts, so that they remain available for cgroup2 mounts.

Example use:

cgroup_no_v1=memory,cpu
cgroup_no_v1=all

Disabling will be confirmed at boot-time as such:

[    0.013770] Disabling cpu control group subsystem in v1 mounts
[    0.016004] Disabling memory control group subsystem in v1 mounts

Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
---
 kernel/cgroup.c | 43 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)

diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index d27904c193da..7ad61915967f 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -180,6 +180,9 @@ EXPORT_SYMBOL_GPL(cgrp_dfl_root);
  */
 static bool cgrp_dfl_root_visible;
 
+/* Controllers blocked by the commandline in v1 */
+static unsigned long cgroup_no_v1_mask;
+
 /* some controllers are not supported in the default hierarchy */
 static unsigned long cgrp_dfl_root_inhibit_ss_mask;
 
@@ -241,6 +244,11 @@ static bool cgroup_ssid_enabled(int ssid)
 	return static_key_enabled(cgroup_subsys_enabled_key[ssid]);
 }
 
+static bool cgroup_ssid_no_v1(int ssid)
+{
+	return cgroup_no_v1_mask & (1 << ssid);
+}
+
 /**
  * cgroup_on_dfl - test whether a cgroup is on the default hierarchy
  * @cgrp: the cgroup of interest
@@ -1678,6 +1686,8 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts)
 				continue;
 			if (!cgroup_ssid_enabled(i))
 				continue;
+			if (cgroup_ssid_no_v1(i))
+				continue;
 
 			/* Mutually exclusive option 'all' + subsystem name */
 			if (all_ss)
@@ -1698,7 +1708,7 @@ static int parse_cgroupfs_options(char *data, struct cgroup_sb_opts *opts)
 	 */
 	if (all_ss || (!one_ss && !opts->none && !opts->name))
 		for_each_subsys(ss, i)
-			if (cgroup_ssid_enabled(i))
+			if (cgroup_ssid_enabled(i) && !cgroup_ssid_no_v1(i))
 				opts->subsys_mask |= (1 << i);
 
 	/*
@@ -5324,6 +5334,10 @@ int __init cgroup_init(void)
 			continue;
 		}
 
+		if (cgroup_ssid_no_v1(ssid))
+			printk(KERN_INFO "Disabling %s control group subsystem in v1 mounts\n",
+			       ss->name);
+
 		cgrp_dfl_root.subsys_mask |= 1 << ss->id;
 
 		if (!ss->dfl_cftypes)
@@ -5750,6 +5764,33 @@ static int __init cgroup_disable(char *str)
 }
 __setup("cgroup_disable=", cgroup_disable);
 
+static int __init cgroup_no_v1(char *str)
+{
+	struct cgroup_subsys *ss;
+	char *token;
+	int i;
+
+	while ((token = strsep(&str, ",")) != NULL) {
+		if (!*token)
+			continue;
+
+		if (!strcmp(token, "all")) {
+			cgroup_no_v1_mask = ~0UL;
+			break;
+		}
+
+		for_each_subsys(ss, i) {
+			if (strcmp(token, ss->name) &&
+			    strcmp(token, ss->legacy_name))
+				continue;
+
+			cgroup_no_v1_mask |= 1 << i;
+		}
+	}
+	return 1;
+}
+__setup("cgroup_no_v1=", cgroup_no_v1);
+
 /**
  * css_tryget_online_from_dir - get corresponding css from a cgroup dentry
  * @dentry: directory dentry of interest
-- 
2.7.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] cgroup: provide cgroup_nov1= to disable controllers in v1 mounts
  2016-02-11 18:34   ` Johannes Weiner
@ 2016-02-12 20:03     ` Tejun Heo
  2016-02-16 18:21       ` Johannes Weiner
  0 siblings, 1 reply; 6+ messages in thread
From: Tejun Heo @ 2016-02-12 20:03 UTC (permalink / raw)
  To: Johannes Weiner; +Cc: cgroups, linux-kernel, kernel-team

On Thu, Feb 11, 2016 at 01:34:49PM -0500, Johannes Weiner wrote:
> From 89e581ca54bdca37d6c464334d2217d14a229540 Mon Sep 17 00:00:00 2001
> From: Johannes Weiner <hannes@cmpxchg.org>
> Date: Wed, 10 Feb 2016 17:29:31 -0500
> Subject: [PATCH] cgroup: provide cgroup_no_v1= to disable controllers in v1
>  mounts

Applied to cgroup/for-4.6.  Can you please send another patch to
update Documentation/kernel-parameters.txt and cgroup.txt for the new
knob?

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] cgroup: provide cgroup_nov1= to disable controllers in v1 mounts
  2016-02-12 20:03     ` Tejun Heo
@ 2016-02-16 18:21       ` Johannes Weiner
  2016-02-16 18:26         ` Tejun Heo
  0 siblings, 1 reply; 6+ messages in thread
From: Johannes Weiner @ 2016-02-16 18:21 UTC (permalink / raw)
  To: Tejun Heo; +Cc: cgroups, linux-kernel, kernel-team

On Fri, Feb 12, 2016 at 03:03:34PM -0500, Tejun Heo wrote:
> On Thu, Feb 11, 2016 at 01:34:49PM -0500, Johannes Weiner wrote:
> > From 89e581ca54bdca37d6c464334d2217d14a229540 Mon Sep 17 00:00:00 2001
> > From: Johannes Weiner <hannes@cmpxchg.org>
> > Date: Wed, 10 Feb 2016 17:29:31 -0500
> > Subject: [PATCH] cgroup: provide cgroup_no_v1= to disable controllers in v1
> >  mounts
> 
> Applied to cgroup/for-4.6.  Can you please send another patch to
> update Documentation/kernel-parameters.txt and cgroup.txt for the new
> knob?

How about this?

>From 95ae2ca2211e0db4db63d2dd1b187e299d9490fb Mon Sep 17 00:00:00 2001
From: Johannes Weiner <hannes@cmpxchg.org>
Date: Tue, 16 Feb 2016 13:19:11 -0500
Subject: [PATCH] cgroup: document cgroup_no_v1=

Add cgroup_no_v1= to kernel-parameters.txt, and a small blurb to
cgroup-v2.txt section about transitioning from cgroup to cgroup2.

Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
---
 Documentation/cgroup-v2.txt         | 6 ++++++
 Documentation/kernel-parameters.txt | 5 +++++
 2 files changed, 11 insertions(+)

diff --git a/Documentation/cgroup-v2.txt b/Documentation/cgroup-v2.txt
index e2f4e7948a66..e892c7ab39ef 100644
--- a/Documentation/cgroup-v2.txt
+++ b/Documentation/cgroup-v2.txt
@@ -132,6 +132,12 @@ strongly discouraged for production use.  It is recommended to decide
 the hierarchies and controller associations before starting using the
 controllers after system boot.
 
+During transition to v2, system management software might still
+automount the v1 cgroup filesystem and so hijack all controllers
+during boot, before manual intervention is possible. To make testing
+and experimenting easier, the kernel parameter cgroup_no_v1= allows
+disabling controllers in v1 and make them always available in v2.
+
 
 2-2. Organizing Processes
 
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index 444bff30e1cf..150173f47115 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -608,6 +608,11 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
 			cut the overhead, others just disable the usage. So
 			only cgroup_disable=memory is actually worthy}
 
+	cgroup_no_v1=	[KNL] Disable one, multiple, all cgroup controllers in v1
+			Format: { controller[,controller...] | "all" }
+			Like cgroup_disable, but only applies to cgroup v1;
+			the blacklisted controllers remain available in cgroup2.
+
 	cgroup.memory=	[KNL] Pass options to the cgroup memory controller.
 			Format: <string>
 			nosocket -- Disable socket memory accounting.
-- 
2.7.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] cgroup: provide cgroup_nov1= to disable controllers in v1 mounts
  2016-02-16 18:21       ` Johannes Weiner
@ 2016-02-16 18:26         ` Tejun Heo
  0 siblings, 0 replies; 6+ messages in thread
From: Tejun Heo @ 2016-02-16 18:26 UTC (permalink / raw)
  To: Johannes Weiner; +Cc: cgroups, linux-kernel, kernel-team

On Tue, Feb 16, 2016 at 01:21:14PM -0500, Johannes Weiner wrote:
> From 95ae2ca2211e0db4db63d2dd1b187e299d9490fb Mon Sep 17 00:00:00 2001
> From: Johannes Weiner <hannes@cmpxchg.org>
> Date: Tue, 16 Feb 2016 13:19:11 -0500
> Subject: [PATCH] cgroup: document cgroup_no_v1=
> 
> Add cgroup_no_v1= to kernel-parameters.txt, and a small blurb to
> cgroup-v2.txt section about transitioning from cgroup to cgroup2.
> 
> Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>

Applied to cgroup/for-4.6.

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-02-16 18:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-10 22:59 [PATCH] cgroup: provide cgroup_nov1= to disable controllers in v1 mounts Johannes Weiner
2016-02-11 15:17 ` Tejun Heo
2016-02-11 18:34   ` Johannes Weiner
2016-02-12 20:03     ` Tejun Heo
2016-02-16 18:21       ` Johannes Weiner
2016-02-16 18:26         ` Tejun Heo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).