systemd+cgroupv1: fix updating CPUQuotaPerSecUSec
1. do not allow to set quota without period or period without quota, as we won't be able to calculate new value for CPUQuotaPerSecUSec otherwise. 2. do not ignore setting quota to -1 when a period is not set. 3. update the test case accordingly. Note that systemd value checks will be added in the next commit. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
parent
7abd93d156
commit
06d7c1d261
|
@ -4,6 +4,7 @@ package systemd
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"os"
|
||||
|
@ -89,7 +90,18 @@ func genV1ResourcesProperties(c *configs.Cgroup) ([]systemdDbus.Property, error)
|
|||
}
|
||||
|
||||
// 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
|
||||
// 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
|
||||
|
|
|
@ -252,15 +252,24 @@ EOF
|
|||
check_cgroup_value "cpu.cfs_quota_us" 500000
|
||||
check_cgroup_value "cpu.shares" 100
|
||||
|
||||
# update cpu-period
|
||||
runc update test_update --cpu-period 900000
|
||||
[ "$status" -eq 0 ]
|
||||
check_cgroup_value "cpu.cfs_period_us" 900000
|
||||
# systemd driver does not allow to update quota and period separately
|
||||
if [ -z "$RUNC_USE_SYSTEMD" ]; then
|
||||
# update cpu period
|
||||
runc update test_update --cpu-period 900000
|
||||
[ "$status" -eq 0 ]
|
||||
check_cgroup_value "cpu.cfs_period_us" 900000
|
||||
|
||||
# update cpu-quota
|
||||
runc update test_update --cpu-quota 600000
|
||||
[ "$status" -eq 0 ]
|
||||
check_cgroup_value "cpu.cfs_quota_us" 600000
|
||||
# update cpu quota
|
||||
runc update test_update --cpu-quota 600000
|
||||
[ "$status" -eq 0 ]
|
||||
check_cgroup_value "cpu.cfs_quota_us" 600000
|
||||
else
|
||||
# update cpu quota and period together
|
||||
runc update test_update --cpu-period 900000 --cpu-quota 600000
|
||||
[ "$status" -eq 0 ]
|
||||
check_cgroup_value "cpu.cfs_period_us" 900000
|
||||
check_cgroup_value "cpu.cfs_quota_us" 600000
|
||||
fi
|
||||
|
||||
# update cpu-shares
|
||||
runc update test_update --cpu-share 200
|
||||
|
|
Loading…
Reference in New Issue