1

for some weeks I struggling with the OutOfMemory issue on our SharePoint 2007 (published intranet with many customizations) WFEs (SP 2 and Win 2003 32 Bit Servers). After I received a crashed memory dump I found out that we have a memory fragmentation issue. For the dump analysis I use the following two tools: DiagDebug and Windbg with sos.dll.

Result: 96,74% Free Memory Fragmentation

DebugDiag (Memory Pressure Analyzers)

    Virtual Memory Summary
    Size of largest free VM block   23,63 MBytes 
    Free memory fragmentation   96,74% 
    Free Memory   725,52 MBytes   (35,43% of Total Memory) 
    Reserved Memory   406,88 MBytes   (19,87% of Total Memory) 
    Committed Memory   915,54 MBytes   (44,71% of Total Memory) 
    Total Memory   2,00 GBytes 
    Largest free block at   0x00000000`4b0b0000 

DebugDiag (SharePoint Analyzers)

    Undisposed SPRequest objects: 9
    Disposed SPRequest objects: 187
    Undisposed SPWeb objects: 185
    Disposed SPWeb objects: 34
    Undisposed SPSite objects: 8
    Disposed SPSite objects: 22
    undisposed special purpose (AllowCleanupWhenThreadEnds = false) SPRequest object found at: 0x02320dd0.
    undisposed special purpose (AllowCleanupWhenThreadEnds = false) SPRequest object found at: 0x4e8296f8.
    undisposed special purpose (AllowCleanupWhenThreadEnds = false) SPRequest object found at: 0x4e869a20.
    undisposed SPWeb object 0x02701168 references a disposed or invalid SPRequest object: 0x0270137c
    undisposed SPWeb object 0x027013cc references a disposed or invalid SPRequest object: 0x027015e0
    undisposed SPWeb object 0x02720824 references a disposed or invalid SPRequest object: 0x02720a20
    undisposed SPWeb object 0x02d2aa74 references a disposed or invalid SPRequest object: 0x02d2ac70
   ...

    Undisposed SPRequest Objects per managed Thread:
    Thread ID: 6714, Undisposed SPRequest: 4
    Thread ID: 4c68, Undisposed SPRequest: 3
    Thread ID: 5e8c, Undisposed SPRequest: 1
    Thread ID: 6180, Undisposed SPRequest: 1

So now I would like to understand what causes the memory fragmentation. Hope you can help me. These are the steps I did to get the right information.

Windbg with sos.dll

!address summary

-------------------- Usage SUMMARY --------------------------
TotSize (      KB)   Pct(Tots) Pct(Busy)   Usage
2c748000 (  728352) : 34.73%    53.79%    : RegionUsageIsVAD
2d584000 (  742928) : 35.43%    00.00%    : RegionUsageFree
f987000 (  255516) : 12.18%    18.87%    : RegionUsageImage
10fc000 (   17392) : 00.83%    01.28%    : RegionUsageStack
  44000 (     272) : 00.01%    00.02%    : RegionUsageTeb
1585a000 (  352616) : 16.81%    26.04%    : RegionUsageHeap
      0 (       0) : 00.00%    00.00%    : RegionUsagePageHeap
   1000 (       4) : 00.00%    00.00%    : RegionUsagePeb
   1000 (       4) : 00.00%    00.00%    : RegionUsageProcessParametrs
   1000 (       4) : 00.00%    00.00%    : RegionUsageEnvironmentBlock
   Tot: 7fff0000 (2097088 KB) Busy: 52a6c000 (1354160 KB)

-------------------- Type SUMMARY --------------------------
TotSize (      KB)   Pct(Tots)  Usage
2d584000 (  742928) : 35.43%   : <free>
154e3000 (  349068) : 16.65%   : MEM_IMAGE
127c000 (   18928) : 00.90%   : MEM_MAPPED
3c30d000 (  986164) : 47.03%   : MEM_PRIVATE

-------------------- State SUMMARY --------------------------
TotSize (      KB)   Pct(Tots)  Usage
3938b000 (  937516) : 44.71%   : MEM_COMMIT
2d584000 (  742928) : 35.43%   : MEM_FREE
196e1000 (  416644) : 19.87%   : MEM_RESERVE

Largest free region: Base 4b0b0000 - Size 017a0000 (24192 KB)

Seems that there is enough free memory (742928 KB) overall but the biggest free chunk has only 24192 KB. Again: Free Memory Fragmentation!

!threads

ThreadCount: 38
UnstartedThread: 0
BackgroundThread: 37
PendingThread: 0
DeadThread: 0
Hosted Runtime: no
                                  PreEmptive   GC Alloc           Lock
   ID OSID ThreadOBJ    State     GC       Context       Domain   Count APT Exception
14    1 5358 0010f718   1808220 Enabled  00000000:00000000 000dd1b8     0 MTA (Threadpool Worker)
18    2 61a4 001118d0      b220 Enabled  00000000:00000000 000dd1b8     0 MTA (Finalizer)
19    3 6060 0012a3f8    80a220 Enabled  00000000:00000000 000dd1b8     0 MTA (Threadpool Completion Port)
20    4 64c8 0012df90      1220 Enabled  00000000:00000000 000dd1b8     0 Ukn
12    5 57f4 00147e80   880a220 Enabled  00000000:00000000 000dd1b8     0 MTA (Threadpool Completion Port)
23    7 6714 0eb89f08   180b220 Enabled  00000000:00000000 0012e6d0     1 MTA (Threadpool Worker)
24    8 66b8 0eb91970   180b220 Enabled  00000000:00000000 000dd1b8     0 MTA (Threadpool Worker)
25    b 6320 0eb942f0   180b220 Disabled 00000000:00000000 0012e6d0     0 MTA (Threadpool Worker)
26    d 2004 0eb97120   180b220 Enabled  00000000:00000000 000dd1b8     0 MTA (Threadpool Worker)
27    e 5bb0 0eb9a438   180b220 Enabled  00000000:00000000 000dd1b8     0 MTA (Threadpool Worker)
28    f 61a8 0eb9dee8   380b220 Enabled  00000000:00000000 0012e6d0     1 MTA (Threadpool Worker)
29   14 3b88 0ebba688   180b220 Enabled  00000000:00000000 000dd1b8     0 MTA (Threadpool Worker)
30   15 5d74 0ebc4840   380b220 Enabled  00000000:00000000 0012e6d0     1 MTA (Threadpool Worker)
31   16 422c 0ebc91b0   180b220 Enabled  00000000:00000000 000dd1b8     0 MTA (Threadpool Worker)
32   18 6544 125242c8   180b220 Enabled  00000000:00000000 000dd1b8     0 MTA (Threadpool Worker)
33   1a 4c68 12534bc8   180b220 Disabled 4e875ac4:4e875d30 0012e6d0     1 MTA (Threadpool Worker)
34   1b 66d4 12539c80   180b220 Enabled  00000000:00000000 000dd1b8     0 MTA (Threadpool Worker)
35   1c 5e8c 12542e58   180b220 Enabled  00000000:00000000 0012e6d0     1 MTA (Threadpool Worker)
36   1d 62f0 1254be90   180b220 Enabled  4e875d84:4e877d30 0012e6d0     2 MTA (Threadpool Worker) System.OutOfMemoryException (4e875d3c)
39   1e 6558 0ec16d28    80a220 Enabled  00000000:00000000 000dd1b8     0 MTA (Threadpool Completion Port)
40   1f 6180 0ec14b70   200b020 Enabled  00000000:00000000 0012e6d0     0 MTA
43   20 592c 0ebd7a00       220 Enabled  00000000:00000000 000dd1b8     0 MTA
45   21 624c 1261a060       220 Enabled  00000000:00000000 000dd1b8     0 MTA
8   22 5c78 125499f8       220 Enabled  00000000:00000000 000dd1b8     0 Ukn
6   23 3c68 126b6e90       220 Enabled  00000000:00000000 000dd1b8     0 Ukn
7   24 6458 36414400       220 Enabled  00000000:00000000 000dd1b8     0 Ukn
44   25 5e60 36675440       220 Enabled  00000000:00000000 000dd1b8     0 MTA
5   26 55d8 364214a0       220 Enabled  00000000:00000000 000dd1b8     0 Ukn
57   27 6534 36622948       220 Enabled  00000000:00000000 000dd1b8     0 Ukn
58   28 59bc 0016f810       220 Enabled  00000000:00000000 000dd1b8     0 Ukn
56   29 3ee0 250fa6d8       220 Enabled  00000000:00000000 000dd1b8     0 Ukn
60   2a 63fc 252da068   200b220 Enabled  00000000:00000000 0012e6d0     0 MTA
59   2b 5fdc 24fc0be8       220 Enabled  00000000:00000000 000dd1b8     0 Ukn
61   2c 4154 25052008       220 Enabled  00000000:00000000 000dd1b8     0 Ukn
62   2d 60fc 250093a8       220 Enabled  00000000:00000000 000dd1b8     0 Ukn
42   2e 1a38 1c99b5d0       220 Enabled  00000000:00000000 000dd1b8     0 MTA
63   13 59e0 0ebb5d48       220 Enabled  00000000:00000000 000dd1b8     0 Ukn
64   19 6420 0ebac6a0   880b220 Enabled  00000000:00000000 000dd1b8     0 MTA     (Threadpool Completion Port)

!eeheap -gc

Number of GC Heaps: 2
------------------------------
Heap 0 (000e2418)
generation 0 starts at 0x432d0c54
generation 1 starts at 0x432c0038
generation 2 starts at 0x02060038
ephemeral segment allocation context: none
segment    begin allocated     size
02060000 02060038  03d0234c 0x01ca2314(30024468)
432c0000 432c0038  441e82f4 0x00f282bc(15893180)
Large object heap starts at 0x0a060038
segment    begin allocated     size
0a060000 0a060038  0bd57530 0x01cf74f8(30373112)
5b920000 5b920038  5c9bf338 0x0109f300(17429248)
Heap Size  0x5960dc8(93720008)
 ------------------------------
Heap 1 (00110750)
generation 0 starts at 0x4e869d30
generation 1 starts at 0x4e820038
generation 2 starts at 0x06060038
ephemeral segment allocation context: none
segment    begin allocated     size
06060000 06060038  07a0af98 0x019aaf60(26914656)
4e820000 4e820038  4e8eaf38 0x000caf00(831232)
Large object heap starts at 0x0c060038
segment    begin allocated     size
0c060000 0c060038  0c9ec998 0x0098c960(10013024)
6e020000 6e020038  6f90f0a8 0x018ef070(26144880)
Heap Size  0x3cf1830(63903792)
------------------------------
GC Heap Size  0x96525f8(157623800)

!dumpheap (heap1 extract)

  • 0a060038 000e1a98 16 Free
  • 0a060048 793042f4 4096
  • 0a061048 000e1a98 16 Free
  • 0a061058 793042f4 528
  • 0a061268 000e1a98 16 Free
  • 0a061278 793042f4 4096
  • 0a062278 000e1a98 16 Free
  • 0a062288 793042f4 5112
  • 0a063680 000e1a98 16 Free
  • 0a063690 793042f4 4096
  • 0a064690 000e1a98 16 Free
  • 0a0646a0 793042f4 4096
  • 0a0656a0 000e1a98 16 Free
  • 0a0656b0 793042f4 5112
  • 0a066aa8 000e1a98 16 Free
  • 0a066ab8 793042f4 4096
  • 0a067ab8 000e1a98 16 Free
  • 0a067ac8 793042f4 4096
  • 0a068ac8 000e1a98 16 Free
  • 0a068ad8 793042f4 4096
  • 0a069ad8 793042f4 528
  • 0a069ce8 000e1a98 16 Free
  • 0a069cf8 793042f4 528
  • 0a069f08 793042f4 528
  • 0a06a118 000e1a98 16 Free
  • 0a06a128 793042f4 528
  • 0a06a338 000e1a98 260096 Free
  • 0a0a9b38 793042f4 4096
  • 0a0aab38 000e1a98 16 Free
  • 0a0aab48 793042f4 5784
  • 0a0ac1e0 000e1a98 16 Free
  • 0a0ac1f0 793042f4 4096
  • 0a0ad1f0 000e1a98 16 Free
  • 0a0ad200 793042f4 528
  • 0a0ad410 000e1a98 16 Free
  • 0a0ad420 793042f4 4096
  • 0a0ae420 000e1a98 16 Free
  • 0a0ae430 793042f4 528
  • 0a0ae640 000e1a98 16 Free
  • 0a0ae650 793042f4 4096
  • 0a0af650 000e1a98 16 Free
  • 0a0af660 793042f4 528
  • 0a0af870 000e1a98 16 Free
  • 0a0af880 793042f4 528
  • 0a0afa90 000e1a98 131120 Free
  • 0a0cfac0 793042f4 528
  • 0a0cfcd0 000e1a98 16 Free
  • 0a0cfce0 793042f4 4096
  • 0a0d0ce0 000e1a98 16 Free
  • 0a0d0cf0 793042f4 528
  • 0a0d0f00 000e1a98 16 Free
  • 0a0d0f10 793042f4 528
  • 0a0d1120 000e1a98 16 Free
  • 0a0d1130 793042f4 528
  • 0a0d1340 000e1a98 16 Free
  • 0a0d1350 793042f4 4096
  • 0a0d2350 000e1a98 16 Free
  • 0a0d2360 793042f4 5784
  • 0a0d39f8 000e1a98 16 Free
  • 0a0d3a08 793042f4 4096
  • 0a0d4a08 000e1a98 348200 Free
  • 0a129a30 793042f4 528
  • 0a129c40 000e1a98 16 Free
  • 0a129c50 793042f4 528
  • 0a129e60 000e1a98 361224 Free
  • 0a182168 793042f4 528
  • 0a182378 000e1a98 16 Free
  • 0a182388 793042f4 7016
  • 0a183ef0 000e1a98 16 Free
  • 0a183f00 793042f4 7016
  • ...
  • 63859d80 14762 413336 System.Xml.XmlElement
  • 6385a090 12103 435708 System.Xml.XmlName
  • 79332b54 21020 504480 System.Collections.ArrayList
  • 6385798c 32932 658640 System.Xml.NameTable+Entry
  • 6385c76c 35215 704300 System.Xml.XmlAttribute
  • 79331754 505 706416 System.Char[]
  • 7932dd5c 12751 714056 System.Reflection.RuntimePropertyInfo
  • 6385a284 36665 733300 System.Xml.XmlText
  • 79332cc0 5530 791644 System.Int32[]
  • 7932fde0 22824 1278144 System.Reflection.RuntimeMethodInfo
  • 79333274 6758 1733808 System.Collections.Hashtable+bucket[]
  • 793042f4 54360 5051132 System.Object[]
  • 79333594 4772 29304312 System.Byte[]
  • 79330b24 225539 33121896 System.String
  • 000e1a98 239 72089072 Free
  • Total 711343 objects
  • Fragmented blocks larger than 0.5 MB:
  • Addr Size Followed by 4331b1d8 14.8MB 441e8270 System.Threading.Overlapped

I looked inside some of the addresses between the "Free" segments but unfortunately I can't find any information about the source that coused the issue.

!do 0a182388

Name: System.Object[]
MethodTable: 793042f4
EEClass: 790eda64
Size: 7012(0x1b64) bytes
Array: Rank 1, Number of elements 1749, Type CLASS
Element Type: System.Object
Fields:
None

!gcroot 0a182388

Note: Roots found on stacks may be false positives. Run "!help gcroot" for
more info.
Scan Thread 14 OSTHread 5358
Scan Thread 18 OSTHread 61a4
Scan Thread 19 OSTHread 6060
Scan Thread 20 OSTHread 64c8
Scan Thread 12 OSTHread 57f4
Scan Thread 23 OSTHread 6714
Scan Thread 24 OSTHread 66b8
Scan Thread 25 OSTHread 6320
Scan Thread 26 OSTHread 2004
Scan Thread 27 OSTHread 5bb0
Scan Thread 28 OSTHread 61a8
Scan Thread 29 OSTHread 3b88
Scan Thread 30 OSTHread 5d74
Scan Thread 31 OSTHread 422c
Scan Thread 32 OSTHread 6544
Scan Thread 33 OSTHread 4c68
Scan Thread 34 OSTHread 66d4
Scan Thread 35 OSTHread 5e8c
Scan Thread 36 OSTHread 62f0
Scan Thread 39 OSTHread 6558
Scan Thread 40 OSTHread 6180
Scan Thread 43 OSTHread 592c
Scan Thread 45 OSTHread 624c
Scan Thread 8 OSTHread 5c78
Scan Thread 6 OSTHread 3c68
Scan Thread 7 OSTHread 6458
Scan Thread 44 OSTHread 5e60
Scan Thread 5 OSTHread 55d8
Scan Thread 57 OSTHread 6534
Scan Thread 58 OSTHread 59bc
Scan Thread 56 OSTHread 3ee0
Scan Thread 60 OSTHread 63fc
Scan Thread 59 OSTHread 5fdc
Scan Thread 61 OSTHread 4154
Scan Thread 62 OSTHread 60fc
Scan Thread 42 OSTHread 1a38
Scan Thread 63 OSTHread 59e0
Scan Thread 64 OSTHread 6420
DOMAIN(0012E6D0):HANDLE(Pinned):e4613d4:Root:0a182388(System.Object[])

!gcroot 0a129a30 ... Scan Thread 64 OSTHread 6420

 DOMAIN(000DD1B8):HANDLE(Pinned):1fc11b8:Root:0a129a30(System.Object[])

!gcroot 0a061278 ... DOMAIN(000DD1B8):HANDLE(Pinned):1fb13f0:Root:0a061278(System.Object[])

!gchandles

GC Handle Statistics:
Strong Handles: 1007
Pinned Handles: 474
Async Pinned Handles: 6
Ref Count Handles: 5
Weak Long Handles: 681
Weak Short Handles: 56
Other Handles: 0
...
661485ec       68         2176 System.Web.NativeFileChangeNotification
66153774       93         2976 System.Web.Hosting.ISAPIAsyncCompletionCallback
793310f8       68         3808 System.Threading.Thread
793141f0      162         6480 System.Reflection.Emit.DynamicResolver
79332070      279         6696 System.Reflection.Assembly
7932f19c      228        10944 System.Reflection.Module
793327e8      328        11808 System.Security.PermissionSet
7932f25c      386        29336 System.RuntimeType+RuntimeTypeCache
793042f4      185       294456 System.Object[]

In the DebugDiag SharePoint Analysis some undisposed SPWeb objects were reported. So trying to find the cause here... Report: "undisposed SPWeb object 0x02701168 references a disposed or invalid SPRequest object: 0x0270137c"

!do 0x02701168

Name: Microsoft.SharePoint.SPWeb
MethodTable: 1325ed80
EEClass: 1669cd80
Size: 508(0x1fc) bytes
(C:\WINDOWS\assembly\GAC_MSIL\Microsoft.SharePoint\12.0.0.0__71e9bce111e9429c\Microsoft.SharePoint.dll)

!gcroot 0x02701168

Note: Roots found on stacks may be false positives. Run "!help gcroot" for
more info.
Scan Thread 14 OSTHread 5358
Scan Thread 18 OSTHread 61a4
Scan Thread 19 OSTHread 6060
Scan Thread 20 OSTHread 64c8
Scan Thread 12 OSTHread 57f4
Scan Thread 23 OSTHread 6714
ESP:efbe92c:Root:07a2cbc8(System.Collections.Hashtable+bucket[])->
023f1044(Microsoft.SharePoint.Publishing.CacheManager)->
023f3df4(Microsoft.SharePoint.Publishing.CachedObjectFactory)->
023f3e7c(Microsoft.SharePoint.Publishing.WssObjectCache)->
023f3f30(System.Collections.Hashtable)->
03b0f448(System.Collections.Hashtable+bucket[])->
0733b918(Microsoft.SharePoint.Publishing.ThreadSafeCache`2+CacheEntry`2[[System.String, mscorlib],[Microsoft.SharePoint.Publishing.CachedObjectWrapper, Microsoft.SharePoint.Publishing],[System.String, mscorlib],[Microsoft.SharePoint.Publishing.CachedObjectWrapper, Microsoft.SharePoint.Publishing]])->
0733b868(Microsoft.SharePoint.Publishing.CachedObjectWrapper)->
035f25b4(Microsoft.SharePoint.Publishing.CachedPage)->
035f2718(System.Collections.Generic.Dictionary`2[[Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider, Microsoft.SharePoint.Publishing],[Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapNode, Microsoft.SharePoint.Publishing]])->
0733ba90(System.Collections.Generic.Dictionary`2+Entry[[Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider, Microsoft.SharePoint.Publishing],[Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapNode, Microsoft.SharePoint.Publishing]][])->
0733b92c(Microsoft.SharePoint.Publishing.Navigation.PortalListItemSiteMapNode)->
069b2f88(Microsoft.SharePoint.Publishing.Navigation.PortalWebSiteMapNode)->
069bfee4(System.Collections.Generic.Dictionary`2[[System.Guid, mscorlib],[Microsoft.SharePoint.Publishing.Navigation.ProxySiteMapNode, Microsoft.SharePoint.Publishing]])->
069d8fe8(System.Collections.Generic.Dictionary`2+Entry[[System.Guid, mscorlib],[Microsoft.SharePoint.Publishing.Navigation.ProxySiteMapNode, Microsoft.SharePoint.Publishing]][])->
069e0934(Microsoft.SharePoint.Publishing.Navigation.ProxySiteMapNode)->
069e04a8(Microsoft.SharePoint.Navigation.SPNavigationNode)->
069bfe28(Microsoft.SharePoint.Navigation.SPNavigation)->
069bf7dc(Microsoft.SharePoint.SPWeb)->
02700dcc(Microsoft.SharePoint.SPSite)->
02701364(System.Collections.Generic.List`1[[Microsoft.SharePoint.SPWeb, Microsoft.SharePoint]])->

The MS disposed checker didn't find any issues too.

So now I don't know how to proceed further to find the (custom) component that causes the memory fragmentation. I hope that someone you could give me some hints, tool suggestion or check list of components that may cause the fragmentation (Antivirus, caching etc). The problem ossurs only in the prod environment and the only thing that we do now is iisreset - sometime 5 times a day…

Thank you in advance and best regards,

Anton

Anton
  • 41
  • 2

1 Answers1

0

Your crash logs might contain the faulting object but more likely the assembly that's executing is changing with every crash and seem random. They might just be the innocent bystander that got left holding the bag when all the memory was gone.

First - can't you configure the app pool to automatically recycle when a certain memory threshold is reached? This might help alleviate your need to constantly monitor and be ready for an IISRESET. Otherwise you might want to schedule regular recycles to keep the memory tidy for the time being.

Next, try to identify when the crashes began and check your deployment logs to see what was installed. (You DO keep logs of software package installs, right?)

Are the custom components developed in-house? You can punt some of the work initially by having the developers check all their projects which have been deployed with the SharePoint Dispose Checker Tool (is this what you were referring to at the end of your question?) Un-disposed SPWeb and SPSite objects seem to be the biggest cause of this fragmentation.

Another avenue to explore is this MSDN question I ran into while looking for something else. It appears the Navigation bar on a publishing page was to blame. There is a hotfix for that issue but you have to request it directly from Microsoft.

I've been developing for SharePoint for a long time but it's always been someone else's job to find these problems! These tidbits are what I've gleaned over time and hopefully something will be useful.

Erik Noren
  • 4,199
  • 1
  • 21
  • 29