Skip to content

Commit 0798f5f

Browse files
authored
Merge pull request #43214 from thaJeztah/carry_42854_rm_options
Remove the deprecated '--kernel-memory' option on API v1.42 and up
2 parents 165fe27 + 427b0cd commit 0798f5f

File tree

9 files changed

+68
-56
lines changed

9 files changed

+68
-56
lines changed

api/server/router/container/container_routes.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,12 @@ func (s *containerRouter) postContainerUpdate(ctx context.Context, w http.Respon
439439
if versions.LessThan(httputils.VersionFromContext(ctx), "1.40") {
440440
updateConfig.PidsLimit = nil
441441
}
442+
443+
if versions.GreaterThanOrEqualTo(httputils.VersionFromContext(ctx), "1.42") {
444+
// Ignore KernelMemory removed in API 1.42.
445+
updateConfig.KernelMemory = 0
446+
}
447+
442448
if updateConfig.PidsLimit != nil && *updateConfig.PidsLimit <= 0 {
443449
// Both `0` and `-1` are accepted to set "unlimited" when updating.
444450
// Historically, any negative value was accepted, so treat them as
@@ -505,6 +511,11 @@ func (s *containerRouter) postContainersCreate(ctx context.Context, w http.Respo
505511
}
506512
}
507513

514+
if hostConfig != nil && versions.GreaterThanOrEqualTo(version, "1.42") {
515+
// Ignore KernelMemory removed in API 1.42.
516+
hostConfig.KernelMemory = 0
517+
}
518+
508519
var platform *specs.Platform
509520
if versions.GreaterThanOrEqualTo(version, "1.41") {
510521
if v := r.Form.Get("platform"); v != "" {

api/server/router/system/system_routes.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ func (s *systemRouter) getInfo(ctx context.Context, w http.ResponseWriter, r *ht
5151
info.Warnings = append(info.Warnings, info.Swarm.Warnings...)
5252
}
5353

54-
if versions.LessThan(httputils.VersionFromContext(ctx), "1.25") {
54+
version := httputils.VersionFromContext(ctx)
55+
if versions.LessThan(version, "1.25") {
5556
// TODO: handle this conversion in engine-api
5657
type oldInfo struct {
5758
*types.Info
@@ -72,14 +73,17 @@ func (s *systemRouter) getInfo(ctx context.Context, w http.ResponseWriter, r *ht
7273
old.SecurityOptions = nameOnlySecurityOptions
7374
return httputils.WriteJSON(w, http.StatusOK, old)
7475
}
75-
if versions.LessThan(httputils.VersionFromContext(ctx), "1.39") {
76+
if versions.LessThan(version, "1.39") {
7677
if info.KernelVersion == "" {
7778
info.KernelVersion = "<unknown>"
7879
}
7980
if info.OperatingSystem == "" {
8081
info.OperatingSystem = "<unknown>"
8182
}
8283
}
84+
if versions.GreaterThanOrEqualTo(version, "1.42") {
85+
info.KernelMemory = false
86+
}
8387
return httputils.WriteJSON(w, http.StatusOK, info)
8488
}
8589

api/swagger.yaml

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -577,19 +577,13 @@ definitions:
577577
type: "array"
578578
items:
579579
$ref: "#/definitions/DeviceRequest"
580-
KernelMemory:
580+
KernelMemoryTCP:
581581
description: |
582-
Kernel memory limit in bytes.
583-
584-
<p><br /></p>
582+
Hard limit for kernel TCP buffer memory (in bytes). Depending on the
583+
OCI runtime in use, this option may be ignored. It is no longer supported
584+
by the default (runc) runtime.
585585

586-
> **Deprecated**: This field is deprecated as the kernel 5.4 deprecated
587-
> `kmem.limit_in_bytes`.
588-
type: "integer"
589-
format: "int64"
590-
example: 209715200
591-
KernelMemoryTCP:
592-
description: "Hard limit for kernel TCP buffer memory (in bytes)."
586+
This field is omitted when empty.
593587
type: "integer"
594588
format: "int64"
595589
MemoryReservation:
@@ -4657,19 +4651,10 @@ definitions:
46574651
description: "Indicates if the host has memory swap limit support enabled."
46584652
type: "boolean"
46594653
example: true
4660-
KernelMemory:
4661-
description: |
4662-
Indicates if the host has kernel memory limit support enabled.
4663-
4664-
<p><br /></p>
4665-
4666-
> **Deprecated**: This field is deprecated as the kernel 5.4 deprecated
4667-
> `kmem.limit_in_bytes`.
4668-
type: "boolean"
4669-
example: true
46704654
KernelMemoryTCP:
46714655
description: |
4672-
Indicates if the host has kernel memory TCP limit support enabled.
4656+
Indicates if the host has kernel memory TCP limit support enabled. This
4657+
field is omitted if not supported.
46734658

46744659
Kernel memory TCP limits are not supported when using cgroups v2, which
46754660
does not support the corresponding `memory.kmem.tcp.limit_in_bytes` cgroup.
@@ -5834,7 +5819,6 @@ paths:
58345819
Memory: 0
58355820
MemorySwap: 0
58365821
MemoryReservation: 0
5837-
KernelMemory: 0
58385822
NanoCpus: 500000
58395823
CpuPercent: 80
58405824
CpuShares: 512
@@ -6126,7 +6110,6 @@ paths:
61266110
Memory: 0
61276111
MemorySwap: 0
61286112
MemoryReservation: 0
6129-
KernelMemory: 0
61306113
OomKillDisable: false
61316114
OomScoreAdj: 500
61326115
NetworkMode: "bridge"
@@ -6871,7 +6854,6 @@ paths:
68716854
Memory: 314572800
68726855
MemorySwap: 514288000
68736856
MemoryReservation: 209715200
6874-
KernelMemory: 52428800
68756857
RestartPolicy:
68766858
MaximumRetryCount: 4
68776859
Name: "on-failure"

api/types/container/host_config.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -376,14 +376,17 @@ type Resources struct {
376376
Devices []DeviceMapping // List of devices to map inside the container
377377
DeviceCgroupRules []string // List of rule to be added to the device cgroup
378378
DeviceRequests []DeviceRequest // List of device requests for device drivers
379-
KernelMemory int64 // Kernel memory limit (in bytes), Deprecated: kernel 5.4 deprecated kmem.limit_in_bytes
380-
KernelMemoryTCP int64 // Hard limit for kernel TCP buffer memory (in bytes)
381-
MemoryReservation int64 // Memory soft limit (in bytes)
382-
MemorySwap int64 // Total memory usage (memory + swap); set `-1` to enable unlimited swap
383-
MemorySwappiness *int64 // Tuning container memory swappiness behaviour
384-
OomKillDisable *bool // Whether to disable OOM Killer or not
385-
PidsLimit *int64 // Setting PIDs limit for a container; Set `0` or `-1` for unlimited, or `null` to not change.
386-
Ulimits []*units.Ulimit // List of ulimits to be set in the container
379+
380+
// KernelMemory specifies the kernel memory limit (in bytes) for the container.
381+
// Deprecated: kernel 5.4 deprecated kmem.limit_in_bytes.
382+
KernelMemory int64 `json:",omitempty"`
383+
KernelMemoryTCP int64 `json:",omitempty"` // Hard limit for kernel TCP buffer memory (in bytes)
384+
MemoryReservation int64 // Memory soft limit (in bytes)
385+
MemorySwap int64 // Total memory usage (memory + swap); set `-1` to enable unlimited swap
386+
MemorySwappiness *int64 // Tuning container memory swappiness behaviour
387+
OomKillDisable *bool // Whether to disable OOM Killer or not
388+
PidsLimit *int64 // Setting PIDs limit for a container; Set `0` or `-1` for unlimited, or `null` to not change.
389+
Ulimits []*units.Ulimit // List of ulimits to be set in the container
387390

388391
// Applicable to Windows
389392
CPUCount int64 `json:"CpuCount"` // CPU count

api/types/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ type Info struct {
239239
Plugins PluginsInfo
240240
MemoryLimit bool
241241
SwapLimit bool
242-
KernelMemory bool // Deprecated: kernel 5.4 deprecated kmem.limit_in_bytes
243-
KernelMemoryTCP bool
242+
KernelMemory bool `json:",omitempty"` // Deprecated: kernel 5.4 deprecated kmem.limit_in_bytes
243+
KernelMemoryTCP bool `json:",omitempty"` // KernelMemoryTCP is not supported on cgroups v2.
244244
CPUCfsPeriod bool `json:"CpuCfsPeriod"`
245245
CPUCfsQuota bool `json:"CpuCfsQuota"`
246246
CPUShares bool

daemon/daemon_unix.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -445,17 +445,16 @@ func verifyPlatformContainerResources(resources *containertypes.Resources, sysIn
445445
// Kernel memory limit is not supported on cgroup v2.
446446
// Even on cgroup v1, kernel memory limit (`kmem.limit_in_bytes`) has been deprecated since kernel 5.4.
447447
// https://github.com/torvalds/linux/commit/0158115f702b0ba208ab0b5adf44cae99b3ebcc7
448-
warnings = append(warnings, "Specifying a kernel memory limit is deprecated and will be removed in a future release.")
449-
}
450-
if resources.KernelMemory > 0 && !sysInfo.KernelMemory {
451-
warnings = append(warnings, "Your kernel does not support kernel memory limit capabilities or the cgroup is not mounted. Limitation discarded.")
452-
resources.KernelMemory = 0
453-
}
454-
if resources.KernelMemory > 0 && resources.KernelMemory < linuxMinMemory {
455-
return warnings, fmt.Errorf("Minimum kernel memory limit allowed is 6MB")
456-
}
457-
if resources.KernelMemory > 0 && !kernel.CheckKernelVersion(4, 0, 0) {
458-
warnings = append(warnings, "You specified a kernel memory limit on a kernel older than 4.0. Kernel memory limits are experimental on older kernels, it won't work as expected and can cause your system to be unstable.")
448+
if !sysInfo.KernelMemory {
449+
warnings = append(warnings, "Your kernel does not support kernel memory limit capabilities or the cgroup is not mounted. Limitation discarded.")
450+
resources.KernelMemory = 0
451+
}
452+
if resources.KernelMemory > 0 && resources.KernelMemory < linuxMinMemory {
453+
return warnings, fmt.Errorf("Minimum kernel memory limit allowed is 6MB")
454+
}
455+
if !kernel.CheckKernelVersion(4, 0, 0) {
456+
warnings = append(warnings, "You specified a kernel memory limit on a kernel older than 4.0. Kernel memory limits are experimental on older kernels, it won't work as expected and can cause your system to be unstable.")
457+
}
459458
}
460459
if resources.OomKillDisable != nil && !sysInfo.OomKillDisable {
461460
// only produce warnings if the setting wasn't to *disable* the OOM Kill; no point

docs/api/version-history.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ keywords: "API, Docker, rcli, REST, documentation"
4242
versioned, and affects all API versions if the daemon has this patch.
4343
* The `POST /containers/{id}/wait` endpoint now returns a `400` status code if an
4444
invalid `condition` is provided (on API 1.30 and up).
45+
* Removed the `KernelMemory` field from the `POST /containers/create` and
46+
`POST /containers/{id}/update` endpoints, any value it is set to will be ignored
47+
on API version `v1.42` and up. Older API versions still accept this field, but
48+
may take no effect, depending on the kernel version and OCI runtime in use.
49+
* `GET /containers/{id}/json` now omits the `KernelMemory` and `KernelMemoryTCP`
50+
if they are not set.
51+
* `GET /info` now omits the `KernelMemory` and `KernelMemoryTCP` if they are not
52+
supported by the host or host's configuration (if cgroups v2 are in use).
4553

4654
## v1.41 API changes
4755

pkg/sysinfo/sysinfo.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,14 @@ type cgroupMemInfo struct {
7171
// Whether memory swappiness is supported or not
7272
MemorySwappiness bool
7373

74-
// Whether kernel memory limit is supported or not
74+
// Whether kernel memory limit is supported or not. This option is used to
75+
// detect support for kernel-memory limits on API < v1.42. Kernel memory
76+
// limit (`kmem.limit_in_bytes`) is not supported on cgroups v2, and has been
77+
// removed in kernel 5.4.
7578
KernelMemory bool
7679

77-
// Whether kernel memory TCP limit is supported or not
80+
// Whether kernel memory TCP limit is supported or not. Kernel memory TCP
81+
// limit (`memory.kmem.tcp.limit_in_bytes`) is not supported on cgroups v2.
7882
KernelMemoryTCP bool
7983
}
8084

pkg/sysinfo/sysinfo_linux.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,15 @@ func applyMemoryCgroupInfo(info *SysInfo) {
149149
if !info.MemorySwappiness {
150150
info.Warnings = append(info.Warnings, "Your kernel does not support memory swappiness")
151151
}
152+
153+
// Option is deprecated, but still accepted on API < v1.42 with cgroups v1,
154+
// so setting the field to allow feature detection.
152155
info.KernelMemory = cgroupEnabled(mountPoint, "memory.kmem.limit_in_bytes")
153-
if !info.KernelMemory {
154-
info.Warnings = append(info.Warnings, "Your kernel does not support kernel memory limit")
155-
}
156+
157+
// Option is deprecated in runc, but still accepted in our API, so setting
158+
// the field to allow feature detection, but don't warn if it's missing, to
159+
// make the daemon logs a bit less noisy.
156160
info.KernelMemoryTCP = cgroupEnabled(mountPoint, "memory.kmem.tcp.limit_in_bytes")
157-
if !info.KernelMemoryTCP {
158-
info.Warnings = append(info.Warnings, "Your kernel does not support kernel memory TCP limit")
159-
}
160161
}
161162

162163
// applyCPUCgroupInfo adds the cpu cgroup controller information to the info.

0 commit comments

Comments
 (0)