Linux — cgroups (Control Groups) — Part 1

Shlomi Boutnaru, Ph.D.
2 min readJan 4, 2023

--

“Control Groups” (aka cgroups) is a Linux kernel feature that organizes processes into hierarchical groups. Based on those groups we can limit and monitor different types of OS resources. Among those resources are: disk I/O usage , network usage, memory usage, CPU usage and more (https://man7.org/linux/man-pages/man7/cgroups.7.html). cgroups are one of the building blocks used for creating containers (which include other stuff like namespaces, capabilities and overlay filesystems).

The cgroups functionality has been merged into the Linux kernel since version 2.6.24 (released in January 2008). Overall, cgroups provide the following features: resource limiting (as explained above), prioritization (some process groups can have larger shares of resources), control (freezing group of processes) and accounting (https://docs.kernel.org/admin-guide/cgroup-v1/cgroups.html).

Moreover, there are two versions of cgroups. cgroups v1 was created by Paul Menage and Rohit Seth. cgroups v2 was redesigned and rewritten by Tejun Heo https://www.wikiwand.com/en/Cgroups . The documentation for cgroups v2 first appeared in the Linux kernel 4.5 release on March 2016 (https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/diff/Documentation/cgroup-v2.txt?id=v4.5&id2=v4.4).

I will write on the differences between the two versions and how to use them in the upcoming writeups. A nice explanation regarding the concept of cgroups is shown in the image below (https://twitter.com/b0rk/status/1214341831049252870). By the way, since kernel 4.19 OOM killer (https://medium.com/@boutnaru/linux-out-of-memory-killer-oom-killer-bb2523da15fc) is aware of cgroups, which means the OS can kill a cgroup as a single unit.

You can follow me on twitter — @boutnaru (https://twitter.com/boutnaru).

https://twitter.com/b0rk/status/1214341831049252870/photo/1

--

--