Skip to content

Commit 9b81d3a

Browse files
luizcaphtejun
authored andcommitted
cgroup: add cgroup_favordynmods= command-line option
We have a need of using favordynmods with cgroup v1, which doesn't support changing mount flags during remount. Enabling CONFIG_CGROUP_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_CGROUP_FAVOR_DYNMODS=y. Also, note that when cgroup_favordynmods=true favordynmods is never disabled in cgroup_destroy_root(). Signed-off-by: Luiz Capitulino <luizcap@amazon.com> Reviewed-by: Michal Koutný <mkoutny@suse.com> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent 105f3fe commit 9b81d3a

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,10 @@
580580
named mounts. Specifying both "all" and "named" disables
581581
all v1 hierarchies.
582582

583+
cgroup_favordynmods= [KNL] Enable or Disable favordynmods.
584+
Format: { "true" | "false" }
585+
Defaults to the value of CONFIG_CGROUP_FAVOR_DYNMODS.
586+
583587
cgroup.memory= [KNL] Pass options to the cgroup memory controller.
584588
Format: <string>
585589
nosocket -- Disable socket memory accounting.

kernel/cgroup/cgroup.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ static u16 have_exit_callback __read_mostly;
207207
static u16 have_release_callback __read_mostly;
208208
static u16 have_canfork_callback __read_mostly;
209209

210+
static bool have_favordynmods __ro_after_init = IS_ENABLED(CONFIG_CGROUP_FAVOR_DYNMODS);
211+
210212
/* cgroup namespace for init task */
211213
struct cgroup_namespace init_cgroup_ns = {
212214
.ns.count = REFCOUNT_INIT(2),
@@ -1350,7 +1352,9 @@ static void cgroup_destroy_root(struct cgroup_root *root)
13501352
cgroup_root_count--;
13511353
}
13521354

1353-
cgroup_favor_dynmods(root, false);
1355+
if (!have_favordynmods)
1356+
cgroup_favor_dynmods(root, false);
1357+
13541358
cgroup_exit_root_id(root);
13551359

13561360
cgroup_unlock();
@@ -2245,9 +2249,9 @@ static int cgroup_init_fs_context(struct fs_context *fc)
22452249
fc->user_ns = get_user_ns(ctx->ns->user_ns);
22462250
fc->global = true;
22472251

2248-
#ifdef CONFIG_CGROUP_FAVOR_DYNMODS
2249-
ctx->flags |= CGRP_ROOT_FAVOR_DYNMODS;
2250-
#endif
2252+
if (have_favordynmods)
2253+
ctx->flags |= CGRP_ROOT_FAVOR_DYNMODS;
2254+
22512255
return 0;
22522256
}
22532257

@@ -6766,6 +6770,12 @@ static int __init enable_cgroup_debug(char *str)
67666770
}
67676771
__setup("cgroup_debug", enable_cgroup_debug);
67686772

6773+
static int __init cgroup_favordynmods_setup(char *str)
6774+
{
6775+
return (kstrtobool(str, &have_favordynmods) == 0);
6776+
}
6777+
__setup("cgroup_favordynmods=", cgroup_favordynmods_setup);
6778+
67696779
/**
67706780
* css_tryget_online_from_dir - get corresponding css from a cgroup dentry
67716781
* @dentry: directory dentry of interest

0 commit comments

Comments
 (0)