by JoKeru

cgroups in Debian 6 - a mess

Control Groups are good, but the implementation in Debian 6 is a mess! I know that this OS is not the latest, but when you have production servers, you don't always get the chance to run latest versions.

A good documentation about cgroups can be found at

Let's take the issues one by one:

$ uname -a
Linux box 2.6.32-5-amd64 #1 SMP Fri May 10 08:43:19 UTC 2013 x86_64 GNU/Linux

$ cat /proc/cgroups
#subsys_name hierarchy num_cgroups enabled
cpuset 0 1 1
ns 0 1 1
cpu 0 1 1
cpuacct 0 1 1
devices 0 1 1
freezer 0 1 1
net_cls 0 1 1

The memory and blkio controllers are missing! For my case, I didn't need disk control, but memory would have been nice. To enable memory control may need kernel compilation.

Problem number two:

$ apt-get install cgroup-bin -y

After the install, the services are started automatically. But with some bad default settings (CREATE_DEFAULT=yes in /etc/default/cgconfig). In my case I had to interrupt the installer because it hanged doing nothing (I guess it was creating the default cgroup and moving all processes there - not nice for busy server with tons of tasks running). Also the subsystem is mounted under /mnt/cgroups/ - why ??  

Problem number three: - the CGroup Rules Engine Daemon that was supposed to apply the cgroup mapping was not able to detect the new processes, so your configuration was worth nothing (unless manually applying it).

And the last one:

$ echo '2428' > /sys/fs/cgroup/cpuset/limited/cgroup.procs
-bash: echo: write error: Invalid argument

I cannot add the parent pid to the cgroup (which would automatically add also all threads belonging to the parent to the same cgroup). So in my case, I had to add 1 parent and 256 threads to /sys/fs/cgroup/cpuset/limited/tasks, and I had to do it one by one, you cannot add all 257 pids at once.  

Bottom line is cgroups are good, implementation sucks and I ended up in uninstalling the package and making a script to wrap up everything:

  • mounting the needed controller
  • creating the custom cgroup
  • pushing all threads to the custom cgroup
$ mount -t tmpfs cgroup_root /sys/fs/cgroup
$ mkdir /sys/fs/cgroup/cpuset
$ mount -t cgroup cpuset -ocpuset /sys/fs/cgroup/cpuset
$ cd /sys/fs/cgroup/cpuset
$ mkdir logstash
$ cd logstash
$ /bin/echo 22-23 > cpuset.cpus
$ /bin/echo 1 > cpuset.mems
$ for t in `ls /proc/$(cat /var/run/`; do echo $t > tasks; done