Reputation: 6371
/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.
Upvotes: 0
Views: 1994
Reputation: 1093
It seems the cgroups setting cpu.shares
should be correctly applied.
Modern computer usually have a multi-core cpu. The python script used for testing can only use 100% of one core. So if there are still idle cpu cores, the other script could also use 100% from that core.
The better way to test cpu.shares
is to run a number of processes more than the number of the cpu cores.
cat /proc/cpuinfo
to indicate the number of cpu cores.
Upvotes: 1