Intermediate LevelLinux Commands & SysAdmin
How do Cgroups v2 manage CPU, RAM, and I/O resource limits for container engines?
❓ Interview Prompt: Explain Control Groups (Cgroups v2), systemd resource slices, resource controllers (cpu, memory, io, pids), and OOM prevention.
Cgroups v2 (Control Groups) is a Linux kernel feature that limits, accounts for, and isolates resource usage (CPU, Memory, I/O, PIDs) for groups of processes:
Resource Controllers:
•
memory.max: Hard RAM limit; triggers OOM killer if exceeded.
•
cpu.max: Limits CPU time quota allocation.
•
pids.max: Prevents fork-bomb attacks by limiting maximum process count.
Code Implementation Example
bash
# Create cgroup v2 slice and set 1GB RAM limit
sudo mkdir -p /sys/fs/cgroup/custom-app
echo "1G" | sudo tee /sys/fs/cgroup/custom-app/memory.max
# Attach running process PID to cgroup
echo 1234 | sudo tee /sys/fs/cgroup/custom-app/cgroup.procs💡Setting process memory resource limits using Cgroups v2.
🎯 Interview Key Takeaway
Cgroups v2 underpins Docker and Kubernetes container isolation, enforcing strict CPU, RAM, and PID caps.
#Cgroups v2#Resource Limits#Containers#Intermediate
Back to all Linux Commands & SysAdmin Questions→