|
|
2aacef |
From 9603354ef8d1e0456718703920e41e6fadad95a8 Mon Sep 17 00:00:00 2001
|
|
|
2aacef |
From: Mark Laws <mdl@60hz.org>
|
|
|
2aacef |
Date: Mon, 14 Nov 2022 21:48:09 +0900
|
|
|
2aacef |
Subject: [PATCH] systemd: Support OOMPolicy in scope units
|
|
|
2aacef |
|
|
|
2aacef |
Closes #25376.
|
|
|
2aacef |
|
|
|
2aacef |
(cherry picked from commit 5fa098357e0ea9f05b00ed5b04a36ef9f64037db)
|
|
|
2aacef |
|
|
|
2aacef |
Resolves: #2175619
|
|
|
2aacef |
---
|
|
|
2aacef |
man/org.freedesktop.systemd1.xml | 6 ++++++
|
|
|
2aacef |
src/core/dbus-scope.c | 6 ++++++
|
|
|
2aacef |
src/core/scope.c | 19 ++++++++++++++++---
|
|
|
2aacef |
src/core/scope.h | 2 ++
|
|
|
2aacef |
src/shared/bus-unit-util.c | 3 +++
|
|
|
2aacef |
5 files changed, 33 insertions(+), 3 deletions(-)
|
|
|
2aacef |
|
|
|
2aacef |
diff --git a/man/org.freedesktop.systemd1.xml b/man/org.freedesktop.systemd1.xml
|
|
|
2aacef |
index c2f70870c7..40510c43eb 100644
|
|
|
2aacef |
--- a/man/org.freedesktop.systemd1.xml
|
|
|
2aacef |
+++ b/man/org.freedesktop.systemd1.xml
|
|
|
2aacef |
@@ -10150,6 +10150,8 @@ node /org/freedesktop/systemd1/unit/session_2d1_2escope {
|
|
|
2aacef |
readonly t RuntimeMaxUSec = ...;
|
|
|
2aacef |
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
|
|
|
2aacef |
readonly t RuntimeRandomizedExtraUSec = ...;
|
|
|
2aacef |
+ @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
|
|
|
2aacef |
+ readonly s OOMPolicy = '...';
|
|
|
2aacef |
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
|
|
|
2aacef |
readonly s Slice = '...';
|
|
|
2aacef |
@org.freedesktop.DBus.Property.EmitsChangedSignal("false")
|
|
|
2aacef |
@@ -10324,6 +10326,8 @@ node /org/freedesktop/systemd1/unit/session_2d1_2escope {
|
|
|
2aacef |
|
|
|
2aacef |
|
|
|
2aacef |
|
|
|
2aacef |
+
|
|
|
2aacef |
+
|
|
|
2aacef |
|
|
|
2aacef |
|
|
|
2aacef |
|
|
|
2aacef |
@@ -10506,6 +10510,8 @@ node /org/freedesktop/systemd1/unit/session_2d1_2escope {
|
|
|
2aacef |
|
|
|
2aacef |
<variablelist class="dbus-property" generated="True" extra-ref="RuntimeRandomizedExtraUSec"/>
|
|
|
2aacef |
|
|
|
2aacef |
+ <variablelist class="dbus-property" generated="True" extra-ref="OOMPolicy"/>
|
|
|
2aacef |
+
|
|
|
2aacef |
<variablelist class="dbus-property" generated="True" extra-ref="Slice"/>
|
|
|
2aacef |
|
|
|
2aacef |
<variablelist class="dbus-property" generated="True" extra-ref="ControlGroup"/>
|
|
|
2aacef |
diff --git a/src/core/dbus-scope.c b/src/core/dbus-scope.c
|
|
|
2aacef |
index 7d2ceb0765..7b07bb8bb9 100644
|
|
|
2aacef |
--- a/src/core/dbus-scope.c
|
|
|
2aacef |
+++ b/src/core/dbus-scope.c
|
|
|
2aacef |
@@ -5,6 +5,7 @@
|
|
|
2aacef |
#include "bus-get-properties.h"
|
|
|
2aacef |
#include "dbus-cgroup.h"
|
|
|
2aacef |
#include "dbus-kill.h"
|
|
|
2aacef |
+#include "dbus-manager.h"
|
|
|
2aacef |
#include "dbus-scope.h"
|
|
|
2aacef |
#include "dbus-unit.h"
|
|
|
2aacef |
#include "dbus-util.h"
|
|
|
2aacef |
@@ -39,6 +40,7 @@ int bus_scope_method_abandon(sd_bus_message *message, void *userdata, sd_bus_err
|
|
|
2aacef |
}
|
|
|
2aacef |
|
|
|
2aacef |
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_result, scope_result, ScopeResult);
|
|
|
2aacef |
+static BUS_DEFINE_SET_TRANSIENT_PARSE(oom_policy, OOMPolicy, oom_policy_from_string);
|
|
|
2aacef |
|
|
|
2aacef |
const sd_bus_vtable bus_scope_vtable[] = {
|
|
|
2aacef |
SD_BUS_VTABLE_START(0),
|
|
|
2aacef |
@@ -47,6 +49,7 @@ const sd_bus_vtable bus_scope_vtable[] = {
|
|
|
2aacef |
SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Scope, result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
|
|
2aacef |
SD_BUS_PROPERTY("RuntimeMaxUSec", "t", bus_property_get_usec, offsetof(Scope, runtime_max_usec), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
2aacef |
SD_BUS_PROPERTY("RuntimeRandomizedExtraUSec", "t", bus_property_get_usec, offsetof(Scope, runtime_rand_extra_usec), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
2aacef |
+ SD_BUS_PROPERTY("OOMPolicy", "s", bus_property_get_oom_policy, offsetof(Scope, oom_policy), SD_BUS_VTABLE_PROPERTY_CONST),
|
|
|
2aacef |
SD_BUS_SIGNAL("RequestStop", NULL, 0),
|
|
|
2aacef |
SD_BUS_METHOD("Abandon", NULL, NULL, bus_scope_method_abandon, SD_BUS_VTABLE_UNPRIVILEGED),
|
|
|
2aacef |
SD_BUS_VTABLE_END
|
|
|
2aacef |
@@ -77,6 +80,9 @@ static int bus_scope_set_transient_property(
|
|
|
2aacef |
if (streq(name, "RuntimeRandomizedExtraUSec"))
|
|
|
2aacef |
return bus_set_transient_usec(u, name, &s->runtime_rand_extra_usec, message, flags, error);
|
|
|
2aacef |
|
|
|
2aacef |
+ if (streq(name, "OOMPolicy"))
|
|
|
2aacef |
+ return bus_set_transient_oom_policy(u, name, &s->oom_policy, message, flags, error);
|
|
|
2aacef |
+
|
|
|
2aacef |
if (streq(name, "PIDs")) {
|
|
|
2aacef |
_cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
|
|
|
2aacef |
unsigned n = 0;
|
|
|
2aacef |
diff --git a/src/core/scope.c b/src/core/scope.c
|
|
|
2aacef |
index 54a6cc63e4..e2fc4cc995 100644
|
|
|
2aacef |
--- a/src/core/scope.c
|
|
|
2aacef |
+++ b/src/core/scope.c
|
|
|
2aacef |
@@ -43,6 +43,7 @@ static void scope_init(Unit *u) {
|
|
|
2aacef |
s->timeout_stop_usec = u->manager->default_timeout_stop_usec;
|
|
|
2aacef |
u->ignore_on_isolate = true;
|
|
|
2aacef |
s->user = s->group = NULL;
|
|
|
2aacef |
+ s->oom_policy = _OOM_POLICY_INVALID;
|
|
|
2aacef |
}
|
|
|
2aacef |
|
|
|
2aacef |
static void scope_done(Unit *u) {
|
|
|
2aacef |
@@ -194,6 +195,11 @@ static int scope_add_extras(Scope *s) {
|
|
|
2aacef |
if (r < 0)
|
|
|
2aacef |
return r;
|
|
|
2aacef |
|
|
|
2aacef |
+ if (s->oom_policy < 0)
|
|
|
2aacef |
+ s->oom_policy = s->cgroup_context.delegate ? OOM_CONTINUE : UNIT(s)->manager->default_oom_policy;
|
|
|
2aacef |
+
|
|
|
2aacef |
+ s->cgroup_context.memory_oom_group = s->oom_policy == OOM_KILL;
|
|
|
2aacef |
+
|
|
|
2aacef |
return scope_add_default_dependencies(s);
|
|
|
2aacef |
}
|
|
|
2aacef |
|
|
|
2aacef |
@@ -286,11 +292,13 @@ static void scope_dump(Unit *u, FILE *f, const char *prefix) {
|
|
|
2aacef |
"%sScope State: %s\n"
|
|
|
2aacef |
"%sResult: %s\n"
|
|
|
2aacef |
"%sRuntimeMaxSec: %s\n"
|
|
|
2aacef |
- "%sRuntimeRandomizedExtraSec: %s\n",
|
|
|
2aacef |
+ "%sRuntimeRandomizedExtraSec: %s\n"
|
|
|
2aacef |
+ "%sOOMPolicy: %s\n",
|
|
|
2aacef |
prefix, scope_state_to_string(s->state),
|
|
|
2aacef |
prefix, scope_result_to_string(s->result),
|
|
|
2aacef |
prefix, FORMAT_TIMESPAN(s->runtime_max_usec, USEC_PER_SEC),
|
|
|
2aacef |
- prefix, FORMAT_TIMESPAN(s->runtime_rand_extra_usec, USEC_PER_SEC));
|
|
|
2aacef |
+ prefix, FORMAT_TIMESPAN(s->runtime_rand_extra_usec, USEC_PER_SEC),
|
|
|
2aacef |
+ prefix, oom_policy_to_string(s->oom_policy));
|
|
|
2aacef |
|
|
|
2aacef |
cgroup_context_dump(UNIT(s), f, prefix);
|
|
|
2aacef |
kill_context_dump(&s->kill_context, f, prefix);
|
|
|
2aacef |
@@ -635,11 +643,16 @@ static void scope_notify_cgroup_oom_event(Unit *u, bool managed_oom) {
|
|
|
2aacef |
else
|
|
|
2aacef |
log_unit_debug(u, "Process of control group was killed by the OOM killer.");
|
|
|
2aacef |
|
|
|
2aacef |
- /* This will probably need to be modified when scope units get an oom-policy */
|
|
|
2aacef |
+ if (s->oom_policy == OOM_CONTINUE)
|
|
|
2aacef |
+ return;
|
|
|
2aacef |
+
|
|
|
2aacef |
switch (s->state) {
|
|
|
2aacef |
|
|
|
2aacef |
case SCOPE_START_CHOWN:
|
|
|
2aacef |
case SCOPE_RUNNING:
|
|
|
2aacef |
+ scope_enter_signal(s, SCOPE_STOP_SIGTERM, SCOPE_FAILURE_OOM_KILL);
|
|
|
2aacef |
+ break;
|
|
|
2aacef |
+
|
|
|
2aacef |
case SCOPE_STOP_SIGTERM:
|
|
|
2aacef |
scope_enter_signal(s, SCOPE_STOP_SIGKILL, SCOPE_FAILURE_OOM_KILL);
|
|
|
2aacef |
break;
|
|
|
2aacef |
diff --git a/src/core/scope.h b/src/core/scope.h
|
|
|
2aacef |
index 6a228f1177..c9574a32c2 100644
|
|
|
2aacef |
--- a/src/core/scope.h
|
|
|
2aacef |
+++ b/src/core/scope.h
|
|
|
2aacef |
@@ -38,6 +38,8 @@ struct Scope {
|
|
|
2aacef |
|
|
|
2aacef |
char *user;
|
|
|
2aacef |
char *group;
|
|
|
2aacef |
+
|
|
|
2aacef |
+ OOMPolicy oom_policy;
|
|
|
2aacef |
};
|
|
|
2aacef |
|
|
|
2aacef |
extern const UnitVTable scope_vtable;
|
|
|
2aacef |
diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c
|
|
|
2aacef |
index b850a28e85..922011eccd 100644
|
|
|
2aacef |
--- a/src/shared/bus-unit-util.c
|
|
|
2aacef |
+++ b/src/shared/bus-unit-util.c
|
|
|
2aacef |
@@ -2142,6 +2142,9 @@ static int bus_append_scope_property(sd_bus_message *m, const char *field, const
|
|
|
2aacef |
if (STR_IN_SET(field, "User", "Group"))
|
|
|
2aacef |
return bus_append_string(m, field, eq);
|
|
|
2aacef |
|
|
|
2aacef |
+ if (streq(field, "OOMPolicy"))
|
|
|
2aacef |
+ return bus_append_string(m, field, eq);
|
|
|
2aacef |
+
|
|
|
2aacef |
return 0;
|
|
|
2aacef |
}
|
|
|
2aacef |
|