mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
libct/cg/sd/v2: support cpu.weight / CPUWeight
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
@@ -85,6 +85,14 @@ func unifiedResToSystemdProps(conn *systemdDbus.Conn, res map[string]string) (pr
|
||||
}
|
||||
addCpuQuota(conn, &props, quota, period)
|
||||
|
||||
case "cpu.weight":
|
||||
num, err := strconv.ParseUint(v, 10, 64)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unified resource %q value conversion error: %w", k, err)
|
||||
}
|
||||
props = append(props,
|
||||
newProp("CPUWeight", num))
|
||||
|
||||
case "pids.max":
|
||||
num := uint64(math.MaxUint64)
|
||||
if v != "max" {
|
||||
|
||||
@@ -200,7 +200,8 @@ function setup() {
|
||||
"memory.high": "5242880",
|
||||
"memory.max": "10485760",
|
||||
"pids.max": "99",
|
||||
"cpu.max": "10000 100000"
|
||||
"cpu.max": "10000 100000",
|
||||
"cpu.weight": "42"
|
||||
}' "$BUSYBOX_BUNDLE"
|
||||
|
||||
runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_unified
|
||||
@@ -219,15 +220,18 @@ function setup() {
|
||||
|
||||
check_systemd_value "TasksMax" 99
|
||||
check_cpu_quota 10000 100000 "100ms"
|
||||
check_cpu_weight 42
|
||||
}
|
||||
|
||||
@test "runc run (cgroup v2 resources.unified override)" {
|
||||
requires root cgroups_v2
|
||||
|
||||
set_cgroups_path "$BUSYBOX_BUNDLE"
|
||||
# CPU shares of 3333 corresponds to CPU weight of 128.
|
||||
update_config ' .linux.resources.memory |= {"limit": 33554432}
|
||||
| .linux.resources.memorySwap |= {"limit": 33554432}
|
||||
| .linux.resources.cpu |= {
|
||||
"shares": 3333,
|
||||
"quota": 40000,
|
||||
"period": 100000
|
||||
}
|
||||
@@ -235,7 +239,8 @@ function setup() {
|
||||
"memory.min": "131072",
|
||||
"memory.max": "10485760",
|
||||
"pids.max": "42",
|
||||
"cpu.max": "5000 50000"
|
||||
"cpu.max": "5000 50000",
|
||||
"cpu.weight": "42"
|
||||
}' "$BUSYBOX_BUNDLE"
|
||||
|
||||
runc run -d --console-socket "$CONSOLE_SOCKET" test_cgroups_unified
|
||||
@@ -255,4 +260,6 @@ function setup() {
|
||||
check_systemd_value "TasksMax" 42
|
||||
|
||||
check_cpu_quota 5000 50000 "100ms"
|
||||
|
||||
check_cpu_weight 42
|
||||
}
|
||||
|
||||
@@ -235,19 +235,27 @@ function check_cpu_quota() {
|
||||
check_systemd_value "CPUQuotaPeriodUSec" $sd_period $sd_infinity
|
||||
}
|
||||
|
||||
# Works for cgroup v1 and v2, accepts v1 shares as an argument.
|
||||
function check_cpu_shares() {
|
||||
local shares=$1
|
||||
|
||||
if [ "$CGROUP_UNIFIED" = "yes" ]; then
|
||||
local weight=$((1 + ((shares - 2) * 9999) / 262142))
|
||||
check_cgroup_value "cpu.weight" $weight
|
||||
check_systemd_value "CPUWeight" $weight
|
||||
check_cpu_weight "$weight"
|
||||
else
|
||||
check_cgroup_value "cpu.shares" "$shares"
|
||||
check_systemd_value "CPUShares" "$shares"
|
||||
fi
|
||||
}
|
||||
|
||||
# Works only for cgroup v2, accept v2 weight.
|
||||
function check_cpu_weight() {
|
||||
local weight=$1
|
||||
|
||||
check_cgroup_value "cpu.weight" $weight
|
||||
check_systemd_value "CPUWeight" $weight
|
||||
}
|
||||
|
||||
# Helper function to set a resources limit
|
||||
function set_resources_limit() {
|
||||
bundle="${1:-.}"
|
||||
|
||||
@@ -372,12 +372,15 @@ EOF
|
||||
|
||||
# check that initial values were properly set
|
||||
check_cpu_quota 500000 1000000 "500ms"
|
||||
# initial cpu shares of 100 corresponds to weight of 4
|
||||
check_cpu_weight 4
|
||||
check_systemd_value "TasksMax" 20
|
||||
|
||||
runc update -r - test_update <<EOF
|
||||
{
|
||||
"unified": {
|
||||
"cpu.max": "max 100000",
|
||||
"cpu.weight": "16",
|
||||
"pids.max": "10"
|
||||
}
|
||||
}
|
||||
@@ -385,6 +388,7 @@ EOF
|
||||
|
||||
# check the updated systemd unit properties
|
||||
check_cpu_quota -1 100000 "infinity"
|
||||
check_cpu_weight 16
|
||||
check_systemd_value "TasksMax" 10
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user