AlgoViz

Resource limits and pressure inside a container

medium 7 min

A cgroup accounts for a set of processes and can enforce limits on their combined resource usage.

Video lesson · Chapter 1 of 4

When the container runs out of headroom

0:00 / 2:28

Theory

Read or listen first. About 1 min.

What it is

A cgroup accounts for a set of processes and can enforce limits on their combined resource usage. On cgroup v2 a memory.high threshold can trigger reclaim and throttling, while memory.max sets a hard boundary. Pressure stall information measures time lost waiting for resources. It reveals harm that a large byte count alone cannot quantify.

Why it exists

Two workers fit separately but contend when placed together. Follow the hierarchy to include a tighter parent limit. Read memory.events and pressure deltas over one busy interval and compare them with latency. A kill counter describes a past outcome. Increasing stall time can expose degradation while every process is still alive.

If memory stalls and events stay flat, look for CPU throttling or downstream I/O queues within the same workload.

When the container runs out of headroom

Worker processes → Memory controller (charge pages). Memory controller → Reclaim (apply pressure)
Worker processes → Memory controller (charge pages). Memory controller → Reclaim (apply pressure)

Inside this chapter

Cgroups v1 vs. v2 hierarchy
Cgroup v1 can mount controllers in different hierarchies. V2 coordinates enabled controllers in a unified hierarchy. File names and semantics may differ between them.
Limiting CPU quotas
CPU quota limits runtime over a period. Multiple runnable threads can consume it concurrently and leave the group throttled for the rest of that period.
Limiting Memory usage
Memory limits apply to group-accounted usage. Inspect anonymous memory, file cache and events separately before interpreting a large charge as an application leak.
Block I/O throttling
I/O controllers can weight competing groups or impose device-specific limits. Check the actual device hierarchy and measured throughput because buffered writes may be attributed differently from reads.
Freezer cgroup
Freezing suspends tasks in a group without a normal application shutdown. Frozen processes retain resources, which can block dependents until work resumes.
Devices cgroup and PIDs cgroup
The PIDs controller limits task creation in a hierarchy. Device access policy is a different constraint. A failed fork and an inaccessible device need separate evidence.

How it works

Step through the idea, or press Play.

Step 1 of 4

Set the quota. An allowance of 20,000 μs per 100,000 μs period is 20% of one CPU on average.

Understand it

Worked incident

When the container runs out of headroom

ObservationMemory stall time per 10 s (ms)Interpretation
Baseline20The group rarely waits on reclaim.
Incident1800The combined working set triggers sustained stalls.
After intervention45Bound concurrency or redistribute memory. Confirm the chosen change reduces stalls at the same load.
Illustrative measurements from the same workload at three checkpoints.

Choose the next investigation

If memory stalls and events stay flat, look for CPU throttling or downstream I/O queues within the same workload.

Summary

The whole topic in one minute.

The controller can throttle or reclaim while processes survive. The time lost and user-facing delay reveal the cost.

If memory stalls and events stay flat, look for CPU throttling or downstream I/O queues within the same workload.

Sources