Managing cgroups v2
Using sysfs
This section shows you how to create and configure cgroups
to manage the
distribution of resources amongst processes running on the system by using the
sysfs
interface.
Important:
We recommend that you use systemd to handle all resource management. See Oracle Linux 8: Managing the System With systemd for more information. The examples provided here provide the context for actions that systemd performs on a system and show the functionality outside of systemd. The information provided can be helpful when debugging issues with cgroups.
The example procedure involves allocating CPU time between cgroups
that each
have different application PIDs assigned to them. The CPU time and application PID values are
set in each group's cpu.weight
and cgroup.procs
files.
The example also includes the steps required to ensure the cpu
controller
and its associated files, including the cpu.weight
file, are available in the
cgroups
you need to create under /sys/fs/cgroup
.
Preparing the Control Group for Distribution of CPU Time
This procedure describes how to manually prepare a control group to manage the
distribution of CPU time. Note that the recommended approach to configuring control groups is to
use systemd
.
Setting CPU Weight to Regulate Distribution of CPU Time
This procedure describes how to set CPU weight for three different processes by using a control
group to manage the distribution of CPU time. Note that the recommended approach to
configuring control groups is to use systemd
.
This procedure is based on the following assumptions:
-
The application that's consuming CPU resources excessively is
sha1sum
, as shown in the following sample output of thetop
command:sudo top
... PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 33301 root 20 0 18720 1756 1468 R 99.0 0.0 0:31.09 sha1sum 33302 root 20 0 18720 1772 1480 R 99.0 0.0 0:30.54 sha1sum 33303 root 20 0 18720 1772 1480 R 99.0 0.0 0:30.54 sha1sum 1 root 20 0 109724 17196 11032 S 0.0 0.1 0:03.28 systemd 2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd 3 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 rcu_gp 4 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 rcu_par_gp ...
-
The
sha1sum
processes have PIDs 33301, 33302, and 33303, as listed in the preceding sample output.
Important:
As a prerequisite to the following procedure, you must complete the preparations of
cgroup-v2
as described in Preparing the Control Group for Distribution of CPU Time. If you skipped those preparations, you can't
complete this procedure.