]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cgroup: Make empty assignments reset to default
authorMichal Koutný <mkoutny@suse.com>
Tue, 4 Feb 2020 13:50:51 +0000 (14:50 +0100)
committerMichal Koutný <mkoutny@suse.com>
Tue, 2 Jun 2020 16:59:47 +0000 (18:59 +0200)
When MemoryLow= or MemoryMin= is set, it is interpretted as setting the
values to infinity. This is inconsistent with the default initialization
to 0.
It'd be nice to interpret the empty assignment as fallback to
DefaultMemory* of parent slice, however, current DBus API cannot convey
such a NULL value, so stick to simply interpretting that as hard-wired
default.

src/core/load-fragment.c
src/shared/bus-unit-util.c

index a967627946c716b38337cc137d7df75f8e69c746..781fe66f5e2620d0144bcba345843f15391d9be6 100644 (file)
@@ -3371,6 +3371,12 @@ int config_parse_memory_limit(
         uint64_t bytes = CGROUP_LIMIT_MAX;
         int r;
 
+        if (STR_IN_SET(lvalue, "DefaultMemoryLow",
+                               "DefaultMemoryMin",
+                               "MemoryLow",
+                               "MemoryMin"))
+                bytes = CGROUP_LIMIT_MIN;
+
         if (!isempty(rvalue) && !streq(rvalue, "infinity")) {
 
                 r = parse_permille(rvalue);
@@ -3391,17 +3397,11 @@ int config_parse_memory_limit(
         }
 
         if (streq(lvalue, "DefaultMemoryLow")) {
+                c->default_memory_low = bytes;
                 c->default_memory_low_set = true;
-                if (isempty(rvalue))
-                        c->default_memory_low = CGROUP_LIMIT_MIN;
-                else
-                        c->default_memory_low = bytes;
         } else if (streq(lvalue, "DefaultMemoryMin")) {
+                c->default_memory_min = bytes;
                 c->default_memory_min_set = true;
-                if (isempty(rvalue))
-                        c->default_memory_min = CGROUP_LIMIT_MIN;
-                else
-                        c->default_memory_min = bytes;
         } else if (streq(lvalue, "MemoryMin")) {
                 c->memory_min = bytes;
                 c->memory_min_set = true;
index 9a5730f3eae6145092d9a2d202d44b81ffc0dd16..48171469a50d540b3162b3dae1037b015217aecb 100644 (file)
@@ -489,11 +489,24 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons
                               "MemoryLimit",
                               "TasksMax")) {
 
-                if (isempty(eq) || streq(eq, "infinity")) {
+                if (streq(eq, "infinity")) {
                         r = sd_bus_message_append(m, "(sv)", field, "t", CGROUP_LIMIT_MAX);
                         if (r < 0)
                                 return bus_log_create_error(r);
                         return 1;
+                } else if (isempty(eq)) {
+                        uint64_t empty_value = STR_IN_SET(field,
+                                                          "DefaultMemoryLow",
+                                                          "DefaultMemoryMin",
+                                                          "MemoryLow",
+                                                          "MemoryMin") ?
+                                               CGROUP_LIMIT_MIN :
+                                               CGROUP_LIMIT_MAX;
+
+                        r = sd_bus_message_append(m, "(sv)", field, "t", empty_value);
+                        if (r < 0)
+                                return bus_log_create_error(r);
+                        return 1;
                 }
 
                 r = parse_permille(eq);