I recently wanted to limit CPU usage on my Ubuntu Karmic workstation. Since libcgroup is included in the upcoming Karmic release, setting up cgroups on an Ubuntu server has never been easier.
My needs were as follows:
The goal is to only allow kirkland CPU cycles when no other process is requesting them. Similar to a sponge, kirkland will be throttled to 0 if my apache daemon is really busy.
1. Install libcgroup:
$ sudo aptitude install libcgroup cgroup-bin
2. Edit /etc/cgconfig.conf, define a sponge group:
group sponge {
perm {
task {
uid = kirkland;
gid = kirkland;
}
admin {
uid = root;
gid = root;
}
}
cpu {
cpu.shares = 1;
}
}
mount {
cpu = /mnt/cgroups/cpu;
cpuacct = /mnt/cgroups/cpuacct;
}
3. Edit /etc/cgrules.conf, assign kirkland to the sponge group:
kirkland cpu sponge/
* * sysdefault/
4. Restart cgconfig and cgred services:
$ sudo service cgconfig restart
$ sudo service cgred restart
Processes created by kirkland should now automatically get moved into the sponge cgroup and will only recieve CPU cycles when no other processes are in need.
For more information about libgroup, you can visit the libcgroup project page. And for cgroups in general see the current kernel documentation.