]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/systemd.resource-control.xml
c3581e78b331307a56ff09ba34e8b270992f4dd2
[thirdparty/systemd.git] / man / systemd.resource-control.xml
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.resource-control" xmlns:xi="http://www.w3.org/2001/XInclude">
7 <refentryinfo>
8 <title>systemd.resource-control</title>
9 <productname>systemd</productname>
10 </refentryinfo>
11
12 <refmeta>
13 <refentrytitle>systemd.resource-control</refentrytitle>
14 <manvolnum>5</manvolnum>
15 </refmeta>
16
17 <refnamediv>
18 <refname>systemd.resource-control</refname>
19 <refpurpose>Resource control unit settings</refpurpose>
20 </refnamediv>
21
22 <refsynopsisdiv>
23 <para>
24 <filename><replaceable>slice</replaceable>.slice</filename>,
25 <filename><replaceable>scope</replaceable>.scope</filename>,
26 <filename><replaceable>service</replaceable>.service</filename>,
27 <filename><replaceable>socket</replaceable>.socket</filename>,
28 <filename><replaceable>mount</replaceable>.mount</filename>,
29 <filename><replaceable>swap</replaceable>.swap</filename>
30 </para>
31 </refsynopsisdiv>
32
33 <refsect1>
34 <title>Description</title>
35
36 <para>Unit configuration files for services, slices, scopes, sockets, mount points, and swap devices share a subset
37 of configuration options for resource control of spawned processes. Internally, this relies on the Linux Control
38 Groups (cgroups) kernel concept for organizing processes in a hierarchical tree of named groups for the purpose of
39 resource management.</para>
40
41 <para>This man page lists the configuration options shared by
42 those six unit types. See
43 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>
44 for the common options of all unit configuration files, and
45 <citerefentry><refentrytitle>systemd.slice</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
46 <citerefentry><refentrytitle>systemd.scope</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
47 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
48 <citerefentry><refentrytitle>systemd.socket</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
49 <citerefentry><refentrytitle>systemd.mount</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
50 and
51 <citerefentry><refentrytitle>systemd.swap</refentrytitle><manvolnum>5</manvolnum></citerefentry>
52 for more information on the specific unit configuration files. The
53 resource control configuration options are configured in the
54 [Slice], [Scope], [Service], [Socket], [Mount], or [Swap]
55 sections, depending on the unit type.</para>
56
57 <para>In addition, options which control resources available to programs
58 <emphasis>executed</emphasis> by systemd are listed in
59 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
60 Those options complement options listed here.</para>
61
62 <refsect2>
63 <title>Enabling and disabling controllers</title>
64
65 <para>Controllers in the cgroup hierarchy are hierarchical, and resource control is realized by
66 distributing resource assignments between siblings in branches of the cgroup hierarchy. There is no
67 need to explicitly <emphasis>enable</emphasis> a cgroup controller for a unit.
68 <command>systemd</command> will instruct the kernel to enable a controller for a given unit when this
69 unit has configuration for a given controller. For example, when <varname>CPUWeight=</varname> is set,
70 the <option>cpu</option> controller will be enabled, and when <varname>TasksMax=</varname> are set, the
71 <option>pids</option> controller will be enabled. In addition, various controllers may be also be
72 enabled explicitly via the
73 <varname>MemoryAccounting=</varname>/<varname>TasksAccounting=</varname>/<varname>IOAccounting=</varname>
74 settings. Because of how the cgroup hierarchy works, controllers will be automatically enabled for all
75 parent units and for any sibling units starting with the lowest level at which a controller is enabled.
76 Units for which a controller is enabled may be subject to resource control even if they don't have any
77 explicit configuration.</para>
78
79 <para>Setting <varname>Delegate=</varname> enables any delegated controllers for that unit (see below).
80 The delegatee may then enable controllers for its children as appropriate. In particular, if the
81 delegatee is <command>systemd</command> (in the <filename>user@.service</filename> unit), it will
82 repeat the same logic as the system instance and enable controllers for user units which have resource
83 limits configured, and their siblings and parents and parents' siblings.</para>
84
85 <para>Controllers may be <emphasis>disabled</emphasis> for parts of the cgroup hierarchy with
86 <varname>DisableControllers=</varname> (see below).</para>
87
88 <example>
89 <title>Enabling and disabling controllers</title>
90
91 <programlisting>
92 -.slice
93 / \
94 /-----/ \--------------\
95 / \
96 system.slice user.slice
97 / \ / \
98 / \ / \
99 / \ user@42.service user@1000.service
100 / \ Delegate= Delegate=yes
101 a.service b.slice / \
102 CPUWeight=20 DisableControllers=cpu / \
103 / \ app.slice session.slice
104 / \ CPUWeight=100 CPUWeight=100
105 / \
106 b1.service b2.service
107 CPUWeight=1000
108 </programlisting>
109
110 <para>In this hierarchy, the <option>cpu</option> controller is enabled for all units shown except
111 <filename>b1.service</filename> and <filename>b2.service</filename>. Because there is no explicit
112 configuration for <filename>system.slice</filename> and <filename>user.slice</filename>, CPU
113 resources will be split equally between them. Similarly, resources are allocated equally between
114 children of <filename>user.slice</filename> and between the child slices beneath
115 <filename>user@1000.service</filename>. Assuming that there is no further configuration of resources
116 or delegation below slices <filename>app.slice</filename> or <filename>session.slice</filename>, the
117 <option>cpu</option> controller would not be enabled for units in those slices and CPU resources
118 would be further allocated using other mechanisms, e.g. based on nice levels. The manager for user
119 42 has delegation enabled without any controllers, i.e. it can manipulate its subtree of the cgroup
120 hierarchy, but without resource control.</para>
121
122 <para>In the slice <filename>system.slice</filename>, CPU resources are split 1:6 for service
123 <filename>a.service</filename>, and 5:6 for slice <filename>b.slice</filename>, because slice
124 <filename>b.slice</filename> gets the default value of 100 for <filename>cpu.weight</filename> when
125 <varname>CPUWeight=</varname> is not set.</para>
126
127 <para><varname>CPUWeight=</varname> setting in service <filename>b2.service</filename> is neutralized
128 by <varname>DisableControllers=</varname> in slice <filename>b.slice</filename>, so the
129 <option>cpu</option> controller would not be enabled for services <filename>b1.service</filename> and
130 <filename>b2.service</filename>, and CPU resources would be further allocated using other mechanisms,
131 e.g. based on nice levels.</para>
132 </example>
133 </refsect2>
134
135 <refsect2>
136 <title>Setting resource controls for a group of related units</title>
137
138 <para>As described in
139 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>, the
140 settings listed here may be set through the main file of a unit and drop-in snippets in
141 <filename index="false">*.d/</filename> directories. The list of directories searched for drop-ins
142 includes names formed by repeatedly truncating the unit name after all dashes. This is particularly
143 convenient to set resource limits for a group of units with similar names.</para>
144
145 <para>For example, every user gets their own slice
146 <filename>user-<replaceable>nnn</replaceable>.slice</filename>. Drop-ins with local configuration that
147 affect user 1000 may be placed in
148 <filename index="false">/etc/systemd/system/user-1000.slice</filename>,
149 <filename index="false">/etc/systemd/system/user-1000.slice.d/*.conf</filename>, but also
150 <filename index="false">/etc/systemd/system/user-.slice.d/*.conf</filename>. This last directory
151 applies to all user slices.</para>
152 </refsect2>
153
154 <para>See the <ulink
155 url="https://www.freedesktop.org/wiki/Software/systemd/ControlGroupInterface">New
156 Control Group Interfaces</ulink> for an introduction on how to make
157 use of resource control APIs from programs.</para>
158 </refsect1>
159
160 <refsect1>
161 <title>Implicit Dependencies</title>
162
163 <para>The following dependencies are implicitly added:</para>
164
165 <itemizedlist>
166 <listitem><para>Units with the <varname>Slice=</varname> setting set automatically acquire
167 <varname>Requires=</varname> and <varname>After=</varname> dependencies on the specified
168 slice unit.</para></listitem>
169 </itemizedlist>
170 </refsect1>
171
172 <!-- We don't have any default dependency here. -->
173
174 <refsect1>
175 <title>Options</title>
176
177 <para>Units of the types listed above can have settings for resource control configuration:</para>
178
179 <refsect2><title>CPU Accounting and Control</title>
180
181 <variablelist class='unit-directives'>
182
183 <varlistentry>
184 <term><varname>CPUAccounting=</varname></term>
185
186 <listitem>
187 <para>Turn on CPU usage accounting for this unit. Takes a
188 boolean argument. Note that turning on CPU accounting for
189 one unit will also implicitly turn it on for all units
190 contained in the same slice and for all its parent slices
191 and the units contained therein. The system default for this
192 setting may be controlled with
193 <varname>DefaultCPUAccounting=</varname> in
194 <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
195
196 <para>Under the unified cgroup hierarchy, CPU accounting is available for all units and this
197 setting has no effect.</para>
198
199 <xi:include href="version-info.xml" xpointer="v208"/>
200 </listitem>
201 </varlistentry>
202
203 <varlistentry>
204 <term><varname>CPUWeight=<replaceable>weight</replaceable></varname></term>
205 <term><varname>StartupCPUWeight=<replaceable>weight</replaceable></varname></term>
206
207 <listitem>
208 <para>These settings control the <option>cpu</option> controller in the unified hierarchy.</para>
209
210 <para>These options accept an integer value or a the special string "idle":</para>
211 <itemizedlist>
212 <listitem>
213 <para>If set to an integer value, assign the specified CPU time weight to the processes
214 executed, if the unified control group hierarchy is used on the system. These options control
215 the <literal>cpu.weight</literal> control group attribute. The allowed range is 1 to 10000.
216 Defaults to unset, but the kernel default is 100. For details about this control group
217 attribute, see <ulink url="https://docs.kernel.org/admin-guide/cgroup-v2.html">Control Groups
218 v2</ulink> and <ulink url="https://docs.kernel.org/scheduler/sched-design-CFS.html">CFS
219 Scheduler</ulink>. The available CPU time is split up among all units within one slice
220 relative to their CPU time weight. A higher weight means more CPU time, a lower weight means
221 less.</para>
222 </listitem>
223 <listitem>
224 <para>If set to the special string "idle", mark the cgroup for "idle scheduling", which means
225 that it will get CPU resources only when there are no processes not marked in this way to execute in this
226 cgroup or its siblings. This setting corresponds to the <literal>cpu.idle</literal> cgroup attribute.</para>
227
228 <para>Note that this value only has an effect on cgroup-v2, for cgroup-v1 it is equivalent to the minimum weight.</para>
229 </listitem>
230 </itemizedlist>
231
232 <para>While <varname>StartupCPUWeight=</varname> applies to the startup and shutdown phases of the system,
233 <varname>CPUWeight=</varname> applies to normal runtime of the system, and if the former is not set also to
234 the startup and shutdown phases. Using <varname>StartupCPUWeight=</varname> allows prioritizing specific services at
235 boot-up and shutdown differently than during normal runtime.</para>
236
237 <para>In addition to the resource allocation performed by the <option>cpu</option> controller, the
238 kernel may automatically divide resources based on session-id grouping, see "The autogroup feature"
239 in <citerefentry
240 project='man-pages'><refentrytitle>sched</refentrytitle><manvolnum>7</manvolnum></citerefentry>.
241 The effect of this feature is similar to the <option>cpu</option> controller with no explicit
242 configuration, so users should be careful to not mistake one for the other.</para>
243
244 <xi:include href="version-info.xml" xpointer="v232"/>
245 </listitem>
246 </varlistentry>
247
248 <varlistentry>
249 <term><varname>CPUQuota=</varname></term>
250
251 <listitem>
252 <para>This setting controls the <option>cpu</option> controller in the unified hierarchy.</para>
253
254 <para>Assign the specified CPU time quota to the processes executed. Takes a percentage value, suffixed with
255 "%". The percentage specifies how much CPU time the unit shall get at maximum, relative to the total CPU time
256 available on one CPU. Use values &gt; 100% for allotting CPU time on more than one CPU. This controls the
257 <literal>cpu.max</literal> attribute on the unified control group hierarchy and
258 <literal>cpu.cfs_quota_us</literal> on legacy. For details about these control group attributes, see <ulink
259 url="https://docs.kernel.org/admin-guide/cgroup-v2.html">Control Groups v2</ulink> and <ulink
260 url="https://docs.kernel.org/scheduler/sched-bwc.html">CFS Bandwidth Control</ulink>.
261 Setting <varname>CPUQuota=</varname> to an empty value unsets the quota.</para>
262
263 <para>Example: <varname>CPUQuota=20%</varname> ensures that the executed processes will never get more than
264 20% CPU time on one CPU.</para>
265
266 <xi:include href="version-info.xml" xpointer="v213"/>
267
268 </listitem>
269 </varlistentry>
270
271 <varlistentry>
272 <term><varname>CPUQuotaPeriodSec=</varname></term>
273
274 <listitem>
275 <para>This setting controls the <option>cpu</option> controller in the unified hierarchy.</para>
276
277 <para>Assign the duration over which the CPU time quota specified by <varname>CPUQuota=</varname> is measured.
278 Takes a time duration value in seconds, with an optional suffix such as "ms" for milliseconds (or "s" for seconds.)
279 The default setting is 100ms. The period is clamped to the range supported by the kernel, which is [1ms, 1000ms].
280 Additionally, the period is adjusted up so that the quota interval is also at least 1ms.
281 Setting <varname>CPUQuotaPeriodSec=</varname> to an empty value resets it to the default.</para>
282
283 <para>This controls the second field of <literal>cpu.max</literal> attribute on the unified control group hierarchy
284 and <literal>cpu.cfs_period_us</literal> on legacy. For details about these control group attributes, see
285 <ulink url="https://docs.kernel.org/admin-guide/cgroup-v2.html">Control Groups v2</ulink> and
286 <ulink url="https://docs.kernel.org/scheduler/sched-design-CFS.html">CFS Scheduler</ulink>.</para>
287
288 <para>Example: <varname>CPUQuotaPeriodSec=10ms</varname> to request that the CPU quota is measured in periods of 10ms.</para>
289
290 <xi:include href="version-info.xml" xpointer="v242"/>
291 </listitem>
292 </varlistentry>
293
294 <varlistentry>
295 <term><varname>AllowedCPUs=</varname></term>
296 <term><varname>StartupAllowedCPUs=</varname></term>
297
298 <listitem>
299 <para>This setting controls the <option>cpuset</option> controller in the unified hierarchy.</para>
300
301 <para>Restrict processes to be executed on specific CPUs. Takes a list of CPU indices or ranges separated by either
302 whitespace or commas. CPU ranges are specified by the lower and upper CPU indices separated by a dash.</para>
303
304 <para>Setting <varname>AllowedCPUs=</varname> or <varname>StartupAllowedCPUs=</varname> doesn't guarantee that all
305 of the CPUs will be used by the processes as it may be limited by parent units. The effective configuration is
306 reported as <varname>EffectiveCPUs=</varname>.</para>
307
308 <para>While <varname>StartupAllowedCPUs=</varname> applies to the startup and shutdown phases of the system,
309 <varname>AllowedCPUs=</varname> applies to normal runtime of the system, and if the former is not set also to
310 the startup and shutdown phases. Using <varname>StartupAllowedCPUs=</varname> allows prioritizing specific services at
311 boot-up and shutdown differently than during normal runtime.</para>
312
313 <para>This setting is supported only with the unified control group hierarchy.</para>
314
315 <xi:include href="version-info.xml" xpointer="v244"/>
316 </listitem>
317 </varlistentry>
318
319 </variablelist>
320
321 </refsect2><refsect2><title>Memory Accounting and Control</title>
322
323 <variablelist class='unit-directives'>
324
325 <varlistentry>
326 <term><varname>MemoryAccounting=</varname></term>
327
328 <listitem>
329 <para>This setting controls the <option>memory</option> controller in the unified hierarchy.</para>
330
331 <para>Turn on process and kernel memory accounting for this
332 unit. Takes a boolean argument. Note that turning on memory
333 accounting for one unit will also implicitly turn it on for
334 all units contained in the same slice and for all its parent
335 slices and the units contained therein. The system default
336 for this setting may be controlled with
337 <varname>DefaultMemoryAccounting=</varname> in
338 <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
339
340 <xi:include href="version-info.xml" xpointer="v208"/>
341 </listitem>
342 </varlistentry>
343
344 <varlistentry>
345 <term><varname>MemoryMin=<replaceable>bytes</replaceable></varname>, <varname>MemoryLow=<replaceable>bytes</replaceable></varname></term>
346 <term><varname>StartupMemoryLow=<replaceable>bytes</replaceable></varname>, <varname>DefaultStartupMemoryLow=<replaceable>bytes</replaceable></varname></term>
347
348 <listitem>
349 <para>These settings control the <option>memory</option> controller in the unified hierarchy.</para>
350
351 <para>Specify the memory usage protection of the executed processes in this unit.
352 When reclaiming memory, the unit is treated as if it was using less memory resulting in memory
353 to be preferentially reclaimed from unprotected units.
354 Using <varname>MemoryLow=</varname> results in a weaker protection where memory may still
355 be reclaimed to avoid invoking the OOM killer in case there is no other reclaimable memory.</para>
356 <para>
357 For a protection to be effective, it is generally required to set a corresponding
358 allocation on all ancestors, which is then distributed between children
359 (with the exception of the root slice).
360 Any <varname>MemoryMin=</varname> or <varname>MemoryLow=</varname> allocation that is not
361 explicitly distributed to specific children is used to create a shared protection for all children.
362 As this is a shared protection, the children will freely compete for the memory.</para>
363
364 <para>Takes a memory size in bytes. If the value is suffixed with K, M, G or T, the specified memory size is
365 parsed as Kilobytes, Megabytes, Gigabytes, or Terabytes (with the base 1024), respectively. Alternatively, a
366 percentage value may be specified, which is taken relative to the installed physical memory on the
367 system. If assigned the special value <literal>infinity</literal>, all available memory is protected, which may be
368 useful in order to always inherit all of the protection afforded by ancestors.
369 This controls the <literal>memory.min</literal> or <literal>memory.low</literal> control group attribute.
370 For details about this control group attribute, see <ulink
371 url="https://docs.kernel.org/admin-guide/cgroup-v2.html#memory-interface-files">Memory Interface Files</ulink>.</para>
372
373 <para>Units may have their children use a default <literal>memory.min</literal> or
374 <literal>memory.low</literal> value by specifying <varname>DefaultMemoryMin=</varname> or
375 <varname>DefaultMemoryLow=</varname>, which has the same semantics as
376 <varname>MemoryMin=</varname> and <varname>MemoryLow=</varname>, or <varname>DefaultStartupMemoryLow=</varname>
377 which has the same semantics as <varname>StartupMemoryLow=</varname>.
378 This setting does not affect <literal>memory.min</literal> or <literal>memory.low</literal>
379 in the unit itself.
380 Using it to set a default child allocation is only useful on kernels older than 5.7,
381 which do not support the <literal>memory_recursiveprot</literal> cgroup2 mount option.</para>
382
383 <para>While <varname>StartupMemoryLow=</varname> applies to the startup and shutdown phases of the system,
384 <varname>MemoryMin=</varname> applies to normal runtime of the system, and if the former is not set also to
385 the startup and shutdown phases. Using <varname>StartupMemoryLow=</varname> allows prioritizing specific services at
386 boot-up and shutdown differently than during normal runtime.</para>
387
388 <xi:include href="version-info.xml" xpointer="v240"/>
389 </listitem>
390 </varlistentry>
391
392 <varlistentry>
393 <term><varname>MemoryHigh=<replaceable>bytes</replaceable></varname></term>
394 <term><varname>StartupMemoryHigh=<replaceable>bytes</replaceable></varname></term>
395
396 <listitem>
397 <para>These settings control the <option>memory</option> controller in the unified hierarchy.</para>
398
399 <para>Specify the throttling limit on memory usage of the executed processes in this unit. Memory usage may go
400 above the limit if unavoidable, but the processes are heavily slowed down and memory is taken away
401 aggressively in such cases. This is the main mechanism to control memory usage of a unit.</para>
402
403 <para>Takes a memory size in bytes. If the value is suffixed with K, M, G or T, the specified memory size is
404 parsed as Kilobytes, Megabytes, Gigabytes, or Terabytes (with the base 1024), respectively. Alternatively, a
405 percentage value may be specified, which is taken relative to the installed physical memory on the
406 system. If assigned the
407 special value <literal>infinity</literal>, no memory throttling is applied. This controls the
408 <literal>memory.high</literal> control group attribute. For details about this control group attribute, see
409 <ulink url="https://docs.kernel.org/admin-guide/cgroup-v2.html#memory-interface-files">Memory Interface Files</ulink>.</para>
410
411 <para>While <varname>StartupMemoryHigh=</varname> applies to the startup and shutdown phases of the system,
412 <varname>MemoryHigh=</varname> applies to normal runtime of the system, and if the former is not set also to
413 the startup and shutdown phases. Using <varname>StartupMemoryHigh=</varname> allows prioritizing specific services at
414 boot-up and shutdown differently than during normal runtime.</para>
415
416 <xi:include href="version-info.xml" xpointer="v231"/>
417 </listitem>
418 </varlistentry>
419
420 <varlistentry>
421 <term><varname>MemoryMax=<replaceable>bytes</replaceable></varname></term>
422 <term><varname>StartupMemoryMax=<replaceable>bytes</replaceable></varname></term>
423
424 <listitem>
425 <para>These settings control the <option>memory</option> controller in the unified hierarchy.</para>
426
427 <para>Specify the absolute limit on memory usage of the executed processes in this unit. If memory usage
428 cannot be contained under the limit, out-of-memory killer is invoked inside the unit. It is recommended to
429 use <varname>MemoryHigh=</varname> as the main control mechanism and use <varname>MemoryMax=</varname> as the
430 last line of defense.</para>
431
432 <para>Takes a memory size in bytes. If the value is suffixed with K, M, G or T, the specified memory size is
433 parsed as Kilobytes, Megabytes, Gigabytes, or Terabytes (with the base 1024), respectively. Alternatively, a
434 percentage value may be specified, which is taken relative to the installed physical memory on the system. If
435 assigned the special value <literal>infinity</literal>, no memory limit is applied. This controls the
436 <literal>memory.max</literal> control group attribute. For details about this control group attribute, see
437 <ulink url="https://docs.kernel.org/admin-guide/cgroup-v2.html#memory-interface-files">Memory Interface Files</ulink>.</para>
438
439 <para>While <varname>StartupMemoryMax=</varname> applies to the startup and shutdown phases of the system,
440 <varname>MemoryMax=</varname> applies to normal runtime of the system, and if the former is not set also to
441 the startup and shutdown phases. Using <varname>StartupMemoryMax=</varname> allows prioritizing specific services at
442 boot-up and shutdown differently than during normal runtime.</para>
443
444 <xi:include href="version-info.xml" xpointer="v231"/>
445 </listitem>
446 </varlistentry>
447
448 <varlistentry>
449 <term><varname>MemorySwapMax=<replaceable>bytes</replaceable></varname></term>
450 <term><varname>StartupMemorySwapMax=<replaceable>bytes</replaceable></varname></term>
451
452 <listitem>
453 <para>These settings control the <option>memory</option> controller in the unified hierarchy.</para>
454
455 <para>Specify the absolute limit on swap usage of the executed processes in this unit.</para>
456
457 <para>Takes a swap size in bytes. If the value is suffixed with K, M, G or T, the specified swap size is
458 parsed as Kilobytes, Megabytes, Gigabytes, or Terabytes (with the base 1024), respectively. If assigned the
459 special value <literal>infinity</literal>, no swap limit is applied. These settings control the
460 <literal>memory.swap.max</literal> control group attribute. For details about this control group attribute,
461 see <ulink url="https://docs.kernel.org/admin-guide/cgroup-v2.html#memory-interface-files">Memory Interface Files</ulink>.</para>
462
463 <para>While <varname>StartupMemorySwapMax=</varname> applies to the startup and shutdown phases of the system,
464 <varname>MemorySwapMax=</varname> applies to normal runtime of the system, and if the former is not set also to
465 the startup and shutdown phases. Using <varname>StartupMemorySwapMax=</varname> allows prioritizing specific services at
466 boot-up and shutdown differently than during normal runtime.</para>
467
468 <xi:include href="version-info.xml" xpointer="v232"/>
469 </listitem>
470 </varlistentry>
471
472 <varlistentry>
473 <term><varname>MemoryZSwapMax=<replaceable>bytes</replaceable></varname></term>
474 <term><varname>StartupMemoryZSwapMax=<replaceable>bytes</replaceable></varname></term>
475
476 <listitem>
477 <para>These settings control the <option>memory</option> controller in the unified hierarchy.</para>
478
479 <para>Specify the absolute limit on zswap usage of the processes in this unit. Zswap is a lightweight compressed
480 cache for swap pages. It takes pages that are in the process of being swapped out and attempts to compress them into a
481 dynamically allocated RAM-based memory pool. If the limit specified is hit, no entries from this unit will be
482 stored in the pool until existing entries are faulted back or written out to disk. See the kernel's
483 <ulink url="https://www.kernel.org/doc/html/latest/admin-guide/mm/zswap.html">Zswap</ulink> documentation for more details.</para>
484
485 <para>Takes a size in bytes. If the value is suffixed with K, M, G or T, the specified size is
486 parsed as Kilobytes, Megabytes, Gigabytes, or Terabytes (with the base 1024), respectively. If assigned the
487 special value <literal>infinity</literal>, no limit is applied. These settings control the
488 <literal>memory.zswap.max</literal> control group attribute. For details about this control group attribute,
489 see <ulink url="https://docs.kernel.org/admin-guide/cgroup-v2.html#memory-interface-files">Memory Interface Files</ulink>.</para>
490
491 <para>While <varname>StartupMemoryZSwapMax=</varname> applies to the startup and shutdown phases of the system,
492 <varname>MemoryZSwapMax=</varname> applies to normal runtime of the system, and if the former is not set also to
493 the startup and shutdown phases. Using <varname>StartupMemoryZSwapMax=</varname> allows prioritizing specific services at
494 boot-up and shutdown differently than during normal runtime.</para>
495
496 <xi:include href="version-info.xml" xpointer="v253"/>
497 </listitem>
498 </varlistentry>
499
500 <varlistentry>
501 <term><varname>AllowedMemoryNodes=</varname></term>
502 <term><varname>StartupAllowedMemoryNodes=</varname></term>
503
504 <listitem>
505 <para>These settings control the <option>cpuset</option> controller in the unified hierarchy.</para>
506
507 <para>Restrict processes to be executed on specific memory NUMA nodes. Takes a list of memory NUMA nodes indices
508 or ranges separated by either whitespace or commas. Memory NUMA nodes ranges are specified by the lower and upper
509 NUMA nodes indices separated by a dash.</para>
510
511 <para>Setting <varname>AllowedMemoryNodes=</varname> or <varname>StartupAllowedMemoryNodes=</varname> doesn't
512 guarantee that all of the memory NUMA nodes will be used by the processes as it may be limited by parent units.
513 The effective configuration is reported as <varname>EffectiveMemoryNodes=</varname>.</para>
514
515 <para>While <varname>StartupAllowedMemoryNodes=</varname> applies to the startup and shutdown phases of the system,
516 <varname>AllowedMemoryNodes=</varname> applies to normal runtime of the system, and if the former is not set also to
517 the startup and shutdown phases. Using <varname>StartupAllowedMemoryNodes=</varname> allows prioritizing specific services at
518 boot-up and shutdown differently than during normal runtime.</para>
519
520 <para>This setting is supported only with the unified control group hierarchy.</para>
521
522 <xi:include href="version-info.xml" xpointer="v244"/>
523 </listitem>
524 </varlistentry>
525
526 </variablelist>
527
528 </refsect2><refsect2><title>Process Accounting and Control</title>
529
530 <variablelist class='unit-directives'>
531
532 <varlistentry>
533 <term><varname>TasksAccounting=</varname></term>
534
535 <listitem>
536 <para>This setting controls the <option>pids</option> controller in the unified hierarchy.</para>
537
538 <para>Turn on task accounting for this unit. Takes a boolean argument. If enabled, the kernel will
539 keep track of the total number of tasks in the unit and its children. This number includes both
540 kernel threads and userspace processes, with each thread counted individually. Note that turning on
541 tasks accounting for one unit will also implicitly turn it on for all units contained in the same
542 slice and for all its parent slices and the units contained therein. The system default for this
543 setting may be controlled with <varname>DefaultTasksAccounting=</varname> in
544 <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
545
546 <xi:include href="version-info.xml" xpointer="v227"/>
547 </listitem>
548 </varlistentry>
549
550 <varlistentry>
551 <term><varname>TasksMax=<replaceable>N</replaceable></varname></term>
552
553 <listitem>
554 <para>This setting controls the <option>pids</option> controller in the unified hierarchy.</para>
555
556 <para>Specify the maximum number of tasks that may be created in the unit. This ensures that the
557 number of tasks accounted for the unit (see above) stays below a specific limit. This either takes
558 an absolute number of tasks or a percentage value that is taken relative to the configured maximum
559 number of tasks on the system. If assigned the special value <literal>infinity</literal>, no tasks
560 limit is applied. This controls the <literal>pids.max</literal> control group attribute. For
561 details about this control group attribute, the
562 <ulink url="https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html#pid">pids controller
563 </ulink>.</para>
564
565 <para>The system default for this setting may be controlled with
566 <varname>DefaultTasksMax=</varname> in
567 <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
568
569 <xi:include href="version-info.xml" xpointer="v227"/>
570 </listitem>
571 </varlistentry>
572
573 </variablelist>
574
575 </refsect2><refsect2><title>IO Accounting and Control</title>
576
577 <variablelist class='unit-directives'>
578
579 <varlistentry>
580 <term><varname>IOAccounting=</varname></term>
581
582 <listitem>
583 <para>This setting controls the <option>io</option> controller in the unified hierarchy.</para>
584
585 <para>Turn on Block I/O accounting for this unit, if the unified control group hierarchy is used on the
586 system. Takes a boolean argument. Note that turning on block I/O accounting for one unit will also implicitly
587 turn it on for all units contained in the same slice and all for its parent slices and the units contained
588 therein. The system default for this setting may be controlled with <varname>DefaultIOAccounting=</varname>
589 in
590 <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
591
592 <xi:include href="version-info.xml" xpointer="v230"/>
593 </listitem>
594 </varlistentry>
595
596 <varlistentry>
597 <term><varname>IOWeight=<replaceable>weight</replaceable></varname></term>
598 <term><varname>StartupIOWeight=<replaceable>weight</replaceable></varname></term>
599
600 <listitem>
601 <para>These settings control the <option>io</option> controller in the unified hierarchy.</para>
602
603 <para>Set the default overall block I/O weight for the executed processes, if the unified control
604 group hierarchy is used on the system. Takes a single weight value (between 1 and 10000) to set the
605 default block I/O weight. This controls the <literal>io.weight</literal> control group attribute,
606 which defaults to 100. For details about this control group attribute, see <ulink
607 url="https://docs.kernel.org/admin-guide/cgroup-v2.html#io-interface-files">IO
608 Interface Files</ulink>. The available I/O bandwidth is split up among all units within one slice
609 relative to their block I/O weight. A higher weight means more I/O bandwidth, a lower weight means
610 less.</para>
611
612 <para>While <varname>StartupIOWeight=</varname> applies
613 to the startup and shutdown phases of the system,
614 <varname>IOWeight=</varname> applies to the later runtime of
615 the system, and if the former is not set also to the startup
616 and shutdown phases. This allows prioritizing specific services at boot-up
617 and shutdown differently than during runtime.</para>
618
619 <xi:include href="version-info.xml" xpointer="v230"/>
620 </listitem>
621 </varlistentry>
622
623 <varlistentry>
624 <term><varname>IODeviceWeight=<replaceable>device</replaceable> <replaceable>weight</replaceable></varname></term>
625
626 <listitem>
627 <para>This setting controls the <option>io</option> controller in the unified hierarchy.</para>
628
629 <para>Set the per-device overall block I/O weight for the executed processes, if the unified control group
630 hierarchy is used on the system. Takes a space-separated pair of a file path and a weight value to specify
631 the device specific weight value, between 1 and 10000. (Example: <literal>/dev/sda 1000</literal>). The file
632 path may be specified as path to a block device node or as any other file, in which case the backing block
633 device of the file system of the file is determined. This controls the <literal>io.weight</literal> control
634 group attribute, which defaults to 100. Use this option multiple times to set weights for multiple devices.
635 For details about this control group attribute, see <ulink
636 url="https://docs.kernel.org/admin-guide/cgroup-v2.html#io-interface-files">IO Interface Files</ulink>.</para>
637
638 <para>The specified device node should reference a block device that has an I/O scheduler
639 associated, i.e. should not refer to partition or loopback block devices, but to the originating,
640 physical device. When a path to a regular file or directory is specified it is attempted to
641 discover the correct originating device backing the file system of the specified path. This works
642 correctly only for simpler cases, where the file system is directly placed on a partition or
643 physical block device, or where simple 1:1 encryption using dm-crypt/LUKS is used. This discovery
644 does not cover complex storage and in particular RAID and volume management storage devices.</para>
645
646 <xi:include href="version-info.xml" xpointer="v230"/>
647 </listitem>
648 </varlistentry>
649
650 <varlistentry>
651 <term><varname>IOReadBandwidthMax=<replaceable>device</replaceable> <replaceable>bytes</replaceable></varname></term>
652 <term><varname>IOWriteBandwidthMax=<replaceable>device</replaceable> <replaceable>bytes</replaceable></varname></term>
653
654 <listitem>
655 <para>These settings control the <option>io</option> controller in the unified hierarchy.</para>
656
657 <para>Set the per-device overall block I/O bandwidth maximum limit for the executed processes, if the unified
658 control group hierarchy is used on the system. This limit is not work-conserving and the executed processes
659 are not allowed to use more even if the device has idle capacity. Takes a space-separated pair of a file
660 path and a bandwidth value (in bytes per second) to specify the device specific bandwidth. The file path may
661 be a path to a block device node, or as any other file in which case the backing block device of the file
662 system of the file is used. If the bandwidth is suffixed with K, M, G, or T, the specified bandwidth is
663 parsed as Kilobytes, Megabytes, Gigabytes, or Terabytes, respectively, to the base of 1000. (Example:
664 "/dev/disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0 5M"). This controls the <literal>io.max</literal> control
665 group attributes. Use this option multiple times to set bandwidth limits for multiple devices. For details
666 about this control group attribute, see <ulink
667 url="https://docs.kernel.org/admin-guide/cgroup-v2.html#io-interface-files">IO Interface Files</ulink>.
668 </para>
669
670 <para>Similar restrictions on block device discovery as for <varname>IODeviceWeight=</varname> apply, see above.</para>
671
672 <xi:include href="version-info.xml" xpointer="v230"/>
673 </listitem>
674 </varlistentry>
675
676 <varlistentry>
677 <term><varname>IOReadIOPSMax=<replaceable>device</replaceable> <replaceable>IOPS</replaceable></varname></term>
678 <term><varname>IOWriteIOPSMax=<replaceable>device</replaceable> <replaceable>IOPS</replaceable></varname></term>
679
680 <listitem>
681 <para>These settings control the <option>io</option> controller in the unified hierarchy.</para>
682
683 <para>Set the per-device overall block I/O IOs-Per-Second maximum limit for the executed processes, if the
684 unified control group hierarchy is used on the system. This limit is not work-conserving and the executed
685 processes are not allowed to use more even if the device has idle capacity. Takes a space-separated pair of
686 a file path and an IOPS value to specify the device specific IOPS. The file path may be a path to a block
687 device node, or as any other file in which case the backing block device of the file system of the file is
688 used. If the IOPS is suffixed with K, M, G, or T, the specified IOPS is parsed as KiloIOPS, MegaIOPS,
689 GigaIOPS, or TeraIOPS, respectively, to the base of 1000. (Example:
690 "/dev/disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0 1K"). This controls the <literal>io.max</literal> control
691 group attributes. Use this option multiple times to set IOPS limits for multiple devices. For details about
692 this control group attribute, see <ulink
693 url="https://docs.kernel.org/admin-guide/cgroup-v2.html#io-interface-files">IO Interface Files</ulink>.
694 </para>
695
696 <para>Similar restrictions on block device discovery as for <varname>IODeviceWeight=</varname> apply, see above.</para>
697
698 <xi:include href="version-info.xml" xpointer="v230"/>
699 </listitem>
700 </varlistentry>
701
702 <varlistentry>
703 <term><varname>IODeviceLatencyTargetSec=<replaceable>device</replaceable> <replaceable>target</replaceable></varname></term>
704
705 <listitem>
706 <para>This setting controls the <option>io</option> controller in the unified hierarchy.</para>
707
708 <para>Set the per-device average target I/O latency for the executed processes, if the unified control group
709 hierarchy is used on the system. Takes a file path and a timespan separated by a space to specify
710 the device specific latency target. (Example: "/dev/sda 25ms"). The file path may be specified
711 as path to a block device node or as any other file, in which case the backing block device of the file
712 system of the file is determined. This controls the <literal>io.latency</literal> control group
713 attribute. Use this option multiple times to set latency target for multiple devices. For details about this
714 control group attribute, see <ulink
715 url="https://docs.kernel.org/admin-guide/cgroup-v2.html#io-interface-files">IO Interface Files</ulink>.</para>
716
717 <para>Implies <literal>IOAccounting=yes</literal>.</para>
718
719 <para>These settings are supported only if the unified control group hierarchy is used.</para>
720
721 <para>Similar restrictions on block device discovery as for <varname>IODeviceWeight=</varname> apply, see above.</para>
722
723 <xi:include href="version-info.xml" xpointer="v240"/>
724 </listitem>
725 </varlistentry>
726
727 </variablelist>
728
729 </refsect2><refsect2><title>Network Accounting and Control</title>
730
731 <variablelist class='unit-directives'>
732
733 <varlistentry>
734 <term><varname>IPAccounting=</varname></term>
735
736 <listitem>
737 <para>Takes a boolean argument. If true, turns on IPv4 and IPv6 network traffic accounting for packets sent
738 or received by the unit. When this option is turned on, all IPv4 and IPv6 sockets created by any process of
739 the unit are accounted for.</para>
740
741 <para>When this option is used in socket units, it applies to all IPv4 and IPv6 sockets
742 associated with it (including both listening and connection sockets where this applies). Note that for
743 socket-activated services, this configuration setting and the accounting data of the service unit and the
744 socket unit are kept separate, and displayed separately. No propagation of the setting and the collected
745 statistics is done, in either direction. Moreover, any traffic sent or received on any of the socket unit's
746 sockets is accounted to the socket unit — and never to the service unit it might have activated, even if the
747 socket is used by it.</para>
748
749 <para>The system default for this setting may be controlled with <varname>DefaultIPAccounting=</varname> in
750 <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
751
752 <xi:include href="version-info.xml" xpointer="v235"/>
753 </listitem>
754 </varlistentry>
755
756 <varlistentry>
757 <term><varname>IPAddressAllow=<replaceable>ADDRESS[/PREFIXLENGTH]…</replaceable></varname></term>
758 <term><varname>IPAddressDeny=<replaceable>ADDRESS[/PREFIXLENGTH]…</replaceable></varname></term>
759
760 <listitem>
761 <para>Turn on network traffic filtering for IP packets sent and received over
762 <constant>AF_INET</constant> and <constant>AF_INET6</constant> sockets. Both directives take a
763 space separated list of IPv4 or IPv6 addresses, each optionally suffixed with an address prefix
764 length in bits after a <literal>/</literal> character. If the suffix is omitted, the address is
765 considered a host address, i.e. the filter covers the whole address (32 bits for IPv4, 128 bits for
766 IPv6).</para>
767
768 <para>The access lists configured with this option are applied to all sockets created by processes
769 of this unit (or in the case of socket units, associated with it). The lists are implicitly
770 combined with any lists configured for any of the parent slice units this unit might be a member
771 of. By default both access lists are empty. Both ingress and egress traffic is filtered by these
772 settings. In case of ingress traffic the source IP address is checked against these access lists,
773 in case of egress traffic the destination IP address is checked. The following rules are applied in
774 turn:</para>
775
776 <itemizedlist>
777 <listitem><para>Access is granted when the checked IP address matches an entry in the
778 <varname>IPAddressAllow=</varname> list.</para></listitem>
779
780 <listitem><para>Otherwise, access is denied when the checked IP address matches an entry in the
781 <varname>IPAddressDeny=</varname> list.</para></listitem>
782
783 <listitem><para>Otherwise, access is granted.</para></listitem>
784 </itemizedlist>
785
786 <para>In order to implement an allow-listing IP firewall, it is recommended to use a
787 <varname>IPAddressDeny=</varname><constant>any</constant> setting on an upper-level slice unit
788 (such as the root slice <filename>-.slice</filename> or the slice containing all system services
789 <filename>system.slice</filename> – see
790 <citerefentry><refentrytitle>systemd.special</refentrytitle><manvolnum>7</manvolnum></citerefentry>
791 for details on these slice units), plus individual per-service <varname>IPAddressAllow=</varname>
792 lines permitting network access to relevant services, and only them.</para>
793
794 <para>Note that for socket-activated services, the IP access list configured on the socket unit
795 applies to all sockets associated with it directly, but not to any sockets created by the
796 ultimately activated services for it. Conversely, the IP access list configured for the service is
797 not applied to any sockets passed into the service via socket activation. Thus, it is usually a
798 good idea to replicate the IP access lists on both the socket and the service unit. Nevertheless,
799 it may make sense to maintain one list more open and the other one more restricted, depending on
800 the use case.</para>
801
802 <para>If these settings are used multiple times in the same unit the specified lists are combined. If an
803 empty string is assigned to these settings the specific access list is reset and all previous settings undone.</para>
804
805 <para>In place of explicit IPv4 or IPv6 address and prefix length specifications a small set of symbolic
806 names may be used. The following names are defined:</para>
807
808 <table>
809 <title>Special address/network names</title>
810
811 <tgroup cols='3'>
812 <colspec colname='name'/>
813 <colspec colname='definition'/>
814 <colspec colname='meaning'/>
815
816 <thead>
817 <row>
818 <entry>Symbolic Name</entry>
819 <entry>Definition</entry>
820 <entry>Meaning</entry>
821 </row>
822 </thead>
823
824 <tbody>
825 <row>
826 <entry><constant>any</constant></entry>
827 <entry>0.0.0.0/0 ::/0</entry>
828 <entry>Any host</entry>
829 </row>
830
831 <row>
832 <entry><constant>localhost</constant></entry>
833 <entry>127.0.0.0/8 ::1/128</entry>
834 <entry>All addresses on the local loopback</entry>
835 </row>
836
837 <row>
838 <entry><constant>link-local</constant></entry>
839 <entry>169.254.0.0/16 fe80::/64</entry>
840 <entry>All link-local IP addresses</entry>
841 </row>
842
843 <row>
844 <entry><constant>multicast</constant></entry>
845 <entry>224.0.0.0/4 ff00::/8</entry>
846 <entry>All IP multicasting addresses</entry>
847 </row>
848 </tbody>
849 </tgroup>
850 </table>
851
852 <para>Note that these settings might not be supported on some systems (for example if eBPF control group
853 support is not enabled in the underlying kernel or container manager). These settings will have no effect in
854 that case. If compatibility with such systems is desired it is hence recommended to not exclusively rely on
855 them for IP security.</para>
856
857 <xi:include href="cgroup-sandboxing.xml" xpointer="singular"/>
858
859 <xi:include href="version-info.xml" xpointer="v235"/>
860 </listitem>
861 </varlistentry>
862
863 <varlistentry>
864 <term><varname>SocketBindAllow=<replaceable>bind-rule</replaceable></varname></term>
865 <term><varname>SocketBindDeny=<replaceable>bind-rule</replaceable></varname></term>
866
867 <listitem>
868 <para>Allow or deny binding a socket address to a socket by matching it with the <replaceable>bind-rule</replaceable> and
869 applying a corresponding action if there is a match.</para>
870
871 <para><replaceable>bind-rule</replaceable> describes socket properties such as <replaceable>address-family</replaceable>,
872 <replaceable>transport-protocol</replaceable> and <replaceable>ip-ports</replaceable>.</para>
873
874 <para><replaceable>bind-rule</replaceable> :=
875 { [<replaceable>address-family</replaceable><constant>:</constant>][<replaceable>transport-protocol</replaceable><constant>:</constant>][<replaceable>ip-ports</replaceable>] | <constant>any</constant> }</para>
876
877 <para><replaceable>address-family</replaceable> := { <constant>ipv4</constant> | <constant>ipv6</constant> }</para>
878
879 <para><replaceable>transport-protocol</replaceable> := { <constant>tcp</constant> | <constant>udp</constant> }</para>
880
881 <para><replaceable>ip-ports</replaceable> := { <replaceable>ip-port</replaceable> | <replaceable>ip-port-range</replaceable> }</para>
882
883 <para>An optional <replaceable>address-family</replaceable> expects <constant>ipv4</constant> or <constant>ipv6</constant> values.
884 If not specified, a rule will be matched for both IPv4 and IPv6 addresses and applied depending on other socket fields, e.g. <replaceable>transport-protocol</replaceable>,
885 <replaceable>ip-port</replaceable>.</para>
886
887 <para>An optional <replaceable>transport-protocol</replaceable> expects <constant>tcp</constant> or <constant>udp</constant> transport protocol names.
888 If not specified, a rule will be matched for any transport protocol.</para>
889
890 <para>An optional <replaceable>ip-port</replaceable> value must lie within 165535 interval inclusively, i.e.
891 dynamic port <constant>0</constant> is not allowed. A range of sequential ports is described by
892 <replaceable>ip-port-range</replaceable> := <replaceable>ip-port-low</replaceable><constant>-</constant><replaceable>ip-port-high</replaceable>,
893 where <replaceable>ip-port-low</replaceable> is smaller than or equal to <replaceable>ip-port-high</replaceable>
894 and both are within 165535 inclusively.</para>
895
896 <para>A special value <constant>any</constant> can be used to apply a rule to any address family, transport protocol and any port with a positive value.</para>
897
898 <para>To allow multiple rules assign <varname>SocketBindAllow=</varname> or <varname>SocketBindDeny=</varname> multiple times.
899 To clear the existing assignments pass an empty <varname>SocketBindAllow=</varname> or <varname>SocketBindDeny=</varname>
900 assignment.</para>
901
902 <para>For each of <varname>SocketBindAllow=</varname> and <varname>SocketBindDeny=</varname>, maximum allowed number of assignments is
903 <constant>128</constant>.</para>
904
905 <itemizedlist>
906 <listitem><para>Binding to a socket is allowed when a socket address matches an entry in the
907 <varname>SocketBindAllow=</varname> list.</para></listitem>
908
909 <listitem><para>Otherwise, binding is denied when the socket address matches an entry in the
910 <varname>SocketBindDeny=</varname> list.</para></listitem>
911
912 <listitem><para>Otherwise, binding is allowed.</para></listitem>
913 </itemizedlist>
914
915 <para>The feature is implemented with <constant>cgroup/bind4</constant> and <constant>cgroup/bind6</constant> cgroup-bpf hooks.</para>
916 <para>Examples:<programlisting>
917 # Allow binding IPv6 socket addresses with a port greater than or equal to 10000.
918 [Service]
919 SocketBindAllow=ipv6:10000-65535
920 SocketBindDeny=any
921
922 # Allow binding IPv4 and IPv6 socket addresses with 1234 and 4321 ports.
923 [Service]
924 SocketBindAllow=1234
925 SocketBindAllow=4321
926 SocketBindDeny=any
927
928 # Deny binding IPv6 socket addresses.
929 [Service]
930 SocketBindDeny=ipv6
931
932 # Deny binding IPv4 and IPv6 socket addresses.
933 [Service]
934 SocketBindDeny=any
935
936 # Allow binding only over TCP
937 [Service]
938 SocketBindAllow=tcp
939 SocketBindDeny=any
940
941 # Allow binding only over IPv6/TCP
942 [Service]
943 SocketBindAllow=ipv6:tcp
944 SocketBindDeny=any
945
946 # Allow binding ports within 10000-65535 range over IPv4/UDP.
947 [Service]
948 SocketBindAllow=ipv4:udp:10000-65535
949 SocketBindDeny=any
950</programlisting></para>
951
952 <xi:include href="cgroup-sandboxing.xml" xpointer="singular"/>
953
954 <xi:include href="version-info.xml" xpointer="v249"/>
955 </listitem>
956 </varlistentry>
957
958 <varlistentry>
959 <term><varname>RestrictNetworkInterfaces=</varname></term>
960
961 <listitem>
962 <para>Takes a list of space-separated network interface names. This option restricts the network
963 interfaces that processes of this unit can use. By default processes can only use the network interfaces
964 listed (allow-list). If the first character of the rule is <literal>~</literal>, the effect is inverted:
965 the processes can only use network interfaces not listed (deny-list).
966 </para>
967
968 <para>This option can appear multiple times, in which case the network interface names are merged. If the
969 empty string is assigned the set is reset, all prior assignments will have not effect.
970 </para>
971
972 <para>If you specify both types of this option (i.e. allow-listing and deny-listing), the first encountered
973 will take precedence and will dictate the default action (allow vs deny). Then the next occurrences of this
974 option will add or delete the listed network interface names from the set, depending of its type and the
975 default action.
976 </para>
977
978 <para>The loopback interface ("lo") is not treated in any special way, you have to configure it explicitly
979 in the unit file.
980 </para>
981 <para>Example 1: allow-list
982 <programlisting>
983 RestrictNetworkInterfaces=eth1
984 RestrictNetworkInterfaces=eth2</programlisting>
985 Programs in the unit will be only able to use the eth1 and eth2 network
986 interfaces.
987 </para>
988
989 <para>Example 2: deny-list
990 <programlisting>
991 RestrictNetworkInterfaces=~eth1 eth2</programlisting>
992 Programs in the unit will be able to use any network interface but eth1 and eth2.
993 </para>
994
995 <para>Example 3: mixed
996 <programlisting>
997 RestrictNetworkInterfaces=eth1 eth2
998 RestrictNetworkInterfaces=~eth1</programlisting>
999 Programs in the unit will be only able to use the eth2 network interface.
1000 </para>
1001
1002 <xi:include href="cgroup-sandboxing.xml" xpointer="singular"/>
1003
1004 <xi:include href="version-info.xml" xpointer="v250"/>
1005 </listitem>
1006 </varlistentry>
1007
1008 <varlistentry>
1009 <term><varname>NFTSet=</varname><replaceable>family</replaceable>:<replaceable>table</replaceable>:<replaceable>set</replaceable></term>
1010 <listitem>
1011 <para>This setting provides a method for integrating dynamic cgroup, user and group IDs into
1012 firewall rules with <ulink url="https://netfilter.org/projects/nftables/index.html">NFT</ulink>
1013 sets. The benefit of using this setting is to be able to use the IDs as selectors in firewall rules
1014 easily and this in turn allows more fine grained filtering. NFT rules for cgroup matching use
1015 numeric cgroup IDs, which change every time a service is restarted, making them hard to use in
1016 systemd environment otherwise. Dynamic and random IDs used by <varname>DynamicUser=</varname> can
1017 be also integrated with this setting.</para>
1018
1019 <para>This option expects a whitespace separated list of NFT set definitions. Each definition
1020 consists of a colon-separated tuple of source type (one of <literal>cgroup</literal>,
1021 <literal>user</literal> or <literal>group</literal>), NFT address family (one of
1022 <literal>arp</literal>, <literal>bridge</literal>, <literal>inet</literal>, <literal>ip</literal>,
1023 <literal>ip6</literal>, or <literal>netdev</literal>), table name and set name. The names of tables
1024 and sets must conform to lexical restrictions of NFT table names. The type of the element used in
1025 the NFT filter must match the type implied by the directive (<literal>cgroup</literal>,
1026 <literal>user</literal> or <literal>group</literal>) as shown in the table below. When a control
1027 group or a unit is realized, the corresponding ID will be appended to the NFT sets and it will be
1028 be removed when the control group or unit is removed. <command>systemd</command> only inserts
1029 elements to (or removes from) the sets, so the related NFT rules, tables and sets must be prepared
1030 elsewhere in advance. Failures to manage the sets will be ignored.</para>
1031
1032 <table>
1033 <title>Defined <varname>source type</varname> values</title>
1034 <tgroup cols='3'>
1035 <colspec colname='source type'/>
1036 <colspec colname='description'/>
1037 <colspec colname='NFT type name'/>
1038 <thead>
1039 <row>
1040 <entry>Source type</entry>
1041 <entry>Description</entry>
1042 <entry>Corresponding NFT type name</entry>
1043 </row>
1044 </thead>
1045
1046 <tbody>
1047 <row>
1048 <entry><literal>cgroup</literal></entry>
1049 <entry>control group ID</entry>
1050 <entry><literal>cgroupsv2</literal></entry>
1051 </row>
1052 <row>
1053 <entry><literal>user</literal></entry>
1054 <entry>user ID</entry>
1055 <entry><literal>meta skuid</literal></entry>
1056 </row>
1057 <row>
1058 <entry><literal>group</literal></entry>
1059 <entry>group ID</entry>
1060 <entry><literal>meta skgid</literal></entry>
1061 </row>
1062 </tbody>
1063 </tgroup>
1064 </table>
1065
1066 <para>If the firewall rules are reinstalled so that the contents of NFT sets are destroyed, command
1067 <command>systemctl daemon-reload</command> can be used to refill the sets.</para>
1068
1069 <para>Example:
1070 <programlisting>[Unit]
1071 NFTSet=cgroup:inet:filter:my_service user:inet:filter:serviceuser
1072 </programlisting>
1073 Corresponding NFT rules:
1074 <programlisting>table inet filter {
1075 set my_service {
1076 type cgroupsv2
1077 }
1078 set serviceuser {
1079 typeof meta skuid
1080 }
1081 chain x {
1082 socket cgroupv2 level 2 @my_service accept
1083 drop
1084 }
1085 chain y {
1086 meta skuid @serviceuser accept
1087 drop
1088 }
1089 }</programlisting>
1090 </para>
1091 <xi:include href="version-info.xml" xpointer="v255"/></listitem>
1092 </varlistentry>
1093
1094 </variablelist>
1095
1096 </refsect2><refsect2><title>BPF Programs</title>
1097
1098 <variablelist class='unit-directives'>
1099
1100 <varlistentry>
1101 <term><varname>IPIngressFilterPath=<replaceable>BPF_FS_PROGRAM_PATH</replaceable></varname></term>
1102 <term><varname>IPEgressFilterPath=<replaceable>BPF_FS_PROGRAM_PATH</replaceable></varname></term>
1103
1104 <listitem>
1105 <para>Add custom network traffic filters implemented as BPF programs, applying to all IP packets
1106 sent and received over <constant>AF_INET</constant> and <constant>AF_INET6</constant> sockets.
1107 Takes an absolute path to a pinned BPF program in the BPF virtual filesystem (<filename>/sys/fs/bpf/</filename>).
1108 </para>
1109
1110 <para>The filters configured with this option are applied to all sockets created by processes
1111 of this unit (or in the case of socket units, associated with it). The filters are loaded in addition
1112 to filters any of the parent slice units this unit might be a member of as well as any
1113 <varname>IPAddressAllow=</varname> and <varname>IPAddressDeny=</varname> filters in any of these units.
1114 By default there are no filters specified.</para>
1115
1116 <para>If these settings are used multiple times in the same unit all the specified programs are attached. If an
1117 empty string is assigned to these settings the program list is reset and all previous specified programs ignored.</para>
1118
1119 <para>If the path <replaceable>BPF_FS_PROGRAM_PATH</replaceable> in <varname>IPIngressFilterPath=</varname> assignment
1120 is already being handled by <varname>BPFProgram=</varname> ingress hook, e.g.
1121 <varname>BPFProgram=</varname><constant>ingress</constant>:<replaceable>BPF_FS_PROGRAM_PATH</replaceable>,
1122 the assignment will be still considered valid and the program will be attached to a cgroup. Same for
1123 <varname>IPEgressFilterPath=</varname> path and <constant>egress</constant> hook.</para>
1124
1125 <para>Note that for socket-activated services, the IP filter programs configured on the socket unit apply to
1126 all sockets associated with it directly, but not to any sockets created by the ultimately activated services
1127 for it. Conversely, the IP filter programs configured for the service are not applied to any sockets passed into
1128 the service via socket activation. Thus, it is usually a good idea, to replicate the IP filter programs on both
1129 the socket and the service unit, however it often makes sense to maintain one configuration more open and the other
1130 one more restricted, depending on the use case.</para>
1131
1132 <para>Note that these settings might not be supported on some systems (for example if eBPF control group
1133 support is not enabled in the underlying kernel or container manager). These settings will fail the service in
1134 that case. If compatibility with such systems is desired it is hence recommended to attach your filter manually
1135 (requires <varname>Delegate=</varname><constant>yes</constant>) instead of using this setting.</para>
1136
1137 <xi:include href="version-info.xml" xpointer="v243"/>
1138 </listitem>
1139 </varlistentry>
1140
1141 <varlistentry>
1142 <term><varname>BPFProgram=<replaceable>type</replaceable>:<replaceable>program-path</replaceable></varname></term>
1143 <listitem>
1144 <para><varname>BPFProgram=</varname> allows attaching custom BPF programs to the cgroup of a
1145 unit. (This generalizes the functionality exposed via <varname>IPEgressFilterPath=</varname> and
1146 and <varname>IPIngressFilterPath=</varname> for other hooks.) Cgroup-bpf hooks in the form of BPF
1147 programs loaded to the BPF filesystem are attached with cgroup-bpf attach flags determined by the
1148 unit. For details about attachment types and flags see <ulink
1149 url="https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/include/uapi/linux/bpf.h"><filename>bpf.h</filename></ulink>. Also
1150 refer to the general <ulink url="https://docs.kernel.org/bpf/">BPF documentation</ulink>.</para>
1151
1152 <para>The specification of BPF program consists of a pair of BPF program type and program path in
1153 the file system, with <literal>:</literal> as the separator:
1154 <replaceable>type</replaceable>:<replaceable>program-path</replaceable>.</para>
1155
1156 <para>The BPF program type is equivalent to the BPF attach type used in
1157 <command>bpftool</command>. It may be one of <constant>egress</constant>,
1158 <constant>ingress</constant>, <constant>sock_create</constant>, <constant>sock_ops</constant>,
1159 <constant>device</constant>, <constant>bind4</constant>, <constant>bind6</constant>,
1160 <constant>connect4</constant>, <constant>connect6</constant>, <constant>post_bind4</constant>,
1161 <constant>post_bind6</constant>, <constant>sendmsg4</constant>, <constant>sendmsg6</constant>,
1162 <constant>sysctl</constant>, <constant>recvmsg4</constant>, <constant>recvmsg6</constant>,
1163 <constant>getsockopt</constant>, <constant>setsockopt</constant>.</para>
1164
1165 <para>The specified program path must be an absolute path referencing a BPF program inode in the
1166 bpffs file system (which generally means it must begin with <filename>/sys/fs/bpf/</filename>). If
1167 a specified program does not exist (i.e. has not been uploaded to the BPF subsystem of the kernel
1168 yet), it will not be installed but unit activation will continue (a warning will be printed to the
1169 logs).</para>
1170
1171 <para>Setting <varname>BPFProgram=</varname> to an empty value makes previous assignments
1172 ineffective.</para>
1173
1174 <para>Multiple assignments of the same program type/path pair have the same effect as a single
1175 assignment: the program will be attached just once.</para>
1176
1177 <para>If BPF <constant>egress</constant> pinned to <replaceable>program-path</replaceable> path is already being
1178 handled by <varname>IPEgressFilterPath=</varname>, <varname>BPFProgram=</varname>
1179 assignment will be considered valid and <varname>BPFProgram=</varname> will be attached to a cgroup.
1180 Similarly for <constant>ingress</constant> hook and <varname>IPIngressFilterPath=</varname> assignment.</para>
1181
1182 <para>BPF programs passed with <varname>BPFProgram=</varname> are attached to the cgroup of a unit
1183 with BPF attach flag <constant>multi</constant>, that allows further attachments of the same
1184 <replaceable>type</replaceable> within cgroup hierarchy topped by the unit cgroup.</para>
1185
1186 <para>Examples:<programlisting>BPFProgram=egress:/sys/fs/bpf/egress-hook
1187 BPFProgram=bind6:/sys/fs/bpf/sock-addr-hook
1188 </programlisting></para>
1189
1190 <xi:include href="version-info.xml" xpointer="v249"/>
1191 </listitem>
1192 </varlistentry>
1193
1194 </variablelist>
1195
1196 </refsect2><refsect2><title>Device Access</title>
1197
1198 <variablelist class='unit-directives'>
1199
1200 <varlistentry>
1201 <term><varname>DeviceAllow=</varname></term>
1202
1203 <listitem>
1204 <para>Control access to specific device nodes by the executed processes. Takes two space-separated
1205 strings: a device node specifier followed by a combination of <constant>r</constant>,
1206 <constant>w</constant>, <constant>m</constant> to control <emphasis>r</emphasis>eading,
1207 <emphasis>w</emphasis>riting, or creation of the specific device nodes by the unit
1208 (<emphasis>m</emphasis>knod), respectively. This functionality is implemented using eBPF
1209 filtering.</para>
1210
1211 <para>When access to <emphasis>all</emphasis> physical devices should be disallowed,
1212 <varname>PrivateDevices=</varname> may be used instead. See
1213 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
1214 </para>
1215
1216 <para>The device node specifier is either a path to a device node in the file system, starting with
1217 <filename>/dev/</filename>, or a string starting with either <literal>char-</literal> or
1218 <literal>block-</literal> followed by a device group name, as listed in
1219 <filename>/proc/devices</filename>. The latter is useful to allow-list all current and future
1220 devices belonging to a specific device group at once. The device group is matched according to
1221 filename globbing rules, you may hence use the <literal>*</literal> and <literal>?</literal>
1222 wildcards. (Note that such globbing wildcards are not available for device node path
1223 specifications!) In order to match device nodes by numeric major/minor, use device node paths in
1224 the <filename>/dev/char/</filename> and <filename>/dev/block/</filename> directories. However,
1225 matching devices by major/minor is generally not recommended as assignments are neither stable nor
1226 portable between systems or different kernel versions.</para>
1227
1228 <para>Examples: <filename>/dev/sda5</filename> is a path to a device node, referring to an ATA or
1229 SCSI block device. <literal>char-pts</literal> and <literal>char-alsa</literal> are specifiers for
1230 all pseudo TTYs and all ALSA sound devices, respectively. <literal>char-cpu/*</literal> is a
1231 specifier matching all CPU related device groups.</para>
1232
1233 <para>Note that allow lists defined this way should only reference device groups which are
1234 resolvable at the time the unit is started. Any device groups not resolvable then are not added to
1235 the device allow list. In order to work around this limitation, consider extending service units
1236 with a pair of <command>After=modprobe@xyz.service</command> and
1237 <command>Wants=modprobe@xyz.service</command> lines that load the necessary kernel module
1238 implementing the device group if missing.
1239 Example: <programlisting>
1240 [Unit]
1241 Wants=modprobe@loop.service
1242 After=modprobe@loop.service
1243
1244 [Service]
1245 DeviceAllow=block-loop
1246 DeviceAllow=/dev/loop-control
1247</programlisting></para>
1248
1249 <xi:include href="cgroup-sandboxing.xml" xpointer="singular"/>
1250
1251 <xi:include href="version-info.xml" xpointer="v208"/>
1252 </listitem>
1253 </varlistentry>
1254
1255 <varlistentry>
1256 <term><varname>DevicePolicy=auto|closed|strict</varname></term>
1257
1258 <listitem>
1259 <para>
1260 Control the policy for allowing device access:
1261 </para>
1262 <variablelist>
1263 <varlistentry>
1264 <term><option>strict</option></term>
1265 <listitem>
1266 <para>means to only allow types of access that are
1267 explicitly specified.</para>
1268
1269 <xi:include href="version-info.xml" xpointer="v208"/>
1270 </listitem>
1271 </varlistentry>
1272
1273 <varlistentry>
1274 <term><option>closed</option></term>
1275 <listitem>
1276 <para>in addition, allows access to standard pseudo
1277 devices including
1278 <filename>/dev/null</filename>,
1279 <filename>/dev/zero</filename>,
1280 <filename>/dev/full</filename>,
1281 <filename>/dev/random</filename>, and
1282 <filename>/dev/urandom</filename>.
1283 </para>
1284
1285 <xi:include href="version-info.xml" xpointer="v208"/>
1286 </listitem>
1287 </varlistentry>
1288
1289 <varlistentry>
1290 <term><option>auto</option></term>
1291 <listitem>
1292 <para>
1293 in addition, allows access to all devices if no
1294 explicit <varname>DeviceAllow=</varname> is present.
1295 This is the default.
1296 </para>
1297
1298 <xi:include href="version-info.xml" xpointer="v208"/>
1299 </listitem>
1300 </varlistentry>
1301 </variablelist>
1302
1303 <xi:include href="cgroup-sandboxing.xml" xpointer="singular"/>
1304
1305 <xi:include href="version-info.xml" xpointer="v208"/>
1306 </listitem>
1307 </varlistentry>
1308
1309 </variablelist>
1310
1311 </refsect2><refsect2><title>Control Group Management</title>
1312
1313 <variablelist class='unit-directives'>
1314
1315 <varlistentry>
1316 <term><varname>Slice=</varname></term>
1317
1318 <listitem>
1319 <para>The name of the slice unit to place the unit
1320 in. Defaults to <filename>system.slice</filename> for all
1321 non-instantiated units of all unit types (except for slice
1322 units themselves see below). Instance units are by default
1323 placed in a subslice of <filename>system.slice</filename>
1324 that is named after the template name.</para>
1325
1326 <para>This option may be used to arrange systemd units in a
1327 hierarchy of slices each of which might have resource
1328 settings applied.</para>
1329
1330 <para>For units of type slice, the only accepted value for
1331 this setting is the parent slice. Since the name of a slice
1332 unit implies the parent slice, it is hence redundant to ever
1333 set this parameter directly for slice units.</para>
1334
1335 <para>Special care should be taken when relying on the default slice assignment in templated service units
1336 that have <varname>DefaultDependencies=no</varname> set, see
1337 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>, section
1338 "Default Dependencies" for details.</para>
1339
1340 <xi:include href="version-info.xml" xpointer="v208"/>
1341
1342 </listitem>
1343 </varlistentry>
1344
1345 <varlistentry>
1346 <term><varname>Delegate=</varname></term>
1347
1348 <listitem>
1349 <para>Turns on delegation of further resource control partitioning to processes of the unit. Units
1350 where this is enabled may create and manage their own private subhierarchy of control groups below
1351 the control group of the unit itself. For unprivileged services (i.e. those using the
1352 <varname>User=</varname> setting) the unit's control group will be made accessible to the relevant
1353 user.</para>
1354
1355 <para>When enabled the service manager will refrain from manipulating control groups or moving
1356 processes below the unit's control group, so that a clear concept of ownership is established: the
1357 control group tree at the level of the unit's control group and above (i.e. towards the root
1358 control group) is owned and managed by the service manager of the host, while the control group
1359 tree below the unit's control group is owned and managed by the unit itself.</para>
1360
1361 <para>Takes either a boolean argument or a (possibly empty) list of control group controller names.
1362 If true, delegation is turned on, and all supported controllers are enabled for the unit, making
1363 them available to the unit's processes for management. If false, delegation is turned off entirely
1364 (and no additional controllers are enabled). If set to a list of controllers, delegation is turned
1365 on, and the specified controllers are enabled for the unit. Assigning the empty string will enable
1366 delegation, but reset the list of controllers, and all assignments prior to this will have no
1367 effect. Note that additional controllers other than the ones specified might be made available as
1368 well, depending on configuration of the containing slice unit or other units contained in it.
1369 Defaults to false.</para>
1370
1371 <para>Note that controller delegation to less privileged code is only safe on the unified control
1372 group hierarchy. Accordingly, access to the specified controllers will not be granted to
1373 unprivileged services on the legacy hierarchy, even when requested.</para>
1374
1375 <xi:include href="supported-controllers.xml" xpointer="controllers-text" />
1376
1377 <para>Not all of these controllers are available on all kernels however, and some are specific to
1378 the unified hierarchy while others are specific to the legacy hierarchy. Also note that the kernel
1379 might support further controllers, which aren't covered here yet as delegation is either not
1380 supported at all for them or not defined cleanly.</para>
1381
1382 <para>Note that because of the hierarchical nature of cgroup hierarchy, any controllers that are
1383 delegated will be enabled for the parent and sibling units of the unit with delegation.</para>
1384
1385 <para>For further details on the delegation model consult <ulink
1386 url="https://systemd.io/CGROUP_DELEGATION">Control Group APIs and Delegation</ulink>.</para>
1387
1388 <xi:include href="version-info.xml" xpointer="v218"/>
1389 </listitem>
1390 </varlistentry>
1391
1392 <varlistentry>
1393 <term><varname>DelegateSubgroup=</varname></term>
1394
1395 <listitem>
1396 <para>Place unit processes in the specified subgroup of the unit's control group. Takes a valid
1397 control group name (not a path!) as parameter, or an empty string to turn this feature
1398 off. Defaults to off. The control group name must be usable as filename and avoid conflicts with
1399 the kernel's control group attribute files (i.e. <filename>cgroup.procs</filename> is not an
1400 acceptable name, since the kernel exposes a native control group attribute file by that name). This
1401 option has no effect unless control group delegation is turned on via <varname>Delegate=</varname>,
1402 see above. Note that this setting only applies to "main" processes of a unit, i.e. for services to
1403 <varname>ExecStart=</varname>, but not for <varname>ExecReload=</varname> and similar. If
1404 delegation is enabled, the latter are always placed inside a subgroup named
1405 <filename>.control</filename>. The specified subgroup is automatically created (and potentially
1406 ownership is passed to the unit's configured user/group) when a process is started in it.</para>
1407
1408 <para>This option is useful to avoid manually moving the invoked process into a subgroup after it
1409 has been started. Since no processes should live in inner nodes of the control group tree it's
1410 almost always necessary to run the main ("supervising") process of a unit that has delegation
1411 turned on in a subgroup.</para>
1412
1413 <xi:include href="version-info.xml" xpointer="v254"/>
1414 </listitem>
1415 </varlistentry>
1416
1417 <varlistentry>
1418 <term><varname>DisableControllers=</varname></term>
1419
1420 <listitem>
1421 <para>Disables controllers from being enabled for a unit's children. If a controller listed is
1422 already in use in its subtree, the controller will be removed from the subtree. This can be used to
1423 avoid configuration in child units from being able to implicitly or explicitly enable a controller.
1424 Defaults to empty.</para>
1425
1426 <para>Multiple controllers may be specified, separated by spaces. You may also pass
1427 <varname>DisableControllers=</varname> multiple times, in which case each new instance adds another controller
1428 to disable. Passing <varname>DisableControllers=</varname> by itself with no controller name present resets
1429 the disabled controller list.</para>
1430
1431 <para>It may not be possible to disable a controller after units have been started, if the unit or
1432 any child of the unit in question delegates controllers to its children, as any delegated subtree
1433 of the cgroup hierarchy is unmanaged by systemd.</para>
1434
1435 <xi:include href="supported-controllers.xml" xpointer="controllers-text" />
1436
1437 <xi:include href="version-info.xml" xpointer="v240"/>
1438 </listitem>
1439 </varlistentry>
1440
1441 </variablelist>
1442
1443 </refsect2><refsect2><title>Memory Pressure Control</title>
1444
1445 <variablelist class='unit-directives'>
1446
1447 <varlistentry>
1448 <term><varname>ManagedOOMSwap=auto|kill</varname></term>
1449 <term><varname>ManagedOOMMemoryPressure=auto|kill</varname></term>
1450
1451 <listitem>
1452 <para>Specifies how
1453 <citerefentry><refentrytitle>systemd-oomd.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
1454 will act on this unit's cgroups. Defaults to <option>auto</option>.</para>
1455
1456 <para>When set to <option>kill</option>, the unit becomes a candidate for monitoring by
1457 <command>systemd-oomd</command>. If the cgroup passes the limits set by
1458 <citerefentry><refentrytitle>oomd.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry> or
1459 the unit configuration, <command>systemd-oomd</command> will select a descendant cgroup and send
1460 <constant>SIGKILL</constant> to all of the processes under it. You can find more details on
1461 candidates and kill behavior at
1462 <citerefentry><refentrytitle>systemd-oomd.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
1463 and
1464 <citerefentry><refentrytitle>oomd.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
1465
1466 <para>Setting either of these properties to <option>kill</option> will also result in
1467 <varname>After=</varname> and <varname>Wants=</varname> dependencies on
1468 <filename>systemd-oomd.service</filename> unless <varname>DefaultDependencies=no</varname>.</para>
1469
1470 <para>When set to <option>auto</option>, <command>systemd-oomd</command> will not actively use this
1471 cgroup's data for monitoring and detection. However, if an ancestor cgroup has one of these
1472 properties set to <option>kill</option>, a unit with <option>auto</option> can still be a candidate
1473 for <command>systemd-oomd</command> to terminate.</para>
1474
1475 <xi:include href="version-info.xml" xpointer="v247"/>
1476 </listitem>
1477 </varlistentry>
1478
1479 <varlistentry>
1480 <term><varname>ManagedOOMMemoryPressureLimit=</varname></term>
1481
1482 <listitem>
1483 <para>Overrides the default memory pressure limit set by
1484 <citerefentry><refentrytitle>oomd.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
1485 this unit (cgroup). Takes a percentage value between 0% and 100%, inclusive. This property is
1486 ignored unless <varname>ManagedOOMMemoryPressure=</varname><option>kill</option>. Defaults to 0%,
1487 which means to use the default set by
1488 <citerefentry><refentrytitle>oomd.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
1489 </para>
1490
1491 <xi:include href="version-info.xml" xpointer="v247"/>
1492 </listitem>
1493 </varlistentry>
1494
1495 <varlistentry>
1496 <term><varname>ManagedOOMPreference=none|avoid|omit</varname></term>
1497
1498 <listitem>
1499 <para>Allows deprioritizing or omitting this unit's cgroup as a candidate when
1500 <command>systemd-oomd</command> needs to act. Requires support for extended attributes (see
1501 <citerefentry project='man-pages'><refentrytitle>xattr</refentrytitle><manvolnum>7</manvolnum></citerefentry>)
1502 in order to use <option>avoid</option> or <option>omit</option>.</para>
1503
1504 <para>When calculating candidates to relieve swap usage, <command>systemd-oomd</command> will
1505 only respect these extended attributes if the unit's cgroup is owned by root.</para>
1506
1507 <para>When calculating candidates to relieve memory pressure, <command>systemd-oomd</command>
1508 will only respect these extended attributes if the unit's cgroup is owned by root, or if the
1509 unit's cgroup owner, and the owner of the monitored ancestor cgroup are the same. For example,
1510 if <command>systemd-oomd</command> is calculating candidates for <filename>-.slice</filename>,
1511 then extended attributes set on descendants of <filename>/user.slice/user-1000.slice/user@1000.service/</filename>
1512 will be ignored because the descendants are owned by UID 1000, and <filename>-.slice</filename>
1513 is owned by UID 0. But, if calculating candidates for
1514 <filename>/user.slice/user-1000.slice/user@1000.service/</filename>, then extended attributes set
1515 on the descendants would be respected.</para>
1516
1517 <para>If this property is set to <option>avoid</option>, the service manager will convey this to
1518 <command>systemd-oomd</command>, which will only select this cgroup if there are no other viable
1519 candidates.</para>
1520
1521 <para>If this property is set to <option>omit</option>, the service manager will convey this to
1522 <command>systemd-oomd</command>, which will ignore this cgroup as a candidate and will not perform
1523 any actions on it.</para>
1524
1525 <para>It is recommended to use <option>avoid</option> and <option>omit</option> sparingly, as it
1526 can adversely affect <command>systemd-oomd</command>'s kill behavior. Also note that these extended
1527 attributes are not applied recursively to cgroups under this unit's cgroup.</para>
1528
1529 <para>Defaults to <option>none</option> which means <command>systemd-oomd</command> will rank this
1530 unit's cgroup as defined in
1531 <citerefentry><refentrytitle>systemd-oomd.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
1532 and <citerefentry><refentrytitle>oomd.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
1533 </para>
1534
1535 <xi:include href="version-info.xml" xpointer="v248"/>
1536 </listitem>
1537 </varlistentry>
1538
1539 <varlistentry>
1540 <term><varname>MemoryPressureWatch=</varname></term>
1541
1542 <listitem><para>Controls memory pressure monitoring for invoked processes. Takes one of
1543 <literal>off</literal>, <literal>on</literal>, <literal>auto</literal> or <literal>skip</literal>. If
1544 <literal>off</literal> tells the service not to watch for memory pressure events, by setting the
1545 <varname>$MEMORY_PRESSURE_WATCH</varname> environment variable to the literal string
1546 <filename>/dev/null</filename>. If <literal>on</literal> tells the service to watch for memory
1547 pressure events. This enables memory accounting for the service, and ensures the
1548 <filename>memory.pressure</filename> cgroup attribute files is accessible for read and write to the
1549 service's user. It then sets the <varname>$MEMORY_PRESSURE_WATCH</varname> environment variable for
1550 processes invoked by the unit to the file system path to this file. The threshold information
1551 configured with <varname>MemoryPressureThresholdSec=</varname> is encoded in the
1552 <varname>$MEMORY_PRESSURE_WRITE</varname> environment variable. If the <literal>auto</literal> value
1553 is set the protocol is enabled if memory accounting is anyway enabled for the unit, and disabled
1554 otherwise. If set to <literal>skip</literal> the logic is neither enabled, nor disabled and the two
1555 environment variables are not set.</para>
1556
1557 <para>Note that services are free to use the two environment variables, but it's unproblematic if
1558 they ignore them. Memory pressure handling must be implemented individually in each service, and
1559 usually means different things for different software. For further details on memory pressure
1560 handling see <ulink url="https://systemd.io/MEMORY_PRESSURE">Memory Pressure Handling in
1561 systemd</ulink>.</para>
1562
1563 <para>Services implemented using
1564 <citerefentry><refentrytitle>sd-event</refentrytitle><manvolnum>3</manvolnum></citerefentry> may use
1565 <citerefentry><refentrytitle>sd_event_add_memory_pressure</refentrytitle><manvolnum>3</manvolnum></citerefentry>
1566 to watch for and handle memory pressure events.</para>
1567
1568 <para>If not explicit set, defaults to the <varname>DefaultMemoryPressureWatch=</varname> setting in
1569 <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
1570
1571 <xi:include href="version-info.xml" xpointer="v254"/></listitem>
1572 </varlistentry>
1573
1574 <varlistentry>
1575 <term><varname>MemoryPressureThresholdSec=</varname></term>
1576
1577 <listitem><para>Sets the memory pressure threshold time for memory pressure monitor as configured via
1578 <varname>MemoryPressureWatch=</varname>. Specifies the maximum allocation latency before a memory
1579 pressure event is signalled to the service, per 2s window. If not specified defaults to the
1580 <varname>DefaultMemoryPressureThresholdSec=</varname> setting in
1581 <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>
1582 (which in turn defaults to 200ms). The specified value expects a time unit such as
1583 <literal>ms</literal> or <literal>μs</literal>, see
1584 <citerefentry><refentrytitle>systemd.time</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
1585 details on the permitted syntax.</para>
1586
1587 <xi:include href="version-info.xml" xpointer="v254"/></listitem>
1588 </varlistentry>
1589 </variablelist>
1590
1591 </refsect2><refsect2><title>Coredump Control</title>
1592
1593 <variablelist class='unit-directives'>
1594
1595 <varlistentry>
1596 <term><varname>CoredumpReceive=</varname></term>
1597
1598 <listitem><para>Takes a boolean argument. This setting is used to enable coredump forwarding for containers
1599 that belong to this unit's cgroup. Units with <varname>CoredumpReceive=yes</varname> must also be configured
1600 with <varname>Delegate=yes</varname>. Defaults to false.</para>
1601
1602 <para>When <command>systemd-coredump</command> is handling a coredump for a process from a container,
1603 if the container's leader process is a descendant of a cgroup with <varname>CoredumpReceive=yes</varname>
1604 and <varname>Delegate=yes</varname>, then <command>systemd-coredump</command> will attempt to forward
1605 the coredump to <command>systemd-coredump</command> within the container.</para>
1606
1607 <xi:include href="version-info.xml" xpointer="v255"/></listitem>
1608 </varlistentry>
1609
1610 </variablelist>
1611 </refsect2>
1612 </refsect1>
1613
1614 <refsect1>
1615 <title>History</title>
1616
1617 <variablelist>
1618 <varlistentry>
1619 <term>systemd 252</term>
1620 <listitem><para> Options for controlling the Legacy Control Group Hierarchy (<ulink
1621 url="https://docs.kernel.org/admin-guide/cgroup-v1/index.html">Control Groups version 1</ulink>)
1622 are now fully deprecated:
1623 <varname>CPUShares=<replaceable>weight</replaceable></varname>,
1624 <varname>StartupCPUShares=<replaceable>weight</replaceable></varname>,
1625 <varname>MemoryLimit=<replaceable>bytes</replaceable></varname>,
1626 <varname>BlockIOAccounting=</varname>,
1627 <varname>BlockIOWeight=<replaceable>weight</replaceable></varname>,
1628 <varname>StartupBlockIOWeight=<replaceable>weight</replaceable></varname>,
1629 <varname>BlockIODeviceWeight=<replaceable>device</replaceable>
1630 <replaceable>weight</replaceable></varname>,
1631 <varname>BlockIOReadBandwidth=<replaceable>device</replaceable>
1632 <replaceable>bytes</replaceable></varname>,
1633 <varname>BlockIOWriteBandwidth=<replaceable>device</replaceable> <replaceable>bytes</replaceable></varname>.
1634 Please switch to the unified cgroup hierarchy.</para>
1635
1636 <xi:include href="version-info.xml" xpointer="v252"/></listitem>
1637 </varlistentry>
1638 </variablelist>
1639 </refsect1>
1640
1641 <refsect1>
1642 <title>See Also</title>
1643 <para>
1644 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
1645 <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
1646 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
1647 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
1648 <citerefentry><refentrytitle>systemd.slice</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
1649 <citerefentry><refentrytitle>systemd.scope</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
1650 <citerefentry><refentrytitle>systemd.socket</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
1651 <citerefentry><refentrytitle>systemd.mount</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
1652 <citerefentry><refentrytitle>systemd.swap</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
1653 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
1654 <citerefentry><refentrytitle>systemd.directives</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
1655 <citerefentry><refentrytitle>systemd.special</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
1656 <citerefentry><refentrytitle>systemd-oomd.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
1657 The documentation for control groups and specific controllers in the Linux kernel:
1658 <ulink url="https://docs.kernel.org/admin-guide/cgroup-v2.html">Control Groups v2</ulink>.
1659 </para>
1660 </refsect1>
1661 </refentry>