ryantimwilson / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone
52b84b
From 614b43fcad3a16dfde5ad606b43c3aa1adacc30a Mon Sep 17 00:00:00 2001
52b84b
From: Chris Down <chris@chrisdown.name>
52b84b
Date: Fri, 3 May 2019 08:32:41 -0400
52b84b
Subject: [PATCH] cgroup: Support 0-value for memory protection directives
52b84b
52b84b
These make sense to be explicitly set at 0 (which has a different effect
52b84b
than the default, since it can affect processing of `DefaultMemoryXXX`).
52b84b
52b84b
Without this, it's not easily possible to relinquish memory protection
52b84b
for a subtree, which is not great.
52b84b
52b84b
(cherry picked from commit 22bf131be278b95a4a204514d37a4344cf6365c6)
52b84b
52b84b
Related: #1763435
52b84b
---
52b84b
 src/core/dbus-cgroup.c   | 17 +++++++++--------
52b84b
 src/core/load-fragment.c |  2 +-
52b84b
 2 files changed, 10 insertions(+), 9 deletions(-)
52b84b
52b84b
diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c
52b84b
index e34ff3a016..39778a8dd4 100644
52b84b
--- a/src/core/dbus-cgroup.c
52b84b
+++ b/src/core/dbus-cgroup.c
52b84b
@@ -606,6 +606,7 @@ BUS_DEFINE_SET_CGROUP_WEIGHT(cpu_shares, CGROUP_MASK_CPU, CGROUP_CPU_SHARES_IS_O
52b84b
 BUS_DEFINE_SET_CGROUP_WEIGHT(io_weight, CGROUP_MASK_IO, CGROUP_WEIGHT_IS_OK, CGROUP_WEIGHT_INVALID);
52b84b
 BUS_DEFINE_SET_CGROUP_WEIGHT(blockio_weight, CGROUP_MASK_BLKIO, CGROUP_BLKIO_WEIGHT_IS_OK, CGROUP_BLKIO_WEIGHT_INVALID);
52b84b
 BUS_DEFINE_SET_CGROUP_LIMIT(memory, CGROUP_MASK_MEMORY, physical_memory_scale, 1);
52b84b
+BUS_DEFINE_SET_CGROUP_LIMIT(memory_protection, CGROUP_MASK_MEMORY, physical_memory_scale, 0);
52b84b
 BUS_DEFINE_SET_CGROUP_LIMIT(swap, CGROUP_MASK_MEMORY, physical_memory_scale, 0);
52b84b
 BUS_DEFINE_SET_CGROUP_LIMIT(tasks_max, CGROUP_MASK_PIDS, system_tasks_max_scale, 1);
52b84b
 #pragma GCC diagnostic pop
52b84b
@@ -665,16 +666,16 @@ int bus_cgroup_set_property(
52b84b
                 return bus_cgroup_set_boolean(u, name, &c->memory_accounting, CGROUP_MASK_MEMORY, message, flags, error);
52b84b
 
52b84b
         if (streq(name, "MemoryMin"))
52b84b
-                return bus_cgroup_set_memory(u, name, &c->memory_min, message, flags, error);
52b84b
+                return bus_cgroup_set_memory_protection(u, name, &c->memory_min, message, flags, error);
52b84b
 
52b84b
         if (streq(name, "MemoryLow"))
52b84b
-                return bus_cgroup_set_memory(u, name, &c->memory_low, message, flags, error);
52b84b
+                return bus_cgroup_set_memory_protection(u, name, &c->memory_low, message, flags, error);
52b84b
 
52b84b
         if (streq(name, "DefaultMemoryMin"))
52b84b
-                return bus_cgroup_set_memory(u, name, &c->default_memory_min, message, flags, error);
52b84b
+                return bus_cgroup_set_memory_protection(u, name, &c->default_memory_min, message, flags, error);
52b84b
 
52b84b
         if (streq(name, "DefaultMemoryLow"))
52b84b
-                return bus_cgroup_set_memory(u, name, &c->default_memory_low, message, flags, error);
52b84b
+                return bus_cgroup_set_memory_protection(u, name, &c->default_memory_low, message, flags, error);
52b84b
 
52b84b
         if (streq(name, "MemoryHigh"))
52b84b
                 return bus_cgroup_set_memory(u, name, &c->memory_high, message, flags, error);
52b84b
@@ -689,16 +690,16 @@ int bus_cgroup_set_property(
52b84b
                 return bus_cgroup_set_memory(u, name, &c->memory_limit, message, flags, error);
52b84b
 
52b84b
         if (streq(name, "MemoryMinScale"))
52b84b
-                return bus_cgroup_set_memory_scale(u, name, &c->memory_min, message, flags, error);
52b84b
+                return bus_cgroup_set_memory_protection_scale(u, name, &c->memory_min, message, flags, error);
52b84b
 
52b84b
         if (streq(name, "MemoryLowScale"))
52b84b
-                return bus_cgroup_set_memory_scale(u, name, &c->memory_low, message, flags, error);
52b84b
+                return bus_cgroup_set_memory_protection_scale(u, name, &c->memory_low, message, flags, error);
52b84b
 
52b84b
         if (streq(name, "DefaultMemoryMinScale"))
52b84b
-                return bus_cgroup_set_memory_scale(u, name, &c->default_memory_min, message, flags, error);
52b84b
+                return bus_cgroup_set_memory_protection_scale(u, name, &c->default_memory_min, message, flags, error);
52b84b
 
52b84b
         if (streq(name, "DefaultMemoryLowScale"))
52b84b
-                return bus_cgroup_set_memory_scale(u, name, &c->default_memory_low, message, flags, error);
52b84b
+                return bus_cgroup_set_memory_protection_scale(u, name, &c->default_memory_low, message, flags, error);
52b84b
 
52b84b
         if (streq(name, "MemoryHighScale"))
52b84b
                 return bus_cgroup_set_memory_scale(u, name, &c->memory_high, message, flags, error);
52b84b
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
52b84b
index 3b8ee6b124..33fdb82754 100644
52b84b
--- a/src/core/load-fragment.c
52b84b
+++ b/src/core/load-fragment.c
52b84b
@@ -3090,7 +3090,7 @@ int config_parse_memory_limit(
52b84b
                         bytes = physical_memory_scale(r, 100U);
52b84b
 
52b84b
                 if (bytes >= UINT64_MAX ||
52b84b
-                    (bytes <= 0 && !streq(lvalue, "MemorySwapMax"))) {
52b84b
+                    (bytes <= 0 && !STR_IN_SET(lvalue, "MemorySwapMax", "MemoryLow", "MemoryMin", "DefaultMemoryLow", "DefaultMemoryMin"))) {
52b84b
                         log_syntax(unit, LOG_ERR, filename, line, 0, "Memory limit '%s' out of range, ignoring.", rvalue);
52b84b
                         return 0;
52b84b
                 }