问题
I want to restrict cpu usage of users to only 25% . For this i am using cgroups.
Here is the guide that I am following : http://kaivanov.blogspot.in/2012/07/setting-up-linux-cgroups-control-groups.html
This guide work with one core cpu machine, but when i am using with the 4 core cpu machine this configuraion doe not work.
Here is my configuration:
# Configuration file generated by cgsnapshot
mount {
cpu = /cgroup/cpu;
}
group test1 {
cpu {
cpu.rt_period_us="1000000";
cpu.rt_runtime_us="0";
cpu.cfs_period_us="100000";
cpu.cfs_quota_us="-1";
cpu.shares="250";
}
}
group test2 {
cpu {
cpu.rt_period_us="1000000";
cpu.rt_runtime_us="0";
cpu.cfs_period_us="100000";
cpu.cfs_quota_us="-1";
cpu.shares="500";
}
}
What i am missing?
Thanks in advance.
回答1:
The configuration you shared just means that test2 will get twice the cpu as test1. Shares are proportional, they don't take machine size into account. If you want to hard-cap the usage for a cgroup, you need to use cfs_period_us and cfs_quota_us. To use 1 core worth of cpu from a machine, set cfs_quota_us to be same as cfs_period_us (100000).
来源:https://stackoverflow.com/questions/28719109/restrict-cpu-usage-to-25-per-customer-base-using-cgroups