8 Managing Resources Using Control Groups
Control groups, referred to as cgroups, are an Oracle Linux kernel feature that organizes systemd
services, and if required, individual processes (PIDs), into hierarchical
groups for allocating system resources, such as CPU, memory, and I/O.
For example, if you have identified three processes that need to be allocated CPU time in a
ratio of 150:100:50, you can create three cgroups, each with a CPU weight
corresponding to one of the three values in the ratio, and assign the appropriate process to
each cgroup.
Important:
Use systemd to configure cgroups.
Manual creation of cgroup directories in the
/sys/fs/cgroup virtual file system (as discussed in this topic) can be
helpful for illustrating underlying concepts. However, this approach should only be used for
specific scenarios, such as temporary debugging or testing. For most use cases, we recommend
using systemd to configure cgroups to ensure correct and
persistent resource management.
By default, systemd creates a cgroup for the following:
-
Each
systemdservice set up on the host.For example, a server might have control group
NetworkManager.serviceto group processes owned by theNetworkManagerservice, and control groupfirewalld.serviceto group processes owned by thefirewalldservice, and so on. -
Each user (
UID) on the host.
The cgroup functionality is mounted as a virtual file system under
/sys/fs/cgroup. Each cgroup has a corresponding directory within
/sys/fs/cgroup file system. For example, the cgroups
created by systemd for the services it manages can be seen by running the
command ls -l /sys/fs/cgroup/system.slice | grep ".service" as shown in the
following sample code block:
ls -l /sys/fs/cgroup/system.slice | grep ".service"
...root root 0 Mar 22 10:47 atd.service
...root root 0 Mar 22 10:47 auditd.service
...root root 0 Mar 22 10:47 chronyd.service
...root root 0 Mar 22 10:47 crond.service
...root root 0 Mar 22 10:47 dbus-broker.service
...root root 0 Mar 22 10:47 dtprobed.service
...root root 0 Mar 22 10:47 firewalld.service
...root root 0 Mar 22 10:47 httpd.service
...You can also create custom cgroups by creating directories under the
/sys/fs/cgroup virtual file system and assigning process IDs
(PIDs) to different cgroups according to system
requirements. However, the recommended practice is to use systemd to
configure cgroups instead of creating the cgroups
manually under /sys/fs/cgroup. See
Oracle Linux 8: Managing the System With
systemd
for the recommended method of managing
cgroups through systemd.
Oracle Linux provides two types of control groups:
- Control groups version 1 (
cgroups v1) -
These groups provide a per-resource controller hierarchy. Each resource, such as CPU, memory, I/O, and so on, has its own control group hierarchy. A disadvantage of this group is the difficulty of establishing proper coordination of resource use among groups that might belong to different process hierarchies.
- Control groups version 2 (
cgroups v2) -
These groups provide a single control group hierarchy against which all resource controllers are mounted. In this hierarchy, you can obtain better proper coordination of resource uses across different resource controllers. This version is an improvement over
cgroups v1whose over flexibility prevented proper coordination of resource use among the system consumers.
Both versions are present in Oracle Linux. However, by default, the
cgroups v1
functionality is enabled and mounted on Oracle Linux
8 systems.
For more information about control groups, see the cgroups(7) and
sysfs(5) manual pages.