Files
moby/daemon/update_linux.go
Sebastiaan van Stijn c5991341eb remove support for deprecated kernel memory limit
kernel-memory limits are not supported in cgroups v2, and were obsoleted in
[kernel v5.4], producing a `ENOTSUP` in kernel v5.16. Support for this option
was removed in runc and other runtimes, as various LTS kernels contained a
broken implementation, resulting in unpredictable behavior.

We deprecated this option in [moby@b8ca7de], producing a warning when used,
and actively ignore the option since [moby@0798f5f].

Given that setting this option had no effect in most situations, we should
just remove this option instead of continuing to handle it with the expectation
that a runtime may still support it.

Note that we still support RHEL 8 (kernel 4.18) and RHEL 9 (kernel 5.14). We
no longer build packages for Ubuntu 20.04 (kernel 5.4) and Debian Bullseye 11
(kernel 5.10), which still have an LTS / ESM programme, but for those it would
only impact situations where a runtime is used that still supports it, and
an old API version was used.

[kernel v5.4]: https://github.com/torvalds/linux/commit/0158115f702b0ba208ab0
[moby@b8ca7de]: b8ca7de823
[moby@0798f5f]: 0798f5f5cf

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-16 13:08:36 +02:00

73 lines
1.5 KiB
Go

package daemon
import (
"time"
"github.com/moby/moby/api/types/container"
libcontainerdtypes "github.com/moby/moby/v2/daemon/internal/libcontainerd/types"
"github.com/opencontainers/runtime-spec/specs-go"
)
func toContainerdResources(resources container.Resources) *libcontainerdtypes.Resources {
var r libcontainerdtypes.Resources
if resources.BlkioWeight != 0 {
r.BlockIO = &specs.LinuxBlockIO{
Weight: &resources.BlkioWeight,
}
}
cpu := specs.LinuxCPU{
Cpus: resources.CpusetCpus,
Mems: resources.CpusetMems,
}
if resources.CPUShares != 0 {
shares := uint64(resources.CPUShares)
cpu.Shares = &shares
}
var (
period uint64
quota int64
)
if resources.NanoCPUs != 0 {
period = uint64(100 * time.Millisecond / time.Microsecond)
quota = resources.NanoCPUs * int64(period) / 1e9
}
if quota == 0 && resources.CPUQuota != 0 {
quota = resources.CPUQuota
}
if period == 0 && resources.CPUPeriod != 0 {
period = uint64(resources.CPUPeriod)
}
if period != 0 {
cpu.Period = &period
}
if quota != 0 {
cpu.Quota = &quota
}
if cpu != (specs.LinuxCPU{}) {
r.CPU = &cpu
}
var memory specs.LinuxMemory
if resources.Memory != 0 {
memory.Limit = &resources.Memory
}
if resources.MemoryReservation != 0 {
memory.Reservation = &resources.MemoryReservation
}
if resources.MemorySwap > 0 {
memory.Swap = &resources.MemorySwap
}
if memory != (specs.LinuxMemory{}) {
r.Memory = &memory
}
r.Pids = getPidsLimit(resources)
return &r
}