]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/systemd.resource-control.xml
8ebd162be799602b5a1703cfa0adb8aaef97a5aa
[thirdparty/systemd.git] / man / systemd.resource-control.xml
1 <?xml version='1.0'?>
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4
5 <!--
6 SPDX-License-Identifier: LGPL-2.1+
7 -->
8
9 <refentry id="systemd.resource-control">
10 <refentryinfo>
11 <title>systemd.resource-control</title>
12 <productname>systemd</productname>
13 </refentryinfo>
14
15 <refmeta>
16 <refentrytitle>systemd.resource-control</refentrytitle>
17 <manvolnum>5</manvolnum>
18 </refmeta>
19
20 <refnamediv>
21 <refname>systemd.resource-control</refname>
22 <refpurpose>Resource control unit settings</refpurpose>
23 </refnamediv>
24
25 <refsynopsisdiv>
26 <para>
27 <filename><replaceable>slice</replaceable>.slice</filename>,
28 <filename><replaceable>scope</replaceable>.scope</filename>,
29 <filename><replaceable>service</replaceable>.service</filename>,
30 <filename><replaceable>socket</replaceable>.socket</filename>,
31 <filename><replaceable>mount</replaceable>.mount</filename>,
32 <filename><replaceable>swap</replaceable>.swap</filename>
33 </para>
34 </refsynopsisdiv>
35
36 <refsect1>
37 <title>Description</title>
38
39 <para>Unit configuration files for services, slices, scopes, sockets, mount points, and swap devices share a subset
40 of configuration options for resource control of spawned processes. Internally, this relies on the Linux Control
41 Groups (cgroups) kernel concept for organizing processes in a hierarchical tree of named groups for the purpose of
42 resource management.</para>
43
44 <para>This man page lists the configuration options shared by
45 those six unit types. See
46 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>
47 for the common options of all unit configuration files, and
48 <citerefentry><refentrytitle>systemd.slice</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
49 <citerefentry><refentrytitle>systemd.scope</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
50 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
51 <citerefentry><refentrytitle>systemd.socket</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
52 <citerefentry><refentrytitle>systemd.mount</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
53 and
54 <citerefentry><refentrytitle>systemd.swap</refentrytitle><manvolnum>5</manvolnum></citerefentry>
55 for more information on the specific unit configuration files. The
56 resource control configuration options are configured in the
57 [Slice], [Scope], [Service], [Socket], [Mount], or [Swap]
58 sections, depending on the unit type.</para>
59
60 <para>In addition, options which control resources available to programs
61 <emphasis>executed</emphasis> by systemd are listed in
62 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
63 Those options complement options listed here.</para>
64
65 <para>See the <ulink
66 url="https://www.freedesktop.org/wiki/Software/systemd/ControlGroupInterface/">New
67 Control Group Interfaces</ulink> for an introduction on how to make
68 use of resource control APIs from programs.</para>
69 </refsect1>
70
71 <refsect1>
72 <title>Implicit Dependencies</title>
73
74 <para>The following dependencies are implicitly added:</para>
75
76 <itemizedlist>
77 <listitem><para>Units with the <varname>Slice=</varname> setting set automatically acquire
78 <varname>Requires=</varname> and <varname>After=</varname> dependencies on the specified
79 slice unit.</para></listitem>
80 </itemizedlist>
81 </refsect1>
82
83 <!-- We don't have any default dependency here. -->
84
85 <refsect1>
86 <title>Unified and Legacy Control Group Hierarchies</title>
87
88 <para>The unified control group hierarchy is the new version of kernel control group interface, see <ulink
89 url="https://www.kernel.org/doc/Documentation/cgroup-v2.txt">cgroup-v2.txt</ulink>. Depending on the resource type,
90 there are differences in resource control capabilities. Also, because of interface changes, some resource types
91 have separate set of options on the unified hierarchy.</para>
92
93 <para>
94 <variablelist>
95
96 <varlistentry>
97 <term><option>CPU</option></term>
98 <listitem>
99 <para><varname>CPUWeight=</varname> and <varname>StartupCPUWeight=</varname> replace
100 <varname>CPUShares=</varname> and <varname>StartupCPUShares=</varname>, respectively.</para>
101
102 <para>The <literal>cpuacct</literal> controller does not exist separately on the unified hierarchy.</para>
103 </listitem>
104 </varlistentry>
105
106 <varlistentry>
107 <term><option>Memory</option></term>
108 <listitem>
109 <para><varname>MemoryMax=</varname> replaces <varname>MemoryLimit=</varname>. <varname>MemoryLow=</varname>
110 and <varname>MemoryHigh=</varname> are effective only on unified hierarchy.</para>
111 </listitem>
112 </varlistentry>
113
114 <varlistentry>
115 <term><option>IO</option></term>
116 <listitem>
117 <para><varname>IO</varname> prefixed settings are a superset of and replace <varname>BlockIO</varname>
118 prefixed ones. On unified hierarchy, IO resource control also applies to buffered writes.</para>
119 </listitem>
120 </varlistentry>
121
122 </variablelist>
123 </para>
124
125 <para>To ease the transition, there is best-effort translation between the two versions of settings. For each
126 controller, if any of the settings for the unified hierarchy are present, all settings for the legacy hierarchy are
127 ignored. If the resulting settings are for the other type of hierarchy, the configurations are translated before
128 application.</para>
129
130 <para>Legacy control group hierarchy (see <ulink
131 url="https://www.kernel.org/doc/Documentation/cgroup-v1/cgroups.txt">cgroups.txt</ulink>), also called cgroup-v1,
132 doesn't allow safe delegation of controllers to unprivileged processes. If the system uses the legacy control group
133 hierarchy, resource control is disabled for systemd user instance, see
134 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>.
135 </para>
136 </refsect1>
137
138 <refsect1>
139 <title>Options</title>
140
141 <para>Units of the types listed above can have settings
142 for resource control configuration:</para>
143
144 <variablelist class='unit-directives'>
145
146 <varlistentry>
147 <term><varname>CPUAccounting=</varname></term>
148
149 <listitem>
150 <para>Turn on CPU usage accounting for this unit. Takes a
151 boolean argument. Note that turning on CPU accounting for
152 one unit will also implicitly turn it on for all units
153 contained in the same slice and for all its parent slices
154 and the units contained therein. The system default for this
155 setting may be controlled with
156 <varname>DefaultCPUAccounting=</varname> in
157 <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
158 </listitem>
159 </varlistentry>
160
161 <varlistentry>
162 <term><varname>CPUWeight=<replaceable>weight</replaceable></varname></term>
163 <term><varname>StartupCPUWeight=<replaceable>weight</replaceable></varname></term>
164
165 <listitem>
166 <para>Assign the specified CPU time weight to the processes executed, if the unified control group hierarchy
167 is used on the system. These options take an integer value and control the <literal>cpu.weight</literal>
168 control group attribute. The allowed range is 1 to 10000. Defaults to 100. For details about this control
169 group attribute, see <ulink
170 url="https://www.kernel.org/doc/Documentation/cgroup-v2.txt">cgroup-v2.txt</ulink> and <ulink
171 url="https://www.kernel.org/doc/Documentation/scheduler/sched-design-CFS.txt">sched-design-CFS.txt</ulink>.
172 The available CPU time is split up among all units within one slice relative to their CPU time weight.</para>
173
174 <para>While <varname>StartupCPUWeight=</varname> only applies to the startup phase of the system,
175 <varname>CPUWeight=</varname> applies to normal runtime of the system, and if the former is not set also to
176 the startup phase. Using <varname>StartupCPUWeight=</varname> allows prioritizing specific services at
177 boot-up differently than during normal runtime.</para>
178
179 <para>Implies <literal>CPUAccounting=true</literal>.</para>
180
181 <para>These settings replace <varname>CPUShares=</varname> and <varname>StartupCPUShares=</varname>.</para>
182 </listitem>
183 </varlistentry>
184
185 <varlistentry>
186 <term><varname>CPUQuota=</varname></term>
187
188 <listitem>
189 <para>Assign the specified CPU time quota to the processes executed. Takes a percentage value, suffixed with
190 "%". The percentage specifies how much CPU time the unit shall get at maximum, relative to the total CPU time
191 available on one CPU. Use values &gt; 100% for allotting CPU time on more than one CPU. This controls the
192 <literal>cpu.max</literal> attribute on the unified control group hierarchy and
193 <literal>cpu.cfs_quota_us</literal> on legacy. For details about these control group attributes, see <ulink
194 url="https://www.kernel.org/doc/Documentation/cgroup-v2.txt">cgroup-v2.txt</ulink> and <ulink
195 url="https://www.kernel.org/doc/Documentation/scheduler/sched-design-CFS.txt">sched-design-CFS.txt</ulink>.</para>
196
197 <para>Example: <varname>CPUQuota=20%</varname> ensures that the executed processes will never get more than
198 20% CPU time on one CPU.</para>
199
200 <para>Implies <literal>CPUAccounting=true</literal>.</para>
201 </listitem>
202 </varlistentry>
203
204 <varlistentry>
205 <term><varname>MemoryAccounting=</varname></term>
206
207 <listitem>
208 <para>Turn on process and kernel memory accounting for this
209 unit. Takes a boolean argument. Note that turning on memory
210 accounting for one unit will also implicitly turn it on for
211 all units contained in the same slice and for all its parent
212 slices and the units contained therein. The system default
213 for this setting may be controlled with
214 <varname>DefaultMemoryAccounting=</varname> in
215 <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
216 </listitem>
217 </varlistentry>
218
219 <varlistentry>
220 <term><varname>MemoryMin=<replaceable>bytes</replaceable></varname></term>
221
222 <listitem>
223 <para>Specify the memory usage protection of the executed processes in this unit. If the memory usages of
224 this unit and all its ancestors are below their minimum boundaries, this unit's memory won't be reclaimed.</para>
225
226 <para>Takes a memory size in bytes. If the value is suffixed with K, M, G or T, the specified memory size is
227 parsed as Kilobytes, Megabytes, Gigabytes, or Terabytes (with the base 1024), respectively. Alternatively, a
228 percentage value may be specified, which is taken relative to the installed physical memory on the
229 system. This controls the <literal>memory.min</literal> control group attribute. For details about this
230 control group attribute, see <ulink
231 url="https://www.kernel.org/doc/Documentation/cgroup-v2.txt">cgroup-v2.txt</ulink>.</para>
232
233 <para>Implies <literal>MemoryAccounting=true</literal>.</para>
234
235 <para>This setting is supported only if the unified control group hierarchy is used and disables
236 <varname>MemoryLimit=</varname>.</para>
237 </listitem>
238 </varlistentry>
239
240 <varlistentry>
241 <term><varname>MemoryLow=<replaceable>bytes</replaceable></varname></term>
242
243 <listitem>
244 <para>Specify the best-effort memory usage protection of the executed processes in this unit. If the memory
245 usages of this unit and all its ancestors are below their low boundaries, this unit's memory won't be
246 reclaimed as long as memory can be reclaimed from unprotected units.</para>
247
248 <para>Takes a memory size in bytes. If the value is suffixed with K, M, G or T, the specified memory size is
249 parsed as Kilobytes, Megabytes, Gigabytes, or Terabytes (with the base 1024), respectively. Alternatively, a
250 percentage value may be specified, which is taken relative to the installed physical memory on the
251 system. This controls the <literal>memory.low</literal> control group attribute. For details about this
252 control group attribute, see <ulink
253 url="https://www.kernel.org/doc/Documentation/cgroup-v2.txt">cgroup-v2.txt</ulink>.</para>
254
255 <para>Implies <literal>MemoryAccounting=true</literal>.</para>
256
257 <para>This setting is supported only if the unified control group hierarchy is used and disables
258 <varname>MemoryLimit=</varname>.</para>
259 </listitem>
260 </varlistentry>
261
262 <varlistentry>
263 <term><varname>MemoryHigh=<replaceable>bytes</replaceable></varname></term>
264
265 <listitem>
266 <para>Specify the high limit on memory usage of the executed processes in this unit. Memory usage may go
267 above the limit if unavoidable, but the processes are heavily slowed down and memory is taken away
268 aggressively in such cases. This is the main mechanism to control memory usage of a unit.</para>
269
270 <para>Takes a memory size in bytes. If the value is suffixed with K, M, G or T, the specified memory size is
271 parsed as Kilobytes, Megabytes, Gigabytes, or Terabytes (with the base 1024), respectively. Alternatively, a
272 percentage value may be specified, which is taken relative to the installed physical memory on the
273 system. If assigned the
274 special value <literal>infinity</literal>, no memory limit is applied. This controls the
275 <literal>memory.high</literal> control group attribute. For details about this control group attribute, see
276 <ulink url="https://www.kernel.org/doc/Documentation/cgroup-v2.txt">cgroup-v2.txt</ulink>.</para>
277
278 <para>Implies <literal>MemoryAccounting=true</literal>.</para>
279
280 <para>This setting is supported only if the unified control group hierarchy is used and disables
281 <varname>MemoryLimit=</varname>.</para>
282 </listitem>
283 </varlistentry>
284
285 <varlistentry>
286 <term><varname>MemoryMax=<replaceable>bytes</replaceable></varname></term>
287
288 <listitem>
289 <para>Specify the absolute limit on memory usage of the executed processes in this unit. If memory usage
290 cannot be contained under the limit, out-of-memory killer is invoked inside the unit. It is recommended to
291 use <varname>MemoryHigh=</varname> as the main control mechanism and use <varname>MemoryMax=</varname> as the
292 last line of defense.</para>
293
294 <para>Takes a memory size in bytes. If the value is suffixed with K, M, G or T, the specified memory size is
295 parsed as Kilobytes, Megabytes, Gigabytes, or Terabytes (with the base 1024), respectively. Alternatively, a
296 percentage value may be specified, which is taken relative to the installed physical memory on the system. If
297 assigned the special value <literal>infinity</literal>, no memory limit is applied. This controls the
298 <literal>memory.max</literal> control group attribute. For details about this control group attribute, see
299 <ulink url="https://www.kernel.org/doc/Documentation/cgroup-v2.txt">cgroup-v2.txt</ulink>.</para>
300
301 <para>Implies <literal>MemoryAccounting=true</literal>.</para>
302
303 <para>This setting replaces <varname>MemoryLimit=</varname>.</para>
304 </listitem>
305 </varlistentry>
306
307 <varlistentry>
308 <term><varname>MemorySwapMax=<replaceable>bytes</replaceable></varname></term>
309
310 <listitem>
311 <para>Specify the absolute limit on swap usage of the executed processes in this unit.</para>
312
313 <para>Takes a swap size in bytes. If the value is suffixed with K, M, G or T, the specified swap size is
314 parsed as Kilobytes, Megabytes, Gigabytes, or Terabytes (with the base 1024), respectively. If assigned the
315 special value <literal>infinity</literal>, no swap limit is applied. This controls the
316 <literal>memory.swap.max</literal> control group attribute. For details about this control group attribute,
317 see <ulink url="https://www.kernel.org/doc/Documentation/cgroup-v2.txt">cgroup-v2.txt</ulink>.</para>
318
319 <para>Implies <literal>MemoryAccounting=true</literal>.</para>
320
321 <para>This setting is supported only if the unified control group hierarchy is used and disables
322 <varname>MemoryLimit=</varname>.</para>
323 </listitem>
324 </varlistentry>
325
326 <varlistentry>
327 <term><varname>TasksAccounting=</varname></term>
328
329 <listitem>
330 <para>Turn on task accounting for this unit. Takes a
331 boolean argument. If enabled, the system manager will keep
332 track of the number of tasks in the unit. The number of
333 tasks accounted this way includes both kernel threads and
334 userspace processes, with each thread counting
335 individually. Note that turning on tasks accounting for one
336 unit will also implicitly turn it on for all units contained
337 in the same slice and for all its parent slices and the
338 units contained therein. The system default for this setting
339 may be controlled with
340 <varname>DefaultTasksAccounting=</varname> in
341 <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
342 </listitem>
343 </varlistentry>
344
345 <varlistentry>
346 <term><varname>TasksMax=<replaceable>N</replaceable></varname></term>
347
348 <listitem>
349 <para>Specify the maximum number of tasks that may be created in the unit. This ensures that the number of
350 tasks accounted for the unit (see above) stays below a specific limit. This either takes an absolute number
351 of tasks or a percentage value that is taken relative to the configured maximum number of tasks on the
352 system. If assigned the special value <literal>infinity</literal>, no tasks limit is applied. This controls
353 the <literal>pids.max</literal> control group attribute. For details about this control group attribute, see
354 <ulink url="https://www.kernel.org/doc/Documentation/cgroup-v1/pids.txt">pids.txt</ulink>.</para>
355
356 <para>Implies <literal>TasksAccounting=true</literal>. The
357 system default for this setting may be controlled with
358 <varname>DefaultTasksMax=</varname> in
359 <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
360 </listitem>
361 </varlistentry>
362
363 <varlistentry>
364 <term><varname>IOAccounting=</varname></term>
365
366 <listitem>
367 <para>Turn on Block I/O accounting for this unit, if the unified control group hierarchy is used on the
368 system. Takes a boolean argument. Note that turning on block I/O accounting for one unit will also implicitly
369 turn it on for all units contained in the same slice and all for its parent slices and the units contained
370 therein. The system default for this setting may be controlled with <varname>DefaultIOAccounting=</varname>
371 in
372 <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
373
374 <para>This setting replaces <varname>BlockIOAccounting=</varname> and disables settings prefixed with
375 <varname>BlockIO</varname> or <varname>StartupBlockIO</varname>.</para>
376 </listitem>
377 </varlistentry>
378
379 <varlistentry>
380 <term><varname>IOWeight=<replaceable>weight</replaceable></varname></term>
381 <term><varname>StartupIOWeight=<replaceable>weight</replaceable></varname></term>
382
383 <listitem>
384 <para>Set the default overall block I/O weight for the executed processes, if the unified control group
385 hierarchy is used on the system. Takes a single weight value (between 1 and 10000) to set the default block
386 I/O weight. This controls the <literal>io.weight</literal> control group attribute, which defaults to
387 100. For details about this control group attribute, see <ulink
388 url="https://www.kernel.org/doc/Documentation/cgroup-v2.txt">cgroup-v2.txt</ulink>. The available I/O
389 bandwidth is split up among all units within one slice relative to their block I/O weight.</para>
390
391 <para>While <varname>StartupIOWeight=</varname> only applies
392 to the startup phase of the system,
393 <varname>IOWeight=</varname> applies to the later runtime of
394 the system, and if the former is not set also to the startup
395 phase. This allows prioritizing specific services at boot-up
396 differently than during runtime.</para>
397
398 <para>Implies <literal>IOAccounting=true</literal>.</para>
399
400 <para>These settings replace <varname>BlockIOWeight=</varname> and <varname>StartupBlockIOWeight=</varname>
401 and disable settings prefixed with <varname>BlockIO</varname> or <varname>StartupBlockIO</varname>.</para>
402 </listitem>
403 </varlistentry>
404
405 <varlistentry>
406 <term><varname>IODeviceWeight=<replaceable>device</replaceable> <replaceable>weight</replaceable></varname></term>
407
408 <listitem>
409 <para>Set the per-device overall block I/O weight for the executed processes, if the unified control group
410 hierarchy is used on the system. Takes a space-separated pair of a file path and a weight value to specify
411 the device specific weight value, between 1 and 10000. (Example: "/dev/sda 1000"). The file path may be
412 specified as path to a block device node or as any other file, in which case the backing block device of the
413 file system of the file is determined. This controls the <literal>io.weight</literal> control group
414 attribute, which defaults to 100. Use this option multiple times to set weights for multiple devices. For
415 details about this control group attribute, see <ulink
416 url="https://www.kernel.org/doc/Documentation/cgroup-v2.txt">cgroup-v2.txt</ulink>.</para>
417
418 <para>Implies <literal>IOAccounting=true</literal>.</para>
419
420 <para>This setting replaces <varname>BlockIODeviceWeight=</varname> and disables settings prefixed with
421 <varname>BlockIO</varname> or <varname>StartupBlockIO</varname>.</para>
422 </listitem>
423 </varlistentry>
424
425 <varlistentry>
426 <term><varname>IOReadBandwidthMax=<replaceable>device</replaceable> <replaceable>bytes</replaceable></varname></term>
427 <term><varname>IOWriteBandwidthMax=<replaceable>device</replaceable> <replaceable>bytes</replaceable></varname></term>
428
429 <listitem>
430 <para>Set the per-device overall block I/O bandwidth maximum limit for the executed processes, if the unified
431 control group hierarchy is used on the system. This limit is not work-conserving and the executed processes
432 are not allowed to use more even if the device has idle capacity. Takes a space-separated pair of a file
433 path and a bandwidth value (in bytes per second) to specify the device specific bandwidth. The file path may
434 be a path to a block device node, or as any other file in which case the backing block device of the file
435 system of the file is used. If the bandwidth is suffixed with K, M, G, or T, the specified bandwidth is
436 parsed as Kilobytes, Megabytes, Gigabytes, or Terabytes, respectively, to the base of 1000. (Example:
437 "/dev/disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0 5M"). This controls the <literal>io.max</literal> control
438 group attributes. Use this option multiple times to set bandwidth limits for multiple devices. For details
439 about this control group attribute, see <ulink
440 url="https://www.kernel.org/doc/Documentation/cgroup-v2.txt">cgroup-v2.txt</ulink>.
441 </para>
442
443 <para>Implies <literal>IOAccounting=true</literal>.</para>
444
445 <para>These settings replace <varname>BlockIOReadBandwidth=</varname> and
446 <varname>BlockIOWriteBandwidth=</varname> and disable settings prefixed with <varname>BlockIO</varname> or
447 <varname>StartupBlockIO</varname>.</para>
448 </listitem>
449 </varlistentry>
450
451 <varlistentry>
452 <term><varname>IOReadIOPSMax=<replaceable>device</replaceable> <replaceable>IOPS</replaceable></varname></term>
453 <term><varname>IOWriteIOPSMax=<replaceable>device</replaceable> <replaceable>IOPS</replaceable></varname></term>
454
455 <listitem>
456 <para>Set the per-device overall block I/O IOs-Per-Second maximum limit for the executed processes, if the
457 unified control group hierarchy is used on the system. This limit is not work-conserving and the executed
458 processes are not allowed to use more even if the device has idle capacity. Takes a space-separated pair of
459 a file path and an IOPS value to specify the device specific IOPS. The file path may be a path to a block
460 device node, or as any other file in which case the backing block device of the file system of the file is
461 used. If the IOPS is suffixed with K, M, G, or T, the specified IOPS is parsed as KiloIOPS, MegaIOPS,
462 GigaIOPS, or TeraIOPS, respectively, to the base of 1000. (Example:
463 "/dev/disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0 1K"). This controls the <literal>io.max</literal> control
464 group attributes. Use this option multiple times to set IOPS limits for multiple devices. For details about
465 this control group attribute, see <ulink
466 url="https://www.kernel.org/doc/Documentation/cgroup-v2.txt">cgroup-v2.txt</ulink>.
467 </para>
468
469 <para>Implies <literal>IOAccounting=true</literal>.</para>
470
471 <para>These settings are supported only if the unified control group hierarchy is used and disable settings
472 prefixed with <varname>BlockIO</varname> or <varname>StartupBlockIO</varname>.</para>
473 </listitem>
474 </varlistentry>
475
476 <varlistentry>
477 <term><varname>IPAccounting=</varname></term>
478
479 <listitem>
480 <para>Takes a boolean argument. If true, turns on IPv4 and IPv6 network traffic accounting for packets sent
481 or received by the unit. When this option is turned on, all IPv4 and IPv6 sockets created by any process of
482 the unit are accounted for.</para>
483
484 <para>When this option is used in socket units, it applies to all IPv4 and IPv6 sockets
485 associated with it (including both listening and connection sockets where this applies). Note that for
486 socket-activated services, this configuration setting and the accounting data of the service unit and the
487 socket unit are kept separate, and displayed separately. No propagation of the setting and the collected
488 statistics is done, in either direction. Moreover, any traffic sent or received on any of the socket unit's
489 sockets is accounted to the socket unit — and never to the service unit it might have activated, even if the
490 socket is used by it.</para>
491
492 <para>The system default for this setting may be controlled with <varname>DefaultIPAccounting=</varname> in
493 <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
494 </listitem>
495 </varlistentry>
496
497 <varlistentry>
498 <term><varname>IPAddressAllow=<replaceable>ADDRESS[/PREFIXLENGTH]…</replaceable></varname></term>
499 <term><varname>IPAddressDeny=<replaceable>ADDRESS[/PREFIXLENGTH]…</replaceable></varname></term>
500
501 <listitem>
502 <para>Turn on address range network traffic filtering for packets sent and received over AF_INET and AF_INET6
503 sockets. Both directives take a space separated list of IPv4 or IPv6 addresses, each optionally suffixed
504 with an address prefix length (separated by a <literal>/</literal> character). If the latter is omitted, the
505 address is considered a host address, i.e. the prefix covers the whole address (32 for IPv4, 128 for IPv6).
506 </para>
507
508 <para>The access lists configured with this option are applied to all sockets created by processes of this
509 unit (or in the case of socket units, associated with it). The lists are implicitly combined with any lists
510 configured for any of the parent slice units this unit might be a member of. By default all access lists are
511 empty. When configured the lists are enforced as follows:</para>
512
513 <itemizedlist>
514 <listitem><para>Access will be granted in case its destination/source address matches any entry in the
515 <varname>IPAddressAllow=</varname> setting.</para></listitem>
516
517 <listitem><para>Otherwise, access will be denied in case its destination/source address matches any entry
518 in the <varname>IPAddressDeny=</varname> setting.</para></listitem>
519
520 <listitem><para>Otherwise, access will be granted.</para></listitem>
521 </itemizedlist>
522
523 <para>In order to implement a whitelisting IP firewall, it is recommended to use a
524 <varname>IPAddressDeny=</varname><constant>any</constant> setting on an upper-level slice unit (such as the
525 root slice <filename>-.slice</filename> or the slice containing all system services
526 <filename>system.slice</filename> – see
527 <citerefentry><refentrytitle>systemd.special</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
528 details on these slice units), plus individual per-service <varname>IPAddressAllow=</varname> lines
529 permitting network access to relevant services, and only them.</para>
530
531 <para>Note that for socket-activated services, the IP access list configured on the socket unit applies to
532 all sockets associated with it directly, but not to any sockets created by the ultimately activated services
533 for it. Conversely, the IP access list configured for the service is not applied to any sockets passed into
534 the service via socket activation. Thus, it is usually a good idea, to replicate the IP access lists on both
535 the socket and the service unit, however it often makes sense to maintain one list more open and the other
536 one more restricted, depending on the usecase.</para>
537
538 <para>If these settings are used multiple times in the same unit the specified lists are combined. If an
539 empty string is assigned to these settings the specific access list is reset and all previous settings undone.</para>
540
541 <para>In place of explicit IPv4 or IPv6 address and prefix length specifications a small set of symbolic
542 names may be used. The following names are defined:</para>
543
544 <table>
545 <title>Special address/network names</title>
546
547 <tgroup cols='3'>
548 <colspec colname='name'/>
549 <colspec colname='definition'/>
550 <colspec colname='meaning'/>
551
552 <thead>
553 <row>
554 <entry>Symbolic Name</entry>
555 <entry>Definition</entry>
556 <entry>Meaning</entry>
557 </row>
558 </thead>
559
560 <tbody>
561 <row>
562 <entry><constant>any</constant></entry>
563 <entry>0.0.0.0/0 ::/0</entry>
564 <entry>Any host</entry>
565 </row>
566
567 <row>
568 <entry><constant>localhost</constant></entry>
569 <entry>127.0.0.0/8 ::1/128</entry>
570 <entry>All addresses on the local loopback</entry>
571 </row>
572
573 <row>
574 <entry><constant>link-local</constant></entry>
575 <entry>169.254.0.0/16 fe80::/64</entry>
576 <entry>All link-local IP addresses</entry>
577 </row>
578
579 <row>
580 <entry><constant>multicast</constant></entry>
581 <entry>224.0.0.0/4 ff00::/8</entry>
582 <entry>All IP multicasting addresses</entry>
583 </row>
584 </tbody>
585 </tgroup>
586 </table>
587
588 <para>Note that these settings might not be supported on some systems (for example if eBPF control group
589 support is not enabled in the underlying kernel or container manager). These settings will have no effect in
590 that case. If compatibility with such systems is desired it is hence recommended to not exclusively rely on
591 them for IP security.</para>
592 </listitem>
593 </varlistentry>
594
595 <varlistentry>
596 <term><varname>DeviceAllow=</varname></term>
597
598 <listitem>
599 <para>Control access to specific device nodes by the
600 executed processes. Takes two space-separated strings: a
601 device node specifier followed by a combination of
602 <constant>r</constant>, <constant>w</constant>,
603 <constant>m</constant> to control
604 <emphasis>r</emphasis>eading, <emphasis>w</emphasis>riting,
605 or creation of the specific device node(s) by the unit
606 (<emphasis>m</emphasis>knod), respectively. This controls
607 the <literal>devices.allow</literal> and
608 <literal>devices.deny</literal> control group
609 attributes. For details about these control group
610 attributes, see <ulink
611 url="https://www.kernel.org/doc/Documentation/cgroup-v1/devices.txt">devices.txt</ulink>.</para>
612
613 <para>The device node specifier is either a path to a device
614 node in the file system, starting with
615 <filename>/dev/</filename>, or a string starting with either
616 <literal>char-</literal> or <literal>block-</literal>
617 followed by a device group name, as listed in
618 <filename>/proc/devices</filename>. The latter is useful to
619 whitelist all current and future devices belonging to a
620 specific device group at once. The device group is matched
621 according to filename globbing rules, you may hence use the
622 <literal>*</literal> and <literal>?</literal>
623 wildcards. Examples: <filename>/dev/sda5</filename> is a
624 path to a device node, referring to an ATA or SCSI block
625 device. <literal>char-pts</literal> and
626 <literal>char-alsa</literal> are specifiers for all pseudo
627 TTYs and all ALSA sound devices,
628 respectively. <literal>char-cpu/*</literal> is a specifier
629 matching all CPU related device groups.</para>
630 </listitem>
631 </varlistentry>
632
633 <varlistentry>
634 <term><varname>DevicePolicy=auto|closed|strict</varname></term>
635
636 <listitem>
637 <para>
638 Control the policy for allowing device access:
639 </para>
640 <variablelist>
641 <varlistentry>
642 <term><option>strict</option></term>
643 <listitem>
644 <para>means to only allow types of access that are
645 explicitly specified.</para>
646 </listitem>
647 </varlistentry>
648
649 <varlistentry>
650 <term><option>closed</option></term>
651 <listitem>
652 <para>in addition, allows access to standard pseudo
653 devices including
654 <filename>/dev/null</filename>,
655 <filename>/dev/zero</filename>,
656 <filename>/dev/full</filename>,
657 <filename>/dev/random</filename>, and
658 <filename>/dev/urandom</filename>.
659 </para>
660 </listitem>
661 </varlistentry>
662
663 <varlistentry>
664 <term><option>auto</option></term>
665 <listitem>
666 <para>
667 in addition, allows access to all devices if no
668 explicit <varname>DeviceAllow=</varname> is present.
669 This is the default.
670 </para>
671 </listitem>
672 </varlistentry>
673 </variablelist>
674 </listitem>
675 </varlistentry>
676
677 <varlistentry>
678 <term><varname>Slice=</varname></term>
679
680 <listitem>
681 <para>The name of the slice unit to place the unit
682 in. Defaults to <filename>system.slice</filename> for all
683 non-instantiated units of all unit types (except for slice
684 units themselves see below). Instance units are by default
685 placed in a subslice of <filename>system.slice</filename>
686 that is named after the template name.</para>
687
688 <para>This option may be used to arrange systemd units in a
689 hierarchy of slices each of which might have resource
690 settings applied.</para>
691
692 <para>For units of type slice, the only accepted value for
693 this setting is the parent slice. Since the name of a slice
694 unit implies the parent slice, it is hence redundant to ever
695 set this parameter directly for slice units.</para>
696
697 <para>Special care should be taken when relying on the default slice assignment in templated service units
698 that have <varname>DefaultDependencies=no</varname> set, see
699 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>, section
700 "Default Dependencies" for details.</para>
701
702 </listitem>
703 </varlistentry>
704
705 <varlistentry>
706 <term><varname>Delegate=</varname></term>
707
708 <listitem>
709 <para>Turns on delegation of further resource control partitioning to processes of the unit. Units where this
710 is enabled may create and manage their own private subhierarchy of control groups below the control group of
711 the unit itself. For unprivileged services (i.e. those using the <varname>User=</varname> setting) the unit's
712 control group will be made accessible to the relevant user. When enabled the service manager will refrain
713 from manipulating control groups or moving processes below the unit's control group, so that a clear concept
714 of ownership is established: the control group tree above the unit's control group (i.e. towards the root
715 control group) is owned and managed by the service manager of the host, while the control group tree below
716 the unit's control group is owned and managed by the unit itself. Takes either a boolean argument or a list
717 of control group controller names. If true, delegation is turned on, and all supported controllers are
718 enabled for the unit, making them available to the unit's processes for management. If false, delegation is
719 turned off entirely (and no additional controllers are enabled). If set to a list of controllers, delegation
720 is turned on, and the specified controllers are enabled for the unit. Note that additional controllers than
721 the ones specified might be made available as well, depending on configuration of the containing slice unit
722 or other units contained in it. Note that assigning the empty string will enable delegation, but reset the
723 list of controllers, all assignments prior to this will have no effect. Defaults to false.</para>
724
725 <para>Note that controller delegation to less privileged code is only safe on the unified control group
726 hierarchy. Accordingly, access to the specified controllers will not be granted to unprivileged services on
727 the legacy hierarchy, even when requested.</para>
728
729 <para>The following controller names may be specified: <option>cpu</option>, <option>cpuacct</option>,
730 <option>io</option>, <option>blkio</option>, <option>memory</option>, <option>devices</option>,
731 <option>pids</option>. Not all of these controllers are available on all kernels however, and some are
732 specific to the unified hierarchy while others are specific to the legacy hierarchy. Also note that the
733 kernel might support further controllers, which aren't covered here yet as delegation is either not supported
734 at all for them or not defined cleanly.</para>
735 </listitem>
736 </varlistentry>
737
738 </variablelist>
739 </refsect1>
740
741 <refsect1>
742 <title>Deprecated Options</title>
743
744 <para>The following options are deprecated. Use the indicated superseding options instead:</para>
745
746 <variablelist class='unit-directives'>
747
748 <varlistentry>
749 <term><varname>CPUShares=<replaceable>weight</replaceable></varname></term>
750 <term><varname>StartupCPUShares=<replaceable>weight</replaceable></varname></term>
751
752 <listitem>
753 <para>Assign the specified CPU time share weight to the processes executed. These options take an integer
754 value and control the <literal>cpu.shares</literal> control group attribute. The allowed range is 2 to
755 262144. Defaults to 1024. For details about this control group attribute, see <ulink
756 url="https://www.kernel.org/doc/Documentation/scheduler/sched-design-CFS.txt">sched-design-CFS.txt</ulink>.
757 The available CPU time is split up among all units within one slice relative to their CPU time share
758 weight.</para>
759
760 <para>While <varname>StartupCPUShares=</varname> only applies to the startup phase of the system,
761 <varname>CPUShares=</varname> applies to normal runtime of the system, and if the former is not set also to
762 the startup phase. Using <varname>StartupCPUShares=</varname> allows prioritizing specific services at
763 boot-up differently than during normal runtime.</para>
764
765 <para>Implies <literal>CPUAccounting=true</literal>.</para>
766
767 <para>These settings are deprecated. Use <varname>CPUWeight=</varname> and
768 <varname>StartupCPUWeight=</varname> instead.</para>
769 </listitem>
770 </varlistentry>
771
772 <varlistentry>
773 <term><varname>MemoryLimit=<replaceable>bytes</replaceable></varname></term>
774
775 <listitem>
776 <para>Specify the limit on maximum memory usage of the executed processes. The limit specifies how much
777 process and kernel memory can be used by tasks in this unit. Takes a memory size in bytes. If the value is
778 suffixed with K, M, G or T, the specified memory size is parsed as Kilobytes, Megabytes, Gigabytes, or
779 Terabytes (with the base 1024), respectively. Alternatively, a percentage value may be specified, which is
780 taken relative to the installed physical memory on the system. If assigned the special value
781 <literal>infinity</literal>, no memory limit is applied. This controls the
782 <literal>memory.limit_in_bytes</literal> control group attribute. For details about this control group
783 attribute, see <ulink
784 url="https://www.kernel.org/doc/Documentation/cgroup-v1/memory.txt">memory.txt</ulink>.</para>
785
786 <para>Implies <literal>MemoryAccounting=true</literal>.</para>
787
788 <para>This setting is deprecated. Use <varname>MemoryMax=</varname> instead.</para>
789 </listitem>
790 </varlistentry>
791
792 <varlistentry>
793 <term><varname>BlockIOAccounting=</varname></term>
794
795 <listitem>
796 <para>Turn on Block I/O accounting for this unit, if the legacy control group hierarchy is used on the
797 system. Takes a boolean argument. Note that turning on block I/O accounting for one unit will also implicitly
798 turn it on for all units contained in the same slice and all for its parent slices and the units contained
799 therein. The system default for this setting may be controlled with
800 <varname>DefaultBlockIOAccounting=</varname> in
801 <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
802
803 <para>This setting is deprecated. Use <varname>IOAccounting=</varname> instead.</para>
804 </listitem>
805 </varlistentry>
806
807 <varlistentry>
808 <term><varname>BlockIOWeight=<replaceable>weight</replaceable></varname></term>
809 <term><varname>StartupBlockIOWeight=<replaceable>weight</replaceable></varname></term>
810
811 <listitem><para>Set the default overall block I/O weight for the executed processes, if the legacy control
812 group hierarchy is used on the system. Takes a single weight value (between 10 and 1000) to set the default
813 block I/O weight. This controls the <literal>blkio.weight</literal> control group attribute, which defaults to
814 500. For details about this control group attribute, see <ulink
815 url="https://www.kernel.org/doc/Documentation/cgroup-v1/blkio-controller.txt">blkio-controller.txt</ulink>.
816 The available I/O bandwidth is split up among all units within one slice relative to their block I/O
817 weight.</para>
818
819 <para>While <varname>StartupBlockIOWeight=</varname> only
820 applies to the startup phase of the system,
821 <varname>BlockIOWeight=</varname> applies to the later runtime
822 of the system, and if the former is not set also to the
823 startup phase. This allows prioritizing specific services at
824 boot-up differently than during runtime.</para>
825
826 <para>Implies
827 <literal>BlockIOAccounting=true</literal>.</para>
828
829 <para>These settings are deprecated. Use <varname>IOWeight=</varname> and <varname>StartupIOWeight=</varname>
830 instead.</para>
831
832 </listitem>
833 </varlistentry>
834
835 <varlistentry>
836 <term><varname>BlockIODeviceWeight=<replaceable>device</replaceable> <replaceable>weight</replaceable></varname></term>
837
838 <listitem>
839 <para>Set the per-device overall block I/O weight for the executed processes, if the legacy control group
840 hierarchy is used on the system. Takes a space-separated pair of a file path and a weight value to specify
841 the device specific weight value, between 10 and 1000. (Example: "/dev/sda 500"). The file path may be
842 specified as path to a block device node or as any other file, in which case the backing block device of the
843 file system of the file is determined. This controls the <literal>blkio.weight_device</literal> control group
844 attribute, which defaults to 1000. Use this option multiple times to set weights for multiple devices. For
845 details about this control group attribute, see <ulink
846 url="https://www.kernel.org/doc/Documentation/cgroup-v1/blkio-controller.txt">blkio-controller.txt</ulink>.</para>
847
848 <para>Implies
849 <literal>BlockIOAccounting=true</literal>.</para>
850
851 <para>This setting is deprecated. Use <varname>IODeviceWeight=</varname> instead.</para>
852 </listitem>
853 </varlistentry>
854
855 <varlistentry>
856 <term><varname>BlockIOReadBandwidth=<replaceable>device</replaceable> <replaceable>bytes</replaceable></varname></term>
857 <term><varname>BlockIOWriteBandwidth=<replaceable>device</replaceable> <replaceable>bytes</replaceable></varname></term>
858
859 <listitem>
860 <para>Set the per-device overall block I/O bandwidth limit for the executed processes, if the legacy control
861 group hierarchy is used on the system. Takes a space-separated pair of a file path and a bandwidth value (in
862 bytes per second) to specify the device specific bandwidth. The file path may be a path to a block device
863 node, or as any other file in which case the backing block device of the file system of the file is used. If
864 the bandwidth is suffixed with K, M, G, or T, the specified bandwidth is parsed as Kilobytes, Megabytes,
865 Gigabytes, or Terabytes, respectively, to the base of 1000. (Example:
866 "/dev/disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0 5M"). This controls the
867 <literal>blkio.throttle.read_bps_device</literal> and <literal>blkio.throttle.write_bps_device</literal>
868 control group attributes. Use this option multiple times to set bandwidth limits for multiple devices. For
869 details about these control group attributes, see <ulink
870 url="https://www.kernel.org/doc/Documentation/cgroup-v1/blkio-controller.txt">blkio-controller.txt</ulink>.
871 </para>
872
873 <para>Implies
874 <literal>BlockIOAccounting=true</literal>.</para>
875
876 <para>These settings are deprecated. Use <varname>IOReadBandwidthMax=</varname> and
877 <varname>IOWriteBandwidthMax=</varname> instead.</para>
878 </listitem>
879 </varlistentry>
880
881 </variablelist>
882 </refsect1>
883
884 <refsect1>
885 <title>See Also</title>
886 <para>
887 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
888 <citerefentry><refentrytitle>systemd.unit</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
889 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
890 <citerefentry><refentrytitle>systemd.slice</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
891 <citerefentry><refentrytitle>systemd.scope</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
892 <citerefentry><refentrytitle>systemd.socket</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
893 <citerefentry><refentrytitle>systemd.mount</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
894 <citerefentry><refentrytitle>systemd.swap</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
895 <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
896 <citerefentry><refentrytitle>systemd.directives</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
897 <citerefentry><refentrytitle>systemd.special</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
898 The documentation for control groups and specific controllers in the Linux kernel:
899 <ulink url="https://www.kernel.org/doc/Documentation/cgroup-v1/cgroups.txt">cgroups.txt</ulink>,
900 <ulink url="https://www.kernel.org/doc/Documentation/cgroup-v1/cpuacct.txt">cpuacct.txt</ulink>,
901 <ulink url="https://www.kernel.org/doc/Documentation/cgroup-v1/memory.txt">memory.txt</ulink>,
902 <ulink url="https://www.kernel.org/doc/Documentation/cgroup-v1/blkio-controller.txt">blkio-controller.txt</ulink>.
903 </para>
904 </refsect1>
905 </refentry>