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