-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Determine any memory/CPU limitations from sysfs cgroup #74237
Conversation
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
If this code is adapated from CoreCLR, is there a plan to share the code eventually, or need it all be duplicated? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SamMonoRT I think we want to take a backport of this for net7. I don't think this will impact mobile or wasm. (But the "DOTNET_PROCESSOR_COUNT" support might be a nice thing to bring along on those platforms for diagnostic scenarios)
Yes, once all suggestions are addressed and CI lanes look green, will issue a backport command. |
@nealef - please let us know when all suggested changes are completed. |
The only one missing is the explicit cast from |
- Adhere to call statement convention - Remove unnecessary cast * mono-proclib.c - Explicit cast
/backport to release/7.0 |
Started backporting to release/7.0: https://github.com/dotnet/runtime/actions/runs/2965665895 |
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
src/mono/cmake/config.h.in
src/mono/mono/metadata/icall.c
src/mono/mono/sgen/sgen-marksweep.c
src/mono/mono/sgen/sgen-simple-nursery.c
src/mono/mono/utils/CMakeLists.txt
src/mono/mono/utils/memfuncs.c
getRestrictedPhysicalMemoryLimit()
orgetPhyscalMemoryAvail()
src/mono/mono/utils/memfuncs.h
src/mono/mono/utils/mono-cgroup.c
src/mono/mono/utils/mono-proclib.c
getCpuLimit()
src/mono/mono/utils/mono-proclib.h