Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is meant by "Memory Pressure"?

Reading through Tess Ferrandez' Blog on garbage collection, she says that there are 3 possible causes for a collection:

  1. When you allocate a new object and the generation 0 budget is reached, i.e. if the new object would cause it to go over-budget.
  2. When someone calls GC.Collect (Induced GC)
  3. Based on memory pressure

I understand points 1 and 2, but what is meant by memory pressure in point 3?

I had assumed it was the general memory available in the system, but if the system really did use up all of its memory then I'd imagine the whole system would blue-screen.

What is actually meant by memory pressure? How does it differ from exceeding a generation's budget?

like image 918
BanksySan Avatar asked May 12 '18 12:05

BanksySan


1 Answers

In point 3, Tess refers to "low memory notification" send by Windows in case of running out of available memory. Applications may listen to that notification - to react somehow before something worse happens (for example, saving its crucial data and so on, so forth). Well-behaving applications may even try to help the OS by trimming their own memory usage.

CLR is listening for low memory notification. When it happens, GC is triggered and generally, it makes GCs more aggressive. The benefits are mutual because reducing the pressure on memory helps all applications in the system (including the .NET app itself).

When exactly low memory notification is sent is not so well documented. According to the comment in the internal System.Runtime.Caching.PhysicalMemoryMonitor class, that in turn is based on comments from internal Windows implementations, the low memory notification is signaled when about 97-99% of physical memory is occupied (depending on the physical RAM amount installed in the system).

like image 98
Konrad Kokosa Avatar answered Sep 28 '22 02:09

Konrad Kokosa