Product SiteDocumentation Site

Chapter 2. Using Control Groups

2.1. The cgconfig Service
2.1.1. The cgconfig.conf File
2.2. Creating a Hierarchy and Attaching Subsystems
2.3. Attaching Subsystems to, and Detaching Them From, an Existing Hierarchy
2.4. Unmounting a Hierarchy
2.5. Creating Cgroups
2.6. Removing Cgroups
2.7. Setting Parameters
2.8. Moving a Process to a Control Group
2.8.1. The cgred Daemon
2.9. Starting a Process in a Control Group
2.9.1. Starting a Service in a Control Group
2.10. Obtaining Information About Control Groups
2.10.1. Finding a Process
2.10.2. Finding a Subsystem
2.10.3. Finding Hierarchies
2.10.4. Finding Control Groups
2.10.5. Displaying Parameters of Control Groups
2.11. Unloading Groups
2.12. Additional Resources
The easiest way to work with control groups is to install the libcgroup package, which contains a number of cgroup-related command line utilities and their associated man pages. It is possible to mount hierarchies and set cgroup parameters (non-persistently) using shell commands and utilities available on any system. However, using the libcgroup-provided utilities simplifies the process and extends your capabilities. Therefore, this guide focuses on libcgroup commands throughout. In most cases, we have included the equivalent shell commands to help describe the underlying mechanism. However, we recommend that you use the libcgroup commands wherever practical.

Note: Installing the libcgroup package

In order to use cgroups, first ensure the libcgroup package is installed on your system by running, as root:
~]# yum install libcgroup

2.1. The cgconfig Service

The cgconfig service installed with the libcgroup package provides a convenient way to create hierarchies, attach subsystems to hierarchies, and manage cgroups within those hierarchies. We recommend that you use cgconfig to manage hierarchies and cgroups on your system.
The cgconfig service is not started by default on Red Hat Enterprise Linux 6. When you start the service with chkconfig, it reads the control group configuration file — /etc/cgconfig.conf. Control groups are therefore recreated from session to session and become persistent. Depending on the contents of the configuration file, cgconfig can create hierarchies, mount necessary file systems, create control groups, and set subsystem parameters for each group.
The default cgconfig.conf file installed with the libcgroup package creates and mounts an individual hierarchy for each subsystem, and attaches the subsystems to these hierarchies.
If you stop the cgconfig service (with service cgconfig stop), it unmounts all the hierarchies that it mounted.

2.1.1. The cgconfig.conf File

The cgconfig.conf file contains two major types of entry — mount and group. Mount entries create and mount hierarchies as virtual filesystems, and attach subsystems to those hierarchies. For example:
mount {
    cpuset = /cgroup/cpuset;
}
creates a hierarchy for the cpuset subsystem, the equivalent of the shell commands:
        mkdir /cgroup/cpuset
        mount -t cgroup -o cpuset cpuset /cgroup/cpuset
Group entries create control groups and set subsystem parameters. For example:
group daemons/sql {
    perm {
        task {
            uid = root;
            gid = sqladmin;
        } admin {
            uid = root;
            gid = root;
        }
    } cpuset {
        cpuset.cpus = 0-3;
    }
}
creates a control group for sql daemons, with permissions for users in the sqladmin group to add tasks to the control group and the root user to modify subsystem parameters. When combined with the example of the mount entry above, the equivalent shell commands are:
mkdir -p /cgroup/cpu/daemons/sql
chown root:root /cgroup/cpu/daemons/sql/*
chown root:sqladmin /cgroup/cpu/daemons/sql/tasks
echo 0-3 > /cgroup/cpu/daemons/sql/cpuset.cpus
When you install cgroups, a sample config file is written to /etc/cgconfig.conf. The # symbols at the start of each line comment that line out and make it invisible to the cgconfig service.