lxd
lxd copied to clipboard
Changing `limits.cpu` of a container can be racy
In tests/cgroup from lxd-ci.git, the following sometimes fail when unsetting the limits.cpu and immediately checking if the limit is gone:
echo "==> Testing CPU limits"
lxc config set c1 limits.cpu=2
[ "$(lxc exec c1 -- nproc)" = "2" ]
lxc config set c1 limits.cpu=200
[ "$(lxc exec c1 -- nproc)" = "$(nproc)" ]
lxc config set c1 limits.cpu=0,2
[ "$(lxc exec c1 -- nproc)" = "2" ]
lxc config set c1 limits.cpu=2-2
[ "$(lxc exec c1 -- nproc)" = "1" ]
lxc config unset c1 limits.cpu
[ "$(lxc exec c1 -- nproc)" = "$(nproc)" ]
If a sleep 2 is introduced between the last 2 lines, the race is avoided.
Additional information:
# snap list lxd
Name Version Rev Tracking Publisher Notes
lxd git-7294d23 26547 latest/edge canonical✓ -
So the application of the limit is still always taking effect, its just that there can be a short delay between the set/unset command returning and the limit actually being applied.