c2dfb7
From 69dbbc29f26569fd09f0109e6fbebde98c0c8567 Mon Sep 17 00:00:00 2001
c2dfb7
From: Chris Down <chris@chrisdown.name>
c2dfb7
Date: Tue, 16 Apr 2019 18:44:05 +0100
c2dfb7
Subject: [PATCH] unit: Add DefaultMemoryMin
c2dfb7
c2dfb7
(cherry picked from commit 7ad5439e0663e39e36619957fa37eefe8026bcab)
c2dfb7
c2dfb7
Related: #1763435
c2dfb7
---
c2dfb7
 src/core/cgroup.c         |  3 +++
c2dfb7
 src/core/cgroup.h         |  4 ++++
c2dfb7
 src/core/dbus-cgroup.c    |  6 ++++++
c2dfb7
 src/core/load-fragment.c  | 11 +++++++++--
c2dfb7
 src/systemctl/systemctl.c |  2 ++
c2dfb7
 5 files changed, 24 insertions(+), 2 deletions(-)
c2dfb7
c2dfb7
diff --git a/src/core/cgroup.c b/src/core/cgroup.c
c2dfb7
index 46a89ff5e1..d40f9cbc2a 100644
c2dfb7
--- a/src/core/cgroup.c
c2dfb7
+++ b/src/core/cgroup.c
c2dfb7
@@ -220,6 +220,7 @@ void cgroup_context_dump(CGroupContext *c, FILE* f, const char *prefix) {
c2dfb7
                 "%sStartupIOWeight=%" PRIu64 "\n"
c2dfb7
                 "%sBlockIOWeight=%" PRIu64 "\n"
c2dfb7
                 "%sStartupBlockIOWeight=%" PRIu64 "\n"
c2dfb7
+                "%sDefaultMemoryMin=%" PRIu64 "\n"
c2dfb7
                 "%sDefaultMemoryLow=%" PRIu64 "\n"
c2dfb7
                 "%sMemoryMin=%" PRIu64 "\n"
c2dfb7
                 "%sMemoryLow=%" PRIu64 "\n"
c2dfb7
@@ -248,6 +249,7 @@ void cgroup_context_dump(CGroupContext *c, FILE* f, const char *prefix) {
c2dfb7
                 prefix, c->startup_io_weight,
c2dfb7
                 prefix, c->blockio_weight,
c2dfb7
                 prefix, c->startup_blockio_weight,
c2dfb7
+                prefix, c->default_memory_min,
c2dfb7
                 prefix, c->default_memory_low,
c2dfb7
                 prefix, c->memory_min,
c2dfb7
                 prefix, c->memory_low,
c2dfb7
@@ -402,6 +404,7 @@ int cgroup_add_device_allow(CGroupContext *c, const char *dev, const char *mode)
c2dfb7
 }
c2dfb7
 
c2dfb7
 UNIT_DEFINE_ANCESTOR_MEMORY_LOOKUP(memory_low);
c2dfb7
+UNIT_DEFINE_ANCESTOR_MEMORY_LOOKUP(memory_min);
c2dfb7
 
c2dfb7
 static int lookup_block_device(const char *p, dev_t *ret) {
c2dfb7
         struct stat st;
c2dfb7
diff --git a/src/core/cgroup.h b/src/core/cgroup.h
c2dfb7
index a263d6a169..976224336d 100644
c2dfb7
--- a/src/core/cgroup.h
c2dfb7
+++ b/src/core/cgroup.h
c2dfb7
@@ -95,6 +95,7 @@ struct CGroupContext {
c2dfb7
         LIST_HEAD(CGroupIODeviceLimit, io_device_limits);
c2dfb7
         LIST_HEAD(CGroupIODeviceLatency, io_device_latencies);
c2dfb7
 
c2dfb7
+        uint64_t default_memory_min;
c2dfb7
         uint64_t default_memory_low;
c2dfb7
         uint64_t memory_min;
c2dfb7
         uint64_t memory_low;
c2dfb7
@@ -102,7 +103,9 @@ struct CGroupContext {
c2dfb7
         uint64_t memory_max;
c2dfb7
         uint64_t memory_swap_max;
c2dfb7
 
c2dfb7
+        bool default_memory_min_set;
c2dfb7
         bool default_memory_low_set;
c2dfb7
+        bool memory_min_set;
c2dfb7
         bool memory_low_set;
c2dfb7
 
c2dfb7
         LIST_HEAD(IPAddressAccessItem, ip_address_allow);
c2dfb7
@@ -195,6 +198,7 @@ Unit *manager_get_unit_by_cgroup(Manager *m, const char *cgroup);
c2dfb7
 Unit *manager_get_unit_by_pid_cgroup(Manager *m, pid_t pid);
c2dfb7
 Unit* manager_get_unit_by_pid(Manager *m, pid_t pid);
c2dfb7
 
c2dfb7
+uint64_t unit_get_ancestor_memory_min(Unit *u);
c2dfb7
 uint64_t unit_get_ancestor_memory_low(Unit *u);
c2dfb7
 
c2dfb7
 int unit_search_main_pid(Unit *u, pid_t *ret);
c2dfb7
diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c
c2dfb7
index 2115d43b0c..e1278c317a 100644
c2dfb7
--- a/src/core/dbus-cgroup.c
c2dfb7
+++ b/src/core/dbus-cgroup.c
c2dfb7
@@ -669,6 +669,9 @@ int bus_cgroup_set_property(
c2dfb7
         if (streq(name, "MemoryLow"))
c2dfb7
                 return bus_cgroup_set_memory(u, name, &c->memory_low, message, flags, error);
c2dfb7
 
c2dfb7
+        if (streq(name, "DefaultMemoryMin"))
c2dfb7
+                return bus_cgroup_set_memory(u, name, &c->default_memory_min, message, flags, error);
c2dfb7
+
c2dfb7
         if (streq(name, "DefaultMemoryLow"))
c2dfb7
                 return bus_cgroup_set_memory(u, name, &c->default_memory_low, message, flags, error);
c2dfb7
 
c2dfb7
@@ -690,6 +693,9 @@ int bus_cgroup_set_property(
c2dfb7
         if (streq(name, "MemoryLowScale"))
c2dfb7
                 return bus_cgroup_set_memory_scale(u, name, &c->memory_low, message, flags, error);
c2dfb7
 
c2dfb7
+        if (streq(name, "DefaultMemoryMinScale"))
c2dfb7
+                return bus_cgroup_set_memory_scale(u, name, &c->default_memory_min, message, flags, error);
c2dfb7
+
c2dfb7
         if (streq(name, "DefaultMemoryLowScale"))
c2dfb7
                 return bus_cgroup_set_memory_scale(u, name, &c->default_memory_low, message, flags, error);
c2dfb7
 
c2dfb7
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
c2dfb7
index 20faed02ad..3b8ee6b124 100644
c2dfb7
--- a/src/core/load-fragment.c
c2dfb7
+++ b/src/core/load-fragment.c
c2dfb7
@@ -3102,9 +3102,16 @@ int config_parse_memory_limit(
c2dfb7
                         c->default_memory_low = CGROUP_LIMIT_MIN;
c2dfb7
                 else
c2dfb7
                         c->default_memory_low = bytes;
c2dfb7
-        } else if (streq(lvalue, "MemoryMin"))
c2dfb7
+        } else if (streq(lvalue, "DefaultMemoryMin")) {
c2dfb7
+                c->default_memory_min_set = true;
c2dfb7
+                if (isempty(rvalue))
c2dfb7
+                        c->default_memory_min = CGROUP_LIMIT_MIN;
c2dfb7
+                else
c2dfb7
+                        c->default_memory_min = bytes;
c2dfb7
+        } else if (streq(lvalue, "MemoryMin")) {
c2dfb7
                 c->memory_min = bytes;
c2dfb7
-        else if (streq(lvalue, "MemoryLow")) {
c2dfb7
+                c->memory_min_set = true;
c2dfb7
+        } else if (streq(lvalue, "MemoryLow")) {
c2dfb7
                 c->memory_low = bytes;
c2dfb7
                 c->memory_low_set = true;
c2dfb7
         } else if (streq(lvalue, "MemoryHigh"))
c2dfb7
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
c2dfb7
index 763ca0c6b7..e0db97e339 100644
c2dfb7
--- a/src/systemctl/systemctl.c
c2dfb7
+++ b/src/systemctl/systemctl.c
c2dfb7
@@ -3918,6 +3918,7 @@ typedef struct UnitStatusInfo {
c2dfb7
         uint64_t ip_ingress_bytes;
c2dfb7
         uint64_t ip_egress_bytes;
c2dfb7
 
c2dfb7
+        uint64_t default_memory_min;
c2dfb7
         uint64_t default_memory_low;
c2dfb7
 
c2dfb7
         LIST_HEAD(ExecStatusInfo, exec);
c2dfb7
@@ -5030,6 +5031,7 @@ static int show_one(
c2dfb7
                 { "Where",                          "s",              NULL,           offsetof(UnitStatusInfo, where)                             },
c2dfb7
                 { "What",                           "s",              NULL,           offsetof(UnitStatusInfo, what)                              },
c2dfb7
                 { "MemoryCurrent",                  "t",              NULL,           offsetof(UnitStatusInfo, memory_current)                    },
c2dfb7
+                { "DefaultMemoryMin",               "t",              NULL,           offsetof(UnitStatusInfo, default_memory_min)                },
c2dfb7
                 { "DefaultMemoryLow",               "t",              NULL,           offsetof(UnitStatusInfo, default_memory_low)                },
c2dfb7
                 { "MemoryMin",                      "t",              NULL,           offsetof(UnitStatusInfo, memory_min)                        },
c2dfb7
                 { "MemoryLow",                      "t",              NULL,           offsetof(UnitStatusInfo, memory_low)                        },