map / systems / cgroups-namespaces

Systems · principle 7 of 7

cgroups & namespaces

A container is a process with namespaces (what it can see) and cgroups (what it can use) — not a tiny VM.

01 · Why it’s true

A container isn’t a virtual machine. It’s an ordinary process on a shared kernel with two kernel features applied. Namespaces control what the process can see: its own process IDs, network interfaces, filesystem mounts, and hostname.

Control groups (cgroups) control what it can use: CPU, memory, I/O, and number of processes. Because the kernel is shared, a container that exceeds its memory limit is OOM-killed by the host kernel, and one that uses up its CPU quota is throttled — slowed down, not stopped.

02 · Picture it

Namespaces: what it can seePID: its own process treeNetwork: its own interfaces and portsMount: its own filesystem viewUTS: its own hostnameUser: its own user IDscgroups: what it can useCPU: shares and quotas — over quotameans throttledMemory: a hard limit — over it meansOOM-killedI/O: bandwidth and operation limitsPIDs: a cap on process countvsA container is just a process on the shared host kernel with both applied.
Namespaces: what it can seePID: its own process treeNetwork: its own interfaces andportsMount: its own filesystem viewUTS: its own hostnameUser: its own user IDscgroups: what it can useCPU: shares and quotas — over quotameans throttledMemory: a hard limit — over itmeans OOM-killedI/O: bandwidth and operation limitsPIDs: a cap on process countA container is just a process on theshared host kernel with both applied.
Namespaces limit what a container sees; cgroups limit what it uses.

03 · In the interview

  • Explaining what a container really is.
  • Diagnosing CPU throttling: latency spikes while average CPU looks fine.
  • Understanding container memory limits and OOM kills.

04 · Practice question

“A container averages 40% of its CPU limit, yet its latency spikes regularly. What could cause that?”

A strong answer covers

  1. CPU limits are enforced over short periods (the CFS quota), so a burst can use the whole quota early in a period and be throttled until the next one.
  2. Averages hide this; check the cgroup’s throttling counters (nr_throttled and throttled_usec in cpu.stat).
  3. Multi-threaded apps use quota faster because several threads run at once.
  4. Fixes: raise or remove the CPU limit, reduce parallelism, or rely on CPU requests instead of hard limits.