在cgroup的上下文中,cpu.shares和cpu.cfs_quota_us之间是什么关系? [英] What is the relationship between cpu.shares and cpu.cfs_quota_us in context of cgroup?

查看:641
本文介绍了在cgroup的上下文中,cpu.shares和cpu.cfs_quota_us之间是什么关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用centos6/7并使用cgroup来管理cpu资源.我已经阅读了 RHEL文档,但没有回答以下问题:

如果同时设置cfs_quota_us和cgroup之间的共享,那么会发生什么?

(例如cfs_quota_us是否优先于共享?)

谢谢您!

解决方案

我的理解是,对于两个cgroup相同级别(仅),例如:

  foo|+-栏|+-baz 

然后 bar baz 将首先根据 cpu.share 共享 foo 上占用的cpu./p>

让我们说总体cpu是1核心,其中 cpu.cfs_period_us 设置为 100ms . bar cpu.share 设置为 1024 baz 1024 设置./p>

    例如,如果 bar baz 都将 cpu.cfs_quota_us 设置为超过 50ms ,则
  1. 75ms .然后,两个cgroup将共享一半的CPU,确切值为 50ms .

  2. ,如果他们两个都将 cpu.cfs_quota_us 设置为小于 50ms ,例如, 25ms .他们仍将共享1:1的cpu,但确切值为 25ms .

  3. 如果 bar 将配额设置为 25ms ,而 baz 将配额设置为 75ms (这正是我所想的).由于 bar baz 具有相同的 cpu.share ,并且 bar 的上限设置为 25ms,这意味着 bar 不得超过 25ms .因此,给定100ms的时间段, bar 将消耗 25ms .由于相同的 cpu.share baz 还会消耗25ms的时间作为 bar 吗?如果是,那我们该如何剩下50ms?

    根据RHEL6的文档:

    由于CFS并不需要相等的CPU使用率,因此很难预测cgroup将被允许使用多少CPU时间.当一个cgroup中的任务处于空闲状态并且不使用任何CPU时间时,剩余时间将收集在未使用的CPU周期的全局池中.允许其他cgroup从该池借用CPU周期.

    我们可以看到, baz 消耗未使用的CPU周期是合法的,即 baz 将在一个周期内消耗 75ms .

结论

cpu.share cpu.cfs_quota_us 一起工作.

鉴于总的cpu配额,我们应该首先分配每个cgroup的 cpu.share .然后找到其确切配额超出其 cpu.cfs_quota_us 的cgroup,找到所有此类cgroup并将其配额保留为其 cpu.cfs_quota_us ,并将超出的部分收集为未使用的cpu池.再次通过 cpu.share 在其他cgroup之间分配这些未使用的cpu池,并按上述步骤进行迭代,直到没有cgroup超过上限为止.

I'm using centos6/7 and using cgroup to manage cpu resources. I have read through the RHEL document but have no answer to my question below:

If I set both cfs_quota_us and shares among cgroups, then what will happen?

(e.g. will cfs_quota_us take precedence over shares?)

Thank you in anticipation!

解决方案

My understanding is that for the same level of two cgroups (only), e.g.:

foo
 |
 +- bar
 |
 +- baz

Then bar and baz will firstly share the cpu occupied on foo according to cpu.share.

Let's say the overall cpu is 1 core with cpu.cfs_period_us set as 100ms. cpu.share is set as 1024 for bar and 1024 for baz.

  1. if both bar and baz are setting cpu.cfs_quota_us more than 50ms, for example, 75ms. Then both cgroup will share the cpu by half, with exact value of 50ms.

  2. if both of them has cpu.cfs_quota_us set less than 50ms, for example, 25ms. They will still share cpu 1:1, but with the exact value of 25ms.

  3. what if bar is setting quota as 25ms, while baz setting quota as 75ms (this is exactly what I wondered). Since bar and baz has the same cpu.share, and bar has upper limit set as 25ms, this means bar should never exceeds 25ms. So given a 100ms period, bar will consume 25ms. Will baz also consume 25ms as bar because of same cpu.share? If yes, then how do we put the 50ms left?

    According to RHEL6's document:

    Because the CFS does not demand equal usage of CPU, it is hard to predict how much CPU time a cgroup will be allowed to utilize. When tasks in one cgroup are idle and are not using any CPU time, the leftover time is collected in a global pool of unused CPU cycles. Other cgroups are allowed to borrow CPU cycles from this pool.

    We can see that it is legal for baz to consume the unsed CPU cycles, i.e. baz will consume 75ms in one period.

Conclusion

cpu.share and cpu.cfs_quota_us are working together.

Given a total cpu quota, we should firstly distribute the cpu.share of each cgroup. Then find the cgroups whose exact quota exceeds their cpu.cfs_quota_us, find all such cgroups and keep their quota as their cpu.cfs_quota_us, and collect the exceeded part as unused cpu pool. Distribute these unused cpu pool among other cgroups by cpu.share again, and iterate as above, until no cgroup is exceeding the upper limit.

这篇关于在cgroup的上下文中,cpu.shares和cpu.cfs_quota_us之间是什么关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆