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