System information
Kernel Control Groups 127
Network Traffic (Resource Control)
With cgroup_tc, a network traffic controller is available. It can be used
to manage traffic that is associated with the tasks in a cgroup. Additionally,
cls_flow can classify packets based on the tc_classid field in the packet.
For example, to limit the traffic from all tasks from a file_server cgroup to
100Mbps, proceed as follows:
# create a file_transfer cgroup and assign it a unique classid
# of 0x10 - this will be used later to direct packets.
mkdir -p /dev/cgroup
mount -t cgroup tc -otc /dev/cgroup
mkdir /dev/cgroup/file_transfer
echo 0x10 > /dev/cgroup/file_transfer/tc.classid
echo $PID_OF_FILE_XFER_PROCESS > /dev/cgroup/file_transfer/tasks
# Now create an HTB class that rate-limits traffic to 100 mbits and
attach
# a filter to direct all traffic from the file_transfer cgroup
# to this new class.
tc qdisc add dev eth0 root handle 1: htb
tc class add dev eth0 parent 1: classid 1:10 htb rate 100mbit ceil
100mbit
tc filter add dev eth0 parent 1: handle 800 protocol ip prio 1 \
flow map key cgroup-classid baseclass 1:10
This example is taken from https://lwn.net/Articles/291161/,
where you can find more information about this feature.
10.4 Using Controller Groups
10.4.1 Prerequisites
To conveniently use cgroups, install the following additional packages:
• libcgroup1 — basic user space tools to simplify resource management
• cpuset — contains the cset to manipulate cpusets
• libcpuset1 — C API to cpusets
• kernel-source — only needed for documentation purposes
• lxc — Linux container implementation