diff --git a/src/coreclr/gc/unix/cgroup.cpp b/src/coreclr/gc/unix/cgroup.cpp index ff1712235a339d..5312ad290739e6 100644 --- a/src/coreclr/gc/unix/cgroup.cpp +++ b/src/coreclr/gc/unix/cgroup.cpp @@ -10,9 +10,10 @@ Module Name: Abstract: Read the memory limit for the current process --*/ -#ifdef __FreeBSD__ -#define _WITH_GETLINE -#endif +#include "cgroup.h" +#include + +#if defined(TARGET_LINUX) || defined(TARGET_ANDROID) #include #include @@ -21,19 +22,12 @@ Module Name: #include #include #include -#if defined(__APPLE__) || defined(__FreeBSD__) -#include -#include -#elif !defined(__HAIKU__) #include -#endif #include #include #include "config.gc.h" -#include "cgroup.h" - #ifndef SIZE_T_MAX #define SIZE_T_MAX (~(size_t)0) #endif @@ -122,10 +116,6 @@ class CGroup // modes because both of those involve cgroup v1 controllers managing // resources. -#if !HAVE_NON_LEGACY_STATFS || TARGET_WASM - return 0; -#else - struct statfs stats; int result = statfs("/sys/fs/cgroup", &stats); if (result != 0) @@ -142,7 +132,6 @@ class CGroup // been seen in the wild. return 1; } -#endif } static bool IsCGroup1MemorySubsystem(const char *strTok){ @@ -656,3 +645,25 @@ bool GetPhysicalMemoryUsed(size_t* val) free(line); return result; } + +#else // !(TARGET_LINUX || TARGET_ANDROID) + +void InitializeCGroup() +{ +} + +void CleanupCGroup() +{ +} + +size_t GetRestrictedPhysicalMemoryLimit() +{ + return 0; +} + +bool GetPhysicalMemoryUsed(size_t* val) +{ + return false; +} + +#endif // TARGET_LINUX || TARGET_ANDROID diff --git a/src/coreclr/nativeaot/Runtime/unix/cgroupcpu.cpp b/src/coreclr/nativeaot/Runtime/unix/cgroupcpu.cpp index 7543c0aa2a53b9..37ecc29be7f2dd 100644 --- a/src/coreclr/nativeaot/Runtime/unix/cgroupcpu.cpp +++ b/src/coreclr/nativeaot/Runtime/unix/cgroupcpu.cpp @@ -10,11 +10,11 @@ Module Name: Abstract: Read cpu limits for the current process --*/ -#ifdef __FreeBSD__ -#define _WITH_GETLINE -#endif - #include +#include "cgroupcpu.h" + +#if defined(TARGET_LINUX) || defined(TARGET_ANDROID) + #include #include #include @@ -22,19 +22,12 @@ Module Name: #include #include #include -#if defined(__APPLE__) || defined(__FreeBSD__) -#include -#include -#elif !defined(__HAIKU__) #include -#endif #include #include #include "config.gc.h" -#include "cgroupcpu.h" - #define CGROUP2_SUPER_MAGIC 0x63677270 #define BASE_TEN 10 @@ -90,10 +83,6 @@ class CGroup // modes because both of those involve cgroup v1 controllers managing // resources. -#if !HAVE_NON_LEGACY_STATFS - return 0; -#else - struct statfs stats; int result = statfs("/sys/fs/cgroup", &stats); if (result != 0) @@ -110,7 +99,6 @@ class CGroup // been seen in the wild. return 1; } -#endif } static bool IsCGroup1CpuSubsystem(const char *strTok){ @@ -510,3 +498,16 @@ bool GetCpuLimit(uint32_t* val) return CGroup::GetCpuLimit(val); } + +#else // !(TARGET_LINUX || TARGET_ANDROID) + +void InitializeCpuCGroup() +{ +} + +bool GetCpuLimit(uint32_t* val) +{ + return false; +} + +#endif // TARGET_LINUX || TARGET_ANDROID diff --git a/src/coreclr/pal/src/misc/cgroup.cpp b/src/coreclr/pal/src/misc/cgroup.cpp index 8e36f120797dc3..0fc6f1883c6f8d 100644 --- a/src/coreclr/pal/src/misc/cgroup.cpp +++ b/src/coreclr/pal/src/misc/cgroup.cpp @@ -20,12 +20,10 @@ SET_DEFAULT_DEBUG_CHANNEL(MISC); #include "pal/virtual.h" #include "pal/cgroup.h" #include -#if defined(__APPLE__) || defined(__FreeBSD__) -#include -#include -#elif !defined(__HAIKU__) + +#if defined(TARGET_LINUX) || defined(TARGET_ANDROID) + #include -#endif #define CGROUP2_SUPER_MAGIC 0x63677270 @@ -87,9 +85,6 @@ class CGroup // modes because both of those involve cgroup v1 controllers managing // resources. -#if !HAVE_NON_LEGACY_STATFS || TARGET_OPENBSD || TARGET_WASM - return 0; -#else struct statfs stats; int result = statfs("/sys/fs/cgroup", &stats); @@ -107,7 +102,6 @@ class CGroup // been seen in the wild. return 1; } -#endif } static bool IsCGroup1CpuSubsystem(const char *strTok){ @@ -525,3 +519,22 @@ PAL_GetCpuLimit(UINT* val) return CGroup::GetCpuLimit(val); } + +#else // !(TARGET_LINUX || TARGET_ANDROID) + +void InitializeCGroup() +{ +} + +void CleanupCGroup() +{ +} + +BOOL +PALAPI +PAL_GetCpuLimit(UINT* val) +{ + return FALSE; +} + +#endif // TARGET_LINUX || TARGET_ANDROID