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    <para>See the <ulink
63    url="https://www.freedesktop.org/wiki/Software/systemd/ControlGroupInterface/">New
64    Control Group Interfaces</ulink> for an introduction on how to make
65    use of resource control APIs from programs.</para>
66
67    <refsect2>
68      <title>Setting resource controls for a group of related units</title>
69
70      <para>As described in
71      <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>, the
72      settings listed here may be set through the main file of a unit and drop-in snippets in
73      <filename index="false">*.d/</filename> directories. The list of directories searched for drop-ins
74      includes names formed by repeatedly truncating the unit name after all dashes. This is particularly
75      convenient to set resource limits for a group of units with similar names.</para>
76
77      <para>For example, every user gets their own slice
78      <filename>user-<replaceable>nnn</replaceable>.slice</filename>. Drop-ins with local configuration that
79      affect user 1000 may be placed in
80      <filename index="false">/etc/systemd/system/user-1000.slice</filename>,
81      <filename index="false">/etc/systemd/system/user-1000.slice.d/*.conf</filename>, but also
82      <filename index="false">/etc/systemd/system/user-.slice.d/*.conf</filename>. This last directory
83      applies to all user slices.</para>
84    </refsect2>
85  </refsect1>
86
87  <refsect1>
88    <title>Implicit Dependencies</title>
89
90    <para>The following dependencies are implicitly added:</para>
91
92    <itemizedlist>
93      <listitem><para>Units with the <varname>Slice=</varname> setting set automatically acquire
94      <varname>Requires=</varname> and <varname>After=</varname> dependencies on the specified
95      slice unit.</para></listitem>
96    </itemizedlist>
97  </refsect1>
98
99  <!-- We don't have any default dependency here. -->
100
101  <refsect1>
102    <title>Unified and Legacy Control Group Hierarchies</title>
103
104    <para>The unified control group hierarchy is the new version of kernel control group interface, see
105    <ulink url="https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html">Control Groups v2</ulink>.
106    Depending on the resource type, there are differences in resource control capabilities. Also, because of
107    interface changes, some resource types have separate set of options on the unified hierarchy.</para>
108
109    <para>
110      <variablelist>
111
112        <varlistentry>
113          <term>CPU</term>
114          <listitem>
115            <para><varname>CPUWeight=</varname> and <varname>StartupCPUWeight=</varname> replace
116            <varname>CPUShares=</varname> and <varname>StartupCPUShares=</varname>, respectively.</para>
117
118            <para>The <literal>cpuacct</literal> controller does not exist separately on the unified hierarchy.</para>
119          </listitem>
120        </varlistentry>
121
122        <varlistentry>
123          <term>Memory</term>
124          <listitem>
125            <para><varname>MemoryMax=</varname> replaces <varname>MemoryLimit=</varname>. <varname>MemoryLow=</varname>
126            and <varname>MemoryHigh=</varname> are effective only on unified hierarchy.</para>
127          </listitem>
128        </varlistentry>
129
130        <varlistentry>
131          <term>IO</term>
132          <listitem>
133            <para><literal>IO</literal>-prefixed settings are a superset of and replace
134            <literal>BlockIO</literal>-prefixed ones. On unified hierarchy, IO resource control also applies
135            to buffered writes.</para>
136          </listitem>
137        </varlistentry>
138
139      </variablelist>
140    </para>
141
142    <para>To ease the transition, there is best-effort translation between the two versions of settings. For each
143    controller, if any of the settings for the unified hierarchy are present, all settings for the legacy hierarchy are
144    ignored. If the resulting settings are for the other type of hierarchy, the configurations are translated before
145    application.</para>
146
147    <para>Legacy control group hierarchy (see <ulink
148    url="https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v1/">Control Groups version 1</ulink>),
149    also called cgroup-v1, doesn't allow safe delegation of controllers to unprivileged processes. If the
150    system uses the legacy control group hierarchy, resource control is disabled for the systemd user
151    instance, see
152    <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>.</para>
153  </refsect1>
154
155  <refsect1>
156    <title>Options</title>
157
158    <para>Units of the types listed above can have settings
159    for resource control configuration:</para>
160
161    <variablelist class='unit-directives'>
162
163      <varlistentry>
164        <term><varname>CPUAccounting=</varname></term>
165
166        <listitem>
167          <para>Turn on CPU usage accounting for this unit. Takes a
168          boolean argument. Note that turning on CPU accounting for
169          one unit will also implicitly turn it on for all units
170          contained in the same slice and for all its parent slices
171          and the units contained therein. The system default for this
172          setting may be controlled with
173          <varname>DefaultCPUAccounting=</varname> in
174          <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
175        </listitem>
176      </varlistentry>
177
178      <varlistentry>
179        <term><varname>CPUWeight=<replaceable>weight</replaceable></varname></term>
180        <term><varname>StartupCPUWeight=<replaceable>weight</replaceable></varname></term>
181
182        <listitem>
183          <para>Assign the specified CPU time weight to the processes executed, if the unified control group
184          hierarchy is used on the system. These options take an integer value and control the
185          <literal>cpu.weight</literal> control group attribute. The allowed range is 1 to 10000. Defaults to
186          100. For details about this control group attribute, see <ulink
187          url="https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html">Control Groups v2</ulink>
188          and <ulink url="https://www.kernel.org/doc/html/latest/scheduler/sched-design-CFS.html">CFS
189          Scheduler</ulink>.  The available CPU time is split up among all units within one slice relative to
190          their CPU time weight. A higher weight means more CPU time, a lower weight means less.</para>
191
192          <para>While <varname>StartupCPUWeight=</varname> applies to the startup and shutdown phases of the system,
193          <varname>CPUWeight=</varname> applies to normal runtime of the system, and if the former is not set also to
194          the startup and shutdown phases. Using <varname>StartupCPUWeight=</varname> allows prioritizing specific services at
195          boot-up and shutdown differently than during normal runtime.</para>
196
197          <para>These settings replace <varname>CPUShares=</varname> and <varname>StartupCPUShares=</varname>.</para>
198        </listitem>
199      </varlistentry>
200
201      <varlistentry>
202        <term><varname>CPUQuota=</varname></term>
203
204        <listitem>
205          <para>Assign the specified CPU time quota to the processes executed. Takes a percentage value, suffixed with
206          "%". The percentage specifies how much CPU time the unit shall get at maximum, relative to the total CPU time
207          available on one CPU. Use values &gt; 100% for allotting CPU time on more than one CPU. This controls the
208          <literal>cpu.max</literal> attribute on the unified control group hierarchy and
209          <literal>cpu.cfs_quota_us</literal> on legacy. For details about these control group attributes, see <ulink
210          url="https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html">Control Groups v2</ulink> and <ulink
211          url="https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt">sched-bwc.txt</ulink>.
212          Setting <varname>CPUQuota=</varname> to an empty value unsets the quota.</para>
213
214          <para>Example: <varname>CPUQuota=20%</varname> ensures that the executed processes will never get more than
215          20% CPU time on one CPU.</para>
216
217        </listitem>
218      </varlistentry>
219
220      <varlistentry>
221        <term><varname>CPUQuotaPeriodSec=</varname></term>
222
223        <listitem>
224          <para>Assign the duration over which the CPU time quota specified by <varname>CPUQuota=</varname> is measured.
225          Takes a time duration value in seconds, with an optional suffix such as "ms" for milliseconds (or "s" for seconds.)
226          The default setting is 100ms. The period is clamped to the range supported by the kernel, which is [1ms, 1000ms].
227          Additionally, the period is adjusted up so that the quota interval is also at least 1ms.
228          Setting <varname>CPUQuotaPeriodSec=</varname> to an empty value resets it to the default.</para>
229
230          <para>This controls the second field of <literal>cpu.max</literal> attribute on the unified control group hierarchy
231          and <literal>cpu.cfs_period_us</literal> on legacy. For details about these control group attributes, see
232          <ulink url="https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html">Control Groups v2</ulink> and
233          <ulink url="https://www.kernel.org/doc/html/latest/scheduler/sched-design-CFS.html">CFS Scheduler</ulink>.</para>
234
235          <para>Example: <varname>CPUQuotaPeriodSec=10ms</varname> to request that the CPU quota is measured in periods of 10ms.</para>
236        </listitem>
237      </varlistentry>
238
239      <varlistentry>
240        <term><varname>AllowedCPUs=</varname></term>
241        <term><varname>StartupAllowedCPUs=</varname></term>
242
243        <listitem>
244          <para>Restrict processes to be executed on specific CPUs. Takes a list of CPU indices or ranges separated by either
245          whitespace or commas. CPU ranges are specified by the lower and upper CPU indices separated by a dash.</para>
246
247          <para>Setting <varname>AllowedCPUs=</varname> or <varname>StartupAllowedCPUs=</varname> doesn't guarantee that all
248          of the CPUs will be used by the processes as it may be limited by parent units. The effective configuration is
249          reported as <varname>EffectiveCPUs=</varname>.</para>
250
251          <para>While <varname>StartupAllowedCPUs=</varname> applies to the startup and shutdown phases of the system,
252          <varname>AllowedCPUs=</varname> applies to normal runtime of the system, and if the former is not set also to
253          the startup and shutdown phases. Using <varname>StartupAllowedCPUs=</varname> allows prioritizing specific services at
254          boot-up and shutdown differently than during normal runtime.</para>
255
256          <para>This setting is supported only with the unified control group hierarchy.</para>
257        </listitem>
258      </varlistentry>
259
260      <varlistentry>
261        <term><varname>AllowedMemoryNodes=</varname></term>
262        <term><varname>StartupAllowedMemoryNodes=</varname></term>
263
264        <listitem>
265          <para>Restrict processes to be executed on specific memory NUMA nodes. Takes a list of memory NUMA nodes indices
266          or ranges separated by either whitespace or commas. Memory NUMA nodes ranges are specified by the lower and upper
267          NUMA nodes indices separated by a dash.</para>
268
269          <para>Setting <varname>AllowedMemoryNodes=</varname> or <varname>StartupAllowedMemoryNodes=</varname> doesn't
270          guarantee that all of the memory NUMA nodes will be used by the processes as it may be limited by parent units.
271          The effective configuration is reported as <varname>EffectiveMemoryNodes=</varname>.</para>
272
273          <para>While <varname>StartupAllowedMemoryNodes=</varname> applies to the startup and shutdown phases of the system,
274          <varname>AllowedMemoryNodes=</varname> applies to normal runtime of the system, and if the former is not set also to
275          the startup and shutdown phases. Using <varname>StartupAllowedMemoryNodes=</varname> allows prioritizing specific services at
276          boot-up and shutdown differently than during normal runtime.</para>
277
278          <para>This setting is supported only with the unified control group hierarchy.</para>
279        </listitem>
280      </varlistentry>
281
282      <varlistentry>
283        <term><varname>MemoryAccounting=</varname></term>
284
285        <listitem>
286          <para>Turn on process and kernel memory accounting for this
287          unit. Takes a boolean argument. Note that turning on memory
288          accounting for one unit will also implicitly turn it on for
289          all units contained in the same slice and for all its parent
290          slices and the units contained therein. The system default
291          for this setting may be controlled with
292          <varname>DefaultMemoryAccounting=</varname> in
293          <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
294        </listitem>
295      </varlistentry>
296
297      <varlistentry>
298        <term><varname>MemoryMin=<replaceable>bytes</replaceable></varname>, <varname>MemoryLow=<replaceable>bytes</replaceable></varname></term>
299
300        <listitem>
301          <para>Specify the memory usage protection of the executed processes in this unit.
302          When reclaiming memory, the unit is treated as if it was using less memory resulting in memory
303          to be preferentially reclaimed from unprotected units.
304          Using <varname>MemoryLow=</varname> results in a weaker protection where memory may still
305          be reclaimed to avoid invoking the OOM killer in case there is no other reclaimable memory.</para>
306          <para>
307          For a protection to be effective, it is generally required to set a corresponding
308          allocation on all ancestors, which is then distributed between children
309          (with the exception of the root slice).
310          Any <varname>MemoryMin=</varname> or <varname>MemoryLow=</varname> allocation that is not
311          explicitly distributed to specific children is used to create a shared protection for all children.
312          As this is a shared protection, the children will freely compete for the memory.</para>
313
314          <para>Takes a memory size in bytes. If the value is suffixed with K, M, G or T, the specified memory size is
315          parsed as Kilobytes, Megabytes, Gigabytes, or Terabytes (with the base 1024), respectively. Alternatively, a
316          percentage value may be specified, which is taken relative to the installed physical memory on the
317          system. If assigned the special value <literal>infinity</literal>, all available memory is protected, which may be
318          useful in order to always inherit all of the protection afforded by ancestors.
319          This controls the <literal>memory.min</literal> or <literal>memory.low</literal> control group attribute.
320          For details about this control group attribute, see <ulink
321          url="https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html#memory-interface-files">Memory Interface Files</ulink>.</para>
322
323          <para>This setting is supported only if the unified control group hierarchy is used and disables
324          <varname>MemoryLimit=</varname>.</para>
325
326          <para>Units may have their children use a default <literal>memory.min</literal> or
327          <literal>memory.low</literal> value by specifying <varname>DefaultMemoryMin=</varname> or
328          <varname>DefaultMemoryLow=</varname>, which has the same semantics as
329          <varname>MemoryMin=</varname> and <varname>MemoryLow=</varname>.
330          This setting does not affect <literal>memory.min</literal> or <literal>memory.low</literal>
331          in the unit itself.
332          Using it to set a default child allocation is only useful on kernels older than 5.7,
333          which do not support the <literal>memory_recursiveprot</literal> cgroup2 mount option.</para>
334        </listitem>
335      </varlistentry>
336
337      <varlistentry>
338        <term><varname>MemoryHigh=<replaceable>bytes</replaceable></varname></term>
339
340        <listitem>
341          <para>Specify the throttling limit on memory usage of the executed processes in this unit. Memory usage may go
342          above the limit if unavoidable, but the processes are heavily slowed down and memory is taken away
343          aggressively in such cases. This is the main mechanism to control memory usage of a unit.</para>
344
345          <para>Takes a memory size in bytes. If the value is suffixed with K, M, G or T, the specified memory size is
346          parsed as Kilobytes, Megabytes, Gigabytes, or Terabytes (with the base 1024), respectively. Alternatively, a
347          percentage value may be specified, which is taken relative to the installed physical memory on the
348          system. If assigned the
349          special value <literal>infinity</literal>, no memory throttling is applied. This controls the
350          <literal>memory.high</literal> control group attribute. For details about this control group attribute, see
351          <ulink url="https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html#memory-interface-files">Memory Interface Files</ulink>.</para>
352
353          <para>This setting is supported only if the unified control group hierarchy is used and disables
354          <varname>MemoryLimit=</varname>.</para>
355        </listitem>
356      </varlistentry>
357
358      <varlistentry>
359        <term><varname>MemoryMax=<replaceable>bytes</replaceable></varname></term>
360
361        <listitem>
362          <para>Specify the absolute limit on memory usage of the executed processes in this unit. If memory usage
363          cannot be contained under the limit, out-of-memory killer is invoked inside the unit. It is recommended to
364          use <varname>MemoryHigh=</varname> as the main control mechanism and use <varname>MemoryMax=</varname> as the
365          last line of defense.</para>
366
367          <para>Takes a memory size in bytes. If the value is suffixed with K, M, G or T, the specified memory size is
368          parsed as Kilobytes, Megabytes, Gigabytes, or Terabytes (with the base 1024), respectively. Alternatively, a
369          percentage value may be specified, which is taken relative to the installed physical memory on the system. If
370          assigned the special value <literal>infinity</literal>, no memory limit is applied. This controls the
371          <literal>memory.max</literal> control group attribute. For details about this control group attribute, see
372          <ulink url="https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html#memory-interface-files">Memory Interface Files</ulink>.</para>
373
374          <para>This setting replaces <varname>MemoryLimit=</varname>.</para>
375        </listitem>
376      </varlistentry>
377
378      <varlistentry>
379        <term><varname>MemorySwapMax=<replaceable>bytes</replaceable></varname></term>
380
381        <listitem>
382          <para>Specify the absolute limit on swap usage of the executed processes in this unit.</para>
383
384          <para>Takes a swap size in bytes. If the value is suffixed with K, M, G or T, the specified swap size is
385          parsed as Kilobytes, Megabytes, Gigabytes, or Terabytes (with the base 1024), respectively. If assigned the
386          special value <literal>infinity</literal>, no swap limit is applied. This controls the
387          <literal>memory.swap.max</literal> control group attribute. For details about this control group attribute,
388          see <ulink url="https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html#memory-interface-files">Memory Interface Files</ulink>.</para>
389
390          <para>This setting is supported only if the unified control group hierarchy is used and disables
391          <varname>MemoryLimit=</varname>.</para>
392        </listitem>
393      </varlistentry>
394
395      <varlistentry>
396        <term><varname>TasksAccounting=</varname></term>
397
398        <listitem>
399          <para>Turn on task accounting for this unit. Takes a
400          boolean argument. If enabled, the system manager will keep
401          track of the number of tasks in the unit. The number of
402          tasks accounted this way includes both kernel threads and
403          userspace processes, with each thread counting
404          individually. Note that turning on tasks accounting for one
405          unit will also implicitly turn it on for all units contained
406          in the same slice and for all its parent slices and the
407          units contained therein. The system default for this setting
408          may be controlled with
409          <varname>DefaultTasksAccounting=</varname> in
410          <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
411        </listitem>
412      </varlistentry>
413
414      <varlistentry>
415        <term><varname>TasksMax=<replaceable>N</replaceable></varname></term>
416
417        <listitem>
418          <para>Specify the maximum number of tasks that may be created in the unit. This ensures that the number of
419          tasks accounted for the unit (see above) stays below a specific limit. This either takes an absolute number
420          of tasks or a percentage value that is taken relative to the configured maximum number of tasks on the
421          system.  If assigned the special value <literal>infinity</literal>, no tasks limit is applied. This controls
422          the <literal>pids.max</literal> control group attribute. For details about this control group attribute, see
423          <ulink url="https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v1/pids.html">Process Number Controller</ulink>.
424          </para>
425
426          <para>The system default for this setting may be controlled with
427          <varname>DefaultTasksMax=</varname> in
428          <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
429        </listitem>
430      </varlistentry>
431
432      <varlistentry>
433        <term><varname>IOAccounting=</varname></term>
434
435        <listitem>
436          <para>Turn on Block I/O accounting for this unit, if the unified control group hierarchy is used on the
437          system. Takes a boolean argument. Note that turning on block I/O accounting for one unit will also implicitly
438          turn it on for all units contained in the same slice and all for its parent slices and the units contained
439          therein. The system default for this setting may be controlled with <varname>DefaultIOAccounting=</varname>
440          in
441          <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
442
443          <para>This setting replaces <varname>BlockIOAccounting=</varname> and disables settings prefixed with
444          <varname>BlockIO</varname> or <varname>StartupBlockIO</varname>.</para>
445        </listitem>
446      </varlistentry>
447
448      <varlistentry>
449        <term><varname>IOWeight=<replaceable>weight</replaceable></varname></term>
450        <term><varname>StartupIOWeight=<replaceable>weight</replaceable></varname></term>
451
452        <listitem>
453          <para>Set the default overall block I/O weight for the executed processes, if the unified control
454          group hierarchy is used on the system. Takes a single weight value (between 1 and 10000) to set the
455          default block I/O weight. This controls the <literal>io.weight</literal> control group attribute,
456          which defaults to 100. For details about this control group attribute, see <ulink
457          url="https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html#io-interface-files">IO
458          Interface Files</ulink>.  The available I/O bandwidth is split up among all units within one slice
459          relative to their block I/O weight. A higher weight means more I/O bandwidth, a lower weight means
460          less.</para>
461
462          <para>While <varname>StartupIOWeight=</varname> applies
463          to the startup and shutdown phases of the system,
464          <varname>IOWeight=</varname> applies to the later runtime of
465          the system, and if the former is not set also to the startup
466          and shutdown phases. This allows prioritizing specific services at boot-up
467          and shutdown differently than during runtime.</para>
468
469          <para>These settings replace <varname>BlockIOWeight=</varname> and <varname>StartupBlockIOWeight=</varname>
470          and disable settings prefixed with <varname>BlockIO</varname> or <varname>StartupBlockIO</varname>.</para>
471        </listitem>
472      </varlistentry>
473
474      <varlistentry>
475        <term><varname>IODeviceWeight=<replaceable>device</replaceable> <replaceable>weight</replaceable></varname></term>
476
477        <listitem>
478          <para>Set the per-device overall block I/O weight for the executed processes, if the unified control group
479          hierarchy is used on the system. Takes a space-separated pair of a file path and a weight value to specify
480          the device specific weight value, between 1 and 10000. (Example: <literal>/dev/sda 1000</literal>). The file
481          path may be specified as path to a block device node or as any other file, in which case the backing block
482          device of the file system of the file is determined. This controls the <literal>io.weight</literal> control
483          group attribute, which defaults to 100. Use this option multiple times to set weights for multiple devices.
484          For details about this control group attribute, see <ulink
485          url="https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html#io-interface-files">IO Interface Files</ulink>.</para>
486
487          <para>This setting replaces <varname>BlockIODeviceWeight=</varname> and disables settings prefixed with
488          <varname>BlockIO</varname> or <varname>StartupBlockIO</varname>.</para>
489
490          <para>The specified device node should reference a block device that has an I/O scheduler
491          associated, i.e. should not refer to partition or loopback block devices, but to the originating,
492          physical device. When a path to a regular file or directory is specified it is attempted to
493          discover the correct originating device backing the file system of the specified path. This works
494          correctly only for simpler cases, where the file system is directly placed on a partition or
495          physical block device, or where simple 1:1 encryption using dm-crypt/LUKS is used. This discovery
496          does not cover complex storage and in particular RAID and volume management storage devices.</para>
497        </listitem>
498      </varlistentry>
499
500      <varlistentry>
501        <term><varname>IOReadBandwidthMax=<replaceable>device</replaceable> <replaceable>bytes</replaceable></varname></term>
502        <term><varname>IOWriteBandwidthMax=<replaceable>device</replaceable> <replaceable>bytes</replaceable></varname></term>
503
504        <listitem>
505          <para>Set the per-device overall block I/O bandwidth maximum limit for the executed processes, if the unified
506          control group hierarchy is used on the system. This limit is not work-conserving and the executed processes
507          are not allowed to use more even if the device has idle capacity.  Takes a space-separated pair of a file
508          path and a bandwidth value (in bytes per second) to specify the device specific bandwidth. The file path may
509          be a path to a block device node, or as any other file in which case the backing block device of the file
510          system of the file is used. If the bandwidth is suffixed with K, M, G, or T, the specified bandwidth is
511          parsed as Kilobytes, Megabytes, Gigabytes, or Terabytes, respectively, to the base of 1000. (Example:
512          "/dev/disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0 5M"). This controls the <literal>io.max</literal> control
513          group attributes. Use this option multiple times to set bandwidth limits for multiple devices. For details
514          about this control group attribute, see <ulink
515          url="https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html#io-interface-files">IO Interface Files</ulink>.
516          </para>
517
518          <para>These settings replace <varname>BlockIOReadBandwidth=</varname> and
519          <varname>BlockIOWriteBandwidth=</varname> and disable settings prefixed with <varname>BlockIO</varname> or
520          <varname>StartupBlockIO</varname>.</para>
521
522          <para>Similar restrictions on block device discovery as for <varname>IODeviceWeight=</varname> apply, see above.</para>
523        </listitem>
524      </varlistentry>
525
526      <varlistentry>
527        <term><varname>IOReadIOPSMax=<replaceable>device</replaceable> <replaceable>IOPS</replaceable></varname></term>
528        <term><varname>IOWriteIOPSMax=<replaceable>device</replaceable> <replaceable>IOPS</replaceable></varname></term>
529
530        <listitem>
531          <para>Set the per-device overall block I/O IOs-Per-Second maximum limit for the executed processes, if the
532          unified control group hierarchy is used on the system. This limit is not work-conserving and the executed
533          processes are not allowed to use more even if the device has idle capacity.  Takes a space-separated pair of
534          a file path and an IOPS value to specify the device specific IOPS. The file path may be a path to a block
535          device node, or as any other file in which case the backing block device of the file system of the file is
536          used. If the IOPS is suffixed with K, M, G, or T, the specified IOPS is parsed as KiloIOPS, MegaIOPS,
537          GigaIOPS, or TeraIOPS, respectively, to the base of 1000. (Example:
538          "/dev/disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0 1K"). This controls the <literal>io.max</literal> control
539          group attributes. Use this option multiple times to set IOPS limits for multiple devices. For details about
540          this control group attribute, see <ulink
541          url="https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html#io-interface-files">IO Interface Files</ulink>.
542          </para>
543
544          <para>These settings are supported only if the unified control group hierarchy is used and disable settings
545          prefixed with <varname>BlockIO</varname> or <varname>StartupBlockIO</varname>.</para>
546
547          <para>Similar restrictions on block device discovery as for <varname>IODeviceWeight=</varname> apply, see above.</para>
548        </listitem>
549      </varlistentry>
550
551      <varlistentry>
552        <term><varname>IODeviceLatencyTargetSec=<replaceable>device</replaceable> <replaceable>target</replaceable></varname></term>
553
554        <listitem>
555          <para>Set the per-device average target I/O latency for the executed processes, if the unified control group
556          hierarchy is used on the system. Takes a file path and a timespan separated by a space to specify
557          the device specific latency target. (Example: "/dev/sda 25ms"). The file path may be specified
558          as path to a block device node or as any other file, in which case the backing block device of the file
559          system of the file is determined. This controls the <literal>io.latency</literal> control group
560          attribute. Use this option multiple times to set latency target for multiple devices. For details about this
561          control group attribute, see <ulink
562          url="https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html#io-interface-files">IO Interface Files</ulink>.</para>
563
564          <para>Implies <literal>IOAccounting=yes</literal>.</para>
565
566          <para>These settings are supported only if the unified control group hierarchy is used.</para>
567
568          <para>Similar restrictions on block device discovery as for <varname>IODeviceWeight=</varname> apply, see above.</para>
569        </listitem>
570      </varlistentry>
571
572      <varlistentry>
573        <term><varname>IPAccounting=</varname></term>
574
575        <listitem>
576          <para>Takes a boolean argument. If true, turns on IPv4 and IPv6 network traffic accounting for packets sent
577          or received by the unit. When this option is turned on, all IPv4 and IPv6 sockets created by any process of
578          the unit are accounted for.</para>
579
580          <para>When this option is used in socket units, it applies to all IPv4 and IPv6 sockets
581          associated with it (including both listening and connection sockets where this applies). Note that for
582          socket-activated services, this configuration setting and the accounting data of the service unit and the
583          socket unit are kept separate, and displayed separately. No propagation of the setting and the collected
584          statistics is done, in either direction. Moreover, any traffic sent or received on any of the socket unit's
585          sockets is accounted to the socket unit — and never to the service unit it might have activated, even if the
586          socket is used by it.</para>
587
588          <para>The system default for this setting may be controlled with <varname>DefaultIPAccounting=</varname> in
589          <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
590        </listitem>
591      </varlistentry>
592
593      <varlistentry>
594        <term><varname>IPAddressAllow=<replaceable>ADDRESS[/PREFIXLENGTH]…</replaceable></varname></term>
595        <term><varname>IPAddressDeny=<replaceable>ADDRESS[/PREFIXLENGTH]…</replaceable></varname></term>
596
597        <listitem>
598          <para>Turn on network traffic filtering for IP packets sent and received over
599          <constant>AF_INET</constant> and <constant>AF_INET6</constant> sockets. Both directives take a
600          space separated list of IPv4 or IPv6 addresses, each optionally suffixed with an address prefix
601          length in bits after a <literal>/</literal> character. If the suffix is omitted, the address is
602          considered a host address, i.e. the filter covers the whole address (32 bits for IPv4, 128 bits for
603          IPv6).</para>
604
605          <para>The access lists configured with this option are applied to all sockets created by processes
606          of this unit (or in the case of socket units, associated with it). The lists are implicitly
607          combined with any lists configured for any of the parent slice units this unit might be a member
608          of. By default both access lists are empty. Both ingress and egress traffic is filtered by these
609          settings. In case of ingress traffic the source IP address is checked against these access lists,
610          in case of egress traffic the destination IP address is checked. The following rules are applied in
611          turn:</para>
612
613          <itemizedlist>
614            <listitem><para>Access is granted when the checked IP address matches an entry in the
615            <varname>IPAddressAllow=</varname> list.</para></listitem>
616
617            <listitem><para>Otherwise, access is denied when the checked IP address matches an entry in the
618            <varname>IPAddressDeny=</varname> list.</para></listitem>
619
620            <listitem><para>Otherwise, access is granted.</para></listitem>
621          </itemizedlist>
622
623          <para>In order to implement an allow-listing IP firewall, it is recommended to use a
624          <varname>IPAddressDeny=</varname><constant>any</constant> setting on an upper-level slice unit
625          (such as the root slice <filename>-.slice</filename> or the slice containing all system services
626          <filename>system.slice</filename> – see
627          <citerefentry><refentrytitle>systemd.special</refentrytitle><manvolnum>7</manvolnum></citerefentry>
628          for details on these slice units), plus individual per-service <varname>IPAddressAllow=</varname>
629          lines permitting network access to relevant services, and only them.</para>
630
631          <para>Note that for socket-activated services, the IP access list configured on the socket unit
632          applies to all sockets associated with it directly, but not to any sockets created by the
633          ultimately activated services for it. Conversely, the IP access list configured for the service is
634          not applied to any sockets passed into the service via socket activation. Thus, it is usually a
635          good idea to replicate the IP access lists on both the socket and the service unit. Nevertheless,
636          it may make sense to maintain one list more open and the other one more restricted, depending on
637          the usecase.</para>
638
639          <para>If these settings are used multiple times in the same unit the specified lists are combined. If an
640          empty string is assigned to these settings the specific access list is reset and all previous settings undone.</para>
641
642          <para>In place of explicit IPv4 or IPv6 address and prefix length specifications a small set of symbolic
643          names may be used. The following names are defined:</para>
644
645          <table>
646            <title>Special address/network names</title>
647
648            <tgroup cols='3'>
649              <colspec colname='name'/>
650              <colspec colname='definition'/>
651              <colspec colname='meaning'/>
652
653              <thead>
654                <row>
655                  <entry>Symbolic Name</entry>
656                  <entry>Definition</entry>
657                  <entry>Meaning</entry>
658                </row>
659              </thead>
660
661            <tbody>
662              <row>
663                <entry><constant>any</constant></entry>
664                <entry>0.0.0.0/0 ::/0</entry>
665                <entry>Any host</entry>
666              </row>
667
668              <row>
669                <entry><constant>localhost</constant></entry>
670                <entry>127.0.0.0/8 ::1/128</entry>
671                <entry>All addresses on the local loopback</entry>
672              </row>
673
674              <row>
675                <entry><constant>link-local</constant></entry>
676                <entry>169.254.0.0/16 fe80::/64</entry>
677                <entry>All link-local IP addresses</entry>
678              </row>
679
680              <row>
681                <entry><constant>multicast</constant></entry>
682                <entry>224.0.0.0/4 ff00::/8</entry>
683                <entry>All IP multicasting addresses</entry>
684              </row>
685            </tbody>
686            </tgroup>
687          </table>
688
689          <para>Note that these settings might not be supported on some systems (for example if eBPF control group
690          support is not enabled in the underlying kernel or container manager). These settings will have no effect in
691          that case. If compatibility with such systems is desired it is hence recommended to not exclusively rely on
692          them for IP security.</para>
693        </listitem>
694      </varlistentry>
695
696      <varlistentry>
697        <term><varname>IPIngressFilterPath=<replaceable>BPF_FS_PROGRAM_PATH</replaceable></varname></term>
698        <term><varname>IPEgressFilterPath=<replaceable>BPF_FS_PROGRAM_PATH</replaceable></varname></term>
699
700        <listitem>
701          <para>Add custom network traffic filters implemented as BPF programs, applying to all IP packets
702          sent and received over <constant>AF_INET</constant> and <constant>AF_INET6</constant> sockets.
703          Takes an absolute path to a pinned BPF program in the BPF virtual filesystem (<filename>/sys/fs/bpf/</filename>).
704          </para>
705
706          <para>The filters configured with this option are applied to all sockets created by processes
707          of this unit (or in the case of socket units, associated with it). The filters are loaded in addition
708          to filters any of the parent slice units this unit might be a member of as well as any
709          <varname>IPAddressAllow=</varname> and <varname>IPAddressDeny=</varname> filters in any of these units.
710          By default there are no filters specified.</para>
711
712          <para>If these settings are used multiple times in the same unit all the specified programs are attached. If an
713          empty string is assigned to these settings the program list is reset and all previous specified programs ignored.</para>
714
715          <para>If the path <replaceable>BPF_FS_PROGRAM_PATH</replaceable> in <varname>IPIngressFilterPath=</varname> assignment
716          is already being handled by <varname>BPFProgram=</varname> ingress hook, e.g.
717          <varname>BPFProgram=</varname><constant>ingress</constant>:<replaceable>BPF_FS_PROGRAM_PATH</replaceable>,
718          the assignment will be still considered valid and the program will be attached to a cgroup. Same for
719          <varname>IPEgressFilterPath=</varname> path and <constant>egress</constant> hook.</para>
720
721          <para>Note that for socket-activated services, the IP filter programs configured on the socket unit apply to
722          all sockets associated with it directly, but not to any sockets created by the ultimately activated services
723          for it. Conversely, the IP filter programs configured for the service are not applied to any sockets passed into
724          the service via socket activation. Thus, it is usually a good idea, to replicate the IP filter programs on both
725          the socket and the service unit, however it often makes sense to maintain one configuration more open and the other
726          one more restricted, depending on the usecase.</para>
727
728          <para>Note that these settings might not be supported on some systems (for example if eBPF control group
729          support is not enabled in the underlying kernel or container manager). These settings will fail the service in
730          that case. If compatibility with such systems is desired it is hence recommended to attach your filter manually
731          (requires <varname>Delegate=</varname><constant>yes</constant>) instead of using this setting.</para>
732        </listitem>
733      </varlistentry>
734
735      <varlistentry>
736        <term><varname>BPFProgram=<replaceable>type</replaceable><constant>:</constant><replaceable>program-path</replaceable></varname></term>
737        <listitem>
738          <para>Add a custom cgroup BPF program.</para>
739
740          <para><varname>BPFProgram=</varname> allows attaching BPF hooks to the cgroup of a systemd unit.
741          (This generalizes the functionality exposed via <varname>IPEgressFilterPath=</varname> for egress and
742          <varname>IPIngressFilterPath=</varname> for ingress.)
743          Cgroup-bpf hooks in the form of BPF programs loaded to the BPF filesystem are attached with cgroup-bpf attach
744          flags determined by the unit. For details about attachment types and flags see <ulink
745          url="https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/include/uapi/linux/bpf.h"/>.
746          For general BPF documentation please refer to <ulink url="https://www.kernel.org/doc/html/latest/bpf/index.html"/>.</para>
747
748          <para>The specification of BPF program consists of a <replaceable>type</replaceable> followed by a
749          <replaceable>program-path</replaceable> with <literal>:</literal> as the separator:
750          <replaceable>type</replaceable><constant>:</constant><replaceable>program-path</replaceable>.</para>
751
752          <para><replaceable>type</replaceable> is the string name of BPF attach type also used in
753          <command>bpftool</command>. <replaceable>type</replaceable> can be one of <constant>egress</constant>,
754          <constant>ingress</constant>, <constant>sock_create</constant>, <constant>sock_ops</constant>,
755          <constant>device</constant>, <constant>bind4</constant>, <constant>bind6</constant>,
756          <constant>connect4</constant>, <constant>connect6</constant>, <constant>post_bind4</constant>,
757          <constant>post_bind6</constant>, <constant>sendmsg4</constant>, <constant>sendmsg6</constant>,
758          <constant>sysctl</constant>, <constant>recvmsg4</constant>, <constant>recvmsg6</constant>,
759          <constant>getsockopt</constant>, <constant>setsockopt</constant>.</para>
760
761          <para>Setting <varname>BPFProgram=</varname> to an empty value makes previous assignments ineffective.</para>
762          <para>Multiple assignments of the same <replaceable>type</replaceable>:<replaceable>program-path</replaceable>
763          value have the same effect as a single assignment: the program with the path <replaceable>program-path</replaceable>
764          will be attached to cgroup hook <replaceable>type</replaceable> just once.</para>
765          <para>If BPF <constant>egress</constant> pinned to <replaceable>program-path</replaceable> path is already being
766          handled by <varname>IPEgressFilterPath=</varname>, <varname>BPFProgram=</varname>
767          assignment will be considered valid and <varname>BPFProgram=</varname> will be attached to a cgroup.
768          Similarly for <constant>ingress</constant> hook and <varname>IPIngressFilterPath=</varname> assignment.</para>
769
770          <para>BPF programs passed with <varname>BPFProgram=</varname> are attached to the cgroup of a unit with BPF
771          attach flag <constant>multi</constant>, that allows further attachments of the same
772          <replaceable>type</replaceable> within cgroup hierarchy topped by the unit cgroup.</para>
773
774          <para>Examples:<programlisting>
775BPFProgram=egress:/sys/fs/bpf/egress-hook
776BPFProgram=bind6:/sys/fs/bpf/sock-addr-hook
777</programlisting></para>
778        </listitem>
779      </varlistentry>
780
781      <varlistentry>
782        <term><varname>SocketBindAllow=<replaceable>bind-rule</replaceable></varname></term>
783        <term><varname>SocketBindDeny=<replaceable>bind-rule</replaceable></varname></term>
784
785        <listitem>
786          <para>Allow or deny binding a socket address to a socket by matching it with the <replaceable>bind-rule</replaceable> and
787          applying a corresponding action if there is a match.</para>
788
789          <para><replaceable>bind-rule</replaceable> describes socket properties such as <replaceable>address-family</replaceable>,
790          <replaceable>transport-protocol</replaceable> and <replaceable>ip-ports</replaceable>.</para>
791
792          <para><replaceable>bind-rule</replaceable> :=
793          { [<replaceable>address-family</replaceable><constant>:</constant>][<replaceable>transport-protocol</replaceable><constant>:</constant>][<replaceable>ip-ports</replaceable>] | <constant>any</constant> }</para>
794
795          <para><replaceable>address-family</replaceable> := { <constant>ipv4</constant> | <constant>ipv6</constant> }</para>
796
797          <para><replaceable>transport-protocol</replaceable> := { <constant>tcp</constant> | <constant>udp</constant> }</para>
798
799          <para><replaceable>ip-ports</replaceable> := { <replaceable>ip-port</replaceable> | <replaceable>ip-port-range</replaceable> }</para>
800
801          <para>An optional <replaceable>address-family</replaceable> expects <constant>ipv4</constant> or <constant>ipv6</constant> values.
802          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>,
803          <replaceable>ip-port</replaceable>.</para>
804
805          <para>An optional <replaceable>transport-protocol</replaceable> expects <constant>tcp</constant> or <constant>udp</constant> transport protocol names.
806          If not specified, a rule will be matched for any transport protocol.</para>
807
808          <para>An optional <replaceable>ip-port</replaceable> value must lie within 1…65535 interval inclusively, i.e.
809          dynamic port <constant>0</constant> is not allowed. A range of sequential ports is described by
810          <replaceable>ip-port-range</replaceable> := <replaceable>ip-port-low</replaceable><constant>-</constant><replaceable>ip-port-high</replaceable>,
811          where <replaceable>ip-port-low</replaceable> is smaller than or equal to <replaceable>ip-port-high</replaceable>
812          and both are within 1…65535 inclusively.</para>
813
814          <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>
815
816          <para>To allow multiple rules assign <varname>SocketBindAllow=</varname> or <varname>SocketBindDeny=</varname> multiple times.
817          To clear the existing assignments pass an empty <varname>SocketBindAllow=</varname> or <varname>SocketBindDeny=</varname>
818          assignment.</para>
819
820          <para>For each of <varname>SocketBindAllow=</varname> and <varname>SocketBindDeny=</varname>, maximum allowed number of assignments is
821          <constant>128</constant>.</para>
822
823          <itemizedlist>
824            <listitem><para>Binding to a socket is allowed when a socket address matches an entry in the
825            <varname>SocketBindAllow=</varname> list.</para></listitem>
826
827            <listitem><para>Otherwise, binding is denied when the socket address matches an entry in the
828            <varname>SocketBindDeny=</varname> list.</para></listitem>
829
830            <listitem><para>Otherwise, binding is allowed.</para></listitem>
831          </itemizedlist>
832
833          <para>The feature is implemented with <constant>cgroup/bind4</constant> and <constant>cgroup/bind6</constant> cgroup-bpf hooks.</para>
834          <para>Examples:<programlisting>…
835# Allow binding IPv6 socket addresses with a port greater than or equal to 10000.
836[Service]
837SocketBindAllow=ipv6:10000-65535
838SocketBindDeny=any
839840# Allow binding IPv4 and IPv6 socket addresses with 1234 and 4321 ports.
841[Service]
842SocketBindAllow=1234
843SocketBindAllow=4321
844SocketBindDeny=any
845846# Deny binding IPv6 socket addresses.
847[Service]
848SocketBindDeny=ipv6
849850# Deny binding IPv4 and IPv6 socket addresses.
851[Service]
852SocketBindDeny=any
853854# Allow binding only over TCP
855[Service]
856SocketBindAllow=tcp
857SocketBindDeny=any
858859# Allow binding only over IPv6/TCP
860[Service]
861SocketBindAllow=ipv6:tcp
862SocketBindDeny=any
863864# Allow binding ports within 10000-65535 range over IPv4/UDP.
865[Service]
866SocketBindAllow=ipv4:udp:10000-65535
867SocketBindDeny=any
868…</programlisting></para>
869        </listitem>
870      </varlistentry>
871
872      <varlistentry>
873        <term><varname>RestrictNetworkInterfaces=</varname></term>
874
875        <listitem>
876          <para>Takes a list of space-separated network interface names. This option restricts the network
877          interfaces that processes of this unit can use. By default processes can only use the network interfaces
878          listed (allow-list). If the first character of the rule is <literal>~</literal>, the effect is inverted:
879          the processes can only use network interfaces not listed (deny-list).
880          </para>
881
882          <para>This option can appear multiple times, in which case the network interface names are merged. If the
883          empty string is assigned the set is reset, all prior assignments will have not effect.
884          </para>
885
886          <para>If you specify both types of this option (i.e. allow-listing and deny-listing), the first encountered
887          will take precedence and will dictate the default action (allow vs deny). Then the next occurrences of this
888          option will add or delete the listed network interface names from the set, depending of its type and the
889          default action.
890          </para>
891
892          <para>The loopback interface ("lo") is not treated in any special way, you have to configure it explicitly
893          in the unit file.
894          </para>
895          <para>Example 1: allow-list
896          <programlisting>
897RestrictNetworkInterfaces=eth1
898RestrictNetworkInterfaces=eth2</programlisting>
899          Programs in the unit will be only able to use the eth1 and eth2 network
900          interfaces.
901          </para>
902
903          <para>Example 2: deny-list
904          <programlisting>
905RestrictNetworkInterfaces=~eth1 eth2</programlisting>
906          Programs in the unit will be able to use any network interface but eth1 and eth2.
907          </para>
908
909          <para>Example 3: mixed
910          <programlisting>
911RestrictNetworkInterfaces=eth1 eth2
912RestrictNetworkInterfaces=~eth1</programlisting>
913          Programs in the unit will be only able to use the eth2 network interface.
914          </para>
915        </listitem>
916      </varlistentry>
917
918      <varlistentry>
919        <term><varname>DeviceAllow=</varname></term>
920
921        <listitem>
922          <para>Control access to specific device nodes by the executed processes. Takes two space-separated
923          strings: a device node specifier followed by a combination of <constant>r</constant>,
924          <constant>w</constant>, <constant>m</constant> to control <emphasis>r</emphasis>eading,
925          <emphasis>w</emphasis>riting, or creation of the specific device node(s) by the unit
926          (<emphasis>m</emphasis>knod), respectively. On cgroup-v1 this controls the
927          <literal>devices.allow</literal> control group attribute. For details about this control group
928          attribute, see <ulink
929          url="https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v1/devices.html">Device Whitelist Controller</ulink>.
930          In the unified cgroup hierarchy this functionality is implemented using eBPF filtering.</para>
931
932          <para>When access to <emphasis>all</emphasis> physical devices should be disallowed,
933          <varname>PrivateDevices=</varname> may be used instead. See
934          <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
935          </para>
936
937          <para>The device node specifier is either a path to a device node in the file system, starting with
938          <filename>/dev/</filename>, or a string starting with either <literal>char-</literal> or
939          <literal>block-</literal> followed by a device group name, as listed in
940          <filename>/proc/devices</filename>. The latter is useful to allow-list all current and future
941          devices belonging to a specific device group at once. The device group is matched according to
942          filename globbing rules, you may hence use the <literal>*</literal> and <literal>?</literal>
943          wildcards. (Note that such globbing wildcards are not available for device node path
944          specifications!) In order to match device nodes by numeric major/minor, use device node paths in
945          the <filename>/dev/char/</filename> and <filename>/dev/block/</filename> directories. However,
946          matching devices by major/minor is generally not recommended as assignments are neither stable nor
947          portable between systems or different kernel versions.</para>
948
949          <para>Examples: <filename>/dev/sda5</filename> is a path to a device node, referring to an ATA or
950          SCSI block device. <literal>char-pts</literal> and <literal>char-alsa</literal> are specifiers for
951          all pseudo TTYs and all ALSA sound devices, respectively. <literal>char-cpu/*</literal> is a
952          specifier matching all CPU related device groups.</para>
953
954          <para>Note that allow lists defined this way should only reference device groups which are
955          resolvable at the time the unit is started. Any device groups not resolvable then are not added to
956          the device allow list. In order to work around this limitation, consider extending service units
957          with a pair of <command>After=modprobe@xyz.service</command> and
958          <command>Wants=modprobe@xyz.service</command> lines that load the necessary kernel module
959          implementing the device group if missing.
960          Example: <programlisting>…
961[Unit]
962Wants=modprobe@loop.service
963After=modprobe@loop.service
964
965[Service]
966DeviceAllow=block-loop
967DeviceAllow=/dev/loop-control
968…</programlisting></para>
969
970        </listitem>
971      </varlistentry>
972
973      <varlistentry>
974        <term><varname>DevicePolicy=auto|closed|strict</varname></term>
975
976        <listitem>
977          <para>
978            Control the policy for allowing device access:
979          </para>
980          <variablelist>
981            <varlistentry>
982              <term><option>strict</option></term>
983              <listitem>
984                <para>means to only allow types of access that are
985                explicitly specified.</para>
986              </listitem>
987            </varlistentry>
988
989            <varlistentry>
990              <term><option>closed</option></term>
991              <listitem>
992                <para>in addition, allows access to standard pseudo
993                devices including
994                <filename>/dev/null</filename>,
995                <filename>/dev/zero</filename>,
996                <filename>/dev/full</filename>,
997                <filename>/dev/random</filename>, and
998                <filename>/dev/urandom</filename>.
999                </para>
1000              </listitem>
1001            </varlistentry>
1002
1003            <varlistentry>
1004              <term><option>auto</option></term>
1005              <listitem>
1006                <para>
1007                  in addition, allows access to all devices if no
1008                  explicit <varname>DeviceAllow=</varname> is present.
1009                  This is the default.
1010                </para>
1011              </listitem>
1012            </varlistentry>
1013          </variablelist>
1014        </listitem>
1015      </varlistentry>
1016
1017      <varlistentry>
1018        <term><varname>Slice=</varname></term>
1019
1020        <listitem>
1021          <para>The name of the slice unit to place the unit
1022          in. Defaults to <filename>system.slice</filename> for all
1023          non-instantiated units of all unit types (except for slice
1024          units themselves see below). Instance units are by default
1025          placed in a subslice of <filename>system.slice</filename>
1026          that is named after the template name.</para>
1027
1028          <para>This option may be used to arrange systemd units in a
1029          hierarchy of slices each of which might have resource
1030          settings applied.</para>
1031
1032          <para>For units of type slice, the only accepted value for
1033          this setting is the parent slice. Since the name of a slice
1034          unit implies the parent slice, it is hence redundant to ever
1035          set this parameter directly for slice units.</para>
1036
1037          <para>Special care should be taken when relying on the default slice assignment in templated service units
1038          that have <varname>DefaultDependencies=no</varname> set, see
1039          <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>, section
1040          "Default Dependencies" for details.</para>
1041
1042        </listitem>
1043      </varlistentry>
1044
1045      <varlistentry>
1046        <term><varname>Delegate=</varname></term>
1047
1048        <listitem>
1049          <para>Turns on delegation of further resource control partitioning to processes of the unit. Units where this
1050          is enabled may create and manage their own private subhierarchy of control groups below the control group of
1051          the unit itself. For unprivileged services (i.e. those using the <varname>User=</varname> setting) the unit's
1052          control group will be made accessible to the relevant user. When enabled the service manager will refrain
1053          from manipulating control groups or moving processes below the unit's control group, so that a clear concept
1054          of ownership is established: the control group tree above the unit's control group (i.e. towards the root
1055          control group) is owned and managed by the service manager of the host, while the control group tree below
1056          the unit's control group is owned and managed by the unit itself. Takes either a boolean argument or a list
1057          of control group controller names. If true, delegation is turned on, and all supported controllers are
1058          enabled for the unit, making them available to the unit's processes for management. If false, delegation is
1059          turned off entirely (and no additional controllers are enabled). If set to a list of controllers, delegation
1060          is turned on, and the specified controllers are enabled for the unit. Note that additional controllers than
1061          the ones specified might be made available as well, depending on configuration of the containing slice unit
1062          or other units contained in it. Note that assigning the empty string will enable delegation, but reset the
1063          list of controllers, all assignments prior to this will have no effect.  Defaults to false.</para>
1064
1065          <para>Note that controller delegation to less privileged code is only safe on the unified control group
1066          hierarchy. Accordingly, access to the specified controllers will not be granted to unprivileged services on
1067          the legacy hierarchy, even when requested.</para>
1068
1069          <xi:include href="supported-controllers.xml"  xpointer="controllers-text" />
1070
1071          <para>Not all of these controllers are available on all kernels however, and some are
1072          specific to the unified hierarchy while others are specific to the legacy hierarchy. Also note that the
1073          kernel might support further controllers, which aren't covered here yet as delegation is either not supported
1074          at all for them or not defined cleanly.</para>
1075
1076          <para>For further details on the delegation model consult <ulink
1077          url="https://systemd.io/CGROUP_DELEGATION">Control Group APIs and Delegation</ulink>.</para>
1078        </listitem>
1079      </varlistentry>
1080
1081      <varlistentry>
1082        <term><varname>DisableControllers=</varname></term>
1083
1084        <listitem>
1085          <para>Disables controllers from being enabled for a unit's children. If a controller listed is already in use
1086          in its subtree, the controller will be removed from the subtree. This can be used to avoid child units being
1087          able to implicitly or explicitly enable a controller. Defaults to not disabling any controllers.</para>
1088
1089          <para>It may not be possible to successfully disable a controller if the unit or any child of the unit in
1090          question delegates controllers to its children, as any delegated subtree of the cgroup hierarchy is unmanaged
1091          by systemd.</para>
1092
1093          <para>Multiple controllers may be specified, separated by spaces. You may also pass
1094          <varname>DisableControllers=</varname> multiple times, in which case each new instance adds another controller
1095          to disable. Passing <varname>DisableControllers=</varname> by itself with no controller name present resets
1096          the disabled controller list.</para>
1097
1098          <xi:include href="supported-controllers.xml"  xpointer="controllers-text" />
1099        </listitem>
1100      </varlistentry>
1101
1102      <varlistentry>
1103        <term><varname>ManagedOOMSwap=auto|kill</varname></term>
1104        <term><varname>ManagedOOMMemoryPressure=auto|kill</varname></term>
1105
1106        <listitem>
1107          <para>Specifies how
1108          <citerefentry><refentrytitle>systemd-oomd.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
1109          will act on this unit's cgroups. Defaults to <option>auto</option>.</para>
1110
1111          <para>When set to <option>kill</option>, the unit becomes a candidate for monitoring by
1112          <command>systemd-oomd</command>. If the cgroup passes the limits set by
1113          <citerefentry><refentrytitle>oomd.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry> or
1114          the unit configuration, <command>systemd-oomd</command> will select a descendant cgroup and send
1115          <constant>SIGKILL</constant> to all of the processes under it. You can find more details on
1116          candidates and kill behavior at
1117          <citerefentry><refentrytitle>systemd-oomd.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
1118          and
1119          <citerefentry><refentrytitle>oomd.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
1120
1121          <para>Setting either of these properties to <option>kill</option> will also result in
1122          <varname>After=</varname> and <varname>Wants=</varname> dependencies on
1123          <filename>systemd-oomd.service</filename> unless <varname>DefaultDependencies=no</varname>.</para>
1124
1125          <para>When set to <option>auto</option>, <command>systemd-oomd</command> will not actively use this
1126          cgroup's data for monitoring and detection. However, if an ancestor cgroup has one of these
1127          properties set to <option>kill</option>, a unit with <option>auto</option> can still be a candidate
1128          for <command>systemd-oomd</command> to terminate.</para>
1129        </listitem>
1130      </varlistentry>
1131
1132      <varlistentry>
1133        <term><varname>ManagedOOMMemoryPressureLimit=</varname></term>
1134
1135        <listitem>
1136          <para>Overrides the default memory pressure limit set by
1137          <citerefentry><refentrytitle>oomd.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry> for
1138          this unit (cgroup). Takes a percentage value between 0% and 100%, inclusive. This property is
1139          ignored unless <varname>ManagedOOMMemoryPressure=</varname><option>kill</option>. Defaults to 0%,
1140          which means to use the default set by
1141          <citerefentry><refentrytitle>oomd.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
1142          </para>
1143        </listitem>
1144      </varlistentry>
1145
1146      <varlistentry>
1147        <term><varname>ManagedOOMPreference=none|avoid|omit</varname></term>
1148
1149        <listitem>
1150          <para>Allows deprioritizing or omitting this unit's cgroup as a candidate when
1151          <command>systemd-oomd</command> needs to act. Requires support for extended attributes (see
1152          <citerefentry project='man-pages'><refentrytitle>xattr</refentrytitle><manvolnum>7</manvolnum></citerefentry>)
1153          in order to use <option>avoid</option> or <option>omit</option>. Additionally,
1154          <command>systemd-oomd</command> will ignore these extended attributes if the unit's cgroup is not
1155          owned by the root user.</para>
1156
1157          <para>If this property is set to <option>avoid</option>, the service manager will convey this to
1158          <command>systemd-oomd</command>, which will only select this cgroup if there are no other viable
1159          candidates.</para>
1160
1161          <para>If this property is set to <option>omit</option>, the service manager will convey this to
1162          <command>systemd-oomd</command>, which will ignore this cgroup as a candidate and will not perform
1163          any actions on it.</para>
1164
1165          <para>It is recommended to use <option>avoid</option> and <option>omit</option> sparingly, as it
1166          can adversely affect <command>systemd-oomd</command>'s kill behavior. Also note that these extended
1167          attributes are not applied recursively to cgroups under this unit's cgroup.</para>
1168
1169          <para>Defaults to <option>none</option> which means <command>systemd-oomd</command> will rank this
1170          unit's cgroup as defined in
1171          <citerefentry><refentrytitle>systemd-oomd.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
1172          and <citerefentry><refentrytitle>oomd.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
1173          </para>
1174        </listitem>
1175      </varlistentry>
1176    </variablelist>
1177  </refsect1>
1178
1179  <refsect1>
1180    <title>Deprecated Options</title>
1181
1182    <para>The following options are deprecated. Use the indicated superseding options instead:</para>
1183
1184    <variablelist class='unit-directives'>
1185
1186      <varlistentry>
1187        <term><varname>CPUShares=<replaceable>weight</replaceable></varname></term>
1188        <term><varname>StartupCPUShares=<replaceable>weight</replaceable></varname></term>
1189
1190        <listitem>
1191          <para>Assign the specified CPU time share weight to the processes executed. These options take an integer
1192          value and control the <literal>cpu.shares</literal> control group attribute. The allowed range is 2 to
1193          262144. Defaults to 1024. For details about this control group attribute, see <ulink
1194          url="https://www.kernel.org/doc/html/latest/scheduler/sched-design-CFS.html">CFS Scheduler</ulink>.
1195          The available CPU time is split up among all units within one slice relative to their CPU time share
1196          weight.</para>
1197
1198          <para>While <varname>StartupCPUShares=</varname> applies to the startup and shutdown phases of the system,
1199          <varname>CPUShares=</varname> applies to normal runtime of the system, and if the former is not set also to
1200          the startup and shutdown phases. Using <varname>StartupCPUShares=</varname> allows prioritizing specific services at
1201          boot-up and shutdown differently than during normal runtime.</para>
1202
1203          <para>Implies <literal>CPUAccounting=yes</literal>.</para>
1204
1205          <para>These settings are deprecated. Use <varname>CPUWeight=</varname> and
1206          <varname>StartupCPUWeight=</varname> instead.</para>
1207        </listitem>
1208      </varlistentry>
1209
1210      <varlistentry>
1211        <term><varname>MemoryLimit=<replaceable>bytes</replaceable></varname></term>
1212
1213        <listitem>
1214          <para>Specify the limit on maximum memory usage of the executed processes. The limit specifies how much
1215          process and kernel memory can be used by tasks in this unit. Takes a memory size in bytes. If the value is
1216          suffixed with K, M, G or T, the specified memory size is parsed as Kilobytes, Megabytes, Gigabytes, or
1217          Terabytes (with the base 1024), respectively. Alternatively, a percentage value may be specified, which is
1218          taken relative to the installed physical memory on the system. If assigned the special value
1219          <literal>infinity</literal>, no memory limit is applied. This controls the
1220          <literal>memory.limit_in_bytes</literal> control group attribute. For details about this control group
1221          attribute, see <ulink
1222          url="https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v1/memory.html">Memory Resource Controller</ulink>.</para>
1223
1224          <para>Implies <literal>MemoryAccounting=yes</literal>.</para>
1225
1226          <para>This setting is deprecated. Use <varname>MemoryMax=</varname> instead.</para>
1227        </listitem>
1228      </varlistentry>
1229
1230      <varlistentry>
1231        <term><varname>BlockIOAccounting=</varname></term>
1232
1233        <listitem>
1234          <para>Turn on Block I/O accounting for this unit, if the legacy control group hierarchy is used on the
1235          system. Takes a boolean argument. Note that turning on block I/O accounting for one unit will also implicitly
1236          turn it on for all units contained in the same slice and all for its parent slices and the units contained
1237          therein. The system default for this setting may be controlled with
1238          <varname>DefaultBlockIOAccounting=</varname> in
1239          <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
1240
1241          <para>This setting is deprecated. Use <varname>IOAccounting=</varname> instead.</para>
1242        </listitem>
1243      </varlistentry>
1244
1245      <varlistentry>
1246        <term><varname>BlockIOWeight=<replaceable>weight</replaceable></varname></term>
1247        <term><varname>StartupBlockIOWeight=<replaceable>weight</replaceable></varname></term>
1248
1249        <listitem><para>Set the default overall block I/O weight for the executed processes, if the legacy control
1250        group hierarchy is used on the system. Takes a single weight value (between 10 and 1000) to set the default
1251        block I/O weight. This controls the <literal>blkio.weight</literal> control group attribute, which defaults to
1252        500. For details about this control group attribute, see <ulink
1253        url="https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v1/blkio-controller.html">Block IO Controller</ulink>.
1254        The available I/O bandwidth is split up among all units within one slice relative to their block I/O
1255        weight.</para>
1256
1257        <para>While <varname>StartupBlockIOWeight=</varname> only
1258        applies to the startup and shutdown phases of the system,
1259        <varname>BlockIOWeight=</varname> applies to the later runtime
1260        of the system, and if the former is not set also to the
1261        startup and shutdown phases. This allows prioritizing specific services at
1262        boot-up and shutdown differently than during runtime.</para>
1263
1264        <para>Implies
1265        <literal>BlockIOAccounting=yes</literal>.</para>
1266
1267        <para>These settings are deprecated. Use <varname>IOWeight=</varname> and <varname>StartupIOWeight=</varname>
1268        instead.</para>
1269
1270      </listitem>
1271      </varlistentry>
1272
1273      <varlistentry>
1274        <term><varname>BlockIODeviceWeight=<replaceable>device</replaceable> <replaceable>weight</replaceable></varname></term>
1275
1276        <listitem>
1277          <para>Set the per-device overall block I/O weight for the executed processes, if the legacy control group
1278          hierarchy is used on the system. Takes a space-separated pair of a file path and a weight value to specify
1279          the device specific weight value, between 10 and 1000. (Example: "/dev/sda 500"). The file path may be
1280          specified as path to a block device node or as any other file, in which case the backing block device of the
1281          file system of the file is determined. This controls the <literal>blkio.weight_device</literal> control group
1282          attribute, which defaults to 1000. Use this option multiple times to set weights for multiple devices. For
1283          details about this control group attribute, see <ulink
1284          url="https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v1/blkio-controller.html">Block IO Controller</ulink>.</para>
1285
1286          <para>Implies
1287          <literal>BlockIOAccounting=yes</literal>.</para>
1288
1289          <para>This setting is deprecated. Use <varname>IODeviceWeight=</varname> instead.</para>
1290        </listitem>
1291      </varlistentry>
1292
1293      <varlistentry>
1294        <term><varname>BlockIOReadBandwidth=<replaceable>device</replaceable> <replaceable>bytes</replaceable></varname></term>
1295        <term><varname>BlockIOWriteBandwidth=<replaceable>device</replaceable> <replaceable>bytes</replaceable></varname></term>
1296
1297        <listitem>
1298          <para>Set the per-device overall block I/O bandwidth limit for the executed processes, if the legacy control
1299          group hierarchy is used on the system. Takes a space-separated pair of a file path and a bandwidth value (in
1300          bytes per second) to specify the device specific bandwidth. The file path may be a path to a block device
1301          node, or as any other file in which case the backing block device of the file system of the file is used. If
1302          the bandwidth is suffixed with K, M, G, or T, the specified bandwidth is parsed as Kilobytes, Megabytes,
1303          Gigabytes, or Terabytes, respectively, to the base of 1000. (Example:
1304          "/dev/disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0 5M"). This controls the
1305          <literal>blkio.throttle.read_bps_device</literal> and <literal>blkio.throttle.write_bps_device</literal>
1306          control group attributes. Use this option multiple times to set bandwidth limits for multiple devices. For
1307          details about these control group attributes, see <ulink
1308          url="https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v1/blkio-controller.html">Block IO Controller</ulink>.
1309          </para>
1310
1311          <para>Implies
1312          <literal>BlockIOAccounting=yes</literal>.</para>
1313
1314          <para>These settings are deprecated. Use <varname>IOReadBandwidthMax=</varname> and
1315          <varname>IOWriteBandwidthMax=</varname> instead.</para>
1316        </listitem>
1317      </varlistentry>
1318
1319    </variablelist>
1320  </refsect1>
1321
1322  <refsect1>
1323    <title>See Also</title>
1324    <para>
1325      <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
1326      <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
1327      <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
1328      <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
1329      <citerefentry><refentrytitle>systemd.slice</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
1330      <citerefentry><refentrytitle>systemd.scope</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
1331      <citerefentry><refentrytitle>systemd.socket</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
1332      <citerefentry><refentrytitle>systemd.mount</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
1333      <citerefentry><refentrytitle>systemd.swap</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
1334      <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
1335      <citerefentry><refentrytitle>systemd.directives</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
1336      <citerefentry><refentrytitle>systemd.special</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
1337      <citerefentry><refentrytitle>systemd-oomd.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
1338      The documentation for control groups and specific controllers in the Linux kernel:
1339      <ulink url="https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html">Control Groups v2</ulink>.
1340    </para>
1341  </refsect1>
1342</refentry>
1343