使用 cpu.cfs_quota_us 和 cpu.cfs_period_us 来限制 CPU 使用

使用 cpu.cfs_quota_us 和 cpu.cfs_period_us 来限制 CPU 使用

系统中有 32 个核心(2 个 cpu,每个 16 个核心),我想限制用户仅使用 4 个核心(这 4 个核心的使用率为 100%)。根据手册,有两个内核参数: cpu.cfs_quota_uscpu.cfs_period_us

kernel.org 上的示例文档说:

   With 500ms period and 1000ms quota, the group
   can get 2 CPUs worth of runtime every 500ms.
   # echo 1000000 > cpu.cfs_quota_us /* quota = 1000ms */
   # echo 500000 > cpu.cfs_period_us /* period = 500ms */

我想知道这些ms是怎么确定的?就我而言,我认为配额是32000000,期限是4000000。我对吗?其内容etc/cgconfig.conf为:

group ansys {
  cpu {
    cpu.cfs_quota_us = 32000000;
    cpu.cfs_period_us = 4000000;
  }
  memory {
    memory.limit_in_bytes = 8000m;
  }
}

但这不起作用!当我运行时出现错误/etc.init.d.cgconfig start,我收到以下错误:

Failed to parse /etc/cgconfig.conf or /etc/cgconfig.d
[FAILED]Starting cgconfig service: /sbin/cgconfigparser; error loading
/etc/cgconfig.conf: Failed to remove a non-empty group

答案1

看一下中央处理器组cgroup/容器参数。它可以让你将容器固定到特定的 cpu 核心。在您的情况下,您可以只为核心 0-3 指定一个容器,并且不允许其他容器在同一核心上执行,从而允许每个容器有 4 个核心,利用率为 100%。

此外,与 cpu(使用份额/配额)相比,cpuset 是一种更有效的分配机制。

相关内容