Control Groups (cgroups) — The Resource Police
LEVEL 0
The Problem
Namespaces solve the isolation problem. They make each container think it’s alone, with its own filesystem, network, and process list.
But there’s another problem: resource abuse.
Imagine you’re running three containers on your laptop:
- Container A: A web server
- Container B: A database
- Container C: A machine learning training job
Container C starts running. It’s training a neural network. It’s CPU-intensive. Within seconds, it’s using 100% of all your CPU cores.
Containers A and B slow to a crawl. Your web server can’t respond to requests. Your database queries time out.
Even worse, Container C starts allocating memory. 1GB. 2GB. 4GB. It keeps growing. Eventually, your system runs out of memory and starts killing processes.
How do you prevent one container from hogging all the resources?
This is what control groups (cgroups) solve.