Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

There used to be a kernel config option called sched_user or similar under cgroups. This allowed (to my knowledge) all users to fairly share system resources. In 2.6.35 it is not available. Is there a way I can configure my system to automatically share io/cpu/memory resources between all users (including root?). I have never set up a cgroup before, is there a good tutorial for doing so? Thank you very much.

share|improve this question
    
Well, I took a loot at the cgroups-bin package on Ubuntu, and I am fairly sure it "does this" by default if I just install it. I assumed it would require setup, however I suppose it just does if you have special needs. I tested by running stress with 2 cpu threads under root and 2 under my user and all 4 threads seem to share 50% in top, which makes me think it is working. This may "solve it" for me, however if anything I would like to have a more clear way to confirm, or a better idea how to configure it, thanks again! –  NightwishFan Dec 24 '10 at 3:04
add comment

1 Answer

up vote 9 down vote accepted

The kernel documentation provides a general coverage of cgroups with examples.

The cgroups-bin package (which depends on libcgroup1) already provided by the distribution should be fine.

Configuration is done by editing the following two files:

/etc/cgconfig.conf

Used by libcgroup to define control groups, their parameters and mount points.

/etc/cgrules.conf

Used by libcgroup to define the control groups to which the process belongs to.

Those configuration files already have examples in it, so try adjusting them to your requirements. The man pages cover their configuration quite well.

Afterwards, start the workload manager and rules daemon:

service cgconfig restart
service cgred restart

The workload manager (cgconfig) is responsible for allocating the ressources.
Adding a new process to the manager:

cgexec [-g <controllers>:<path>] command [args]

Adding a already running process to the manager:

cgclassify [-g <controllers>:<path>] <pidlist>

Or automatically over the cgrules.conf file and the CGroup Rules Daemon (cgred), which forces every newly spawned process into the specified group.


Example /etc/cgconfig.conf :

group group1 {
    perm {
            task {
                    uid = alice;
                    gid = alice;
            }
            admin {
                    uid = root;
                    gid = root;
            }
    }

    cpu {
            cpu.shares = 500;
    }

}

group group2 {
    perm {
            task {
                    uid = bob;
                    gid = bob;
            }
            admin {
                    uid = root;
                    gid = root;
            }
    }

    cpu {
            cpu.shares = 500;
    }

}

mount {
    cpu = /dev/cgroups/cpu;
    cpuacct = /dev/cgroups/cpuacct;
}

Example /etc/cgrules.conf :

alice            cpu             group1/
bob              cpu             group2/

This will share the CPU ressources about 50-50 between the user 'alice' and 'bob'

share|improve this answer
    
Thank you very much! :) –  NightwishFan Dec 24 '10 at 12:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.