Skip to content

Commit

Permalink
To support container scenario, 2 HardLimit configs are added - (dotne…
Browse files Browse the repository at this point in the history
…t/coreclr#22180)

GCHeapHardLimit - specifies a hard limit for the GC heap
GCHeapHardLimitPercent - specifies a percentage of the physical memory this process is allowed to use

If both are specified, GCHeapHardLimit is checked first and only when it's not specified
would we check GCHeapHardLimitPercent.

If neither is specified but the process is running inside a container with a memory
limit specified, we will take this as the hard limit:

max (20mb, 75% of the memory limit on the container)

If one of the HardLimit configs is specified, and the process is running inside a container
with a memory limit, the GC heap usage will not exceed the HardLimit but the total memory
is still the memory limit on the container so when we calculate the memory load it's based
off the container memory limit.

An example,

process is running inside a container with 200mb limit
user also specified GCHeapHardLimit as 100mb.

if 50mb out of the 100mb is used for GC, and 100mb is used for other things, the memory load
is (50 + 100)/200 = 75%.

Some notes on these configs -

+ The limit is the commit size.

+ This is only supported on 64-bit.

+ For Server GC the minimum *reserved* segment size is 16mb per heap, this is to avoid the
scenario where the hard limit is small but the process can use many procs and we end up
with tiny segments which doesn't make sense. We then keep track of the committed on the segments
so the total does not exceed the hard limit.

Commit migrated from dotnet/coreclr@ed52a00
  • Loading branch information
Maoni0 authored Jan 29, 2019
1 parent 0994a1c commit d44cb27
Show file tree
Hide file tree
Showing 15 changed files with 887 additions and 274 deletions.
2 changes: 0 additions & 2 deletions src/coreclr/src/ToolBox/SOS/Strike/sos.def
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ EXPORTS
dumpdelegate=DumpDelegate
DumpDomain
dumpdomain=DumpDomain
#ifdef TRACE_GC
DumpGCLog
dumpgclog=DumpGCLog
dlog=DumpGCLog
#endif
DumpGCData
dumpgcdata=DumpGCData
dgc=DumpGCData
Expand Down
19 changes: 11 additions & 8 deletions src/coreclr/src/ToolBox/SOS/Strike/strike.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9414,8 +9414,7 @@ DECLARE_API(DumpLog)
return Status;
}

#ifdef TRACE_GC

#ifndef FEATURE_PAL
DECLARE_API (DumpGCLog)
{
INIT_API_NODAC();
Expand All @@ -9428,6 +9427,10 @@ DECLARE_API (DumpGCLog)
}

const char* fileName = "GCLog.txt";
int iLogSize = 1024*1024;
BYTE* bGCLog = NULL;
int iRealLogSize = iLogSize - 1;
DWORD dwWritten = 0;

while (isspace (*args))
args ++;
Expand Down Expand Up @@ -9472,8 +9475,7 @@ DECLARE_API (DumpGCLog)
goto exit;
}

int iLogSize = 1024*1024;
BYTE* bGCLog = new NOTHROW BYTE[iLogSize];
bGCLog = new NOTHROW BYTE[iLogSize];
if (bGCLog == NULL)
{
ReportOOM();
Expand All @@ -9486,7 +9488,6 @@ DECLARE_API (DumpGCLog)
ExtOut("failed to read memory from %08x\n", dwAddr);
}

int iRealLogSize = iLogSize - 1;
while (iRealLogSize >= 0)
{
if (bGCLog[iRealLogSize] != '*')
Expand All @@ -9497,13 +9498,17 @@ DECLARE_API (DumpGCLog)
iRealLogSize--;
}

DWORD dwWritten = 0;
WriteFile (hGCLog, bGCLog, iRealLogSize + 1, &dwWritten, NULL);

Status = S_OK;

exit:

if (bGCLog != NULL)
{
delete [] bGCLog;
}

if (hGCLog != INVALID_HANDLE_VALUE)
{
CloseHandle (hGCLog);
Expand All @@ -9518,9 +9523,7 @@ DECLARE_API (DumpGCLog)

return Status;
}
#endif //TRACE_GC

#ifndef FEATURE_PAL
DECLARE_API (DumpGCConfigLog)
{
INIT_API();
Expand Down
6 changes: 5 additions & 1 deletion src/coreclr/src/gc/env/gcenv.os.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,14 @@ class GCToOSInterface
// Get the physical memory that this process can use.
// Return:
// non zero if it has succeeded, 0 if it has failed
// *is_restricted is set to true if asked and running in restricted.
// Remarks:
// If a process runs with a restricted memory limit, it returns the limit. If there's no limit
// specified, it returns amount of actual physical memory.
static uint64_t GetPhysicalMemoryLimit();
//
// PERF TODO: Requires more work to not treat the restricted case to be special.
// To be removed before 3.0 ships.
static uint64_t GetPhysicalMemoryLimit(bool* is_restricted=NULL);

// Get memory status
// Parameters:
Expand Down
Loading

0 comments on commit d44cb27

Please sign in to comment.