SteveGr2015 SteveGr2015 - 2 years ago 170
Linux Question

Using Cgroups to limit cpu usage

I am trying to use cgroups in order to limit the CPU usage. I am using this guide

My /etc/cgconfig.conf file is the following

mount {
cpu = /mnt/cgroup/cpu,cpuacct;
cpuacct = /mnt/cgroup/cpu,cpuacct;

group wheel {
cpu {
cpuacct {
group test1 {
cpu {
cpuacct {

My cgrules.conf is the following

@wheel cpu,cpuacct wheel
@test1 cpu,cpuacct test1

Althouth when I try to run:

dd if=/dev/zero of=/dev/null bs=1024k

I see that the cpu usage in 100% for the users belong to group wheel and test1

I have checked the services with
service cgconfig status
and is up

Loaded: loaded (/usr/lib/systemd/system/cgconfig.service; disabled)
Active: active (exited) since Mon 2015-03-02 17:29:19 EET; 7min ago
Process: 1240 ExecStop=/usr/sbin/cgclear -l /etc/cgconfig.conf -e (code=exited, status=3)
Process: 56536 ExecStart=/usr/sbin/cgconfigparser -l /etc/cgconfig.conf -s 1664 (code=exited, status=0/SUCCESS)
Main PID: 56536 (code=exited, status=0/SUCCESS)

Can anyone tell me what am I doing wrong?
Thanks a lot

Answer Source

cpu cgroup is work conserving, ie. a task would not be stopped from using cpu if there is no competition. If you want to put a hard limit on amount of cpu a task can use, try setting cpu.cfs_quota_us and cpu.cfs_period_us.

Look at the documentation here.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download