I'd like to limit the container to 25% of the system's total CPU bandwidth.
Here's my setup:
- LXC version 1.0.2
- kernel 3.2.45
- one user created cgroup (foo) for an LXC container
- 40 available cores on the host
- the host and container have default values for every other cgroup subsystem except:
/sys/fs/cgroup/cpu/lxc/foo/cpu.cfs_quota_us = 400000
/sys/fs/cgroup/cpu/lxc/foo/cpu.cfs_period_us = 100000
/sys/fs/cgroup/cpuset/lxc/foo/cpuset.cpus = 0-15
I calculated the quota using this formula:
(# of cpus available to container) * (cpu.cfs_period_us) * (.25) so 16 * 100000 * .25 = 400000
I ran a basic stress-ng inside and outside the container at the same time to get a gauge of how many operations per second were being allowed inside and out and the results were basically the same as running with a quota of "-1", which is to say no quota.
Outside Run:
$ ./stress-ng --cpu-load 50 -c 40 --timeout 20s --metrics-brief
stress-ng: info: [25649] dispatching hogs: 40 cpu
stress-ng: info: [25649] successful run completed in 20.44s
stress-ng: info: [25649] stressor bogo ops real time usr time sys time bogo ops/s bogo ops/s
stress-ng: info: [25649] (secs) (secs) (secs) (real time) (usr+sys time)
stress-ng: info: [25649] cpu 37348 20.18 380.56 0.58 1850.85 97.99
Inside Run:
$ ./stress-ng --cpu-load 100 -c 16 --timeout 20s --metrics-brief
stress-ng: info: [34256] dispatching hogs: 16 cpu
stress-ng: info: [34256] successful run completed in 20.10s
stress-ng: info: [34256] stressor bogo ops real time usr time sys time bogo ops/s bogo ops/s
stress-ng: info: [34256] (secs) (secs) (secs) (real time) (usr+sys time)
stress-ng: info: [34256] cpu 24147 20.03 205.20 0.17 1205.67 117.58
Based on the ops/s I'm getting 39%. Why does this happen? Shouldn't it be limited by cpu.cfs_quota_us
?
Thanks for the help in advance.