| 1 |
<?xml version='1.0'?> |
| 2 |
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" |
| 3 |
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"> |
| 4 |
<!-- SPDX-License-Identifier: LGPL-2.1-or-later --> |
| 5 |
|
| 6 |
<refentry id="systemd-oomd.service" conditional='ENABLE_OOMD' |
| 7 |
xmlns:xi="http://www.w3.org/2001/XInclude"> |
| 8 |
|
| 9 |
<refentryinfo> |
| 10 |
<title>systemd-oomd.service</title> |
| 11 |
<productname>systemd</productname> |
| 12 |
</refentryinfo> |
| 13 |
|
| 14 |
<refmeta> |
| 15 |
<refentrytitle>systemd-oomd.service</refentrytitle> |
| 16 |
<manvolnum>8</manvolnum> |
| 17 |
</refmeta> |
| 18 |
|
| 19 |
<refnamediv> |
| 20 |
<refname>systemd-oomd.service</refname> |
| 21 |
<refname>systemd-oomd</refname> |
| 22 |
<refpurpose>A userspace out-of-memory (OOM) killer</refpurpose> |
| 23 |
</refnamediv> |
| 24 |
|
| 25 |
<refsynopsisdiv> |
| 26 |
<para><filename>systemd-oomd.service</filename></para> |
| 27 |
<para><filename>/usr/lib/systemd/systemd-oomd</filename></para> |
| 28 |
</refsynopsisdiv> |
| 29 |
|
| 30 |
<refsect1> |
| 31 |
<title>Description</title> |
| 32 |
|
| 33 |
<para><command>systemd-oomd</command> is a system service that uses cgroups-v2 and pressure stall |
| 34 |
information (PSI) to monitor and take corrective action before an OOM occurs in the kernel space.</para> |
| 35 |
|
| 36 |
<para>You can enable monitoring and actions on units by setting <varname>ManagedOOMSwap=</varname> and |
| 37 |
<varname>ManagedOOMMemoryPressure=</varname> in the unit configuration, see |
| 38 |
<citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>. |
| 39 |
<command>systemd-oomd</command> retrieves information about such units from |
| 40 |
<citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry> |
| 41 |
when it starts and watches for subsequent changes.</para> |
| 42 |
|
| 43 |
<para>Cgroups of units with <varname>ManagedOOMSwap=</varname> or |
| 44 |
<varname>ManagedOOMMemoryPressure=</varname> set to <option>kill</option> will be monitored. |
| 45 |
<command>systemd-oomd</command> periodically polls PSI statistics for the system and those cgroups to |
| 46 |
decide when to take action. If the configured limits are exceeded, <command>systemd-oomd</command> will |
| 47 |
select a cgroup to terminate, and send <constant>SIGKILL</constant> to all processes in it. Note that |
| 48 |
only descendant cgroups are eligible candidates for killing; the unit with its property set to |
| 49 |
<option>kill</option> is not a candidate (unless one of its ancestors set their property to |
| 50 |
<option>kill</option>). Also only leaf cgroups and cgroups with <filename>memory.oom.group</filename> set |
| 51 |
to <constant>1</constant> are eligible candidates; see <varname>OOMPolicy=</varname> in |
| 52 |
<citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>. |
| 53 |
</para> |
| 54 |
|
| 55 |
<para><citerefentry><refentrytitle>oomctl</refentrytitle><manvolnum>1</manvolnum></citerefentry> can |
| 56 |
be used to list monitored cgroups and pressure information.</para> |
| 57 |
|
| 58 |
<para>See <citerefentry><refentrytitle>oomd.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry> |
| 59 |
for more information about the configuration of this service.</para> |
| 60 |
|
| 61 |
<para>See |
| 62 |
<citerefentry><refentrytitle>org.freedesktop.oom1</refentrytitle><manvolnum>5</manvolnum></citerefentry> |
| 63 |
and |
| 64 |
<citerefentry><refentrytitle>org.freedesktop.LogControl1</refentrytitle><manvolnum>5</manvolnum></citerefentry> |
| 65 |
for a description of the D-Bus API.</para> |
| 66 |
</refsect1> |
| 67 |
|
| 68 |
<refsect1> |
| 69 |
<title>System requirements and configuration</title> |
| 70 |
|
| 71 |
<para>The system must be running systemd with a full unified cgroup hierarchy for the expected cgroups-v2 features. |
| 72 |
Furthermore, memory accounting must be turned on for all units monitored by <command>systemd-oomd</command>. |
| 73 |
The easiest way to turn on memory accounting is by ensuring the value for <varname>DefaultMemoryAccounting=</varname> |
| 74 |
is set to <constant>true</constant> in |
| 75 |
<citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para> |
| 76 |
|
| 77 |
<para>The kernel must be compiled with PSI support. This is available in Linux 4.20 and above.</para> |
| 78 |
|
| 79 |
<para>It is highly recommended for the system to have swap enabled for <command>systemd-oomd</command> to |
| 80 |
function optimally. With swap enabled, the system spends enough time swapping pages to let |
| 81 |
<command>systemd-oomd</command> react. Without swap, the system enters a livelocked state much more |
| 82 |
quickly and may prevent <command>systemd-oomd</command> from responding in a reasonable amount of |
| 83 |
time. See <ulink url="https://chrisdown.name/2018/01/02/in-defence-of-swap.html">"In defence of swap: |
| 84 |
common misconceptions"</ulink> for more details on swap. Any swap-based actions on systems without swap |
| 85 |
will be ignored. While <command>systemd-oomd</command> can perform pressure-based actions on such a |
| 86 |
system, the pressure increases will be more abrupt and may require more tuning to get the desired |
| 87 |
thresholds and behavior.</para> |
| 88 |
|
| 89 |
<para>Be aware that if you intend to enable monitoring and actions on <filename>user.slice</filename>, |
| 90 |
<filename>user-$UID.slice</filename>, or their ancestor cgroups, it is highly recommended that your |
| 91 |
programs be managed by the systemd user manager to prevent running too many processes under the same |
| 92 |
session scope (and thus avoid a situation where memory intensive tasks trigger |
| 93 |
<command>systemd-oomd</command> to kill everything under the cgroup). If you're using a desktop |
| 94 |
environment like GNOME or KDE, it already spawns many session components with the systemd user manager. |
| 95 |
</para> |
| 96 |
</refsect1> |
| 97 |
|
| 98 |
<refsect1> |
| 99 |
<title>Usage Recommendations</title> |
| 100 |
|
| 101 |
<para><varname>ManagedOOMSwap=</varname> works with the system-wide swap values, so setting it on the root slice |
| 102 |
<filename>-.slice</filename>, and allowing all descendant cgroups to be eligible candidates may make the most |
| 103 |
sense.</para> |
| 104 |
|
| 105 |
<para><varname>ManagedOOMMemoryPressure=</varname> tends to work better on the cgroups below the root |
| 106 |
slice. For units which tend to have processes that are less latency sensitive (e.g. |
| 107 |
<filename>system.slice</filename>), a higher limit like the default of 60% may be acceptable, as those |
| 108 |
processes can usually ride out slowdowns caused by lack of memory without serious consequences. However, |
| 109 |
something like <filename>user@$UID.service</filename> may prefer a much lower value like 40%.</para> |
| 110 |
</refsect1> |
| 111 |
|
| 112 |
<refsect1> |
| 113 |
<title>Options</title> |
| 114 |
|
| 115 |
<variablelist> |
| 116 |
<varlistentry> |
| 117 |
<term><option>--dry-run</option></term> |
| 118 |
|
| 119 |
<listitem><para>Do a dry run of <command>systemd-oomd</command>: when a kill is triggered, print it |
| 120 |
to the log instead of killing the cgroup.</para> |
| 121 |
|
| 122 |
<xi:include href="version-info.xml" xpointer="v253"/></listitem> |
| 123 |
</varlistentry> |
| 124 |
|
| 125 |
<xi:include href="standard-options.xml" xpointer="help" /> |
| 126 |
<xi:include href="standard-options.xml" xpointer="version" /> |
| 127 |
</variablelist> |
| 128 |
</refsect1> |
| 129 |
|
| 130 |
<refsect1> |
| 131 |
<title>Signals</title> |
| 132 |
|
| 133 |
<variablelist> |
| 134 |
<varlistentry> |
| 135 |
<term><constant>SIGHUP</constant></term> |
| 136 |
|
| 137 |
<listitem><para>Upon reception of the <constant>SIGHUP</constant> process signal |
| 138 |
<command>systemd-oomd</command> will reload its configuration file.</para> |
| 139 |
|
| 140 |
<xi:include href="version-info.xml" xpointer="v258"/></listitem> |
| 141 |
</varlistentry> |
| 142 |
</variablelist> |
| 143 |
</refsect1> |
| 144 |
|
| 145 |
<refsect1> |
| 146 |
<title>See Also</title> |
| 147 |
<para><simplelist type="inline"> |
| 148 |
<member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 149 |
<member><citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry></member> |
| 150 |
<member><citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry></member> |
| 151 |
<member><citerefentry><refentrytitle>oomd.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry></member> |
| 152 |
<member><citerefentry><refentrytitle>oomctl</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 153 |
<member><citerefentry><refentrytitle>org.freedesktop.oom1</refentrytitle><manvolnum>5</manvolnum></citerefentry></member> |
| 154 |
</simplelist></para> |
| 155 |
</refsect1> |
| 156 |
</refentry> |