1

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.

  • 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). – Rohit Jnagal Feb 25 '15 at 22:33
  • Thank you so much. Is there a way to restrict the no of processes using cgroups? – Divij Satra Feb 26 '15 at 12:50
  • Not at the moment. There have been proposed patches, but none of those made it into upstream linux kernel. – Rohit Jnagal Feb 26 '15 at 18:55

1 Answers1

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).

Rohit Jnagal
  • 1,182
  • 9
  • 8