Linux cgroups:以绝对值限制CPU使用率,不依赖于CPU速度
作者:互联网
我有一台2.4GHz处理器的服务器.并且有几个cgroup,每个允许使用25%的CPU.这相当于600MHz.
然后我用更快的CPU更换CPU,比方说3.0GHz.如果我使用cpu.shares,我的容器将继续获得3.0GHz的25%,现在等于750MHz.
这意味着在更换CPU之后,我必须重新配置我的cgroup,使它们消耗的CPU不超过20%.
有没有办法在CPU升级期间避免这种麻烦?
解决方法:
股票是相对的.例如,分配25%的CPU意味着cgroup将“至少”观察到大部分CPU,但它可以使用更多.从red hat docs on cgroups:
Note that shares of CPU time are distributed per all CPU cores on multi-core systems. Even if a cgroup is limited to less than 100% of CPU on a multi-core system, it may use 100% of each individual CPU core.
…
The actual amount of CPU time that is available to a cgroup can vary depending on the number of cgroups that exist on the system. If a cgroup has a relative share of 1000 and two other cgroups have a relative share of 500, the first cgroup receives 50% of all CPU time in cases when processes in all cgroups attempt to use 100% of the CPU. However, if another cgroup is added with a relative share of 1000, the first cgroup is only allowed 33% of the CPU (the rest of the cgroups receive 16.5%, 16.5%, and 33% of CPU).
如果要对CPU带宽进行硬限制,可以使用cpu.cfs_quota_us和cpu.cfs_period_us.从Kernel’s CFS docs开始:
The bandwidth allowed for a group is specified using a quota and period. Within each given “period” (microseconds), a group is allowed to consume only up to “quota” microseconds of CPU time. When the CPU bandwidth consumption of a
group exceeds this limit (for that period), the tasks belonging to its hierarchy will be throttled and are not allowed to run again until the next
period.
但是,这两个选项都不允许您在不同CPU之间移植组,而无需更改cgroups配置.
标签:linux,cpu,limit,cgroups,quota 来源: https://codeday.me/bug/20190812/1642209.html