Control Groups (Cgroups)

Note: The cgroups that we are talking in this section mainly concerns about version 1. If it is about version 2, it will be explicit.

Cgroups is a #202204081225 kernel feature that set resource utilisation limits on processes on the system. Default cgroups and their data could be found in /sys/fs/cgroup/.

There are several features introduced by Cgroups, namely:

  • resource restriction
  • prioritisation
  • accounting/logging
  • process control (using freezer to take a snapshot and move process)

Cgroups are created per resource type without associations with each other. This means that Linux kernel could manage different types of applications with different standard of resource management. It is sort of similar to 202203281429 where the view of PID in Cgroups is different from the system and from each other.

One could impose restriction on the resources could be used in one cgroup. For example, we could define the value for CPUShares in cpu.shares file to initialise the weight or priority cgroups on CPU time-share. To avoid the users sharing the precious CPU time with system resources, make sure that cpu.weight in system.slice is larger than user.slice.

Creation

A typical cgroups structure looks like below:

/my_cgroups
  <resource controller type>
    <group 1>
    <group 2>
    <group 3>

Custom cgroups should follow the structure above before mounted using the command mount -t cgroup -o {resource} none {path-to-cgroups-resource-controller}. After the successful mounting, the directory for the resource controller will be populated with files in regard to its corresponding resources specified by the mount option -o.

Links to this page
#linux