Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[release/7.0] [mono] Determine any memory/CPU limitations from sysfs …
…cgroup (#74881) * Determine any memory/CPU limitations from sysfs cgroup (#21280) 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 * Correct var type to match usage * Suggested updates * * mono-cgroup.c - Adhere to call statement convention - Remove unnecessary cast * mono-proclib.c - Explicit cast * Convert spaces to tabs Co-authored-by: Neale Ferguson <neale@sinenomine.net>
- Loading branch information