Part 1 of 7 · 1 min read
Why this page comes fifth
In this module you will
- Define a control group (cgroup) and say what it limits that a namespace does not.
- Name the main controllers (memory, cpu, pids, io) and the file that sets each limit.
- Run a program in a memory-limited group and read the result, including the kill.
- Explain how the CPU quota and period give a share of a core, and how throttling shows.
- Say how container tools turn flags such as
--memoryinto cgroup settings.
Page 4 gave a group of processes a private view, but a view does not stop a loop from eating all the memory. This page covers the second half of a container: a cap on use. It builds on the process limits of Level 10 (rlimit, which capped one process), the scheduling of Level 3, the memory management of Level 6 and the out-of-memory killer of Level 7. Page 6 then joins namespaces and control groups into a container.
About this example About this example
Real: The three C programs were compiled with gcc -Wall -Wextra and run as root on the Linux test machine (kernel 6.18). Every number and message shown is real output. The cgroup files were read and written in /sys/fs/cgroup.
Scripted: The names demo for the groups and the limits of 20 MiB, 5 processes and 50 per cent of a core are made up to show the idea.
Not real: The test machine uses the older cgroup version 1 layout, with one directory per controller, so the file names are the version 1 names (memory.limit_in_bytes). Current systems use version 2, with one tree and names such as memory.max. The table in section 2 gives both.