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.
$ sudo aptitude install libcgroup cgroup-bin
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;
}kirkland cpu sponge/
* * sysdefault/$ 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.