11

I am trying to use cgroups in order to limit the CPU usage. I am using this guide https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Resource_Management_Guide/sec-cpu_and_memory-use_case.html

My /etc/cgconfig.conf file is the following

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

group wheel {
    cpu {
            cpu.shares="800";
    }
    cpuacct {
            cpuacct.usage="0";
    }
}
 group test1 {
    cpu {
            cpu.shares="200";
    }
    cpuacct {
            cpuacct.usage="0";
    }
}

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

4
  • Can you add output of top command when you're running dd if=/dev/zero of=/dev/null bs=1024k?
    – kirill-a
    Mar 2, 2015 at 16:36
  • 6
    cgroup shares will only limit CPU resources when there is competition for them. If, in your example, test1 wants CPU resources, and wheel is not using any, then there is no competition, and test1 can have whatever it wants. If both are demanding resources, then you should see the share-based limiting taking affect.
    – twalberg
    Mar 2, 2015 at 17:36
  • Hello the output is the following: ` PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 51535 user1 20 0 108956 1680 556 R 100.0 0.0 0:27.74 dd 51557 user2 20 0 108956 1676 552 R 100.0 0.0 0:23.57 dd user1 belongs to wheel group and user2 to test1 group Mar 2, 2015 at 17:40
  • @twalberg Thank you very much for your answer. I ran the dd commant for both users at the same time. I put also above the result of the top command. Do you believe that I should try with another command? Mar 2, 2015 at 17:45

1 Answer 1

22

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.

2
  • RedHat documentation link is 404, found this however: stackoverflow.com/a/55914709/130638
    – balupton
    Sep 28, 2021 at 11:17
  • cgroups version 2 use cpu.max instead of cpu.cfs_ (though cgroups man page says "Although cgroups v2 is intended as a replacement for cgroups v1, the older system continues to exist (and for compatibility reasons is un‐ likely to be removed).".) Sep 17 at 3:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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