Chapter 2. Using Control Groups
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 cgroup configuration file — /etc/cgconfig.conf. Cgroups 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 cgroups, and set subsystem parameters for each group.
The default /etc/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 the service cgconfig stop command), it unmounts all the hierarchies that it mounted.
2.1.1. The /etc/cgconfig.conf File
The /etc/cgconfig.conf file contains two major types of entry — mount and group. Mount entries create and mount hierarchies as virtual file systems, and attach subsystems to those hierarchies. Mount entries are defined using the following syntax:
mount {
<controller> = <path>;
…
}
Example 2.1. Creating a mount entry
The following example creates a hierarchy for the cpuset subsystem:
mount {
cpuset = /cgroup/red;
}
the equivalent of the shell commands:
~]# mkdir /cgroup/red
~]# mount -t cgroup -o cpuset red /cgroup/red
Group entries create cgroups and set subsystem parameters. Group entries are defined using the following syntax:
group <name> {
[<permissions>]
<controller> {
<param name> = <param value>;
…
}
…
}
Note that the permissions section is optional. To define permissions for a group entry, use the following syntax:
perm {
task {
uid = <task user>;
gid = <task group>;
}
admin {
uid = <admin name>;
gid = <admin group>;
}
}
Example 2.2. Creating a group entry
The following example creates a cgroup for SQL daemons, with permissions for users in the sqladmin group to add tasks to the cgroup and the root user to modify subsystem parameters:
group daemons/sql {
perm {
task {
uid = root;
gid = sqladmin;
} admin {
uid = root;
gid = root;
}
} cpu {
cpu.shares = 100;
}
}
~]# mkdir -p /cgroup/cpu/daemons/sql
~]# chown root:root /cgroup/cpu/daemons/sql/*
~]# chown root:sqladmin /cgroup/cpu/daemons/sql/tasks
~]# echo 100 > /cgroup/cpu/daemons/sql/cpu.shares
You must restart the
cgconfig service for the changes in the
/etc/cgconfig.conf to take effect:
~]# service cgconfig restart
When you install the libcgroup package, a sample configuration file is written to /etc/cgconfig.conf. The hash symbols ('#') at the start of each line comment that line out and make it invisible to the cgconfig service.