0

given:

  • A machine with 8 cores
  • a cgroup with 1-CPU quota
  • the cgroup has only 1 process
  • the process is single-threaded

How will the CPUs be made available to the process?

  • the process be able to run full-throttle on a single core all of the time?
  • the cgroup being given all 8 cpus at the same time for 1/8 of the time, resulting in 7 CPUs being unused by the cgroup and 1 cpu maxed out (at 1/8 capacity)
  • something like round-robin, where the process will be shuffled from core to core so that overall it has 1/8 of total cpu of the machine, taking turns using 1/64 of each CPUs time (fairly certain this is not going to be the case, would be horrible for caching etc)
John Bachir
  • 2,364
  • 7
  • 29
  • 37

1 Answers1

3

There is no challenge for cgroup in your case. This single threaded app will use 1 core in 100%. Cgroup is a system to solves problem like "we have 1000 processes with difference weight and 10 cores, which we can use to run all of them. Lets queue them all to lead theirs weight".

To understand of cgroups CPU quota just imagine that its just "points". Linux kernel dont care how your application spend it:

  1. you can spend all of them on 1 core
  2. you can spend all of them on N cores (1/N on each of N cores for example)

So, in examples like https://www.golinuxcloud.com/cgroup-limit-cpu-usage-linux/ your app with 256 score in the same group gets 256/(1024+256+512+256) of "CPU time", which u will use only on 1 CPU:

  1. 1 total core and you will get 1/8 (throttled) of 1 CPU
  2. 4 total core and you will get 1/2 (throttled) of 1 CPU
  3. 8 total core and you will get 1 of 1 CPU
  4. 16 total core and you will get 1 of 1 CPU because you app is single threaded

Prefer to use internal scheduler settings to prevent throttling in multi-threaded heavy jobs. For example uber's automaxprocs sets golang's GOMAXPROCS equals to provided cgroup scores to prevent throttling

See in:

https://www.kernel.org/doc/Documentation/scheduler/sched-design-CFS.txt

https://github.com/uber-go/automaxprocs

Alex
  • 46
  • 2