Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/7.0] [mono] Determine any memory/CPU limitations from sysfs cgroup #74881

Merged
merged 5 commits into from
Aug 31, 2022

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Aug 31, 2022

Backport of #74237 to release/7.0

/cc @akoeplinger @nealef

Customer Impact

Add capability to interrogate cgroup limitations when determining CP and memory limits

This code has been adapted from coreCLR. It has been modified from C++ but uses the same naming conventions in the event of a unified mechanism that can be shared between both runtimes being developed. The code has been tested on Ubuntu 20.04 and CentOS 7 with cgroupv1 and cgroupv2.

This code is required in the event of running runtime in a container as the current limitations being discovered by the mono runtime are purely for the machine and not in a container which may have lower quotas.

Testing

Tested in main.

Risk

Low, only applies to Mono running on Linux with cgroup limits.

IMPORTANT: Is this backport for a servicing release? If so and this change touches code that ships in a NuGet package, please make certain that you have added any necessary package authoring and gotten it explicitly reviewed.

Add capability to interrogate cgroup limitations when determining CP and memory limits

This code has been adapted from coreCLR. It has been modified from C++ but uses the same naming conventions in the event of a unified mechanism that can be shared between both runtimes being developed. The code has been tested on Ubuntu 20.04 and CentOS 7 with cgroupv1 and cgroupv2.

This code is required in the event of running runtime in a container as the current limitations being discovered by the mono runtime are purely for the machine and not in a container which may have lower quotas.

* src/mono/CMakeLists.txt
  - Set the HAVE_CGROUP_SUPPORT for Linux hosts

* src/mono/cmake/config.h.in
  - Place holder for HAVE_CGROU_SUPPORT definition

* src/mono/mono/metadata/icall.c
* src/mono/mono/sgen/sgen-marksweep.c
* src/mono/mono/sgen/sgen-simple-nursery.c
  - Use mono_cpu_limit() instead of mono_cpu_count()

* src/mono/mono/utils/CMakeLists.txt
  - Add mono-cgroup.c to the build

* src/mono/mono/utils/memfuncs.c
  - Call `getRestrictedPhysicalMemoryLimit()` or `getPhyscalMemoryAvail()`

* src/mono/mono/utils/memfuncs.h
  - Add prototypes for the new APIs

* src/mono/mono/utils/mono-cgroup.c
  - Code adapted from coreCLR to interrogate sysfs to determine any limitations on memory or CPU

* src/mono/mono/utils/mono-proclib.c
  - Add call to `getCpuLimit()`

* src/mono/mono/utils/mono-proclib.h
  - Add prototype for the new API
@akoeplinger akoeplinger changed the title [release/7.0] Determine any memory/CPU limitations from sysfs cgroup [release/7.0] [mono] Determine any memory/CPU limitations from sysfs cgroup Aug 31, 2022
@akoeplinger
Copy link
Member

@steveisok please approve

@akoeplinger
Copy link
Member

@carlossanlop please merge :)

@carlossanlop
Copy link
Member

Let's do this!

@carlossanlop carlossanlop merged commit 5408b21 into release/7.0 Aug 31, 2022
@carlossanlop carlossanlop deleted the backport/pr-74237-to-release/7.0 branch August 31, 2022 22:35
@ghost ghost locked as resolved and limited conversation to collaborators Oct 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants