executor: set CpuWeight in cgroup-v2 (#11287)
Cgroup-v2 uses `cpu.weight` property instead of cpu shares: https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html#cpu-interface-files . And it uses a different range (i.e. `[1, 10000]`) from cpu.shares (i.e. `[2, 262144]`) to make things more interesting. Luckily, the libcontainer provides a helper function to perform the conversion [`ConvertCPUSharesToCgroupV2Value`](https://pkg.go.dev/github.com/opencontainers/runc@v1.0.2/libcontainer/cgroups#ConvertCPUSharesToCgroupV2Value). I have confirmed that docker/libcontainer performs the conversion as well in https://github.com/opencontainers/runc/blob/v1.0.2/libcontainer/specconv/spec_linux.go#L536-L541 , and that CpuShares is ignored by libcontainer in https://github.com/opencontainers/runc/blob/v1.0.2/libcontainer/cgroups/fs2/cpu.go#L24-L29 .
This commit is contained in:
parent
536a5751ff
commit
d5e136b82b
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
```release-note:bug
|
||||||
|
driver/exec: Set CPU resource limits when cgroup-v2 is enabled
|
||||||
|
```
|
|
@ -697,8 +697,9 @@ func configureCgroups(cfg *lconfigs.Config, command *ExecCommand) error {
|
||||||
return fmt.Errorf("resources.Cpu.CpuShares must be equal to or greater than 2: %v", cpuShares)
|
return fmt.Errorf("resources.Cpu.CpuShares must be equal to or greater than 2: %v", cpuShares)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the relative CPU shares for this cgroup.
|
// Set the relative CPU shares for this cgroup, and convert for cgroupv2
|
||||||
cfg.Cgroups.Resources.CpuShares = uint64(cpuShares)
|
cfg.Cgroups.Resources.CpuShares = uint64(cpuShares)
|
||||||
|
cfg.Cgroups.Resources.CpuWeight = cgroups.ConvertCPUSharesToCgroupV2Value(uint64(cpuShares))
|
||||||
|
|
||||||
if command.Resources.LinuxResources != nil && command.Resources.LinuxResources.CpusetCgroupPath != "" {
|
if command.Resources.LinuxResources != nil && command.Resources.LinuxResources.CpusetCgroupPath != "" {
|
||||||
cfg.Hooks = lconfigs.Hooks{
|
cfg.Hooks = lconfigs.Hooks{
|
||||||
|
|
Loading…
Reference in New Issue