Why a group matters
A service can start many worker processes. Resource controls applied to the group can account for the service as a whole rather than give every worker an unrelated allowance. Cgroups organize workloads and apply resource-specific controls; they do not automatically provide separate filesystem or network views.
The source’s CPU-sharing example
Assumptions: one CPU core, two competing sibling groups, continuously runnable processes, and no relevant competing workload. Group A has weight 1024 and one busy process; Group B has weight 512 and two equally busy processes.
| Group | Weight | Relative group allocation | Allocation per equally busy process |
|---|---|---|---|
| A | 1024 | 1024 / 1536 = 2/3 | 2/3 |
| B | 512 | 512 / 1536 = 1/3 | (1/3) / 2 = 1/6 |
The displayed top output is approximately 66%, 16% and 17%. Actual samples fluctuate; these fractions explain the intended allocation rather than promise exact measured percentages.
If B starts ten equally busy processes, its group share stays approximately one-third under the same assumptions. Each gets roughly one-thirtieth. More workers divide the group’s allocation; they do not multiply its weight. If A becomes idle, B can use otherwise available time because weights are relative competition controls, not permanent ceilings.
Read the source commands
PDF page 8 uses cgroup v1-style CPU controls:
sudo cgcreate -g cpu:/cpufullspeed
sudo cgcreate -g cpu:/cpuhalfspeed
sudo cgset -r cpu.shares=1024 cpufullspeed
sudo cgset -r cpu.shares=512 cpuhalfspeed
sudo cgexec -g cpu:cpufullspeed ./twothirds.sh
sudo cgexec -g cpu:cpuhalfspeed ./onethird1.shThe full source launches three CPU-consuming scripts in the background, two in the second group. cgcreate creates groups, cgset assigns relative shares and cgexec starts work in a group. Names such as cpuhalfspeed do not define the actual ratio: 1024:512 means 2:1 between groups. These are explanatory source commands, not a tested setup recipe or executed workload.
Weight versus quota
| Control | Meaning | When other work is idle |
|---|---|---|
| Weight/shares | Relative allocation when workloads compete | Can use otherwise available CPU time |
| Quota | CPU-time ceiling per period | Ceiling still applies |
Added example: a quota of 50 ms CPU time in each 100 ms period provides half of one CPU’s time on average. The budget is aggregate execution time, not a separate allowance for each process. Parallel execution can consume it faster in wall-clock time. Exhaustion normally throttles the quota-controlled work until budget is available again.
The modern cgroup v2 interface uses cpu.weight and cpu.max; its weight values should not be treated as a verbatim copy of v1’s cpu.shares scale. Linux cgroup v2 CPU controls.
Memory is different from CPU time
A computation can wait for another turn. A new allocation needs memory backing within the applicable constraints. At a hard memory.max limit, Linux attempts reclamation; if usage cannot be reduced, the cgroup can encounter OOM killing. memory.high is a reclaim/throttling threshold rather than the same hard-limit mechanism. This is added detail, not the CPU-weight demonstration’s behavior. Linux cgroup v2 memory controls.
Retrieval practice
Does a generous weight override a strict quota when competitors are idle? No. The weight determines relative allocation; the quota remains a ceiling.
Does a private network namespace protect other services from this group’s memory demand? No. Visibility and consumption are separate policies.
Does the cgroup namespace enforce these limits? No. It changes the view of cgroup membership and hierarchy; the cgroup controllers enforce resource policies. See User UTS IPC and Cgroup Namespaces.
Source and related concepts
Lecture 06 - Lightweight Virtualization - Cgroups and Namespaces, PDF pages 4-8. Quota, memory-controller distinctions and the ten-worker calculation are added study explanations. CoreOS and deployment references are historical source context.