What are Linux control groups (cgroups), and what do they protect against?
A kernel feature that limits and accounts for the resources (CPU, memory, process count, I/O) a group of processes may use — the basis of container resource isolation.
cgroups let the kernel put a ceiling on what a set of processes can consume. Docker uses them so one container cannot starve the host or its neighbours. Typical limits:
- CPU — how many cores, which cores, or a relative share of CPU time.
- Memory — a hard cap in bytes.
- Process count (PIDs) — the maximum number of processes/threads.
- Block I/O — disk bandwidth.
What they defend against: a misbehaving or malicious container that tries to grab all the host's resources — whether through buggy code, a (D)DoS, or a fork bomb. Without a limit, Docker gives a container the host's own limits, i.e. effectively none. By capping CPU, memory and PIDs, cgroups keep one container from taking the whole machine down.
cgroups are about availability (keeping the system responsive), separate from the namespace mechanisms that provide isolation of what a container can see.
Go deeper:
Wikipedia: cgroups — the kernel feature behind container resource limits.
Docker Docs: Resource constraints — the --cpus, --memory and --pids-limit flags in practice.