On this page
cgroup
Coverage: cgroup v2 unified hierarchy → controllers (cpu/memory/io/pids/cpuset) → cgroupfs → memory reclaim → PSI → cgroup programming model Kernel versions: 2.6 (v1) ~ 6.x (v2)
Overview
cgroup (control group) provides resource usage limits, priority control, and statistics for processes. v2 unifies the multiple independent hierarchies of v1 into a single tree, solving the fundamental problem of lack of coordination between controllers.
cgroup v2 vs v1
cgroup v1:
Each controller has its own hierarchy → CPU and memory control trees may differ
→ Cannot express "the CPU and memory limits in this cgroup act together"
cgroup v2 (4.5+, current default):
Single unified hierarchy → all controllers share the same tree
→ Set parameters for all controllers in the same cgroup directory
→ Coordination between controllers becomes possible (e.g., memory pressure → IO throttling)
cgroupfs Interface
# Mount
# Create cgroup
# → Automatically inherits parent controller settings
# Move process
# View process's cgroup
Controller Details
cpu
# Weight (scheduling priority, default 100):
# Bandwidth limit:
memory
# Memory pressure notification (PSI):
io
# Weight:
# Bandwidth limit:
pids
cpuset
# Pin CPU/memory nodes:
Memory Reclaim Deep Dive
mm/memcontrol.c— Kernel path for cgroup memory controller:
PSI (Pressure Stall Information)
# /proc/pressure/ — Three levels of pressure metrics:
# some: At least one task is waiting → Resource contention
# full: All non-idle tasks are waiting → Resources fully saturated
Programming Interface (Kernel Side)
// include/linux/cgroup.h
// Implementation of controllers in the kernel:
;
// memcg: css = mem_cgroup (one per cgroup)
// blkio: css attached to request_queue
References
- Source Code:
kernel/cgroup/cgroup.c(core framework),mm/memcontrol.c(memory),block/blk-cgroup.c(io),kernel/sched/core.c(cpu) - Kernel Documentation:
Documentation/admin-guide/cgroup-v2.rst(Excellent) - LWN: "cgroup v2", "Memory control group design"
Keywords: cgroup v2, controllers, cpu.weight, memory.max, io.max, PSI, memcg reclaim, cgroupfs