Systems and protocols · Intermediate

cgroup v2: controlling process resources

Read hierarchical resource controls without confusing throttling, isolation and machine-wide capacity.

Ask Logeia about this articleTry the three questionsReview your answers

Updated

On this page
  1. Organize resource consumption
  2. Hierarchy affects the effective limit
  3. A memory-limit example
  4. Limits are not a root-cause repair
  5. Ask Logeia about this articleCheck your understanding

Organize resource consumption

A cgroup organizes processes into a hierarchy and supports control and accounting of resources such as CPU and memory. Containers may appear machine-like while still competing for the same underlying host resources. Resource grouping makes that competition observable and controllable.

A namespace primarily changes a process’s view of a resource, whereas a cgroup controls or accounts for its use. Combining the two does not create extra physical memory or CPU capacity. Keep visibility, resource limits and security boundaries distinct when explaining container behavior.

Hierarchy affects the effective limit

A child cgroup cannot simply override an ancestor’s constraint by configuring a larger local value. Effective behavior depends on the hierarchy, so examining only one container’s displayed limit can miss the resource boundary that actually applies.

CPU bandwidth control can also create waiting that is not explained by a single instantaneous utilization number. Distinguish the number of available CPUs, relative weights and bandwidth quotas. They answer different questions about scheduling and entitlement, and none should be substituted for the others in a capacity estimate.

A memory-limit example

Suppose a service is killed for memory pressure while the host still has free capacity. Inspect that service’s cgroup memory.current, memory.max and memory.events instead of concluding that memory could not be involved. A local limit can matter before machine-wide memory is exhausted.

Interpret each file according to its meaning: current usage, a configured boundary or a cumulative event count. Record changes across a workload rather than relying only on one value observed after a restart. Reset points and the cgroup being inspected affect the interpretation.

Limits are not a root-cause repair

Raising a limit can postpone a symptom without fixing a leak or an unbounded queue. Determine whether memory follows useful workload size or remains retained after work is complete. Capacity planning and abnormal retention are different investigations.

Control-file changes can affect real workloads and require appropriate privileges. Start with observation and experiment only in a controlled environment. Removing a limit is not a general repair: consider workload size, concurrency and the impact on neighboring services before changing the allocation policy.

Reading and practice are recorded separately in this browser, for each language.

Learn this in order

Understand the systems behind the web · STEP 24

Choose a learning path