Skip to contentSkip to conversation

cgroup: add cgroup_favordynmods= command-line option

PATH Luiz Capitulino 2 participants 6 messages Aug 31, 2023 – Sep 5, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

We have a need of using favordynmods with cgroup v1, which doesn't support changing mount flags during remount. Enabling CONFIG_FAVOR_DYNMODS at build-time is not an option because we want to be able to selectively enable it for certain systems.

This commit addresses this by introducing the cgroup_favordynmods= command-line option. This option works for both cgroup v1 and v2 and also allows for disabling favorynmods when the kernel built with CONFIG_FAVOR_DYNMODS=y.

---
 Documentation/admin-guide/kernel-parameters.txt |  4 ++++
 kernel/cgroup/cgroup.c                          | 14 +++++++++++---
 2 files changed, 15 insertions(+), 3 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +4 -0
index 0c38a8af95ce..672f76a3c002 100644
@@ -580,6 +580,10 @@
 			named mounts. Specifying both "all" and "named" disables
 			all v1 hierarchies.
 
+	cgroup_favordynmods= [KNL] Enable or Disable favordynmods.
+			Format: { "true" | "false" }
+			Defaults to the value of CONFIG_CGROUP_FAVOR_DYNMODS.
+
 	cgroup.memory=	[KNL] Pass options to the cgroup memory controller.
 			Format: <string>
 			nosocket -- Disable socket memory accounting.
kernel/cgroup/cgroup.c +11 -3
index 5fa95f86cb4d..b625825e270b 100644
@@ -207,6 +207,8 @@ static u16 have_exit_callback __read_mostly;
 static u16 have_release_callback __read_mostly;
 static u16 have_canfork_callback __read_mostly;
 
+static bool have_favordynmods __read_mostly = IS_ENABLED(CONFIG_CGROUP_FAVOR_DYNMODS);
+
 /* cgroup namespace for init task */
 struct cgroup_namespace init_cgroup_ns = {
 	.ns.count	= REFCOUNT_INIT(2),
@@ -2265,9 +2267,9 @@ static int cgroup_init_fs_context(struct fs_context *fc)
 	fc->user_ns = get_user_ns(ctx->ns->user_ns);
 	fc->global = true;
 
-#ifdef CONFIG_CGROUP_FAVOR_DYNMODS
-	ctx->flags |= CGRP_ROOT_FAVOR_DYNMODS;
-#endif
+	if (have_favordynmods)
+		ctx->flags |= CGRP_ROOT_FAVOR_DYNMODS;
+
 	return 0;
 }
 
@@ -6767,6 +6769,12 @@ static int __init enable_cgroup_debug(char *str)
 }
 __setup("cgroup_debug", enable_cgroup_debug);
 
+static int __init cgroup_favordynmods_setup(char *str)
+{
+	return (kstrtobool(str, &have_favordynmods) == 0);
+}
+__setup("cgroup_favordynmods=", cgroup_favordynmods_setup);
+
 /**
  * css_tryget_online_from_dir - get corresponding css from a cgroup dentry
  * @dentry: directory dentry of interest
Signature · 1 line
2.40.1
#1 lore raw
Quoted 11 lines · Luiz Capitulino

We have a need of using favordynmods with cgroup v1, which doesn't support changing mount flags during remount. Enabling CONFIG_FAVOR_DYNMODS at build-time is not an option because we want to be able to selectively enable it for certain systems.

This commit addresses this by introducing the cgroup_favordynmods= command-line option. This option works for both cgroup v1 and v2 and also allows for disabling favorynmods when the kernel built with CONFIG_FAVOR_DYNMODS=y.

Hi,

Would somebody take a look at this patch please?

Thanks,

- Luiz

Quoted 62 lines
---
 Documentation/admin-guide/kernel-parameters.txt |  4 ++++
 kernel/cgroup/cgroup.c                          | 14 +++++++++++---
 2 files changed, 15 insertions(+), 3 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +4 -0
index 0c38a8af95ce..672f76a3c002 100644
@@ -580,6 +580,10 @@
 			named mounts. Specifying both "all" and "named" disables
 			all v1 hierarchies.
 
+	cgroup_favordynmods= [KNL] Enable or Disable favordynmods.
+			Format: { "true" | "false" }
+			Defaults to the value of CONFIG_CGROUP_FAVOR_DYNMODS.
+
 	cgroup.memory=	[KNL] Pass options to the cgroup memory controller.
 			Format: <string>
 			nosocket -- Disable socket memory accounting.
kernel/cgroup/cgroup.c +11 -3
index 5fa95f86cb4d..b625825e270b 100644
@@ -207,6 +207,8 @@ static u16 have_exit_callback __read_mostly;
 static u16 have_release_callback __read_mostly;
 static u16 have_canfork_callback __read_mostly;
 
+static bool have_favordynmods __read_mostly = IS_ENABLED(CONFIG_CGROUP_FAVOR_DYNMODS);
+
 /* cgroup namespace for init task */
 struct cgroup_namespace init_cgroup_ns = {
 	.ns.count	= REFCOUNT_INIT(2),
@@ -2265,9 +2267,9 @@ static int cgroup_init_fs_context(struct fs_context *fc)
 	fc->user_ns = get_user_ns(ctx->ns->user_ns);
 	fc->global = true;
 
-#ifdef CONFIG_CGROUP_FAVOR_DYNMODS
-	ctx->flags |= CGRP_ROOT_FAVOR_DYNMODS;
-#endif
+	if (have_favordynmods)
+		ctx->flags |= CGRP_ROOT_FAVOR_DYNMODS;
+
 	return 0;
 }
 
@@ -6767,6 +6769,12 @@ static int __init enable_cgroup_debug(char *str)
 }
 __setup("cgroup_debug", enable_cgroup_debug);
 
+static int __init cgroup_favordynmods_setup(char *str)
+{
+	return (kstrtobool(str, &have_favordynmods) == 0);
+}
+__setup("cgroup_favordynmods=", cgroup_favordynmods_setup);
+
 /**
  * css_tryget_online_from_dir - get corresponding css from a cgroup dentry
  * @dentry: directory dentry of interest
Signature · 1 line
2.40.1
#2 lore raw
Quoted 11 lines · Luiz Capitulino
Quoted 10 lines · Luiz Capitulino

We have a need of using favordynmods with cgroup v1, which doesn't support changing mount flags during remount. Enabling CONFIG_FAVOR_DYNMODS at build-time is not an option because we want to be able to selectively enable it for certain systems.

This commit addresses this by introducing the cgroup_favordynmods= command-line option. This option works for both cgroup v1 and v2 and also allows for disabling favorynmods when the kernel built with CONFIG_FAVOR_DYNMODS=y.

Quoted 8 lines
Quoted 1 line

Hi,

Would somebody take a look at this patch please?

Thanks,

- Luiz

The patch looks good to me. I do have a minor comment that it may be better to use the relatively new __ro_after_init qualifier instead of __read_mostly.

Cheers,
Longman

Quoted 62 lines
Quoted 62 lines
---
  Documentation/admin-guide/kernel-parameters.txt |  4 ++++
  kernel/cgroup/cgroup.c                          | 14 +++++++++++---
  2 files changed, 15 insertions(+), 3 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +4 -0
index 0c38a8af95ce..672f76a3c002 100644
@@ -580,6 +580,10 @@
  			named mounts. Specifying both "all" and "named" disables
  			all v1 hierarchies.
 
+	cgroup_favordynmods= [KNL] Enable or Disable favordynmods.
+			Format: { "true" | "false" }
+			Defaults to the value of CONFIG_CGROUP_FAVOR_DYNMODS.
+
  	cgroup.memory=	[KNL] Pass options to the cgroup memory controller.
  			Format: <string>
  			nosocket -- Disable socket memory accounting.
kernel/cgroup/cgroup.c +11 -3
index 5fa95f86cb4d..b625825e270b 100644
@@ -207,6 +207,8 @@ static u16 have_exit_callback __read_mostly;
  static u16 have_release_callback __read_mostly;
  static u16 have_canfork_callback __read_mostly;
 
+static bool have_favordynmods __read_mostly = IS_ENABLED(CONFIG_CGROUP_FAVOR_DYNMODS);
+
  /* cgroup namespace for init task */
  struct cgroup_namespace init_cgroup_ns = {
  	.ns.count	= REFCOUNT_INIT(2),
@@ -2265,9 +2267,9 @@ static int cgroup_init_fs_context(struct fs_context *fc)
  	fc->user_ns = get_user_ns(ctx->ns->user_ns);
  	fc->global = true;
 
-#ifdef CONFIG_CGROUP_FAVOR_DYNMODS
-	ctx->flags |= CGRP_ROOT_FAVOR_DYNMODS;
-#endif
+	if (have_favordynmods)
+		ctx->flags |= CGRP_ROOT_FAVOR_DYNMODS;
+
  	return 0;
  }
 
@@ -6767,6 +6769,12 @@ static int __init enable_cgroup_debug(char *str)
  }
  __setup("cgroup_debug", enable_cgroup_debug);
 
+static int __init cgroup_favordynmods_setup(char *str)
+{
+	return (kstrtobool(str, &have_favordynmods) == 0);
+}
+__setup("cgroup_favordynmods=", cgroup_favordynmods_setup);
+
  /**
   * css_tryget_online_from_dir - get corresponding css from a cgroup dentry
   * @dentry: directory dentry of interest
Signature · 1 line
2.40.1
#3 lore raw
Quoted 16 lines · Waiman Long
Quoted 14 lines · Luiz Capitulino
Quoted 11 lines · Luiz Capitulino

We have a need of using favordynmods with cgroup v1, which doesn't support changing mount flags during remount. Enabling CONFIG_FAVOR_DYNMODS at build-time is not an option because we want to be able to selectively enable it for certain systems.

This commit addresses this by introducing the cgroup_favordynmods= command-line option. This option works for both cgroup v1 and v2 and also allows for disabling favorynmods when the kernel built with CONFIG_FAVOR_DYNMODS=y.

Hi,

Quoted 8 lines
Quoted 5 lines

Would somebody take a look at this patch please?

Thanks,

- Luiz

The patch looks good to me. I do have a minor comment that it may be better to use the relatively new __ro_after_init qualifier instead of __read_mostly.

With this patch, CGROUP_FAVOR_DYNMODS kconfig option will have no user. So this config option should be removed as well.

Cheers,
Longman

#4 lore raw
Quoted 20 lines · Waiman Long
Quoted 18 lines · Waiman Long
Quoted 16 lines · Luiz Capitulino
Quoted 11 lines · Luiz Capitulino

We have a need of using favordynmods with cgroup v1, which doesn't support changing mount flags during remount. Enabling CONFIG_FAVOR_DYNMODS at build-time is not an option because we want to be able to selectively enable it for certain systems.

This commit addresses this by introducing the cgroup_favordynmods= command-line option. This option works for both cgroup v1 and v2 and also allows for disabling favorynmods when the kernel built with CONFIG_FAVOR_DYNMODS=y.

Hi,

Would somebody take a look at this patch please?

Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

Thanks,

- Luiz

The patch looks good to me. I do have a minor comment that it may be better to use the relatively new __ro_after_init qualifier instead of __read_mostly.

With this patch, CGROUP_FAVOR_DYNMODS kconfig option will have no user. So this config option should be removed as well.

My bad. That is not true. Please ignore this comment.

Regards,
Longman

#5 lore raw
Quoted 25 lines · Waiman Long
Quoted 21 lines · Waiman Long
Quoted 19 lines · Waiman Long
Quoted 17 lines · Luiz Capitulino
Quoted 6 lines · Luiz Capitulino

We have a need of using favordynmods with cgroup v1, which doesn't support
changing mount flags during remount. Enabling CONFIG_FAVOR_DYNMODS at build-time is not an option because we want to be able to selectively enable it for certain systems.

Quoted 6 lines

This commit addresses this by introducing the cgroup_favordynmods= command-line option. This option works for both cgroup v1 and v2 and also allows for disabling favorynmods when the kernel built with CONFIG_FAVOR_DYNMODS=y.

Hi,

Would somebody take a look at this patch please?

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

Thanks,

- Luiz

The patch looks good to me. I do have a minor comment that it may be better to use the relatively new __ro_after_init qualifier instead of __read_mostly.

Will do the change and post v2 shortly.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

With this patch, CGROUP_FAVOR_DYNMODS kconfig option will have no user. So this config option should be removed as well.

My bad. That is not true. Please ignore this comment.

OK, big thanks for taking a look so quickly!

- Luiz

Quoted 4 lines

Regards,
Longman