mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
cgroupv1: minimal fix for cpu quota regression
This is a quick-n-dirty fix the regression introduced by commit
06d7c1d, which made it impossible to only set CpuQuota
(without the CpuPeriod). It partially reverts the above commit,
and adds a test case.
The proper fix will follow.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
@@ -4,7 +4,6 @@ package systemd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math"
|
"math"
|
||||||
"os"
|
"os"
|
||||||
@@ -90,18 +89,7 @@ func genV1ResourcesProperties(c *configs.Cgroup) ([]systemdDbus.Property, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// cpu.cfs_quota_us and cpu.cfs_period_us are controlled by systemd.
|
// cpu.cfs_quota_us and cpu.cfs_period_us are controlled by systemd.
|
||||||
if c.Resources.CpuQuota != 0 || c.Resources.CpuPeriod != 0 {
|
if c.Resources.CpuQuota != 0 && c.Resources.CpuPeriod != 0 {
|
||||||
if c.Resources.CpuQuota < -1 {
|
|
||||||
return nil, fmt.Errorf("Invalid CPU quota value: %d", c.Resources.CpuQuota)
|
|
||||||
}
|
|
||||||
if c.Resources.CpuQuota != -1 {
|
|
||||||
if c.Resources.CpuQuota == 0 || c.Resources.CpuPeriod == 0 {
|
|
||||||
return nil, errors.New("CPU quota and period should both be set")
|
|
||||||
}
|
|
||||||
if c.Resources.CpuPeriod < 0 {
|
|
||||||
return nil, fmt.Errorf("Invalid CPU period value: %d", c.Resources.CpuPeriod)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// corresponds to USEC_INFINITY in systemd
|
// corresponds to USEC_INFINITY in systemd
|
||||||
// if USEC_INFINITY is provided, CPUQuota is left unbound by systemd
|
// if USEC_INFINITY is provided, CPUQuota is left unbound by systemd
|
||||||
// always setting a property value ensures we can apply a quota and remove it later
|
// always setting a property value ensures we can apply a quota and remove it later
|
||||||
|
|||||||
@@ -281,6 +281,13 @@ EOF
|
|||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
check_cgroup_value "cpu.cfs_quota_us" 600000
|
check_cgroup_value "cpu.cfs_quota_us" 600000
|
||||||
else
|
else
|
||||||
|
# update cpu quota
|
||||||
|
runc update test_update --cpu-quota 600000
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
check_cgroup_value "cpu.cfs_quota_us" 600000
|
||||||
|
# this is currently broken
|
||||||
|
#check_systemd_value "CPUQuotaPerSecUSec" 600ms
|
||||||
|
|
||||||
# update cpu quota and period together
|
# update cpu quota and period together
|
||||||
runc update test_update --cpu-period 900000 --cpu-quota 600000
|
runc update test_update --cpu-period 900000 --cpu-quota 600000
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
|
|||||||
Reference in New Issue
Block a user