Control groups (cgroups)

Collection of processes bound by the same criteria and associated with a set of parameters or limits.

cgroups are organized hierarchically.

  • cgroup file system.

  • Limits can be defined at each hierarchical level.

    • Affecting the sub-hierarchy underneath.

Subsystems.

  • Kernel component that modifies the behaviour of cgroup processes.

  • Resource controllers (or simply controllers).

File system

This file system is created by mounting several controllers as cgroup-type file system entities.

  • Usually /sys/fs/cgroup

  • In V2 all controllers are part of a single cgroup2.

Each controller defines a tree of cgroups below the mount point.

  • e.g. memory controller → /sys/fs/cgroup/…/memory.[…]

cgroup V2 (and V1) controllers

V2 definition

Directory under /sys/fs/cgroup.

  • With a set of controllers defined by cgroup.controllers

  • With hierarchy limits defined by cgroup.depth and cgroup.descendants

  • With files to send KILL signals (cgroup.kill) and freeze/unfreeze orders (cgroup.freeze) to all cgroup processes.

    • Including descendants.

  • The processes using the cgroup are given by cgroup.procs and their status reported by cgroups.events.

    • We can add a process to a cgroup just by writing its PID on the first file.

For each active controller, specific files will exist.

Processes can only belong to leaf cgroups.

  • “No internal processes” rule

cgroups of a process

A process can be controlled by an arbitrary number of cgroups.

The list of a process’ cgroups is given by the /proc file system.

  • /proc/[PID]/cgroup

Last updated