You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Runtime not respecting the “current” cgroups that is associated to a process, but only the system one #850
First thing I found is that the runtime is getting the quotas from the global cgroup, and not from a custom one that it could run from.
When we use “docker --cpus" it’s actually defining the quotas in the global cgroup files, and this is these files that the runtime is reading. In my services I was creating named groups, and starting the process using these. What I was seeing is that dotnet was not respecting the values, and either on 3.0 or 3.1 I would see 12 processors. This might be another issue we want to track, as it’s not respecting the “current” cgroups that is associated to a process, but only the system one.
changed the title [-]Runtime respecting the “current” cgroups that is associated to a process, but only the system one[/-][+]Runtime not respecting the “current” cgroups that is associated to a process, but only the system one[/+]on Dec 13, 2019
This is strange. Out cgroups code actually uses the cgroup of the current process. It gets is from /proc/self/cgroup. I've verified that it works by creating my own memory cgroup called janvorli-subgroup:
sudo cgcreate -g memory:/janvorli-subgroup
Then I've started lldb with a testing .NET Core app in that memory cgroup:
I understand the code that I pointed to better now, I missed the part where it was looking for the current process group. Will try to find where it failed in my case, and only worked once I started setting the global one. Maybe the way I started the process.
It gets the process specific path for the cpu groups too (verified now too). Have you used the same way to create a group and run your service in it as I've used in my example?
I've also sticked call to the GetCpuLimit into the Initialize function to verify the full paths we are using. In my case, we were correctly using /sys/fs/cgroup/cpu,cpuacct/janvorli-subgroup/cpu.cfs_quota_us and /sys/fs/cgroup/cpu,cpuacct/janvorli-subgroup/cpu.cfs_period_us and the resulting values matched to what I've written into those.
I am closing the issue because you have validated what I had questioned, so it must have been an issue on my side. I will add some comment when I find out what my mistake was. Thanks for your time.
I am reopening this issue as @sebastienros and I were able to figure out what's wrong with the named cgroups in his case. The difference between his and my testing was that he was testing the named cgroups inside of a docker container while I was testing it out of a docker container. There is a subtle difference in how the /proc/self/mountinfo and /proc/self/cgroup files report the paths in each case.
In my case, the interesting lines from the mountinfo and cgroup are:
The algorithm to compute the final path of the subsystem to query combines paths from both files. To handle docker case, it also compares whether the path from the /proc/self/cgroup is equal to the hierarchy root path from the /proc/self/mountinfo. If it is, it doesn't include it in the resulting path. That works fine for the cgroups applied via docker (the unnamed one), but it doesn't work for the named cgroup, as the path no longer matches (the /proc/self/cgroup path has the cgroup name appended - the benchmarks in the example above).
So we end up with a non-existent path /sys/fs/cgroup/cpu/docker/c346a454da1aed08d4f4151180fb7f41e3d298ca05f8751803f63479490a3731/benchmarks/cpu.cfs_quota_us instead of /sys/fs/cgroup/cpu/benchmarks/cpu.cfs_quota_us
We need to fix it so that it checks if the path from the /proc/self/mountinfo is a prefix of the path from /proc/self/cgroups and in that case, remove just that prefix and still add the rest.
Activity
jkotas commentedon Dec 13, 2019
cc @janvorli
[-]Runtime respecting the “current” cgroups that is associated to a process, but only the system one[/-][+]Runtime not respecting the “current” cgroups that is associated to a process, but only the system one[/+]janvorli commentedon Dec 14, 2019
This is strange. Out cgroups code actually uses the cgroup of the current process. It gets is from /proc/self/cgroup. I've verified that it works by creating my own memory cgroup called janvorli-subgroup:
Then I've started lldb with a testing .NET Core app in that memory cgroup:
Then I've set a breakpoint at CGroup::Initialize, ran the application and once I've hit the breakpoint, I've stepped over
and then printed the value of s_memory_cgroup_path:
So it is obvious it is not using any global group.
sebastienros commentedon Dec 14, 2019
@janvorli
I verified with
Environment.ProcessorCountonly, and confirmed what I was seeing from this call: https://github.com/dotnet/runtime/blob/master/src/coreclr/src/gc/unix/cgroup.cpp#L120-L126sebastienros commentedon Dec 14, 2019
So maybe not everything is taken from named cgroups
sebastienros commentedon Dec 14, 2019
I understand the code that I pointed to better now, I missed the part where it was looking for the current process group. Will try to find where it failed in my case, and only worked once I started setting the global one. Maybe the way I started the process.
janvorli commentedon Dec 14, 2019
It gets the process specific path for the cpu groups too (verified now too). Have you used the same way to create a group and run your service in it as I've used in my example?
I've also sticked call to the GetCpuLimit into the Initialize function to verify the full paths we are using. In my case, we were correctly using
/sys/fs/cgroup/cpu,cpuacct/janvorli-subgroup/cpu.cfs_quota_usand/sys/fs/cgroup/cpu,cpuacct/janvorli-subgroup/cpu.cfs_period_usand the resulting values matched to what I've written into those.sebastienros commentedon Dec 14, 2019
I am closing the issue because you have validated what I had questioned, so it must have been an issue on my side. I will add some comment when I find out what my mistake was. Thanks for your time.
janvorli commentedon Dec 17, 2019
I am reopening this issue as @sebastienros and I were able to figure out what's wrong with the named cgroups in his case. The difference between his and my testing was that he was testing the named cgroups inside of a docker container while I was testing it out of a docker container. There is a subtle difference in how the /proc/self/mountinfo and /proc/self/cgroup files report the paths in each case.
In my case, the interesting lines from the mountinfo and cgroup are:
In @sebastienros case when running in the docker container, the corresponding lines are:
The algorithm to compute the final path of the subsystem to query combines paths from both files. To handle docker case, it also compares whether the path from the /proc/self/cgroup is equal to the hierarchy root path from the /proc/self/mountinfo. If it is, it doesn't include it in the resulting path. That works fine for the cgroups applied via docker (the unnamed one), but it doesn't work for the named cgroup, as the path no longer matches (the /proc/self/cgroup path has the cgroup name appended - the
benchmarksin the example above).So we end up with a non-existent path
/sys/fs/cgroup/cpu/docker/c346a454da1aed08d4f4151180fb7f41e3d298ca05f8751803f63479490a3731/benchmarks/cpu.cfs_quota_usinstead of/sys/fs/cgroup/cpu/benchmarks/cpu.cfs_quota_usWe need to fix it so that it checks if the path from the /proc/self/mountinfo is a prefix of the path from /proc/self/cgroups and in that case, remove just that prefix and still add the rest.
janvorli commentedon Dec 17, 2019
To summarize my previous comment, the named cgroups don't work only in the case they are used inside of a docker container.