---
title: "Control group"
url: https://www.daytona.com/compute-glossary/kernel/cgroup
---

# Control group

Part of the [Compute Glossary](https://www.daytona.com/compute-glossary.md), section [Kernel](https://www.daytona.com/compute-glossary/kernel.md).

Also called cgroup.

A control group, or cgroup, is a set of [processes](https://www.daytona.com/compute-glossary/kernel/process.md) that the Linux [kernel](https://www.daytona.com/compute-glossary/kernel/kernel.md) measures and limits together, such as with a cap on memory. Every process on a Linux system belongs to one. The kernel counts usage for the group as a whole rather than for each process alone. A process can be moved to another group while it runs, and from then on the limits of the new group apply to it.

Where a [namespace](https://www.daytona.com/compute-glossary/kernel/namespace.md) controls what a process can see, a control group controls how much of the machine it can use. Child processes start in the group of their parent, so a limit covers everything that runs inside the group. A program cannot slip out of its limit by starting helpers, since each helper is counted too. Only a process with the right permissions can move another process into a different group.

Control groups keep one workload from starving another on a shared host. Without them, a single runaway program could take every core or all the memory and slow every neighbor. With limits in place, an operator can put many workloads on one machine and still promise each its share. The caps also make behavior predictable, because no workload can grow past what it was given.

## Controllers

Controllers are the parts of the control group feature that enforce limits, each for one resource. A group is limited only by the controllers enabled for it. Each controller offers its own kinds of limit, such as a hard cap or a relative weight. A weight shares a resource in proportion only while the machine is busy, while a cap holds at all times.

The same controllers report usage as well as limiting it. Container platforms read those reports to measure what each workload consumed and to bill its owner for it. Pressure figures go further, showing how long tasks in a group waited for a resource they could not get. Monitoring tools use those figures to act before a host is fully overloaded.

When a group exceeds its [memory](https://www.daytona.com/compute-glossary/hardware/memory.md) cap, the out-of-memory killer of the kernel acts on that group alone. The rest of the host keeps running, which is the point of the cap. As a group nears its cap, the kernel first reclaims memory from it, dropping file cache and swapping where that is allowed. It kills a process, usually the largest in the group, only when reclaim fails.

| **Controller**                                  | **Description**                                                                                  |
| ----------------------------------------------- | ------------------------------------------------------------------------------------------------ |
| [**cpu**](https://www.daytona.com/compute-glossary/hardware/cpu.md)       | A CPU is the general-purpose processor that runs the programs of a computer.                     |
| **cpuset**                                      | The cpuset controller pins the group to particular cores and NUMA nodes.                         |
| [**memory**](https://www.daytona.com/compute-glossary/hardware/memory.md) | Memory is the fast, temporary storage that holds the instructions and data a processor works on. |
| **io**                                          | The io controller limits or weights reads and writes to block devices.                           |
| **pids**                                        | The pids controller caps the number of processes, which stops a fork bomb.                       |

## Hierarchy

A hierarchy is the tree in which control groups are arranged, which the kernel exposes as a file system. Each directory is a group, and groups nest inside each other. A limit on a parent bounds all its children together, so the children can never use more than the parent allows. Operators use this to split a host first by tenant and then by workload within each tenant.

Reading or writing files in a directory reads or sets the state of that group. Moving a process into a group is a matter of writing its ID into the process list of the group. No special tool is needed, because ordinary file permissions decide who may change a group. A runtime can hand a subtree to an unprivileged user this way, letting that user manage the groups inside it.

The first version of control groups let each controller have its own hierarchy, which proved hard to manage. Control groups v2 put all controllers in one tree with clearer rules. One of those rules keeps processes only in the leaves of the tree, so a parent never splits its resources between its own processes and its children. Some older software still expected the first layout, which slowed the move to v2.

| **Version**           | **Description**                                                                                                        |
| --------------------- | ---------------------------------------------------------------------------------------------------------------------- |
| **Control groups v1** | Control groups were merged into Linux in 2008, from work started by engineers at Google.                               |
| **Control groups v2** | Control groups v2 was declared stable in 2016 and is the default in most current distributions and container runtimes. |

## Fairness and security

Fairness and security are the two goals of isolation, and control groups serve only the first. They do not stop a process from attacking the kernel, so they guard fairness and stability rather than security. A process inside a group can still make every system call the kernel allows. It is only kept from using more than its share.

Control groups are therefore combined with namespaces and, in most runtimes, system call filters such as [seccomp](https://www.daytona.com/compute-glossary/kernel/seccomp.md). Together they make up a [container](https://www.daytona.com/compute-glossary/virtualization/container.md), which control groups make safe to pack densely on one host. Each piece covers a gap the others leave, and none of them is enough alone. A container runtime sets them up before it starts the first process inside.

Control groups also let an operator [overcommit](https://www.daytona.com/compute-glossary/infrastructure/overcommit.md) a host with known bounds. Hypervisors such as Firecracker run the monitor process of each virtual machine inside a control group to cap what the whole guest can consume. Because the memory and virtual processors of the guest all belong to that one process, a single group bounds the whole machine. The guest kernel cannot see or raise that cap, since it sits outside the virtual machine.

## Related terms

- [Namespace](https://www.daytona.com/compute-glossary/kernel/namespace.md)
- [Process](https://www.daytona.com/compute-glossary/kernel/process.md)
- [Container](https://www.daytona.com/compute-glossary/virtualization/container.md)
- [Memory](https://www.daytona.com/compute-glossary/hardware/memory.md)
- [Overcommit](https://www.daytona.com/compute-glossary/infrastructure/overcommit.md)
