diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2019-04-25 11:06:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-25 11:06:45 +0200 |
commit | b6411f716c18e55192c442acbe8fe5595b0c14f4 (patch) | |
tree | 6e635daac0bc0d8703c0c2c2b2716313d57c8bb5 | |
parent | 4275e9b7c3282e50ccfca21b4fd726fc3cdb2992 (diff) | |
parent | 7ad5439e0663e39e36619957fa37eefe8026bcab (diff) | |
download | systemd-b6411f716c18e55192c442acbe8fe5595b0c14f4.tar.gz |
Merge pull request #12332 from cdown/default_min
cgroup: Add support for propagation of memory.min
-rw-r--r-- | src/core/cgroup.c | 58 | ||||
-rw-r--r-- | src/core/cgroup.h | 4 | ||||
-rw-r--r-- | src/core/dbus-cgroup.c | 6 | ||||
-rw-r--r-- | src/core/load-fragment.c | 11 | ||||
-rw-r--r-- | src/systemctl/systemctl.c | 2 |
5 files changed, 54 insertions, 27 deletions
diff --git a/src/core/cgroup.c b/src/core/cgroup.c index a288c07bc9..946fab24c2 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -237,6 +237,7 @@ void cgroup_context_dump(CGroupContext *c, FILE* f, const char *prefix) { "%sStartupIOWeight=%" PRIu64 "\n" "%sBlockIOWeight=%" PRIu64 "\n" "%sStartupBlockIOWeight=%" PRIu64 "\n" + "%sDefaultMemoryMin=%" PRIu64 "\n" "%sDefaultMemoryLow=%" PRIu64 "\n" "%sMemoryMin=%" PRIu64 "\n" "%sMemoryLow=%" PRIu64 "\n" @@ -264,6 +265,7 @@ void cgroup_context_dump(CGroupContext *c, FILE* f, const char *prefix) { prefix, c->startup_io_weight, prefix, c->blockio_weight, prefix, c->startup_blockio_weight, + prefix, c->default_memory_min, prefix, c->default_memory_low, prefix, c->memory_min, prefix, c->memory_low, @@ -389,31 +391,37 @@ int cgroup_add_device_allow(CGroupContext *c, const char *dev, const char *mode) return 0; } -uint64_t unit_get_ancestor_memory_low(Unit *u) { - CGroupContext *c; - - /* 1. Is MemoryLow set in this unit? If so, use that. - * 2. Is DefaultMemoryLow set in any ancestor? If so, use that. - * 3. Otherwise, return CGROUP_LIMIT_MIN. */ - - assert(u); - - c = unit_get_cgroup_context(u); - - if (c->memory_low_set) - return c->memory_low; - - while (UNIT_ISSET(u->slice)) { - u = UNIT_DEREF(u->slice); - c = unit_get_cgroup_context(u); - - if (c->default_memory_low_set) - return c->default_memory_low; - } - - /* We've reached the root, but nobody had DefaultMemoryLow set, so set it to the kernel default. */ - return CGROUP_LIMIT_MIN; -} +#define UNIT_DEFINE_ANCESTOR_MEMORY_LOOKUP(entry) \ + uint64_t unit_get_ancestor_##entry(Unit *u) { \ + CGroupContext *c; \ + \ + /* 1. Is entry set in this unit? If so, use that. \ + * 2. Is the default for this entry set in any \ + * ancestor? If so, use that. \ + * 3. Otherwise, return CGROUP_LIMIT_MIN. */ \ + \ + assert(u); \ + \ + c = unit_get_cgroup_context(u); \ + \ + if (c->entry##_set) \ + return c->entry; \ + \ + while (UNIT_ISSET(u->slice)) { \ + u = UNIT_DEREF(u->slice); \ + c = unit_get_cgroup_context(u); \ + \ + if (c->default_##entry##_set) \ + return c->default_##entry; \ + } \ + \ + /* We've reached the root, but nobody had default for \ + * this entry set, so set it to the kernel default. */ \ + return CGROUP_LIMIT_MIN; \ +} + +UNIT_DEFINE_ANCESTOR_MEMORY_LOOKUP(memory_low); +UNIT_DEFINE_ANCESTOR_MEMORY_LOOKUP(memory_min); static void cgroup_xattr_apply(Unit *u) { char ids[SD_ID128_STRING_MAX]; diff --git a/src/core/cgroup.h b/src/core/cgroup.h index 4bbfa2c3a7..0cac8ce76b 100644 --- a/src/core/cgroup.h +++ b/src/core/cgroup.h @@ -98,6 +98,7 @@ struct CGroupContext { LIST_HEAD(CGroupIODeviceLimit, io_device_limits); LIST_HEAD(CGroupIODeviceLatency, io_device_latencies); + uint64_t default_memory_min; uint64_t default_memory_low; uint64_t memory_min; uint64_t memory_low; @@ -105,7 +106,9 @@ struct CGroupContext { uint64_t memory_max; uint64_t memory_swap_max; + bool default_memory_min_set; bool default_memory_low_set; + bool memory_min_set; bool memory_low_set; LIST_HEAD(IPAddressAccessItem, ip_address_allow); @@ -196,6 +199,7 @@ Unit *manager_get_unit_by_cgroup(Manager *m, const char *cgroup); Unit *manager_get_unit_by_pid_cgroup(Manager *m, pid_t pid); Unit* manager_get_unit_by_pid(Manager *m, pid_t pid); +uint64_t unit_get_ancestor_memory_min(Unit *u); uint64_t unit_get_ancestor_memory_low(Unit *u); int unit_search_main_pid(Unit *u, pid_t *ret); diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c index 74a583d81b..c427c3cafe 100644 --- a/src/core/dbus-cgroup.c +++ b/src/core/dbus-cgroup.c @@ -676,6 +676,9 @@ int bus_cgroup_set_property( if (streq(name, "MemoryLow")) return bus_cgroup_set_memory(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); + if (streq(name, "DefaultMemoryLow")) return bus_cgroup_set_memory(u, name, &c->default_memory_low, message, flags, error); @@ -697,6 +700,9 @@ int bus_cgroup_set_property( if (streq(name, "MemoryLowScale")) return bus_cgroup_set_memory_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); + if (streq(name, "DefaultMemoryLowScale")) return bus_cgroup_set_memory_scale(u, name, &c->default_memory_low, message, flags, error); diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index e7a1f4206b..bb302fb46b 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -3149,9 +3149,16 @@ int config_parse_memory_limit( c->default_memory_low = CGROUP_LIMIT_MIN; else c->default_memory_low = bytes; - } else if (streq(lvalue, "MemoryMin")) + } else if (streq(lvalue, "DefaultMemoryMin")) { + 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; - else if (streq(lvalue, "MemoryLow")) { + c->memory_min_set = true; + } else if (streq(lvalue, "MemoryLow")) { c->memory_low = bytes; c->memory_low_set = true; } else if (streq(lvalue, "MemoryHigh")) diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index c9edefdd82..25621745b1 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -4129,6 +4129,7 @@ typedef struct UnitStatusInfo { uint64_t ip_ingress_bytes; uint64_t ip_egress_bytes; + uint64_t default_memory_min; uint64_t default_memory_low; LIST_HEAD(ExecStatusInfo, exec); @@ -5481,6 +5482,7 @@ static int show_one( { "Where", "s", NULL, offsetof(UnitStatusInfo, where) }, { "What", "s", NULL, offsetof(UnitStatusInfo, what) }, { "MemoryCurrent", "t", NULL, offsetof(UnitStatusInfo, memory_current) }, + { "DefaultMemoryMin", "t", NULL, offsetof(UnitStatusInfo, default_memory_min) }, { "DefaultMemoryLow", "t", NULL, offsetof(UnitStatusInfo, default_memory_low) }, { "MemoryMin", "t", NULL, offsetof(UnitStatusInfo, memory_min) }, { "MemoryLow", "t", NULL, offsetof(UnitStatusInfo, memory_low) }, |