cgroup: Make empty assignments reset to default

When MemoryLow= or MemoryMin= is set, it is interpretted as setting the
values to infinity. This is inconsistent with the default initialization
to 0.
It'd be nice to interpret the empty assignment as fallback to
DefaultMemory* of parent slice, however, current DBus API cannot convey
such a NULL value, so stick to simply interpretting that as hard-wired
default.
This commit is contained in:
Michal Koutný 2020-02-04 14:50:51 +01:00
parent 21c8397694
commit db2b8d2e28
2 changed files with 22 additions and 9 deletions

View File

@ -3371,6 +3371,12 @@ int config_parse_memory_limit(
uint64_t bytes = CGROUP_LIMIT_MAX;
int r;
if (STR_IN_SET(lvalue, "DefaultMemoryLow",
"DefaultMemoryMin",
"MemoryLow",
"MemoryMin"))
bytes = CGROUP_LIMIT_MIN;
if (!isempty(rvalue) && !streq(rvalue, "infinity")) {
r = parse_permille(rvalue);
@ -3391,17 +3397,11 @@ int config_parse_memory_limit(
}
if (streq(lvalue, "DefaultMemoryLow")) {
c->default_memory_low = bytes;
c->default_memory_low_set = true;
if (isempty(rvalue))
c->default_memory_low = CGROUP_LIMIT_MIN;
else
c->default_memory_low = bytes;
} else if (streq(lvalue, "DefaultMemoryMin")) {
c->default_memory_min = bytes;
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;
c->memory_min_set = true;

View File

@ -489,11 +489,24 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons
"MemoryLimit",
"TasksMax")) {
if (isempty(eq) || streq(eq, "infinity")) {
if (streq(eq, "infinity")) {
r = sd_bus_message_append(m, "(sv)", field, "t", CGROUP_LIMIT_MAX);
if (r < 0)
return bus_log_create_error(r);
return 1;
} else if (isempty(eq)) {
uint64_t empty_value = STR_IN_SET(field,
"DefaultMemoryLow",
"DefaultMemoryMin",
"MemoryLow",
"MemoryMin") ?
CGROUP_LIMIT_MIN :
CGROUP_LIMIT_MAX;
r = sd_bus_message_append(m, "(sv)", field, "t", empty_value);
if (r < 0)
return bus_log_create_error(r);
return 1;
}
r = parse_permille(eq);