Skip to content

Commit

Permalink
Fix for running in a container without mem limit set on Windows; (dot…
Browse files Browse the repository at this point in the history
…net/coreclr#23297)

also fixing the LocalGC standalone case on Linux

Commit migrated from dotnet/coreclr@cf887c9
  • Loading branch information
Maoni0 authored and jkotas committed Mar 18, 2019
1 parent 8d49d1b commit 6607f68
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 28 deletions.
13 changes: 11 additions & 2 deletions src/coreclr/src/gc/unix/cgroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,19 @@ void CleanupCGroup()

size_t GetRestrictedPhysicalMemoryLimit()
{
size_t physical_memory_limit;
size_t physical_memory_limit = 0;

if (!CGroup::GetPhysicalMemoryLimit(&physical_memory_limit))
physical_memory_limit = SIZE_T_MAX;
return 0;

// If there's no memory limit specified on the container this
// actually returns 0x7FFFFFFFFFFFF000 (2^63-1 rounded down to
// 4k which is a common page size). So we know we are not
// running in a memory restricted environment.
if (physical_memory_limit > 0x7FFFFFFF00000000)
{
return 0;
}

struct rlimit curr_rlimit;
size_t rlimit_soft_limit = (size_t)RLIM_INFINITY;
Expand Down
21 changes: 13 additions & 8 deletions src/coreclr/src/gc/windows/gcenv.windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,16 +286,21 @@ static size_t GetRestrictedPhysicalMemoryLimit()
if ((limit_info.BasicLimitInformation.LimitFlags & JOB_OBJECT_LIMIT_WORKINGSET) != 0)
job_workingset_limit = limit_info.BasicLimitInformation.MaximumWorkingSetSize;

job_physical_memory_limit = min (job_memory_limit, job_process_memory_limit);
job_physical_memory_limit = min (job_physical_memory_limit, job_workingset_limit);
if ((job_memory_limit != (size_t)UINTPTR_MAX) ||
(job_process_memory_limit != (size_t)UINTPTR_MAX) ||
(job_workingset_limit != (size_t)UINTPTR_MAX))
{
job_physical_memory_limit = min (job_memory_limit, job_process_memory_limit);
job_physical_memory_limit = min (job_physical_memory_limit, job_workingset_limit);

MEMORYSTATUSEX ms;
::GetProcessMemoryLoad(&ms);
total_virtual = ms.ullTotalVirtual;
total_physical = ms.ullAvailPhys;
MEMORYSTATUSEX ms;
::GetProcessMemoryLoad(&ms);
total_virtual = ms.ullTotalVirtual;
total_physical = ms.ullAvailPhys;

// A sanity check in case someone set a larger limit than there is actual physical memory.
job_physical_memory_limit = (size_t) min (job_physical_memory_limit, ms.ullTotalPhys);
// A sanity check in case someone set a larger limit than there is actual physical memory.
job_physical_memory_limit = (size_t) min (job_physical_memory_limit, ms.ullTotalPhys);
}
}
}

Expand Down
18 changes: 8 additions & 10 deletions src/coreclr/src/pal/src/misc/cgroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,20 +386,18 @@ size_t
PALAPI
PAL_GetRestrictedPhysicalMemoryLimit()
{
size_t physical_memory_limit;
size_t physical_memory_limit = 0;

if (!CGroup::GetPhysicalMemoryLimit(&physical_memory_limit))
return 0;
else

// If there's no memory limit specified on the container this
// actually returns 0x7FFFFFFFFFFFF000 (2^63-1 rounded down to
// 4k which is a common page size). So we know we are not
// running in a memory restricted environment.
if (physical_memory_limit > 0x7FFFFFFF00000000)
{
// If there's no memory limit specified on the container this
// actually returns 0x7FFFFFFFFFFFF000 (2^63-1 rounded down to
// 4k which is a common page size). So we know we are not
// running in a memory restricted environment.
if (physical_memory_limit > 0x7FFFFFFF00000000)
{
return 0;
}
return 0;
}

struct rlimit curr_rlimit;
Expand Down
21 changes: 13 additions & 8 deletions src/coreclr/src/vm/gcenv.os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,16 +494,21 @@ static size_t GetRestrictedPhysicalMemoryLimit()
if ((limit_info.BasicLimitInformation.LimitFlags & JOB_OBJECT_LIMIT_WORKINGSET) != 0)
job_workingset_limit = limit_info.BasicLimitInformation.MaximumWorkingSetSize;

job_physical_memory_limit = min (job_memory_limit, job_process_memory_limit);
job_physical_memory_limit = min (job_physical_memory_limit, job_workingset_limit);
if ((job_memory_limit != (size_t)MAX_PTR) ||
(job_process_memory_limit != (size_t)MAX_PTR) ||
(job_workingset_limit != (size_t)MAX_PTR))
{
job_physical_memory_limit = min (job_memory_limit, job_process_memory_limit);
job_physical_memory_limit = min (job_physical_memory_limit, job_workingset_limit);

MEMORYSTATUSEX ms;
::GetProcessMemoryLoad(&ms);
total_virtual = ms.ullTotalVirtual;
total_physical = ms.ullAvailPhys;
MEMORYSTATUSEX ms;
::GetProcessMemoryLoad(&ms);
total_virtual = ms.ullTotalVirtual;
total_physical = ms.ullAvailPhys;

// A sanity check in case someone set a larger limit than there is actual physical memory.
job_physical_memory_limit = (size_t) min (job_physical_memory_limit, ms.ullTotalPhys);
// A sanity check in case someone set a larger limit than there is actual physical memory.
job_physical_memory_limit = (size_t) min (job_physical_memory_limit, ms.ullTotalPhys);
}
}
}

Expand Down

0 comments on commit 6607f68

Please sign in to comment.