asp.netiisdump

w3wp.exe high memory usage yet low managed memory usage?


On one of our production servers, w3wp.exe uses >600 MB private memory for an ASP.NET Core app.

I did a managed memory dump with dotnet-gcdump yet that one one shows about ~23 MB memory usage from managed objects. I also took a full memory dump but didn't see high memory usage by anything I could access.

Doing the gcdump should have cleaned up any unused memory, right? So something is still actively using all these MBs?

What could be going on here?


Solution

  • The answer is the Server Garbage Collector.

    This is a mode that is the default for ASP.NET (Core) application. It runs the GC infrequently and reserves a lot of RAM by default, in case of sudden load increase I assume.

    Using the Workstation Garbage Collector results in a much lower memory footprint (like with desktop apps), at the cost of more frequent garbage collection cycles, so it's a tradeoff between CPU and memory.

    As my apps aren't doing nearly enough processing to justify this much memory, I switched them to Workstation Garbage Collector mode and haven't had problems since.

    You can do that in 2 ways:

    1. Change the csproj, add this property: <ServerGarbageCollection>false</ServerGarbageCollection>

    or

    1. Open the *.runtimeconfig.json, change "System.GC.Server": true to "System.GC.Server": false

    The second option will result automatically from the first one, but it is useful for apps that are already deployed without having to rebuild them.