cgroup: Disable cgroup "memory" by default
authorPhil Elwell <phil@raspberrypi.org>
Mon, 27 Nov 2017 17:14:54 +0000 (17:14 +0000)
committerDom Cobley <popcornmix@gmail.com>
Mon, 19 Feb 2024 11:31:31 +0000 (11:31 +0000)
Some Raspberry Pis have limited RAM and most users won't use the
cgroup memory support so it is disabled by default. Enable with:

    cgroup_enable=memory

See: https://github.com/raspberrypi/linux/issues/1950

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
kernel/cgroup/cgroup.c

index 518725b..5165f5c 100644 (file)
@@ -6051,6 +6051,9 @@ int __init cgroup_init_early(void)
        return 0;
 }
 
+static u16 cgroup_enable_mask __initdata;
+static int __init cgroup_disable(char *str);
+
 /**
  * cgroup_init - cgroup initialization
  *
@@ -6084,6 +6087,12 @@ int __init cgroup_init(void)
 
        cgroup_unlock();
 
+       /*
+        * Apply an implicit disable, knowing that an explicit enable will
+        * prevent if from doing anything.
+        */
+       cgroup_disable("memory");
+
        for_each_subsys(ss, ssid) {
                if (ss->early_init) {
                        struct cgroup_subsys_state *css =
@@ -6724,6 +6733,10 @@ static int __init cgroup_disable(char *str)
                            strcmp(token, ss->legacy_name))
                                continue;
 
+                       /* An explicit cgroup_enable overrides a disable */
+                       if (cgroup_enable_mask & (1 << i))
+                               continue;
+
                        static_branch_disable(cgroup_subsys_enabled_key[i]);
                        pr_info("Disabling %s control group subsystem\n",
                                ss->name);
@@ -6742,6 +6755,31 @@ static int __init cgroup_disable(char *str)
 }
 __setup("cgroup_disable=", cgroup_disable);
 
+static int __init cgroup_enable(char *str)
+{
+       struct cgroup_subsys *ss;
+       char *token;
+       int i;
+
+       while ((token = strsep(&str, ",")) != NULL) {
+               if (!*token)
+                       continue;
+
+               for_each_subsys(ss, i) {
+                       if (strcmp(token, ss->name) &&
+                           strcmp(token, ss->legacy_name))
+                               continue;
+
+                       cgroup_enable_mask |= 1 << i;
+                       static_branch_enable(cgroup_subsys_enabled_key[i]);
+                       pr_info("Enabling %s control group subsystem\n",
+                               ss->name);
+               }
+       }
+       return 1;
+}
+__setup("cgroup_enable=", cgroup_enable);
+
 void __init __weak enable_debug_cgroup(void) { }
 
 static int __init enable_cgroup_debug(char *str)