Skip to content

Runtime not respecting the “current” cgroups that is associated to a process, but only the system one #850

Closed

Description

@jkotas

From @sebastienros :

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.

Activity

  1. added
    untriaged
    on Dec 13, 2019
  2. added
    area-PAL-coreclr
    and removed
    untriaged
    on Dec 13, 2019
  3. jkotas commented on Dec 13, 2019

    @jkotas
    MemberAuthor
  4. 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
  5. janvorli commented on Dec 14, 2019

    @janvorli
    Member

    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:

    sudo cgexec -g memory:janvorli-subgroup lldb-6.0 -- /home/janvorli/git/coreclr/bin/tests/Linux.x64.Debug/Tests/Core_Root//corerun loopEH.dll 
    

    Then I've set a breakpoint at CGroup::Initialize, ran the application and once I've hit the breakpoint, I've stepped over

    s_memory_cgroup_path = FindCgroupPath(&IsMemorySubsystem);
    

    and then printed the value of s_memory_cgroup_path:

    (lldb) p s_memory_cgroup_path
    (char *) $0 = 0x0000555555778490 "/sys/fs/cgroup/memory/janvorli-subgroup"
    

    So it is obvious it is not using any global group.

  6. sebastienros commented on Dec 14, 2019

    @sebastienros
    Member
  7. sebastienros commented on Dec 14, 2019

    @sebastienros
    Member

    So maybe not everything is taken from named cgroups

  8. sebastienros commented on Dec 14, 2019

    @sebastienros
    Member

    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.

  9. janvorli commented on Dec 14, 2019

    @janvorli
    Member

    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.

  10. sebastienros commented on Dec 14, 2019

    @sebastienros
    Member

    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.

  11. janvorli commented on Dec 17, 2019

    @janvorli
    Member

    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:

    34 28 0:28 / /sys/fs/cgroup/cpu,cpuacct rw,nosuid,nodev,noexec,relatime shared:16 - cgroup cgroup rw,cpu,cpuacct
    5:cpu,cpuacct:/janvorli-subgroup
    

    In @sebastienros case when running in the docker container, the corresponding lines are:

    171 168 0:25 /docker/c346a454da1aed08d4f4151180fb7f41e3d298ca05f8751803f63479490a3731 /sys/fs/cgroup/cpu rw,nosuid,nodev,noexec,relatime - cgroup cpu rw,cpu
    3:cpu:/docker/c346a454da1aed08d4f4151180fb7f41e3d298ca05f8751803f63479490a3731/benchmarks
    

    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.

  12. self-assigned this
    on Dec 17, 2019
  13. janvorli commented on Dec 17, 2019

    @janvorli
    Member

    To summarize my previous comment, the named cgroups don't work only in the case they are used inside of a docker container.

  14. ghost locked as resolved and limited conversation to collaborators on Dec 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-PAL-coreclr

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions