Course contentsShow
← Linux
Lesson 1463 of 1,81913. Containerization Primitives and NamespacesFree lesson

Cgroup v2 Hierarchies

Organize system resources into a unified tree structure to enforce strict limits.

In this lesson, you will learn how Cgroup v2 unifies system resource management into a single, strict tree structure to enforce hardware limits on processes.

From Complexity to Unity

In the early days of Linux resource management (Cgroup v1), different resource controllers—like CPU, memory, and I/O—operated as independent, disconnected hierarchies. This often led to fragmented configurations where a process could exist in one group for memory limits but an entirely different group for CPU throttling, creating a nightmare for accounting and orchestration.

Cgroup v2 simplifies this by mandating a unified hierarchy. Under this model, there is only one tree rooted at /sys/fs/cgroup/. Every controller is naturally integrated into this singular structure, ensuring that a process’s resource boundaries are consistently defined by its position in the tree.

The Hierarchical Nature

The hierarchy functions as a parent-child relationship. When you create a subdirectory in the cgroup filesystem, you create a new "cgroup" node. You can then delegate specific resource limits to that node:

# Create a new cgroup named 'web-server'
mkdir /sys/fs/cgroup/web-server

# Assign a process to this group by writing its PID
echo 1234 > /sys/fs/cgroup/web-server/cgroup.procs

# Set a strict memory limit of 512MB for this group
echo "536870912" > /sys/fs/cgroup/web-server/memory.max

Because this is a strict tree, a child group cannot exceed the limits set by its parent. If the parent group is restricted to 1GB of memory, no amount of redistribution among its children can ever grant them more than that aggregate total. This structure allows system administrators to delegate sub-trees to non-root users safely, enabling them to manage their own internal processes while the system enforces a hard ceiling that they cannot bypass. By keeping the hierarchy clean and unified, Cgroup v2 transforms resource management from a collection of "knobs" into a predictable, top-down governance model for your containerized workloads.

Key Takeaway: Cgroup v2 mandates a unified, tree-like hierarchy that enforces strict resource boundaries, ensuring that child groups operate within the rigid constraints defined by their parents.