1
1
.. _cgroups :
2
2
3
- ##############################
4
- Limiting Container Resources
5
- ##############################
3
+ ############################
4
+ Limiting Container Resources
5
+ ############################
6
6
7
7
It's often useful to limit the resources that are consumed by a container, e.g.
8
8
to allow the container to only use 1 CPU, or 50% of the RAM on the system.
@@ -23,16 +23,16 @@ There are three ways to apply limits to a container that is run with
23
23
{Singularity}:
24
24
25
25
* Using the command line flags introduced in v3.10.
26
-
26
+
27
27
* Using the ``--apply-cgroups `` flag to apply a ``cgroups.toml `` file that
28
28
defines the resource limits.
29
29
30
30
* Using external tools such as ``systemd-run `` tool to apply limits, and then
31
31
call ``singularity ``.
32
32
33
- ******************************
34
- Requirements - Linux Cgroups
35
- ******************************
33
+ ****************************
34
+ Requirements - Linux Cgroups
35
+ ****************************
36
36
37
37
Resource limits are applied to containers using functionality in the Linux
38
38
kernel known as *control groups * or *cgroups *. There are two versions of
@@ -63,9 +63,9 @@ about this.
63
63
64
64
.. _cgroup_flags :
65
65
66
- ***************************
67
- Command Line Limit Flags
68
- ***************************
66
+ *************************
67
+ Command Line Limit Flags
68
+ *************************
69
69
70
70
{Singularity} 3.10 introduced a number of simple command line flags that you can
71
71
use with `shell/run/exec ` and the `instance ` commands to directly apply resource
@@ -88,7 +88,7 @@ use. The minimum is ``0.01`` or one tenth of a physical CPU. The maximum is the
88
88
number of CPU cores on your system.
89
89
90
90
.. code ::
91
-
91
+
92
92
# Limit container to 3.5 CPUs
93
93
$ singularity run --cpus 3.5 myfirstapp.sif
94
94
@@ -100,7 +100,7 @@ there is contention for CPUs*, i.e. the containers are able to consume more CPU
100
100
time than is available.
101
101
102
102
.. code ::
103
-
103
+
104
104
# Container A - twice as much CPU priority as container B
105
105
$ singularity run --cpu-shares 1024 myfirstapp.sif
106
106
@@ -115,7 +115,7 @@ run. For example, on a dual CPU system you might pin one container to the first
115
115
should generally be set to the same value as ``--cpu-set-cpus ``.
116
116
117
117
.. code ::
118
-
118
+
119
119
# Container A - first CPU
120
120
$ singularity run --cpu-set-cpus 0-11 --cpu-set-mems 0-11 myfirstapp.sif
121
121
@@ -130,7 +130,7 @@ You can use suffixes such as ``M`` or ``G`` to specify megabytes or gigabytes.
130
130
If the container tries to use more memory than its limit, the system will kill
131
131
it.
132
132
133
- .. code ::
133
+ .. code ::
134
134
135
135
# Run a program that will use 10GB of RAM, with a 100MB limit
136
136
$ singularity exec --memory 100M memhog.sif memhog 10G
140
140
limit set with ``--memory ``. When there is contention for memory, the system
141
141
will attempt to make sure the container doesn't exceed the soft limit.
142
142
143
- .. code ::
143
+ .. code ::
144
144
145
145
# Kill my program if it exceeds 10G, but aim for 8G if there is contention
146
146
$ singularity exec --memory 10G --memory-reservation 8G myfirstapp.sif
@@ -169,7 +169,7 @@ value of ``-1`` means *unlimited swap*. If ``--memory-swap`` is not set or is
169
169
IO Limits
170
170
=========
171
171
172
- .. note ::
172
+ .. note ::
173
173
174
174
Requires the ``cfq `` or ``bfq `` IO scheduler to be configured for block IO on
175
175
the system. This is common on modern distributions, but not universal. Ask
@@ -182,7 +182,7 @@ is contention for I/O with other containers. It may be useful to give high
182
182
priority to a container that needs infrequent but time sensitive data access,
183
183
running alongside an application that is continuously performing bulk reads.
184
184
185
- .. code ::
185
+ .. code ::
186
186
187
187
# Container A - ten times as much block IO priority as container B
188
188
$ singularity run --blkio-weight 1000 myfirstapp.sif
@@ -193,17 +193,17 @@ running alongside an application that is continuously performing bulk reads.
193
193
``--blkio-weight-device `` sets a relative weight for the container when performing
194
194
block I/O on a specific device. Specify the device and weight as ``<device path>:weight ``:
195
195
196
- .. code ::
196
+ .. code ::
197
197
198
198
# Container A - ten times as much block IO priority as container B on disk /dev/sda
199
199
$ singularity run --blkio-weight-device /dev/sda:1000 myfirstapp.sif
200
200
201
201
# Container A - ten times less block IO priority as container A on disk /dev/sda
202
202
$ singularity run --blkio-weight-device /dev/sda:100 mysecondapp.sif
203
203
204
- ********************************************
205
- Applying Resource Limits From a TOML file
206
- ********************************************
204
+ ******************************************
205
+ Applying Resource Limits From a TOML file
206
+ ******************************************
207
207
208
208
{Singularity} 3.9 and above can directly apply resource limitations to systems
209
209
configured for both cgroups v1 and the v2 unified hierarchy, using the
@@ -227,7 +227,7 @@ configuration to be applied:
227
227
228
228
$ singularity shell --apply-cgroups /path/to/cgroups.toml my_container.sif
229
229
230
- .. note ::
230
+ .. note ::
231
231
232
232
Using ``--apply-cgroups `` as a non-root user requires a cgroups v2 system,
233
233
configured to use the ``systemd cgroups `` manager in ``singularity.conf ``.
@@ -379,7 +379,7 @@ is specified in bytes per second.
379
379
Device Limits
380
380
=============
381
381
382
- .. note ::
382
+ .. note ::
383
383
384
384
Device limits can only be applied when running as the root user, and will be
385
385
ignored as a non-root user.
@@ -417,9 +417,9 @@ https://github.com/opencontainers/runtime-spec/blob/master/config-linux.md#contr
417
417
for information about the available limits. Note that {Singularity} uses
418
418
TOML format for the configuration file, rather than JSON.
419
419
420
- **********************************************
421
- Applying Resource Limits With External Tools
422
- **********************************************
420
+ ********************************************
421
+ Applying Resource Limits With External Tools
422
+ ********************************************
423
423
424
424
Because {Singularity} starts a container as a simple process, rather
425
425
than using a daemon, you can limit resource usage by running the
0 commit comments