admin管理员组

文章数量:1291031

I have a Windows Server 2016 with 32 CPUs and 64GB of RAM running a WCF service. My application is consuming a lot of memory, reaching 80% after a recycle, and after about 3 hours, the memory usage drops back to an average of 40%. During peak call times, memory usage exceeds 80% and often reaches 100%, causing a crash. I captured a Dump when the memory was above 80%.

0:000> !address -summary

--- Usage Summary ---------------- RgnCount ----------- Total Size -------- %ofBusy %ofTotal
Free                                    922     7df5`aa94d000 ( 125.960 TB)           98.41%
<unknown>                              7549      20a`2f9b0000 (   2.040 TB)  99.97%    1.59%
Heap                                    769        0`1b2e1000 ( 434.879 MB)   0.02%    0.00%
Image                                   618        0`0543c000 (  84.234 MB)   0.00%    0.00%
Stack                                   502        0`052c0000 (  82.750 MB)   0.00%    0.00%
Other                                     9        0`001c7000 (   1.777 MB)   0.00%    0.00%
TEB                                     167        0`0014e000 (   1.305 MB)   0.00%    0.00%
PEB                                       1        0`00001000 (   4.000 kB)   0.00%    0.00%

--- Type Summary (for busy) ------ RgnCount ----------- Total Size -------- %ofBusy %ofTotal
MEM_MAPPED                              254      200`00df3000 (   2.000 TB)  98.02%    1.56%
MEM_PRIVATE                            3407        a`3fcb4000 (  40.997 GB)   1.96%    0.03%
MEM_IMAGE                              5954        0`14bfc000 ( 331.984 MB)   0.02%    0.00%

--- State Summary ---------------- RgnCount ----------- Total Size -------- %ofBusy %ofTotal
MEM_FREE                                922     7df5`aa94d000 ( 125.960 TB)           98.41%
MEM_RESERVE                            3431      208`c34df000 (   2.034 TB)  99.70%    1.59%
MEM_COMMIT                             6184        1`921c4000 (   6.283 GB)   0.30%    0.00%

--- Protect Summary (for commit) - RgnCount ----------- Total Size -------- %ofBusy %ofTotal
PAGE_READWRITE                         2272        1`7a591000 (   5.912 GB)   0.28%    0.00%
PAGE_READONLY                          3144        0`11c88000 ( 284.531 MB)   0.01%    0.00%
PAGE_EXECUTE_READ                       116        0`03048000 (  48.281 MB)   0.00%    0.00%
PAGE_EXECUTE_READWRITE                   70        0`01bb8000 (  27.719 MB)   0.00%    0.00%
PAGE_NOACCESS                           371        0`01019000 (  16.098 MB)   0.00%    0.00%
PAGE_READWRITE | PAGE_GUARD             167        0`002ed000 (   2.926 MB)   0.00%    0.00%
PAGE_WRITECOPY                           44        0`000a5000 ( 660.000 kB)   0.00%    0.00%

--- Largest Region by Usage ----------- Base Address -------- Region Size ----------
Free                                    14c`ef780000     7ca9`10080000 ( 124.660 TB)
<unknown>                              7df6`014ab000      1ff`faab4000 (   2.000 TB)
Heap                                    14c`c3900000        0`02581000 (  37.504 MB)
Image                                  7fff`8d220000        0`00e46000 (  14.273 MB)
Stack                                    23`74580000        0`0007b000 ( 492.000 kB)
Other                                   142`ab180000        0`00181000 (   1.504 MB)
TEB                                      23`74202000        0`00002000 (   8.000 kB)
PEB                                      23`74335000        0`00001000 (   4.000 kB)

What caught my attention was the unmanaged heap <unknown>, MEM_RESERV at 2TB, and MEM_MAPPED also at 2TB, with about 99% busy. This led me to believe that it is suffering from a memory leak, as the heap size and reserved memory (Virtual Memory) are highly disproportionate. I found 2TB to be an excessive amount for the W3WP process. I suspect that objects or libraries are reserving space in virtual memory and not releasing it after use.

Analyzing the report through DebugDiag, Visual Studio, and WinDbg: The main heap, which is small, has 30% fragmentation. I noticed that there are many static classes, and the cache is set to never expire. I believe that libraries or the Dev team are reserving unmanaged memory, calling VirtualAlloc() but not properly calling VirtualFree(). I identified that there are buffers, but I am unable to verify if they are being correctly reused and then released.

I work in infrastructure and do not have access to the code or much experience with dumps. I am performing troubleshooting because the Dev team says it is an infrastructure issue. However, observing the application's behavior, it is reserving a lot of virtual memory in the unmanaged heap, which leads me to believe that libraries or APIs are causing a memory leak.

本文标签: netMemory Leak in Heap unmanagedStack Overflow