Search code examples
linuxcgroups

cgroups works well until reloading config (hangs on mount)


I am walking around this problem a long time - cgroups just don't want to work when reloading config file again(hangs on mount), have to reboot each time to changes take effect.

This are my steps:

(1.)Fresh start of OS. (2.)cgsnapshot -s

# Configuration file generated by cgsnapshot
mount {
    cpuset = /sys/fs/cgroup/cpuset;
    cpu = /sys/fs/cgroup/cpu;
    cpuacct = /sys/fs/cgroup/cpuacct;
    memory = /sys/fs/cgroup/memory;
    devices = /sys/fs/cgroup/devices;
    freezer = /sys/fs/cgroup/freezer;
    net_cls = /sys/fs/cgroup/net_cls;
    blkio = /sys/fs/cgroup/blkio;
    perf_event = /sys/fs/cgroup/perf_event;
}

(3.)cgclear(4.)cgsnapshot -s

# Configuration file generated by cgsnapshot

(5.)cgconfigparser -l /etc/cgconfig.conf (6.)cgsnapshot -s

mount {
    cpu = /cgroup/cpu_mem_blkio;
    cpuacct = /cgroup/cpu_mem_blkio;
    memory = /cgroup/cpu_mem_blkio;
    blkio = /cgroup/cpu_mem_blkio;
}
group hello1 {
...
group hello2 {
...

(7.)bash script /etc/rc.d/rc.cgred start

Now everything is working, but when i do this (the same config):

(8.)cgclear (9.)cgconfigparser -l /etc/cgconfig.conf

It hangs forever, when i use strace it stops at:

mount("cgroup", "/cgroup/cpu_mem_blkio", "cgroup", 0, "cpu,cpuacct,blkio,memory") = ? ERESTARTNOINTR (To be restarted)

Could someone point me whats wrong? How i can i add new group, without rebooting? Is this normal behavior of cgroups?

I even tried adding this patch from here:

--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
 <at>  <at>  -1909,7 +1909,7  <at>  <at>  static void cgroup_kill_sb(struct super_block *sb)
     *
     * And don't kill the default root.
     */
-   if (css_has_online_children(&root->cgrp.self) ||
+   if (!list_empty(&root->cgrp.self.children) ||
        root == &cgrp_dfl_root)
        cgroup_put(&root->cgrp);
    else

still testing, but looks the same.


Solution

  • Looks like the right way of doing it, is setting everything from the command line.

    mount -t cgroup -o cpu,memory,blkio,cpuacct cpu_mem_blkio /cgroup/cpu_mem_blkio
    mkdir /cgroup/cpu_mem_blkio/hello1
    mkdir /cgroup/cpu_mem_blkio/hello2
    echo 200 > /cgroup/cpu_mem_blkio/hello1/cpu.shares
    echo 200M > /cgroup/cpu_mem_blkio/hello1/memory.limit_in_bytes
    echo 400M > /cgroup/cpu_mem_blkio/hello1/memory.memsw.limit_in_bytes
    echo 100 > /cgroup/cpu_mem_blkio/hello1/blkio.weight
    ...