Skip to content

Commit 54f802f

Browse files
authored
Merge pull request #12037 from poettering/oom-state
add cgroupv2 oom killer event handling to service management
2 parents 3b21fd0 + 7d1d177 commit 54f802f

25 files changed

+528
-57
lines changed

TODO

-4
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,13 @@ Features:
6262

6363
* bootctl,sd-boot: actually honour the "architecture" key
6464

65-
* set memory.oom.group in cgroup v2 for all leaf cgroups (kernel v4.19+)
66-
6765
* add a new syscall group "@esoteric" for more esoteric stuff such as bpf() and
6866
usefaultd() and make systemd-analyze check for it.
6967

7068
* paranoia: whenever we process passwords, call mlock() on the memory
7169
first. i.e. look for all places we use string_erase()/string_free_erase() and
7270
augment them with mlock(). Also use MADV_DONTDUMP
7371

74-
* whenever oom_kill memory.event event is triggered print a nice log message
75-
7672
* Move RestrictAddressFamily= to the new cgroup create socket
7773

7874
* support the bind/connect/sendmsg cgroup stuff for sandboxing, and possibly

catalog/systemd.catalog.in

+13
Original file line numberDiff line numberDiff line change
@@ -391,3 +391,16 @@ The following "tags" are possible:
391391
- "overflowgid-not-65534" — the kernel group ID used for "unknown" users (with
392392
NFS or user namespaces) is not 65534
393393
Current system is tagged as @TAINT@.
394+
395+
-- fe6faa94e7774663a0da52717891d8ef
396+
Subject: A process of @UNIT@ unit has been killed by the OOM killer.
397+
Defined-By: systemd
398+
Support: %SUPPORT_URL%
399+
400+
A process of unit @UNIT has been killed by the Linux kernel out-of-memory (OOM)
401+
killer logic. This usually indicates that the system is low on memory and that
402+
memory needed to be freed. A process associated with @UNIT@ has been determined
403+
as the best process to terminate and has been forcibly terminated by the
404+
kernel.
405+
406+
Note that the memory pressure might or might not have been caused by @UNIT@.

man/systemd-system.conf.xml

+11
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,17 @@
364364
limits are only defaults for units, they are not applied to PID 1
365365
itself.</para></listitem>
366366
</varlistentry>
367+
368+
<varlistentry>
369+
<term><varname>DefaultOOMPolicy=</varname></term>
370+
371+
<listitem><para>Configure the default policy for reacting to processes being killed by the Linux
372+
Out-Of-Memory (OOM) killer. This may be used to pick a global default for the per-unit
373+
<varname>OOMPolicy=</varname> setting. See
374+
<citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
375+
for details. Note that this default is not used for services that have <varname>Delegate=</varname>
376+
turned on.</para></listitem>
377+
</varlistentry>
367378
</variablelist>
368379
</refsect1>
369380

man/systemd.exec.xml

+11-5
Original file line numberDiff line numberDiff line change
@@ -651,11 +651,17 @@ CapabilityBoundingSet=~CAP_B CAP_C</programlisting>
651651
<varlistentry>
652652
<term><varname>OOMScoreAdjust=</varname></term>
653653

654-
<listitem><para>Sets the adjustment level for the Out-Of-Memory killer for executed processes. Takes an integer
655-
between -1000 (to disable OOM killing for this process) and 1000 (to make killing of this process under memory
656-
pressure very likely). See <ulink
657-
url="https://www.kernel.org/doc/Documentation/filesystems/proc.txt">proc.txt</ulink> for
658-
details.</para></listitem>
654+
<listitem><para>Sets the adjustment value for the Linux kernel's Out-Of-Memory (OOM) killer score for
655+
executed processes. Takes an integer between -1000 (to disable OOM killing of processes of this unit)
656+
and 1000 (to make killing of processes of this unit under memory pressure very likely). See <ulink
657+
url="https://www.kernel.org/doc/Documentation/filesystems/proc.txt">proc.txt</ulink> for details. If
658+
not specified defaults to the OOM score adjustment level of the service manager itself, which is
659+
normally at 0.</para>
660+
661+
<para>Use the <varname>OOMPolicy=</varname> setting of service units to configure how the service
662+
manager shall react to the kernel OOM killer terminating a process of the service. See
663+
<citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
664+
for details.</para></listitem>
659665
</varlistentry>
660666

661667
<varlistentry>

man/systemd.service.xml

+23
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,29 @@
963963
above.</para></listitem>
964964
</varlistentry>
965965

966+
<varlistentry>
967+
<term><varname>OOMPolicy=</varname></term>
968+
969+
<listitem><para>Configure the Out-Of-Memory (OOM) killer policy. On Linux, when memory becomes scarce
970+
the kernel might decide to kill a running process in order to free up memory and reduce memory
971+
pressure. This setting takes one of <constant>continue</constant>, <constant>stop</constant> or
972+
<constant>kill</constant>. If set to <constant>continue</constant> and a process of the service is
973+
killed by the kernel's OOM killer this is logged but the service continues running. If set to
974+
<constant>stop</constant> the event is logged but the service is terminated cleanly by the service
975+
manager. If set to <constant>kill</constant> and one of the service's processes is killed by the OOM
976+
killer the kernel is instructed to kill all remaining processes of the service, too. Defaults to the
977+
setting <varname>DefaultOOMPolicy=</varname> in
978+
<citerefentry><refentrytitle>system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry> is
979+
set to, except for services where <varname>Delegate=</varname> is turned on, where it defaults to
980+
<constant>continue</constant>.</para>
981+
982+
<para>Use the <varname>OOMScoreAdjust=</varname> setting to configure whether processes of the unit
983+
shall be considered preferred or less preferred candidates for process termination by the Linux OOM
984+
killer logic. See
985+
<citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
986+
details.</para></listitem>
987+
</varlistentry>
988+
966989
</variablelist>
967990

968991
<para>Check

0 commit comments

Comments
 (0)