Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions src/coreclr/gc/unix/cgroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ Module Name:
#define SIZE_T_MAX (~(size_t)0)
#endif

#if defined(TARGET_LINUX) || defined(TARGET_ANDROID)
Comment thread
jkotas marked this conversation as resolved.
Outdated

#define CGROUP2_SUPER_MAGIC 0x63677270

#define PROC_MOUNTINFO_FILENAME "/proc/self/mountinfo"
Expand Down Expand Up @@ -568,8 +570,21 @@ void CleanupCGroup()
CGroup::Cleanup();
}

#else // !(TARGET_LINUX || TARGET_ANDROID)

void InitializeCGroup()
{
}

void CleanupCGroup()
{
}

#endif // TARGET_LINUX || TARGET_ANDROID

size_t GetRestrictedPhysicalMemoryLimit()
{
#if defined(TARGET_LINUX) || defined(TARGET_ANDROID)
Comment thread
jkotas marked this conversation as resolved.
Outdated
uint64_t physical_memory_limit = 0;

if (!CGroup::GetPhysicalMemoryLimit(&physical_memory_limit))
Expand Down Expand Up @@ -615,17 +630,21 @@ size_t GetRestrictedPhysicalMemoryLimit()
{
return (size_t)physical_memory_limit;
}
#else
return 0;
#endif // TARGET_LINUX || TARGET_ANDROID
}

bool GetPhysicalMemoryUsed(size_t* val)
{
if (val == nullptr)
return false;

#if defined(TARGET_LINUX) || defined(TARGET_ANDROID)
bool result = false;
size_t linelen;
char* line = nullptr;

if (val == nullptr)
Comment thread
jkotas marked this conversation as resolved.
return false;

// Linux uses cgroup usage to trigger oom kills.
if (CGroup::GetPhysicalMemoryUsage(val))
return true;
Expand Down Expand Up @@ -655,4 +674,7 @@ bool GetPhysicalMemoryUsed(size_t* val)
fclose(file);
free(line);
return result;
#else
return false;
#endif // TARGET_LINUX || TARGET_ANDROID
}
15 changes: 15 additions & 0 deletions src/coreclr/nativeaot/Runtime/unix/cgroupcpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Module Name:

#include "cgroupcpu.h"

#if defined(TARGET_LINUX) || defined(TARGET_ANDROID)

#define CGROUP2_SUPER_MAGIC 0x63677270

#define BASE_TEN 10
Expand Down Expand Up @@ -510,3 +512,16 @@ bool GetCpuLimit(uint32_t* val)

return CGroup::GetCpuLimit(val);
}

#else // !(TARGET_LINUX || TARGET_ANDROID)

void InitializeCpuCGroup()
{
}

bool GetCpuLimit(uint32_t* val)
{
Comment thread
jkotas marked this conversation as resolved.
return false;
}

#endif // TARGET_LINUX || TARGET_ANDROID
18 changes: 18 additions & 0 deletions src/coreclr/pal/src/misc/cgroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ SET_DEFAULT_DEBUG_CHANNEL(MISC);
#include <sys/vfs.h>
#endif

#if defined(TARGET_LINUX) || defined(TARGET_ANDROID)

#define CGROUP2_SUPER_MAGIC 0x63677270

#define BASE_TEN 10
Expand Down Expand Up @@ -516,12 +518,28 @@ void CleanupCGroup()
CGroup::Cleanup();
}

#else // !(TARGET_LINUX || TARGET_ANDROID)

void InitializeCGroup()
{
}

void CleanupCGroup()
{
}

#endif // TARGET_LINUX || TARGET_ANDROID

BOOL
PALAPI
Comment thread
jkotas marked this conversation as resolved.
PAL_GetCpuLimit(UINT* val)
{
Comment thread
jkotas marked this conversation as resolved.
if (val == nullptr)
return FALSE;

#if defined(TARGET_LINUX) || defined(TARGET_ANDROID)
Comment thread
jkotas marked this conversation as resolved.
Outdated
return CGroup::GetCpuLimit(val);
#else
return FALSE;
#endif // TARGET_LINUX || TARGET_ANDROID
}
Loading