0

I'm setting up cgroups config for my research team. The server has 8 cpus. The team member could only use part of the cpu time, so for the team I set cpu.cfs_quota_us = 400000. I also want to add task priority with cpu.shares.

for example, here's my cgroup config:

group team {
    cpu {
        cpu.cfs_period_us = 100000;
        cpu.cfs_quota_us = 400000; #4 CPUs
    }
}

group team/user1 {
    cpu {
        cpu.shares = 256;
    }
}

group team/user2 {
    cpu {
        cpu.shares = 768;
    }
}

the cpu.shares only work if I set the parent group's cpu.cfs_quota_us to -1 and all cpu are in use.

Could cpu.cfs_quota_us and children's cpu.shares work together?

1 Answers1

0

cpu.shares is not made to set task priority.

It's used to define a relative (abstract) amount of CPU sharing, meaning, when a CPU is dedicated to tasks of a certain group/user instead of another.

Here you basically say that team/user2 will have three times (768/256) more dedicated computation time than team/user1 for his tasks. In other words, team/user2 will use 75% of CPU time and team/user1 only 25%.

cpu.shares and cpu.cfs_quota_us do the same thing but in two different manners. The former is using relative representation of time sharing and the later is using exact quantification in microseconds. Because they are both used to define CPU time sharing, they cannot be used together.

Some docs: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/resource_management_guide/sec-cpu

A. Gille
  • 912
  • 6
  • 23
  • thanks, any suggestion if I want to set relative cpu time sharing inside a cgroup? install a virtual machine will work, but it is to heavy. – Naich An Feb 20 '19 at 01:09
  • You first wanted to know how to set **priorities** on tasks, which is not possible, you only can set cpu time sharing (in two different ways). Your answer is right to set cpu time sharing per group. You set that group `team/user1` will have less CPU time than `team/user2`. See https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/resource_management_guide/sec-cpu_and_memory-use_case – A. Gille Feb 21 '19 at 09:07
  • @A.Gille can you provide more specific evidence on why they "cannot be used together"? I reviewed the link you provided but could not corroborate that. Also, this SO answer seems to interpret it differently: https://stackoverflow.com/a/55914709/3865626 – oxley Dec 16 '20 at 23:10
  • @oxley Read the docs first. In **3.2.1. CFS Tunable Parameters**: "The following options can be used to configure ceiling enforcement **OR** relative sharing of CPU". As I said, they are two different ways/manners/approaches to achieve the same goal. Try it yourself. https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/resource_management_guide/sec-cpu – A. Gille Dec 20 '20 at 23:18