Docker & Containers (50 Qs)•Part 3: Advanced Internals, Scale & Production Security (Senior / Lead)
Linux Control Groups (cgroups v1 vs cgroups v2): Memory OOM-killer Behavior and CPU CFS Bandwidth Quotas.
senior LevelSecurity & Auth
In Simple Words: cgroups regulate resource allocation and hardware throttling:
- cgroups v1: Had separate, uncoordinated hierarchies per resource controller (
/sys/fs/cgroup/cpu,/sys/fs/cgroup/memory). Suffered from buffer-writeback priority inversions where disk I/O could not be accurately charged to the responsible memory cgroup. - cgroups v2: A single unified hierarchy tree. Correctly handles unified accounting (memory, blkio, cpu) and memory-pressure stalls (PSI - Pressure Stall Information).
CPU Throttling Mechanics: Completely Fair Scheduler (CFS)
- Period:
cpu.cfs_period_us(default: 100,000 microseconds = 100ms). - Quota:
cpu.cfs_quota_us(e.g., 50,000us = 50ms = 0.5 CPU cores). - If a container exhausts its 50ms quota within the first 10ms of the 100ms period, the Linux kernel hard-throttles (freezes) the process for the remaining 90ms, causing massive latency spikes!