summaryrefslogtreecommitdiff
path: root/src/pal
diff options
context:
space:
mode:
authorTom Deseyn <tom.deseyn@gmail.com>2018-08-16 20:47:20 +0200
committerJan Vorlicek <janvorli@microsoft.com>2018-08-16 20:47:20 +0200
commitca5b0d1caa47abdebac13233553c6e44db2e3168 (patch)
treec799ed2aad140fce723ad9a0796c12ae994c90ca /src/pal
parent6a2ce4748f043d8c0dc9e4d30d415cffbef1958f (diff)
downloadcoreclr-ca5b0d1caa47abdebac13233553c6e44db2e3168.tar.gz
coreclr-ca5b0d1caa47abdebac13233553c6e44db2e3168.tar.bz2
coreclr-ca5b0d1caa47abdebac13233553c6e44db2e3168.zip
Determine memory load based on cgroup usage. (#19518)
cgroup usage is used to trigger oom kills. It includes rss and file cache of the cgroup. The implementation was only using the process rss to determine memory load. This is less than the cgroup usage and leads to oom kills due to GC not being triggered soon enough.
Diffstat (limited to 'src/pal')
-rw-r--r--src/pal/inc/pal.h2
-rw-r--r--src/pal/src/misc/cgroup.cpp30
2 files changed, 30 insertions, 2 deletions
diff --git a/src/pal/inc/pal.h b/src/pal/inc/pal.h
index 97fee605e0..9676b437b0 100644
--- a/src/pal/inc/pal.h
+++ b/src/pal/inc/pal.h
@@ -2396,7 +2396,7 @@ PAL_GetRestrictedPhysicalMemoryLimit(VOID);
PALIMPORT
BOOL
PALAPI
-PAL_GetWorkingSetSize(size_t* val);
+PAL_GetPhysicalMemoryUsed(size_t* val);
PALIMPORT
BOOL
diff --git a/src/pal/src/misc/cgroup.cpp b/src/pal/src/misc/cgroup.cpp
index 7a3a9261a1..145586a0b9 100644
--- a/src/pal/src/misc/cgroup.cpp
+++ b/src/pal/src/misc/cgroup.cpp
@@ -23,6 +23,7 @@ SET_DEFAULT_DEBUG_CHANNEL(MISC);
#define PROC_CGROUP_FILENAME "/proc/self/cgroup"
#define PROC_STATM_FILENAME "/proc/self/statm"
#define MEM_LIMIT_FILENAME "/memory.limit_in_bytes"
+#define MEM_USAGE_FILENAME "/memory.usage_in_bytes"
#define CFS_QUOTA_FILENAME "/cpu.cfs_quota_us"
#define CFS_PERIOD_FILENAME "/cpu.cfs_period_us"
class CGroup
@@ -63,6 +64,27 @@ public:
return result;
}
+ bool GetPhysicalMemoryUsage(size_t *val)
+ {
+ char *mem_usage_filename = nullptr;
+ bool result = false;
+
+ if (m_memory_cgroup_path == nullptr)
+ return result;
+
+ size_t len = strlen(m_memory_cgroup_path);
+ len += strlen(MEM_USAGE_FILENAME);
+ mem_usage_filename = (char*)malloc(len+1);
+ if (mem_usage_filename == nullptr)
+ return result;
+
+ strcpy(mem_usage_filename, m_memory_cgroup_path);
+ strcat(mem_usage_filename, MEM_USAGE_FILENAME);
+ result = ReadMemoryValueFromFile(mem_usage_filename, val);
+ free(mem_usage_filename);
+ return result;
+ }
+
bool GetCpuLimit(UINT *val)
{
long long quota;
@@ -384,15 +406,21 @@ PAL_GetRestrictedPhysicalMemoryLimit()
BOOL
PALAPI
-PAL_GetWorkingSetSize(size_t* val)
+PAL_GetPhysicalMemoryUsed(size_t* val)
{
BOOL result = false;
size_t linelen;
char* line = nullptr;
+ CGroup cgroup;
if (val == nullptr)
return FALSE;
+ // Linux uses cgroup usage to trigger oom kills.
+ if (cgroup.GetPhysicalMemoryUsage(val))
+ return TRUE;
+
+ // process resident set size.
FILE* file = fopen(PROC_STATM_FILENAME, "r");
if (file != nullptr && getline(&line, &linelen, file) != -1)
{