CGroups on CentOS 6
Server - CentOS

Cgroups are hierarchically designed just like processes and the child processes that inherit the attributes of the parent process. Since init is ultimately the parent of all processes, because it is the first process to start, this is structured like a tree. For processes this tree structure means that there is just a single hierarchy or tree.


This is different with cgroups because they can have multiple hierarchies. So cgroups may have multiple trees which are not connected, though child cgroups still inherit certain attributes of the parent.


Cgroups can have multiple hierarchies because each hierarchy is attached to one or more subsystems (also known as resources controllers or controllers). This will then create multiple trees which are unconnected. There are nine subsystems available.


blkio sets limits on input/output access on block devices

cpu scheduler for cgroup task access to the CPU

cpuacct generate reports for CPU use and cgroup

cpuset assign CPUs and memory to a cgroup

devices manage access to devices by tasks

freezer suspend/resume tasks

memory limit memory

net_cls tag network packets to allow Linux traffic controller to identify task traffic

ns namespace



Installation requires the libcgroup which includes the utilities that are needed to work with cgroups. These utilities will make it easier to manage cgroups.


yum install -y libcgroup



The /etc/cgconfig.conf file is used to start the cgroups so they are persistent on restarts. By default the cgroup configuration is turned off.


chkconfig –list

cgconfig 0:off 1:off 2:off 3:off 4:off 5:off 6:off


Make it persistent by changing it to on in the runlevel you are using.


chkconfig –level 3 cgconfig on



Here is the default cgconfig.conf which contains mount and group entries.


mount {

cpuset = /cgroup/cpuset;

cpu = /cgroup/cpu;

cpuacct = /cgroup/cpuacct;

memory = /cgroup/memory;

devices = /cgroup/devices;

freezer = /cgroup/freezer;

net_cls = /cgroup/net_cls;

blkio = /cgroup/blkio;




When you start cgconfig you will see new directories created in the /cgroup directory.


service cgconfig start

Starting cgconfig service: [ OK ]


ls /cgroup/

blkio cpu cpuacct cpuset devices freezer memory net_cls


Each one of these directories contains parameters that can be tuned.


ls cpu

cgroup.procs cpu.cfs_quota_us cpu.rt_runtime_us cpu.stat release_agent

cpu.cfs_period_us cpu.rt_period_us cpu.shares notify_on_release tasks



If you look in these directories they are populated with files that indicate the processes that are being managed. For example if you look at cgroup.procs you will see all of the processes by default.


cat /cgroup/cpu/cgroup.procs







The susbsystems can be listed by using the lssubsys command:


lssubsys -am



cpuset /cgroup/cpuset

cpu /cgroup/cpu

cpuacct /cgroup/cpuacct

memory /cgroup/memory

devices /cgroup/devices

freezer /cgroup/freezer

net_cls /cgroup/net_cls

blkio /cgroup/blkio



The /etc/cgroup.conf file uses two types of entries; mount and group. The mount entries create hierarchies and subsystems within those hierarchies. Here is the syntax:


mount {

<controller> = <path>;



The group entries are used to create cgroups and set subsystem parameters.


group <name> {

perm {

task {

uid = root;

gid = root;


admin {

uid = root;

gid = root;



cpu {

cpu.shares = 100;