10.4 Using Controller Groups

10.4.1 Prerequisites

To use cgroups, install the following additional packages:

  • libcgroup1 contains basic user space tools to simplify resource management.

  • cpuset

  • libcpuset1

  • kernel-source (for documentation purposes only)

  • lcx

10.4.2 Checking the Environment

The kernel shipped with openSUSE supports cgroups. There is no need to apply additional patches. Execute lxc-checkconfig to see a cgroups environment similar to the following output:

--- Namespaces ---
Namespaces: enabled
Utsname namespace: enabled
Ipc namespace: enabled
Pid namespace: enabled
User namespace: enabled
Network namespace: enabled
Multiple /dev/pts instances: enabled

--- Control groups ---
Cgroup: enabled
Cgroup namespace: enabled
Cgroup device: enabled
Cgroup sched: enabled
Cgroup cpu account: enabled
Cgroup memory controller: enabled
Cgroup cpuset: enabled

--- Misc ---
Veth pair device: enabled
Macvlan: enabled
Vlan: enabled
File capabilities: enabled

To find out which subsystems are available, proceed as follows:

mkdir /cgroups
mount -t cgroup none /cgroups
grep cgroup /proc/mounts

The following subsystems are available: rw, freezer, devices, cpuacct, cpu, ns, cpuset, memory. Disk and network subsystem controllers may become available during SUSE Linux Enterprise ServerĀ 11 lifetime.

10.4.3 Example: Cpusets

With the command line proceed as follows:

  1. To determine the number of CPUs and memory nodes see /proc/cpuinfo and /proc/zoneinfo.

  2. Create the cpuset hierarchy as a virtual file system (source: /usr/src/linux/Documentation/cgroups/cgroups.txt):

    mkdir /dev/cpuset
    mount -t cpuset cpuset /dev/cpuset
    cd /dev/cpuset
    mkdir Charlie
    cd Charlie
    # List of CPUs in this cpuset:
    /bin/echo 2-3 > cpus
    # List of memory nodes in this cpuset:
    /bin/echo 1 > mems
    /bin/echo $$ > tasks
    # The current shell is now running in the Charlie cpuset
    # The next line should display '/Charlie'
    cat /proc/self/cpuset
    
  3. Remove the cpuset using shell commands:

    rmdir /dev/cpuset/Charlie
       

    This fails as long as this cpuset is in use. First, you have to remove the inside cpusets or tasks (processes) that belong to it. Check this with:

    cat /dev/cpuset/Charlie/tasks

For background information and additional configuration flags, see /usr/src/linux/Documentation/cgroups/cpusets.txt.

With the cset tool, proceed as follows:

# Determine the number of CPUs and memory nodes
cset set --list
# Creating the cpuset hierarchy
cset set --cpu=2-3 --mem=1 --set=Charlie
# Starting processes in a cpuset
cset proc --set Charlie --exec -- stress -c 1 &
# Moving existing processes to a cpuset
cset proc --move --pid PID --toset=Charlie
# List task in a cpuset
cset proc --list --set Charlie
# Removing a cpuset
cset set --destroy Charlie
 

10.4.4 Example: cgroups

Using shell commands, proceed as follows:

  1. Create the cgroups hierarchy:

    mkdir /dev/cgroup
    mount -t cgroup cgroup /dev/cgroup
    cd /dev/cgroup
    mkdir priority
    cd priority
    cat cpu.shares
    
  2. Understanding cpu.shares:

    • 1024 is the default (for more information, see sched-design-CFS.txt) = 50% utilization

    • 1524 = 60% utilization

    • 2048 = 67% utilization

    • 512 = 40% utilization

  3. Changing cpu.shares

    /bin/echo 1024 > cpu.shares