Hello everybody!
After upgrading from Microsoft SQL Server 2008 to Microsoft SQL Server 2012 we faced with CLR allocations problem. In earlier versions of SQL Server CLR allocations were in virtual address space (also known as "Memory-To-Leave").
In SQL Server 2008 you can configure max_server_memory for SQL server, prevent starting other processes on server and it will guaranty you that your CLR will not unload due memory pressure (use “lock pages in memory”)
In SQL Server 2012 there were big changes in memory management. The key change for us was relocating (or splitting) CLR allocations from "Memory-To-Leave" to "max server memory (MB)". And now you can get “AppDomain
2 (work5nt.dbo[runtime].1) is marked for unload due to memory pressure.” message in server log with future unloading AppDomain when “Query Execution Memory” grows fast.
During our stress tests of SQL server 2012 I had rapid growth of “Granted Workspace Memory (KB)” to more than 50% of max_server_memory (72GB). Top wait on server was RESOURCE_SEMAPHORE and «SQL Memory Manager:Memory Grants Pending»
growth up to 154 processes.
Information from log file about unloading:
2015-03-26 19:49:20.15 spid18s AppDomain 13 (work5nt.dbo[runtime].82) is marked for unload due to memory pressure.
2015-03-26 19:49:20.15 spid18s AppDomain 12 (mssqlsystemresource.dbo[runtime].81) is marked for unload due to memory pressure.
2015-03-26 19:49:20.15 spid19s AppDomain 13 (work5nt.dbo[runtime].82) unloaded.
2015-03-26 19:49:20.15 spid18s AppDomain 12 (mssqlsystemresource.dbo[runtime].81) unloaded.
2015-03-26 19:49:20.83 spid419 AppDomain 14 (work5nt.dbo[runtime].94) created.
2015-03-26 19:49:20.86 spid245 Unsafe assembly 'log, version=1.0.5498.27124, culture=neutral, publickeytoken=bb8adbf0186b255f, processorarchitecture=msil'
loaded into appdomain 14 (work5nt.dbo[runtime].94).
2015-03-26 19:49:20.86 spid419 Unsafe assembly 'seed, version=1.0.5539.32591, culture=neutral, publickeytoken=4d4e4ff7fd85d31c, processorarchitecture=msil'
loaded into appdomain 14 (work5nt.dbo[runtime].94).
2015-03-26 19:49:20.89 spid245 Unsafe assembly 'log, version=1.0.5498.27124, culture=neutral, publickeytoken=bb8adbf0186b255f, processorarchitecture=msil'
loaded into appdomain 14 (work5nt.dbo[runtime].94).
2015-03-26 19:49:20.91 spid419 Unsafe assembly 'seed, version=1.0.5539.32591, culture=neutral, publickeytoken=4d4e4ff7fd85d31c, processorarchitecture=msil'
loaded into appdomain 14 (work5nt.dbo[runtime].94).
Our product can get critical error after unloading CLR. (We are working on that problem but it’s not SQL server side problem.)
Main memory counters during stress test (perfmon):
Name | Average | Min | Max |
Total Server Memory (KB) | 75 783 960 | 75 774 432 | 75 880 536 |
ReservedServerMemory (KB) | 18 474 365 | 9 028 744 | 35 325 584 |
GrantedWorkspaceMemory (KB): | 27 173 700 | 16 992 392 | 51 791 136 |
Reserved/Granted Ratio | 0.68 | 0.53 | 0.68 |
So we can see, that highest Reserved Server Memory more than 46% of Total Server Memory! And it is strange.
At the end I have several questions:
Here the first one: How can I avoid unloading CLR due memory pressure on SQL server 2012?
Second one: Can I configure “Reserved Server Memory” for query or server?
And the last one: Is there any extended events to reveal which query consumed a lot of memory? I found sort_memory_grant_adjustment but it does not work or I can’t configure it right.
About my system:
Servers HP Proliant BL620c G7
Duble 3PAR StoreServ Storage 7200 with remote copy “on” and adaptive optimization “on”
Virtualization:ESXi 5.5.0, 2302651
Software:
Microsoft Windows 2008 Server R2 Enterprise 7601
Microsoft SQL Server 2012 - 11.0.5058.0 Enterprise Edition (64-bit) SP2
VM:
Xenon E7-2870 @2.40 GHz 16 cores (2 sockets, 8 cores), RAM 80GB.
SQL Server memory configure:
max server memory (MB) 74000
min memory per query (KB) 2048
minservermemory (MB) 128
sql server starts with -T 1222 -T 1224 -g 512,
Using locked pages in the memory manager,
Large Page Allocated: 32MB,
CLR version v4.0.30319
If you need more information please feel free to contact with me.