Jon Bernard

An Introduction to Resource Management on Ubuntu Server

13 Oct 2009

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.

The Goal

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.

Getting There

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.

blog comments powered by Disqus
Fork me on GitHub