Skip to content

Commit ab4acc0

Browse files
committed
Merge pull request #199 from runcom/rework-runtime-config-linux
runtime: config: linux: add cgroups informations
2 parents f412443 + 2ce2c86 commit ab4acc0

File tree

2 files changed

+160
-43
lines changed

2 files changed

+160
-43
lines changed

runtime-config-linux.md

+144-29
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,24 @@ A namespace wraps a global system resource in an abstraction that makes it appea
66
Changes to the global resource are visible to other processes that are members of the namespace, but are invisible to other processes.
77
For more information, see [the man page](http://man7.org/linux/man-pages/man7/namespaces.7.html).
88

9-
Namespaces are specified in the spec as an array of entries.
10-
Each entry has a type field with possible values described below and an optional path element.
9+
Namespaces are specified as an array of entries inside the `namespaces` root field.
10+
The following parameters can be specified to setup namespaces:
11+
12+
* **`type`** *(string, required)* - namespace type. The following namespaces types are supported:
13+
* **`pid`** processes inside the container will only be able to see other processes inside the same container
14+
* **`network`** the container will have its own network stack
15+
* **`mount`** the container will have an isolated mount table
16+
* **`ipc`** processes inside the container will only be able to communicate to other processes inside the same container via system level IPC
17+
* **`uts`** the container will be able to have its own hostname and domain name
18+
* **`user`** the container will be able to remap user and group IDs from the host to local users and groups within the container
19+
20+
* **`path`** *(string, optional)* - path to namespace file
21+
1122
If a path is specified, that particular file is used to join that type of namespace.
1223
Also, when a path is specified, a runtime MUST assume that the setup for that particular namespace has already been done and error out if the config specifies anything else related to that namespace.
1324

25+
###### Example
26+
1427
```json
1528
"namespaces": [
1629
{
@@ -36,32 +49,29 @@ Also, when a path is specified, a runtime MUST assume that the setup for that pa
3649
]
3750
```
3851

39-
#### Namespace types
52+
## Devices
4053

41-
* **`pid`** processes inside the container will only be able to see other processes inside the same container.
42-
* **`network`** the container will have its own network stack.
43-
* **`mount`** the container will have an isolated mount table.
44-
* **`ipc`** processes inside the container will only be able to communicate to other processes inside the same
45-
container via system level IPC.
46-
* **`uts`** the container will be able to have its own hostname and domain name.
47-
* **`user`** the container will be able to remap user and group IDs from the host to local users and groups
48-
within the container.
54+
`devices` is an array specifying the list of devices to be created in the container.
4955

50-
## Devices
56+
The following parameters can be specified:
57+
58+
* **`type`** *(char, required)* - type of device: `c`, `b`, `u` or `p`. More info in `man mknod`.
59+
60+
* **`path`** *(string, optional)* - full path to device inside container
61+
62+
* **`major, minor`** *(int64, required)* - major, minor numbers for device. More info in `man mknod`. There is a special value: `-1`, which means `*` for `device` cgroup setup.
5163

52-
Devices is an array specifying the list of devices to be created in the container.
53-
Next parameters can be specified:
64+
* **`permissions`** *(string, optional)* - cgroup permissions for device. A composition of `r` (*read*), `w` (*write*), and `m` (*mknod*).
5465

55-
* **`type`** - type of device: `c`, `b`, `u` or `p`. More info in `man mknod`
56-
* **`path`** - full path to device inside container
57-
* **`major, minor`** - major, minor numbers for device. More info in `man mknod`.
58-
There is special value: `-1`, which means `*` for `device`
59-
cgroup setup.
60-
* **`permissions`** - cgroup permissions for device. A composition of `r`
61-
(read), `w` (write), and `m` (mknod).
62-
* **`fileMode`** - file mode for device file
63-
* **`uid`** - uid of device owner
64-
* **`gid`** - gid of device owner
66+
* **`fileMode`** *(uint32, optional)* - file mode for device file
67+
68+
* **`uid`** *(uint32, optional)* - uid of device owner
69+
70+
* **`gid`** *(uint32, optional)* - gid of device owner
71+
72+
**`fileMode`**, **`uid`** and **`gid`** are required if **`path`** is given and are otherwise not allowed.
73+
74+
###### Example
6575

6676
```json
6777
"devices": [
@@ -154,6 +164,16 @@ For example, to run a new process in an existing container without updating limi
154164

155165
#### Disable out-of-memory killer
156166

167+
`disableOOMKiller` contains a boolean (`true` or `false`) that enables or disables the Out of Memory killer for a cgroup.
168+
If enabled (`false`), tasks that attempt to consume more memory than they are allowed are immediately killed by the OOM killer.
169+
The OOM killer is enabled by default in every cgroup using the `memory` subsystem.
170+
To disable it, specify a value of `true`.
171+
For more information, see [the memory cgroup man page](https://www.kernel.org/doc/Documentation/cgroups/memory.txt).
172+
173+
* **`disableOOMKiller`** *(bool, optional)* - enables or disables the OOM killer
174+
175+
###### Example
176+
157177
```json
158178
"disableOOMKiller": false
159179
```
@@ -168,6 +188,23 @@ More information on `oom_score_adj` available [here](https://www.kernel.org/doc/
168188

169189
#### Memory
170190

191+
`memory` represents the cgroup subsystem `memory` and it's used to set limits on the container's memory usage.
192+
For more information, see [the memory cgroup man page](https://www.kernel.org/doc/Documentation/cgroups/memory.txt).
193+
194+
The following parameters can be specified to setup the controller:
195+
196+
* **`limit`** *(uint64, optional)* - sets limit of memory usage
197+
198+
* **`reservation`** *(uint64, optional)* - sets soft limit of memory usage
199+
200+
* **`swap`** *(uint64, optional)* - sets limit of memory+Swap usage
201+
202+
* **`kernel`** *(uint64, optional)* - sets hard limit for kernel memory
203+
204+
* **`swappiness`** *(uint64, optional)* - sets swappiness parameter of vmscan (See sysctl's vm.swappiness)
205+
206+
###### Example
207+
171208
```json
172209
"memory": {
173210
"limit": 0,
@@ -180,6 +217,27 @@ More information on `oom_score_adj` available [here](https://www.kernel.org/doc/
180217

181218
#### CPU
182219

220+
`cpu` represents the cgroup subsystems `cpu` and `cpusets`.
221+
For more information, see [the cpusets cgroup man page](https://www.kernel.org/doc/Documentation/cgroups/cpusets.txt).
222+
223+
The following parameters can be specified to setup the controller:
224+
225+
* **`shares`** *(uint64, optional)* - specifies a relative share of CPU time available to the tasks in a cgroup
226+
227+
* **`quota`** *(uint64, optional)* - specifies the total amount of time in microseconds for which all tasks in a cgroup can run during one period (as defined by **`period`** below)
228+
229+
* **`period`** *(uint64, optional)* - specifies a period of time in microseconds for how regularly a cgroup's access to CPU resources should be reallocated (CFS scheduler only)
230+
231+
* **`realtimeRuntime`** *(uint64, optional)* - specifies a period of time in microseconds for the longest continuous period in which the tasks in a cgroup have access to CPU resources
232+
233+
* **`realtimePeriod`** *(uint64, optional)* - same as **`period`** but applies to realtime scheduler only
234+
235+
* **`cpus`** *(cpus, optional)* - list of CPUs the container will run in
236+
237+
* **`mems`** *(mems, optional)* - list of Memory Nodes the container will run in
238+
239+
###### Example
240+
183241
```json
184242
"cpu": {
185243
"shares": 0,
@@ -195,18 +253,18 @@ More information on `oom_score_adj` available [here](https://www.kernel.org/doc/
195253
#### Block IO Controller
196254

197255
`blockIO` represents the cgroup subsystem `blkio` which implements the block io controller.
198-
For more information, see the [kernel cgroups documentation about `blkio`](https://www.kernel.org/doc/Documentation/cgroups/blkio-controller.txt).
256+
For more information, see [the kernel cgroups documentation about blkio](https://www.kernel.org/doc/Documentation/cgroups/blkio-controller.txt).
199257

200-
The following parameters can be specified to setup the block io controller:
258+
The following parameters can be specified to setup the controller:
201259

202260
* **`blkioWeight`** *(uint16, optional)* - specifies per-cgroup weight. This is default weight of the group on all devices until and unless overridden by per-device rules. The range is from 10 to 1000.
203261

204262
* **`blkioLeafWeight`** *(uint16, optional)* - equivalents of `blkioWeight` for the purpose of deciding how much weight tasks in the given cgroup has while competing with the cgroup's child cgroups. The range is from 10 to 1000.
205263

206264
* **`blkioWeightDevice`** *(array, optional)* - specifies the list of devices which will be bandwidth rate limited. The following parameters can be specified per-device:
207265
* **`major, minor`** *(int64, required)* - major, minor numbers for device. More info in `man mknod`.
208-
* **`weight`** *(uint16, optional)* - bandwidth rate for the device, range is from 10 to 1000.
209-
* **`leafWeight`** *(uint16, optional)* - bandwidth rate for the device while competing with the cgroup's child cgroups, range is from 10 to 1000, cfq scheduler only.
266+
* **`weight`** *(uint16, optional)* - bandwidth rate for the device, range is from 10 to 1000
267+
* **`leafWeight`** *(uint16, optional)* - bandwidth rate for the device while competing with the cgroup's child cgroups, range is from 10 to 1000, CFQ scheduler only
210268

211269
You must specify at least one of `weight` or `leafWeight` in a given entry, and can specify both.
212270

@@ -252,6 +310,18 @@ The following parameters can be specified to setup the block io controller:
252310

253311
#### Huge page limits
254312

313+
`hugepageLimits` represents the `hugetlb` controller which allows to limit the
314+
HugeTLB usage per control group and enforces the controller limit during page fault.
315+
For more information, see the [kernel cgroups documentation about HugeTLB](https://www.kernel.org/doc/Documentation/cgroups/hugetlb.txt).
316+
317+
`hugepageLimits` is an array of entries, each having the following structure:
318+
319+
* **`pageSize`** *(string, required)* - hugepage size
320+
321+
* **`limit`** *(uint64, required)* - limit in bytes of *hugepagesize* HugeTLB usage
322+
323+
###### Example
324+
255325
```json
256326
"hugepageLimits": [
257327
{
@@ -263,9 +333,23 @@ The following parameters can be specified to setup the block io controller:
263333

264334
#### Network
265335

336+
`network` represents the cgroup subsystems `net_cls` and `net_prio`.
337+
For more information, see [the net\_cls cgroup man page](https://www.kernel.org/doc/Documentation/cgroups/net_cls.txt) and [the net\_prio cgroup man page](https://www.kernel.org/doc/Documentation/cgroups/net_prio.txt).
338+
339+
The following parameters can be specified to setup these cgroup controllers:
340+
341+
* **`classID`** *(string, optional)* - is the network class identifier the cgroup's network packets will be tagged with
342+
343+
* **`priorities`** *(array, optional)* - specifies a list of objects of the priorities assigned to traffic originating from
344+
processes in the group and egressing the system on various interfaces. The following parameters can be specified per-priority:
345+
* **`name`** *(string, required)* - interface name
346+
* **`priority`** *(uint32, required)* - priority applied to the interface
347+
348+
###### Example
349+
266350
```json
267351
"network": {
268-
"classId": "ClassId",
352+
"classID": "0x100001",
269353
"priorities": [
270354
{
271355
"name": "eth0",
@@ -279,11 +363,31 @@ The following parameters can be specified to setup the block io controller:
279363
}
280364
```
281365

366+
#### PIDs
367+
368+
`pids` represents the cgroup subsystem `pids`.
369+
For more information, see [the pids cgroup man page](https://www.kernel.org/doc/Documentation/cgroups/pids.txt
370+
).
371+
372+
The following paramters can be specified to setup the controller:
373+
374+
* **`limit`** *(int64, required)* - specifies the maximum number of tasks in the cgroup
375+
376+
###### Example
377+
378+
```json
379+
"pids": {
380+
"limit": 32771
381+
}
382+
```
383+
282384
## Sysctl
283385

284386
sysctl allows kernel parameters to be modified at runtime for the container.
285387
For more information, see [the man page](http://man7.org/linux/man-pages/man8/sysctl.8.html)
286388

389+
###### Example
390+
287391
```json
288392
"sysctl": {
289393
"net.ipv4.ip_forward": "1",
@@ -297,6 +401,8 @@ rlimits allow setting resource limits.
297401
`type` is a string with a value from those defined in [the man page](http://man7.org/linux/man-pages/man2/setrlimit.2.html).
298402
The kernel enforces the `soft` limit for a resource while the `hard` limit acts as a ceiling for that value that could be set by an unprivileged process.
299403

404+
###### Example
405+
300406
```json
301407
"rlimits": [
302408
{
@@ -311,6 +417,9 @@ The kernel enforces the `soft` limit for a resource while the `hard` limit acts
311417

312418
SELinux process label specifies the label with which the processes in a container are run.
313419
For more information about SELinux, see [Selinux documentation](http://selinuxproject.org/page/Main_Page)
420+
421+
###### Example
422+
314423
```json
315424
"selinuxProcessLabel": "system_u:system_r:svirt_lxc_net_t:s0:c124,c675"
316425
```
@@ -320,6 +429,8 @@ For more information about SELinux, see [Selinux documentation](http://selinuxp
320429
Apparmor profile specifies the name of the apparmor profile that will be used for the container.
321430
For more information about Apparmor, see [Apparmor documentation](https://wiki.ubuntu.com/AppArmor)
322431

432+
###### Example
433+
323434
```json
324435
"apparmorProfile": "acme_secure_profile"
325436
```
@@ -361,6 +472,8 @@ Operator Constants:
361472
* `SCMP_CMP_GT`
362473
* `SCMP_CMP_MASKED_EQ`
363474

475+
###### Example
476+
364477
```json
365478
"seccomp": {
366479
"defaultAction": "SCMP_ACT_ALLOW",
@@ -382,6 +495,8 @@ rootfsPropagation sets the rootfs's mount propagation.
382495
Its value is either slave, private, or shared.
383496
[The kernel doc](https://www.kernel.org/doc/Documentation/filesystems/sharedsubtree.txt) has more information about mount propagation.
384497

498+
###### Example
499+
385500
```json
386501
"rootfsPropagation": "slave",
387502
```

runtime_config_linux.go

+16-14
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ type InterfacePriority struct {
103103
// Name is the name of the network interface
104104
Name string `json:"name"`
105105
// Priority for the interface
106-
Priority int64 `json:"priority"`
106+
Priority uint32 `json:"priority"`
107107
}
108108

109109
// blockIODevice holds major:minor format supported in blkio cgroup
@@ -119,7 +119,7 @@ type WeightDevice struct {
119119
blockIODevice
120120
// Weight is the bandwidth rate for the device, range is from 10 to 1000
121121
Weight uint16 `json:"weight"`
122-
// LeafWeight is the bandwidth rate for the device while competing with the cgroup's child cgroups, range is from 10 to 1000, cfq scheduler only
122+
// LeafWeight is the bandwidth rate for the device while competing with the cgroup's child cgroups, range is from 10 to 1000, CFQ scheduler only
123123
LeafWeight uint16 `json:"leafWeight"`
124124
}
125125

@@ -134,7 +134,7 @@ type ThrottleDevice struct {
134134
type BlockIO struct {
135135
// Specifies per cgroup weight, range is from 10 to 1000
136136
Weight uint16 `json:"blkioWeight"`
137-
// Specifies tasks' weight in the given cgroup while competing with the cgroup's child cgroups, range is from 10 to 1000, cfq scheduler only
137+
// Specifies tasks' weight in the given cgroup while competing with the cgroup's child cgroups, range is from 10 to 1000, CFQ scheduler only
138138
LeafWeight uint16 `json:"blkioLeafWeight"`
139139
// Weight per cgroup per device, can override BlkioWeight
140140
WeightDevice []*WeightDevice `json:"blkioWeightDevice"`
@@ -151,29 +151,29 @@ type BlockIO struct {
151151
// Memory for Linux cgroup 'memory' resource management
152152
type Memory struct {
153153
// Memory limit (in bytes)
154-
Limit int64 `json:"limit"`
154+
Limit uint64 `json:"limit"`
155155
// Memory reservation or soft_limit (in bytes)
156-
Reservation int64 `json:"reservation"`
156+
Reservation uint64 `json:"reservation"`
157157
// Total memory usage (memory + swap); set `-1' to disable swap
158-
Swap int64 `json:"swap"`
158+
Swap uint64 `json:"swap"`
159159
// Kernel memory limit (in bytes)
160-
Kernel int64 `json:"kernel"`
160+
Kernel uint64 `json:"kernel"`
161161
// How aggressive the kernel will swap memory pages. Range from 0 to 100. Set -1 to use system default
162-
Swappiness int64 `json:"swappiness"`
162+
Swappiness uint64 `json:"swappiness"`
163163
}
164164

165165
// CPU for Linux cgroup 'cpu' resource management
166166
type CPU struct {
167167
// CPU shares (relative weight vs. other cgroups with cpu shares)
168-
Shares int64 `json:"shares"`
168+
Shares uint64 `json:"shares"`
169169
// CPU hardcap limit (in usecs). Allowed cpu time in a given period
170-
Quota int64 `json:"quota"`
170+
Quota uint64 `json:"quota"`
171171
// CPU period to be used for hardcapping (in usecs). 0 to use system default
172-
Period int64 `json:"period"`
172+
Period uint64 `json:"period"`
173173
// How many time CPU will use in realtime scheduling (in usecs)
174-
RealtimeRuntime int64 `json:"realtimeRuntime"`
174+
RealtimeRuntime uint64 `json:"realtimeRuntime"`
175175
// CPU period to be used for realtime scheduling (in usecs)
176-
RealtimePeriod int64 `json:"realtimePeriod"`
176+
RealtimePeriod uint64 `json:"realtimePeriod"`
177177
// CPU to use within the cpuset
178178
Cpus string `json:"cpus"`
179179
// MEM to use within the cpuset
@@ -189,7 +189,9 @@ type Pids struct {
189189
// Network identification and priority configuration
190190
type Network struct {
191191
// Set class identifier for container's network packets
192-
ClassID string `json:"classId"`
192+
// this is actually a string instead of a uint64 to overcome the json
193+
// limitation of specifying hex numbers
194+
ClassID string `json:"classID"`
193195
// Set priority of network traffic for container
194196
Priorities []InterfacePriority `json:"priorities"`
195197
}

0 commit comments

Comments
 (0)