dcavalca / rpms / systemd

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