libct/cg/v1: workaround CPU quota period set failure

As reported in issue 3084, sometimes setting CPU quota period fails
when a new period is lower and a parent cgroup has CPU quota limit set.

This happens as in cgroup v1 the quota and the period can not be set
together (this is fixed in v2), and since the period is being set first,
new_limit = old_quota/new_period may be higher than the parent cgroup
limit.

The fix is to retry setting the period after the quota, to cover all
possible scenarios.

Add a test case to cover a regression caused by an earlier version of
this patch (ignoring a failure of setting invalid period when quota is
not set).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
(cherry picked from commit 1b77ebe2c4fa0c6d576dc587aa69e05f6bafd898)
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2021-07-28 10:34:26 -07:00
parent 0b77b2d1d5
commit 4c70105b92
2 changed files with 31 additions and 2 deletions
+9
View File
@@ -345,6 +345,15 @@ EOF
check_cpu_quota -1 1000000 "infinity"
}
@test "set cpu period with no quota (invalid period)" {
[[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup
update_config '.linux.resources.cpu |= { "period": 100 }'
runc run -d --console-socket "$CONSOLE_SOCKET" test_update
[ "$status" -eq 1 ]
}
@test "set cpu quota with no period" {
[[ "$ROOTLESS" -ne 0 ]] && requires rootless_cgroup