Add cgroup v2 support to coreclr
authorOmair Majid <omajid@redhat.com>
Tue, 31 Mar 2020 16:06:44 +0000 (12:06 -0400)
committerOmair Majid <omajid@redhat.com>
Mon, 6 Apr 2020 15:35:25 +0000 (11:35 -0400)
commit392dd8b01aab6b3731fe7e5fbacdfd218c57da78
tree306dc08a49e7b942e9974ff88cbed39632da2114
parent372bf426f1e10c2ccab3446cc0043edc86bcad01
Add cgroup v2 support to coreclr

Upstream cgroup v2 documentation is available at:
https://www.kernel.org/doc/Documentation/cgroup-v2.txt

Some notable differences between cgroup v1 and v2, from a coreclr point
of view, include:

- cgroup v2 has a single hierarchy, so we just look for a single "cgroup2"
  entry in /proc/self/mountinfo (without looking for a subsystem match).

- Since cgroup v2 has a single hierarchy, /proc/self/cgroup generally
  has a single line "0::/path". There's no need to match subsystems or
  hierarchy ids here.

- "memory.limit_in_bytes" is now "memory.max". It can contain the
  literal "max" to indicate no limit.

- "memory.usage_in_bytes" is now "memory.current"

- "cpu.cfs_quota_us" and "cpu.cfs_period_us" have been combined into a
  single "cpu.max" file with the format "$MAX $PERIOD". The max value
  can be a literal "max" to indicate a limit is not active.

It is possible to have both cgroup v1 and v2 enabled on a host (but not
inside a container, AFAIK). In that case, this change will pick one
based on /sys/fs/cgroup.
src/coreclr/src/gc/unix/cgroup.cpp
src/coreclr/src/pal/src/misc/cgroup.cpp