Skip to content

Commit db2b8d2

Browse files
committed
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.
1 parent 21c8397 commit db2b8d2

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

src/core/load-fragment.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3371,6 +3371,12 @@ int config_parse_memory_limit(
33713371
uint64_t bytes = CGROUP_LIMIT_MAX;
33723372
int r;
33733373

3374+
if (STR_IN_SET(lvalue, "DefaultMemoryLow",
3375+
"DefaultMemoryMin",
3376+
"MemoryLow",
3377+
"MemoryMin"))
3378+
bytes = CGROUP_LIMIT_MIN;
3379+
33743380
if (!isempty(rvalue) && !streq(rvalue, "infinity")) {
33753381

33763382
r = parse_permille(rvalue);
@@ -3391,17 +3397,11 @@ int config_parse_memory_limit(
33913397
}
33923398

33933399
if (streq(lvalue, "DefaultMemoryLow")) {
3400+
c->default_memory_low = bytes;
33943401
c->default_memory_low_set = true;
3395-
if (isempty(rvalue))
3396-
c->default_memory_low = CGROUP_LIMIT_MIN;
3397-
else
3398-
c->default_memory_low = bytes;
33993402
} else if (streq(lvalue, "DefaultMemoryMin")) {
3403+
c->default_memory_min = bytes;
34003404
c->default_memory_min_set = true;
3401-
if (isempty(rvalue))
3402-
c->default_memory_min = CGROUP_LIMIT_MIN;
3403-
else
3404-
c->default_memory_min = bytes;
34053405
} else if (streq(lvalue, "MemoryMin")) {
34063406
c->memory_min = bytes;
34073407
c->memory_min_set = true;

src/shared/bus-unit-util.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,11 +489,24 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons
489489
"MemoryLimit",
490490
"TasksMax")) {
491491

492-
if (isempty(eq) || streq(eq, "infinity")) {
492+
if (streq(eq, "infinity")) {
493493
r = sd_bus_message_append(m, "(sv)", field, "t", CGROUP_LIMIT_MAX);
494494
if (r < 0)
495495
return bus_log_create_error(r);
496496
return 1;
497+
} else if (isempty(eq)) {
498+
uint64_t empty_value = STR_IN_SET(field,
499+
"DefaultMemoryLow",
500+
"DefaultMemoryMin",
501+
"MemoryLow",
502+
"MemoryMin") ?
503+
CGROUP_LIMIT_MIN :
504+
CGROUP_LIMIT_MAX;
505+
506+
r = sd_bus_message_append(m, "(sv)", field, "t", empty_value);
507+
if (r < 0)
508+
return bus_log_create_error(r);
509+
return 1;
497510
}
498511

499512
r = parse_permille(eq);

0 commit comments

Comments
 (0)