GC.GetTotalMemory(false) vs Container Memory Working Set question (Azure AKS, .NET Core 5)

Viewed 245

I have a container with a dotnet core application running in Azure Kubernetes Service. No memory limits were specified in Pod specs.

The question is why GC.GetTotalMemory(false) shows approx. 3 Gb of memory used while AKS Insights shows 9.5 GB for this Pod container?

enter image description here

enter image description here

Running top reveals these 9.5 GB: enter image description here

2 Answers

why GC.GetTotalMemory(false) shows approx. 3 Gb of memory used while AKS Insights shows 9.5 GB for this Pod container?

GC.GetTotalMemory(false) is define for garbage colllector in POD. The parameter defines whether or not to wait till a full garbage collection happens before running or not.The Approximate value is set as 3GB you can change it also.

The following example demonstrates how to use the GetTotalMemory method to get and display the number of bytes currently allocated in managed memory.

Parameters

forceFullCollection

Type: System.Boolean true to indicate that this method can wait for garbage collection to > occur before returning; otherwise, false.

The reason that diff is still 0 could be because a GC already happend even if you pass false.

Reference : What is the Difference between GC.GetTotalMemory(false) and GC.GetTotalMemory(true) and MS Document

As I understand GC.GetTotalMemory(false) returns the size of managed objects in bytes but the entire working memory set is much larger because memory is allocated in pages and because of managed heap fragmentation and because GC is not performed.

Related