Search code examples
cgroups

Increasing cpu.shares cgroup granularity


By default this value is set to 1024. I'm assuming that means that if I set the shares for my group to 1024, it'll be 100% of the available computing power.

Is there any way for me to increase the granularity for this? For example, rather than maxing out at 1024, I want to max out at 2048 or 8196.


Solution

  • IIRC, cpu.shares is already incredibly granular.

    cpu.shares: The weight of each group living in the same hierarchy, that translates into the amount of CPU it is expected to get. Upon cgroup creation, each group gets assigned a default of 1024. The percentage of CPU assigned to the cgroup is the value of shares divided by the sum of all shares in all cgroups in the same level.

    The value of cpu.shares is used to compare to other cgroups. If you have a single process running under cgroups, no matter the value of cpu.shares it will always get as much CPU as the host can spare. Multiple processes running under cgroups assigned the same value for cpu.shares would split the available CPU evenly.

    When you have multiple processes under cgroups, their cpu.shares values are compared together, and those with a higher number get a higher percent of the available host CPU. If you have cpu.shares=1024 for two cgrouped processes, then assign cpu.shares=2048 for a third process, the first two processes would get equal amounts of the available CPU while the third would get twice as much of the available CPU (roughly 25%, 25%, 50%).

    The actual numbers could be anything you want (now that's granular), only the percentage difference between them matters. The results from the above example would be replicated if you used cpu.shares=5 and cpu.shares=10 or cpu.shares=50000 and cpu.shares=100000