SQL Server 2012 Memory
Posted by Karthick P.K on October 21, 2012
SQL Server 2012 has made many changes to the memory manager to govern the SQL Server memory consumption in efficient way compared with earlier versions. Important changes to SQL Server 2012 memory which every DBA should be aware of is documented in this blog. If you are not familiar with the SQL Server memory architecture of earlier versions I would recommend reading THIS ARTICLE before you continue with changes in Denali memory manager.
Max Server Memory
In previous versions of SQL Server “Max Server Memory” controlled the Maximum physical memory Single page allocator (BPOOL) can consume in SQL Server user address space.
Only the single page allocator was part of BPOOL and Max server memory controlled only BPOOL, so the following allocations came outside BPOOL (Max server memory)
1.Multi-Page allocations from SQL Server [These are allocations which request more > 8 KB and required contiguous memory]
2.CLR allocations [These include the SQL CLR heaps and its global allocations created during startup]
3.Memory used for thread stacks within SQL Server process (Max worker threads * thread stack size). Thread stack size is 512K in 32 bit SQL Server, 904 K in WOW mode and 2 MB in 64-Bit
4.Direct windows allocations made by Non-SQL Server dll’s ([These include windows heap usage and direct virtual allocations made by modules loaded into SQL Server process. Examples: allocations from extended stored procedure dll’s, objects created using OLE Automation procedures (sp_OA calls), allocations from linked server providers loaded in sqlserver process)
SQL Server 2012 memory manager has now clubbed single page allocator and multipage allocator together as any-size page allocator . As a result, the any-size page allocator now manages allocations categorized in the past as single page and Multi-Page allocations.
1. "max server memory" now controls and includes “Multi pages allocations”.
2. In earlier versions of SQL Server CLR allocated memory was outside BPOOL (Max server memory) . SQL Server 2012 includes SQL CLR allocated memory in "max server memory".
SQL Server 2012 "max server memory" configuration does not include only the following allocations:
1. Memory allocations for thread stacks within SQL Server process
2. Memory allocation requests made directly to Windows [Ex: Allocations (Heap,Virtualalloc calls ) from 3rd party Dll’s loaded in SQL Server process , objects created using OLE Automation procedures (sp_oa) etc]
These changes allow DBA’s to configure and control SQL Server more accurately in accordance with the memory requirements and using resource governor.
-g startup parameter
We used the -g startup option to change the default value of a region in SQL Server user address space known as "Memory-To-Reserve". This region was also known as "memory-to-leave or MTL. The "Memory-To-Reserve" (or) -g configuration option are relevant only for a 32-bit instance of SQL Server.
Multi pages allocation and CLR was part of Mem-to-reserve (-g) in In previous SQL Server versions until SQL Server 2008 R2 , From Denali they are part of BPOOL (Controlled by Max server memory) So you may have to remove –g if you have set it to give space for multipage allocator or CLR in earlier versions and migrating to Denali now.
AWE feature removed from SQL Server 2012
AWE feature was used in earlier versions of 32-Bit SQL Server to address more than 4GB of memory . This feature is now removed in Denali refer:"AWE deprecation". So if you need more memory then you may need to migrate to 64-Bit SQL server.
Locked pages in memory
Trace flag 845 is no more required to Lock Pages in memory. As long as the startup account of SQL Server has “Lock pages in memory” privilege Datacenter, Enterprise, standard and Business intelligence edition will use AWE allocator Api’s for memory allocations in BPOOL and this allocations will be locked.
Dynamic virtual address space management
In earlier versions of SQL Server 32-Bit we reserved Bpool at the startup and remaining addresses are left for MTL (Memory to reserve or Memory to leave) . In Denali virtual address space management is dynamic (we don’t reserve at startup) , So it is possible for 3rd part components to use more memory than what is configured in –g parameter.
SQLCLR loaded at startup
In earlier SQL Server versions, Common language runtime (CLR) functionality is initialized inside SQL Server process when the first SQL CLR procedure or function is invoked. SQL Server 2012 performs SQL CLR initialization at startup. The initialization is independent of the ‘clr enabled’ configuration option.
You will notice the following messages in the SQL Server error log during server startup:
2012-10-18 15:23:13.250 spid8s Starting up database ‘master’.
2012-10-18 15:23:13.930 Server CLR version v4.0.30319 loaded.
Total Physical memory and memory model used
Total physical memory available on the server and the memory model used is logged in SQL Server error log
2012-10-18 15:23:06.690 Server Detected 131067 MB of RAM. This is an informational message; no user action is required.
2012-10-18 15:23:06.700 Server Using locked pages in the memory manager
2012-10-22 15:32:20.450 Server Detected 131067 MB of RAM. This is an informational message; no user action is required.
2012-10-22 15:32:20.450 Server Using conventional memory in the memory manager.
DMV and Performance counter changes
In earlier version of SQL Server most of the DMV’s used single_pages_kb and multi_pages_kb to refer allocations by SQL Server with in BPOOL and outside BPOOL. Now they are represented together as pages_kb. More details in THIS link
The views expressed on this website/blog are mine alone and do not reflect the views of my company. All postings on this blog are provided “AS IS” with no warranties, and confers no rights.