/etc/cgconfig.conf
... group memlimit { memory { memory.limit_in_bytes = 8589934592; } } group cpulimit { cpu { cpu.shares = 1024; } } /etc/cgrules.conf:
@gatewayer memory memlimit/ @gatewayer cpu cpulimit/ And I've restarted services via commands:
service cgconfig restart service cgred restart After I execute my python script from user who belongs to group gatewayer, I could see the PID when executing cat /cgroup/memory/memlimit/cgroup.procs and the limit have been applied on the running process. However, limit on cpu does not take effect, and cat /cgroup/cpu/cpulimit/cgroup.procs doesn't print the PID as expected.
I tried to check on the process, and it turns out to be the same result, that memory is limited by cgroups whereas cpu is not:
$ cat /proc/18113/cgroup 174:blkio:/ 173:net_cls:/ 172:freezer:/ 171:devices:/ 170:memory:/memlimit 169:cpuacct:/ 168:cpu:/ 167:cpuset:/ Could anyone give me some help? Many thanks.
cpu.sharesis not a "limit" on CPU usage, if there's no contention for the CPU. If the CPU is otherwise idle, any process can use the entire CPU, regardless of itscpu.sharesvalue. When there is contention for the CPU, however, thecpu.sharesvalue is used to determine the percentage of the CPU time that process is given ("this processcpu.shares" / "sum of allcpu.shares").