Skip to content

Commit e73cd70

Browse files
committed
Make Linux memory allocations int64 not uint64
The kernel ABI to these values is a string, which accepts the value `-1` to mean "unlimited" or an integer up to 2^63 for an amount of memory in bytes. While the internal representation in the kernel is unsigned, this is not exposed in any ABI directly. Because of the user-kernel memory split, values over 2^63 are not really useful; indeed that much memory is not supported, as physical memory is limited to 52 bits in the forthcoming switch to five level page tables. So it is much more natural to support the value `-1` for unlimited, especially as the actual number needed to represent the maximum has varied in different kernel versions, and across 32 and 64 bit architectures, so determining the value to use is not possible, so it is necessary to write the string `-1` to the cgroup files. See also discussion in - opencontainers/runc#1494 - opencontainers/runc#1492 - opencontainers/runc#1375 - opencontainers/runc#1421 Signed-off-by: Justin Cormack <[email protected]>
1 parent 0b38a4c commit e73cd70

File tree

5 files changed

+25
-22
lines changed

5 files changed

+25
-22
lines changed

config-linux.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,16 @@ For more information, see the kernel cgroups documentation about [memory][cgroup
270270
**`memory`** (object, OPTIONAL) represents the cgroup subsystem `memory` and it's used to set limits on the container's memory usage.
271271
For more information, see the kernel cgroups documentation about [memory][cgroup-v1-memory].
272272

273-
The following parameters can be specified to set up the controller:
273+
Values for memory specify the limit in bytes, or `-1` for unlimited memory.
274+
275+
* **`limit`** *(int64, OPTIONAL)* - sets limit of memory usage
276+
* **`reservation`** *(int64, OPTIONAL)* - sets soft limit of memory usage
277+
* **`swap`** *(int64, OPTIONAL)* - sets limit of memory+Swap usage
278+
* **`kernel`** *(int64, OPTIONAL)* - sets hard limit for kernel memory
279+
* **`kernelTCP`** *(int64, OPTIONAL)* - sets hard limit for kernel TCP buffer memory
280+
281+
For `swappiness` the values are from 0 to 100. Higher means more swappy.
274282

275-
* **`limit`** *(uint64, OPTIONAL)* - sets limit of memory usage in bytes
276-
* **`reservation`** *(uint64, OPTIONAL)* - sets soft limit of memory usage in bytes
277-
* **`swap`** *(uint64, OPTIONAL)* - sets limit of memory+Swap usage
278-
* **`kernel`** *(uint64, OPTIONAL)* - sets hard limit for kernel memory
279-
* **`kernelTCP`** *(uint64, OPTIONAL)* - sets hard limit in bytes for kernel TCP buffer memory
280283
* **`swappiness`** *(uint64, OPTIONAL)* - sets swappiness parameter of vmscan (See sysctl's vm.swappiness)
281284

282285
#### Example
@@ -286,8 +289,8 @@ The following parameters can be specified to set up the controller:
286289
"limit": 536870912,
287290
"reservation": 536870912,
288291
"swap": 536870912,
289-
"kernel": 0,
290-
"kernelTCP": 0,
292+
"kernel": -1,
293+
"kernelTCP": -1,
291294
"swappiness": 0
292295
}
293296
```

config.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,8 +689,8 @@ Here is a full example `config.json` for reference.
689689
"limit": 536870912,
690690
"reservation": 536870912,
691691
"swap": 536870912,
692-
"kernel": 0,
693-
"kernelTCP": 0,
692+
"kernel": -1,
693+
"kernelTCP": -1,
694694
"swappiness": 0
695695
},
696696
"cpu": {

schema/config-linux.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,23 +172,23 @@
172172
"properties": {
173173
"kernel": {
174174
"id": "https://opencontainers.org/schema/bundle/linux/resources/memory/kernel",
175-
"$ref": "defs.json#/definitions/uint64"
175+
"$ref": "defs.json#/definitions/int64"
176176
},
177177
"kernelTCP": {
178178
"id": "https://opencontainers.org/schema/bundle/linux/resources/memory/kernelTCP",
179-
"$ref": "defs.json#/definitions/uint64"
179+
"$ref": "defs.json#/definitions/int64"
180180
},
181181
"limit": {
182182
"id": "https://opencontainers.org/schema/bundle/linux/resources/memory/limit",
183-
"$ref": "defs.json#/definitions/uint64"
183+
"$ref": "defs.json#/definitions/int64"
184184
},
185185
"reservation": {
186186
"id": "https://opencontainers.org/schema/bundle/linux/resources/memory/reservation",
187-
"$ref": "defs.json#/definitions/uint64"
187+
"$ref": "defs.json#/definitions/int64"
188188
},
189189
"swap": {
190190
"id": "https://opencontainers.org/schema/bundle/linux/resources/memory/swap",
191-
"$ref": "defs.json#/definitions/uint64"
191+
"$ref": "defs.json#/definitions/int64"
192192
},
193193
"swappiness": {
194194
"id": "https://opencontainers.org/schema/bundle/linux/resources/memory/swappiness",

schema/test/config/good/spec-example.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@
239239
"limit": 536870912,
240240
"reservation": 536870912,
241241
"swap": 536870912,
242-
"kernel": 0,
243-
"kernelTCP": 0,
242+
"kernel": -1,
243+
"kernelTCP": -1,
244244
"swappiness": 0
245245
},
246246
"cpu": {

specs-go/config.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,15 +273,15 @@ type LinuxBlockIO struct {
273273
// LinuxMemory for Linux cgroup 'memory' resource management
274274
type LinuxMemory struct {
275275
// Memory limit (in bytes).
276-
Limit *uint64 `json:"limit,omitempty"`
276+
Limit *int64 `json:"limit,omitempty"`
277277
// Memory reservation or soft_limit (in bytes).
278-
Reservation *uint64 `json:"reservation,omitempty"`
278+
Reservation *int64 `json:"reservation,omitempty"`
279279
// Total memory limit (memory + swap).
280-
Swap *uint64 `json:"swap,omitempty"`
280+
Swap *int64 `json:"swap,omitempty"`
281281
// Kernel memory limit (in bytes).
282-
Kernel *uint64 `json:"kernel,omitempty"`
282+
Kernel *int64 `json:"kernel,omitempty"`
283283
// Kernel memory limit for tcp (in bytes)
284-
KernelTCP *uint64 `json:"kernelTCP,omitempty"`
284+
KernelTCP *int64 `json:"kernelTCP,omitempty"`
285285
// How aggressive the kernel will swap memory pages.
286286
Swappiness *uint64 `json:"swappiness,omitempty"`
287287
}

0 commit comments

Comments
 (0)