cgroup: Add ManagedOOMMemoryPressureDurationSec= override setting for units

This will allow units (scopes/slices/services) to override the default
systemd-oomd setting DefaultMemoryPressureDurationSec=.

The semantics of ManagedOOMMemoryPressureDurationSec= are:
- If >= 1 second, overrides DefaultMemoryPressureDurationSec= from oomd.conf
- If is empty, uses DefaultMemoryPressureDurationSec= from oomd.conf
- Ignored if ManagedOOMMemoryPressure= is not "kill"
- Disallowed if < 1 second

Note the corresponding dbus property is DefaultMemoryPressureDurationUSec
which is in microseconds. This is consistent with other time-based
dbus properties.
This commit is contained in:
Ryan Wilson
2024-10-16 20:12:38 -07:00
parent c43ef2e883
commit 63d4c4271c
21 changed files with 293 additions and 21 deletions
+6
View File
@@ -109,6 +109,12 @@ static int bus_print_property(const char *name, const char *expected_value, sd_b
bus_print_property_value(name, expected_value, flags, FORMAT_TIMESTAMP(u));
/* Managed OOM pressure default implies "unset" and use the default set in oomd.conf. Without
* this condition, we will print "infinity" which implies there is no limit on memory
* pressure duration and is incorrect. */
else if (streq(name, "ManagedOOMMemoryPressureDurationUSec") && u == USEC_INFINITY)
bus_print_property_value(name, expected_value, flags, "[not set]");
else if (strstr(name, "USec"))
bus_print_property_value(name, expected_value, flags, FORMAT_TIMESPAN(u, 0));
+5
View File
@@ -1008,6 +1008,11 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons
if (streq(field, "NFTSet"))
return bus_append_nft_set(m, field, eq);
if (streq(field, "ManagedOOMMemoryPressureDurationSec"))
/* While infinity is disallowed in unit file, infinity is allowed in D-Bus API which
* means use the default memory pressure duration from oomd.conf. */
return bus_append_parse_sec_rename(m, field, isempty(eq) ? "infinity" : eq);
return 0;
}
+2 -1
View File
@@ -12,7 +12,8 @@ SD_VARLINK_DEFINE_STRUCT_TYPE(
SD_VARLINK_DEFINE_FIELD(mode, SD_VARLINK_STRING, 0),
SD_VARLINK_DEFINE_FIELD(path, SD_VARLINK_STRING, 0),
SD_VARLINK_DEFINE_FIELD(property, SD_VARLINK_STRING, 0),
SD_VARLINK_DEFINE_FIELD(limit, SD_VARLINK_INT, SD_VARLINK_NULLABLE));
SD_VARLINK_DEFINE_FIELD(limit, SD_VARLINK_INT, SD_VARLINK_NULLABLE),
SD_VARLINK_DEFINE_FIELD(duration, SD_VARLINK_INT, SD_VARLINK_NULLABLE));
static SD_VARLINK_DEFINE_METHOD(
ReportManagedOOMCGroups,