]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cgroup: Support 0-value for memory protection directives
authorChris Down <chris@chrisdown.name>
Fri, 3 May 2019 12:32:41 +0000 (08:32 -0400)
committerChris Down <chris@chrisdown.name>
Wed, 8 May 2019 11:06:32 +0000 (12:06 +0100)
These make sense to be explicitly set at 0 (which has a different effect
than the default, since it can affect processing of `DefaultMemoryXXX`).

Without this, it's not easily possible to relinquish memory protection
for a subtree, which is not great.

NEWS
src/core/dbus-cgroup.c
src/core/load-fragment.c

diff --git a/NEWS b/NEWS
index 57ed27a61d599072170819cf34f503bcfcaa17ae..78c44db4a6810c86c7c69c0a39a75fbcb0e00825 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -24,6 +24,9 @@ CHANGES WITH 243 in spe:
           hierarchically set default memory protection values for a particular
           subtree of the unit hierarchy.
 
+        * Memory protection directives can now take a value of zero, allowing
+          explicit opting out of a default value propagated by an ancestor.
+
           …
 
 CHANGES WITH 242:
index 4d2bd3d5e1b483500cf092d239d689cae476b127..d75628c663b6623dfa6eb5773dbed3e0c92d092c 100644 (file)
@@ -613,6 +613,7 @@ BUS_DEFINE_SET_CGROUP_WEIGHT(cpu_shares, CGROUP_MASK_CPU, CGROUP_CPU_SHARES_IS_O
 BUS_DEFINE_SET_CGROUP_WEIGHT(io_weight, CGROUP_MASK_IO, CGROUP_WEIGHT_IS_OK, CGROUP_WEIGHT_INVALID);
 BUS_DEFINE_SET_CGROUP_WEIGHT(blockio_weight, CGROUP_MASK_BLKIO, CGROUP_BLKIO_WEIGHT_IS_OK, CGROUP_BLKIO_WEIGHT_INVALID);
 BUS_DEFINE_SET_CGROUP_LIMIT(memory, CGROUP_MASK_MEMORY, physical_memory_scale, 1);
+BUS_DEFINE_SET_CGROUP_LIMIT(memory_protection, CGROUP_MASK_MEMORY, physical_memory_scale, 0);
 BUS_DEFINE_SET_CGROUP_LIMIT(swap, CGROUP_MASK_MEMORY, physical_memory_scale, 0);
 BUS_DEFINE_SET_CGROUP_LIMIT(tasks_max, CGROUP_MASK_PIDS, system_tasks_max_scale, 1);
 #pragma GCC diagnostic pop
@@ -672,16 +673,16 @@ int bus_cgroup_set_property(
                 return bus_cgroup_set_boolean(u, name, &c->memory_accounting, CGROUP_MASK_MEMORY, message, flags, error);
 
         if (streq(name, "MemoryMin"))
-                return bus_cgroup_set_memory(u, name, &c->memory_min, message, flags, error);
+                return bus_cgroup_set_memory_protection(u, name, &c->memory_min, message, flags, error);
 
         if (streq(name, "MemoryLow"))
-                return bus_cgroup_set_memory(u, name, &c->memory_low, message, flags, error);
+                return bus_cgroup_set_memory_protection(u, name, &c->memory_low, message, flags, error);
 
         if (streq(name, "DefaultMemoryMin"))
-                return bus_cgroup_set_memory(u, name, &c->default_memory_min, message, flags, error);
+                return bus_cgroup_set_memory_protection(u, name, &c->default_memory_min, message, flags, error);
 
         if (streq(name, "DefaultMemoryLow"))
-                return bus_cgroup_set_memory(u, name, &c->default_memory_low, message, flags, error);
+                return bus_cgroup_set_memory_protection(u, name, &c->default_memory_low, message, flags, error);
 
         if (streq(name, "MemoryHigh"))
                 return bus_cgroup_set_memory(u, name, &c->memory_high, message, flags, error);
@@ -696,16 +697,16 @@ int bus_cgroup_set_property(
                 return bus_cgroup_set_memory(u, name, &c->memory_limit, message, flags, error);
 
         if (streq(name, "MemoryMinScale"))
-                return bus_cgroup_set_memory_scale(u, name, &c->memory_min, message, flags, error);
+                return bus_cgroup_set_memory_protection_scale(u, name, &c->memory_min, message, flags, error);
 
         if (streq(name, "MemoryLowScale"))
-                return bus_cgroup_set_memory_scale(u, name, &c->memory_low, message, flags, error);
+                return bus_cgroup_set_memory_protection_scale(u, name, &c->memory_low, message, flags, error);
 
         if (streq(name, "DefaultMemoryMinScale"))
-                return bus_cgroup_set_memory_scale(u, name, &c->default_memory_min, message, flags, error);
+                return bus_cgroup_set_memory_protection_scale(u, name, &c->default_memory_min, message, flags, error);
 
         if (streq(name, "DefaultMemoryLowScale"))
-                return bus_cgroup_set_memory_scale(u, name, &c->default_memory_low, message, flags, error);
+                return bus_cgroup_set_memory_protection_scale(u, name, &c->default_memory_low, message, flags, error);
 
         if (streq(name, "MemoryHighScale"))
                 return bus_cgroup_set_memory_scale(u, name, &c->memory_high, message, flags, error);
index bb302fb46b85a442aca1bb3762cbebc25fc1ed7e..11a9a7bdebb62fc6372328b90184c3bef76f5464 100644 (file)
@@ -3137,7 +3137,7 @@ int config_parse_memory_limit(
                         bytes = physical_memory_scale(r, 1000U);
 
                 if (bytes >= UINT64_MAX ||
-                    (bytes <= 0 && !streq(lvalue, "MemorySwapMax"))) {
+                    (bytes <= 0 && !STR_IN_SET(lvalue, "MemorySwapMax", "MemoryLow", "MemoryMin", "DefaultMemoryLow", "DefaultMemoryMin"))) {
                         log_syntax(unit, LOG_ERR, filename, line, 0, "Memory limit '%s' out of range, ignoring.", rvalue);
                         return 0;
                 }