summaryrefslogtreecommitdiffstats
path: root/src/core/manager.h
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2019-03-19 19:05:19 +0100
committerLennart Poettering <lennart@poettering.net>2019-04-09 11:17:58 +0200
commitafcfaa695cd00b713e7d57e1829da90b692ac6f8 (patch)
tree0f0394e7d37d4fbcdcc792cb00d22a2de1df0fc3 /src/core/manager.h
parentservice: beautify debug log message a bit (diff)
downloadsystemd-afcfaa695cd00b713e7d57e1829da90b692ac6f8.tar.xz
systemd-afcfaa695cd00b713e7d57e1829da90b692ac6f8.zip
core: implement OOMPolicy= and watch cgroups for OOM killings
This adds a new per-service OOMPolicy= (along with a global DefaultOOMPolicy=) that controls what to do if a process of the service is killed by the kernel's OOM killer. It has three different values: "continue" (old behaviour), "stop" (terminate the service), "kill" (let the kernel kill all the service's processes). On top of that, track OOM killer events per unit: generate a per-unit structured, recognizable log message when we see an OOM killer event, and put the service in a failure state if an OOM killer event was seen and the selected policy was not "continue". A new "result" is defined for this case: "oom-kill". All of this relies on new cgroupv2 kernel functionality: the "memory.events" notification interface and the "memory.oom.group" attribute (which makes the kernel kill all cgroup processes automatically).
Diffstat (limited to 'src/core/manager.h')
-rw-r--r--src/core/manager.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/core/manager.h b/src/core/manager.h
index ea442596ae..b5def59ed0 100644
--- a/src/core/manager.h
+++ b/src/core/manager.h
@@ -56,6 +56,14 @@ typedef enum StatusType {
STATUS_TYPE_EMERGENCY,
} StatusType;
+typedef enum OOMPolicy {
+ OOM_CONTINUE, /* The kernel kills the process it wants to kill, and that's it */
+ OOM_STOP, /* The kernel kills the process it wants to kill, and we stop the unit */
+ OOM_KILL, /* The kernel kills the process it wants to kill, and all others in the unit, and we stop the unit */
+ _OOM_POLICY_MAX,
+ _OOM_POLICY_INVALID = -1
+} OOMPolicy;
+
/* Notes:
* 1. TIMESTAMP_FIRMWARE, TIMESTAMP_LOADER, TIMESTAMP_KERNEL, TIMESTAMP_INITRD,
* TIMESTAMP_SECURITY_START, and TIMESTAMP_SECURITY_FINISH are set only when
@@ -159,6 +167,9 @@ struct Manager {
/* Units whose cgroup ran empty */
LIST_HEAD(Unit, cgroup_empty_queue);
+ /* Units whose memory.event fired */
+ LIST_HEAD(Unit, cgroup_oom_queue);
+
/* Target units whose default target dependencies haven't been set yet */
LIST_HEAD(Unit, target_deps_queue);
@@ -268,10 +279,15 @@ struct Manager {
/* Notifications from cgroups, when the unified hierarchy is used is done via inotify. */
int cgroup_inotify_fd;
sd_event_source *cgroup_inotify_event_source;
+
+ /* Maps for finding the unit for each inotify watch descriptor for the cgroup.events and
+ * memory.events cgroupv2 attributes. */
Hashmap *cgroup_control_inotify_wd_unit;
+ Hashmap *cgroup_memory_inotify_wd_unit;
/* A defer event for handling cgroup empty events and processing them after SIGCHLD in all cases. */
sd_event_source *cgroup_empty_event_source;
+ sd_event_source *cgroup_oom_event_source;
/* Make sure the user cannot accidentally unmount our cgroup
* file system */
@@ -328,6 +344,8 @@ struct Manager {
uint64_t default_tasks_max;
usec_t default_timer_accuracy_usec;
+ OOMPolicy default_oom_policy;
+
int original_log_level;
LogTarget original_log_target;
bool log_level_overridden:1;
@@ -519,3 +537,6 @@ void manager_disable_confirm_spawn(void);
const char *manager_timestamp_to_string(ManagerTimestamp m) _const_;
ManagerTimestamp manager_timestamp_from_string(const char *s) _pure_;
ManagerTimestamp manager_timestamp_initrd_mangle(ManagerTimestamp s);
+
+const char* oom_policy_to_string(OOMPolicy i) _const_;
+OOMPolicy oom_policy_from_string(const char *s) _pure_;