About the Control Group File System
cgroup functionality is mounted as a hierarchical file system in
/sys/fs/cgroup.
The directory /sys/fs/cgroup is also called the root control group.
The contents of the root control group directory differ depending on which
cgroup version is mounted on the system. For cgroups v2,
the directory contents are as follows
:
ls /sys/fs/cgroupcgroup.controllers cpuset.mems.effective memory.stat
cgroup.max.depth cpu.stat misc.capacity
cgroup.max.descendants dev-hugepages.mount sys-fs-fuse-connections.mount
cgroup.procs dev-mqueue.mount sys-kernel-config.mount
cgroup.stat init.scope sys-kernel-debug.mount
cgroup.subtree_control io.pressure sys-kernel-tracing.mount
cgroup.threads io.stat system.slice
cpu.pressure memory.numa_stat user.slice
cpuset.cpus.effective memory.pressuremkdir command to create cgroup
subdirectories within the root control group. For example, you might create the following
cgroup subdirectories:
-
/sys/fs/cgroup/MyGroups/ -
/sys/fs/cgroup/MyGroups/cgroup1 -
/sys/fs/cgroup/MyGroups/cgroup2
Note:
Best practice is to create childcgroups at least 2 levels deep inside the
/sys/fs/cgroup. The examples in the preceding list
follow this practice by using the first child group,
MyGroups, as a parent that contains the different
cgroups needed for the system.
Each cgroup in the hierarchy contains the following files:
-
cgroup.controllers -
This read-only file lists the controllers available in the current
cgroup. The contents of this file match the contents of thecgroup.subtree_controlfile in the parentcgroup. -
cgroup.subtree_control -
This file contains those controllers in the
cgroup.controllersfile that are enabled for the currentcgroup's immediate childcgroups.When a controller (for example,
pids) is present in thecgroup.subtree_controlfile, the corresponding controller-interface files (for example,pids.max) are automatically created in the immediate children of the currentcgroup.
For a sample procedure that creates child groups where you can implement resource management for an application, see Setting CPU Weight to Regulate Distribution of CPU Time.
To remove a cgroup, ensure that the cgroup doesn't contain
other child groups, and then remove the directory. For example, to remove
child group /sys/fs/cgroup/MyGroups/cgroup1 you can run the
following command:.
sudo rmdir /sys/fs/cgroup/MyGroups/cgroup1