runc update: support per-device weight and iops

This support was missing from runc, and thus the example from the
podman-update wasn't working.

To fix, introduce a function to either update or insert new weights and iops.

Add integration tests.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
(cherry picked from commit 7696402dac)
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2025-05-30 15:08:21 -07:00
parent 7cb4b1878f
commit 80da60e12d
4 changed files with 156 additions and 6 deletions
+29 -6
View File
@@ -174,17 +174,40 @@ function setup() {
runc run -d --console-socket "$CONSOLE_SOCKET" test_dev_weight
[ "$status" -eq 0 ]
# The loop device itself is no longer needed.
losetup -d "$dev"
if [ -v CGROUP_V2 ]; then
file="io.bfq.weight"
else
file="blkio.bfq.weight_device"
fi
weights=$(get_cgroup_value $file)
[[ "$weights" == *"default 333"* ]]
[[ "$weights" == *"$major:$minor 444"* ]]
weights1=$(get_cgroup_value $file)
# Check that runc update works.
runc update -r - test_dev_weight <<EOF
{
"blockIO": {
"weight": 111,
"weightDevice": [
{
"major": $major,
"minor": $minor,
"weight": 222
}
]
}
}
EOF
weights2=$(get_cgroup_value $file)
# The loop device itself is no longer needed.
losetup -d "$dev"
# Check original values.
grep '^default 333$' <<<"$weights1"
grep "^$major:$minor 444$" <<<"$weights1"
# Check updated values.
grep '^default 111$' <<<"$weights2"
grep "^$major:$minor 222$" <<<"$weights2"
}
@test "runc run (per-device multiple iops via unified)" {
+16
View File
@@ -395,6 +395,22 @@ function check_cpu_weight() {
check_systemd_value "CPUWeight" "$weight"
}
function check_cgroup_dev_iops() {
local dev=$1 rbps=$2 wbps=$3 riops=$4 wiops=$5
if [ -v CGROUP_V2 ]; then
iops=$(get_cgroup_value "io.max")
printf "== io.max ==\n%s\n" "$iops"
grep "^$dev rbps=$rbps wbps=$wbps riops=$riops wiops=$wiops$" <<<"$iops"
return
fi
grep "^$dev ${rbps}$" <<<"$(get_cgroup_value blkio.throttle.read_bps_device)"
grep "^$dev ${wbps}$" <<<"$(get_cgroup_value blkio.throttle.write_bps_device)"
grep "^$dev ${riops}$" <<<"$(get_cgroup_value blkio.throttle.read_iops_device)"
grep "^$dev ${wiops}$" <<<"$(get_cgroup_value blkio.throttle.write_iops_device)"
}
# Helper function to set a resources limit
function set_resources_limit() {
update_config '.linux.resources.pids.limit |= 100'
+54
View File
@@ -891,3 +891,57 @@ EOF
runc update test_update --memory 1024
wait_for_container 10 1 test_update stopped
}
@test "update per-device iops/bps values" {
[ $EUID -ne 0 ] && requires rootless_cgroup
# We need a major number of any disk device. Usually those are partitioned,
# with the device itself having minor of 0, and partitions are 1, 2...
major=$(awk '$2 == 0 {print $1; exit}' /proc/partitions)
if [ "$major" = "0" ] || [ "$major" = "" ]; then
echo "=== /proc/partitions ==="
cat /proc/partitions
echo "==="
skip "can't get device major number from /proc/partitions (got $major)"
fi
runc run -d --console-socket "$CONSOLE_SOCKET" test_update
[ "$status" -eq 0 ]
runc update -r - test_update <<EOF
{
"blockIO": {
"throttleReadBpsDevice": [
{
"major": $major,
"minor": 0,
"rate": 10485760
}
],
"throttleWriteBpsDevice": [
{
"major": $major,
"minor": 0,
"rate": 9437184
}
],
"throttleReadIOPSDevice": [
{
"major": $major,
"minor": 0,
"rate": 1000
}
],
"throttleWriteIOPSDevice": [
{
"major": $major,
"minor": 0,
"rate": 900
}
]
}
}
EOF
[ "$status" -eq 0 ]
check_cgroup_dev_iops "$major:0" 10485760 9437184 1000 900
}