Skip to content

Commit

Permalink
libct/cg/sd/v2: support cpuset.* / Allowed*
Browse files Browse the repository at this point in the history
 * cpuset.cpus -> AllowedCPUs
 * cpuset.mems -> AllowedMemoryNodes

No test for cgroup v2 resources.unified override, as this requires a
separate test case, and all the unified resources are handled uniformly
so there's little sense to test all parameters.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Nov 4, 2020
1 parent 25b5cf4 commit b7160aa
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
8 changes: 8 additions & 0 deletions libcontainer/cgroups/systemd/v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ func unifiedResToSystemdProps(conn *systemdDbus.Conn, res map[string]string) (pr
props = append(props,
newProp("CPUWeight", num))

case "cpuset.cpus":
props = append(props,
newProp("AllowedCPUs", v))

case "cpuset.mems":
props = append(props,
newProp("AllowedMemoryNodes", v))

case "pids.max":
num := uint64(math.MaxUint64)
if v != "max" {
Expand Down
6 changes: 6 additions & 0 deletions tests/integration/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,12 @@ function requires() {
skip_me=1
fi
;;
smp)
local cpu_count=$(grep -c '^processor' /proc/cpuinfo)
if [ "$cpu_count" -lt 2 ]; then
skip_me=1
fi
;;
systemd)
if [ -z "${RUNC_USE_SYSTEMD}" ]; then
skip_me=1
Expand Down
40 changes: 40 additions & 0 deletions tests/integration/update.bats
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,46 @@ EOF
check_systemd_value "TasksMax" 10
}

@test "update cpuset parameters via v2 unified map" {
[[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup
requires cgroups_v2 smp

runc run -d --console-socket "$CONSOLE_SOCKET" test_update
[ "$status" -eq 0 ]

# check that initial values were properly set
check_systemd_value "AllowedCPUs" 0
check_systemd_value "AllowedMemoryNodes" 0

runc update -r - test_update <<EOF
{
"unified": {
"cpuset.cpus": "1",
}
}
EOF

# check the updated systemd unit properties
check_systemd_value "AllowedCPUs" 1

# More than 1 numa memory node is required to test this
file="/sys/fs/cgroup/cpuset.mems.effective"
if ! test -r $file || grep -q '^0$' $file; then
# skip the rest of it
return 0
fi

runc update -r - test_update <<EOF
{
"unified": {
"cpuset.mems": "1",
}
}
EOF
# check the updated systemd unit properties
check_systemd_value "AllowedMemoryNodes" 1
}

@test "update rt period and runtime" {
[[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup
requires cgroups_v1 cgroups_rt no_systemd
Expand Down

0 comments on commit b7160aa

Please sign in to comment.