How can I configure cgroups to fairly share resources between users?
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'
Related videos on Youtube
NightwishFan
Updated on September 17, 2022Comments
-
NightwishFan over 1 year
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.
-
Admin over 13 yearsWell, 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!
-
-
Jigar over 9 yearsLearning cgroups, bookmarked this. Thanks.