0% found this document useful (0 votes)
294 views

(DBA-403-M) DBA-403 SQLOS Memory Manager Changes in SQL Server 2012

The document discusses changes to the SQL Server memory manager between SQL Server 2012 and 2008 R2. Key changes include a new memory manager architecture that supports variable page sizes and workspaces to improve scalability. The max server memory configuration option now more accurately limits memory usage. Memory exposures in performance counters and DMVs have been consolidated and standardized to provide memory usage information in a consistent format.

Uploaded by

ebtrain
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
294 views

(DBA-403-M) DBA-403 SQLOS Memory Manager Changes in SQL Server 2012

The document discusses changes to the SQL Server memory manager between SQL Server 2012 and 2008 R2. Key changes include a new memory manager architecture that supports variable page sizes and workspaces to improve scalability. The max server memory configuration option now more accurately limits memory usage. Memory exposures in performance counters and DMVs have been consolidated and standardized to provide memory usage information in a consistent format.

Uploaded by

ebtrain
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

SQLOS Memory Manager

Changes in SQL Server 2012, DBA403


Gus Apostol Principal Program Manager Microsoft SQL Server Jerome Halmans Senior Software Design Engineer Lead Microsoft SQL Server

November 6-9, Seattle, WA

What Happens?

NeedSQL a way Server to predictably likes memory! size memory!

Terms and Concepts


Physical Memory
Refers to Random Access Memory (RAM)

Virtual Address Space (VAS)



A contiguous region of memory addresses Every process has its own which provides isolation Up to 4GB on 32 bit and 8TB on 64 bit, can become fragmented A region has to be reserved and then committed before using
Conventional: Normal physical page size (8KB), page-able, dynamic Locked Pages: Normal physical page size, non-page-able, dynamic Large Pages: Large physical page size (>=2MB), non-page-able, static Page size is 8KB, and allocated through Single Page Allocation/Allocator Contiguous allocation of >8KB is called Multi-Page Allocation

Commitment is backing reserved regions of VAS with physical memory

In SQL Server a page is a fully committed VAS region


Direct Windows Allocations uses VirtualAlloc() and HeapAlloc() calls

Processor Architectures
Symmetric Multi Processing (SMP)
Memory

CPU 0

CPU 1

CPU 2

CPU 3

CPU 4

CPU 5

CPU 6

CPU 7

Non Uniform Memory Access (NUMA)


NUMA NODE 0 NUMA NODE 1

CPU 0

CPU 2

CPU 4

CPU 6

CPU 1
Local Memory Access

CPU 3
Memory

Foreign Memory Access n x local

CPU 5
Memory

CPU 7

SQL Operating System (SQLOS)


What is it?
Granular user mode OS enrichment layer specifically designed and highly optimized for SQL workloads (OLTP & DW) Services provided: scheduling and synchronization support, memory management & caching, resource governance, Diagnostics & debug infrastructure, hosting support, scalability & performance optimization (example >64logical processor support, hot add CPU/memory) Currently the SQLOS is used by SQL Server relational database engine and Reporting Services for system level services Platforms include 32bit, 64bit (Itanium support ends in SQL 2008 R2), SMP, NUMA All SKUs supported except Compact Edition An OS Abstraction layer, i.e. does not wrap OS APIs (like .NET)

What it is not?

SQLOS System Architecture View


Protocols Query Comp. and Execution Engines
SQLOS API
Lazy Writer Scheduler Monitor
= thread

Storage Engine
SQLOS API

Buffer Pool

External Components

Hosting API

Deadlock Monitor Resource Monitor

SQLOS
Scheduling XEvents Memory Manager

Synchronization

I/O

Why change the Memory Manager


Difficult to accurately size and govern SQL Server memory consumption
sp_configure max server memory does not limit all memory committed by SQL Server Resource Governor only governs part of SQL memory consumption single page allocations Must leave enough memory for multi-page allocations which can be troublesome for consolidation scenarios

Complex queries and plans that allocate more than 8KB of memory have poor scalability & performance
Does not support different memory models (locked, large pages) No caching for larger allocations greater than 64KB

Out-of-memory handling is inconsistent across different internal components

Memory Manager Architecture


SQL Server 2008 R2
Page Reservation

SQL Server 2012


Page Reservation

Memory Objects

CLR

Buffer Pool

Memory Objects

CLR

Single-page Allocator

Memory Manager

Any size page Allocator

VAS Allocator

Buffer Pool

Multi-page Allocator

VAS Allocator

Memory Manager

-g MemToReserve

-g MemToReserve

Memory Manager Architecture


SQL Server 2008 R2
Page Reservation

SQL Server 2012


Page Reservation

Memory Objects

CLR

Buffer Pool

Memory Objects

CLR

Single-page Allocator

Memory Manager

Any size page Allocator

VAS Allocator

Buffer Pool

Multi-page Allocator

VAS Allocator

Memory Manager

-g MemToReserve

-g MemToReserve

New Memory Manager Overview


VAS Management
Fragment Manager Fragment: large reserved region of VAS.

Top level committed blocks

Top Level Block Allocator

Top Level Block: Blocks of VAS allocated directly from fragments. All top level blocks have the same size and partitioned by NUMA Workspace: A set of top level blocks. The allocations from a workspace will have similar lifetime..

Hierarchies of fixed size allocators

Workspace 1

Workspace 2

Example of Workspace Hierarchy


16MB

4MB
128KB 512KB

8KB

16KB

32KB

64KB

Example of Workspace Hierarchy


16MB

4MB
128KB 512KB

Workspace hierarchy Tuned for typical SQL Server workloads Allows fast allocation of memory needed for SQL Server workloads

8KB

16KB

32KB

64KB

Surface Area Configuration Changes


sp_configure max server memory

OS
CLR, MPA, DWA, TS
max server memory

OS
DWA, TS

max server memory

Buffer Pool (SPA)

All size page allocations + CLR

Surface Area Configuration Changes


SQL Server 2008 R2
sp_configure option min server memory max server memory Default setting 0 2147483647 (available memory in the system) Min Value 16 (MB) 16 (MB) Max Value Value less than max server memory setting 2147483647 (available memory in the system)

SQL Server 2012


sp_configure option min server memory max server memory Default setting 0 2147483647 (available memory in the system) Min Value 16 (MB) 32 bit - 64 (MB) 64 bit 128 (MB) Max Value Value less than max server memory setting 2147483647 (available memory in the system)

Startup option f (minimal configuration) behavior unchanged

Demo
Sizing SQL Server memory usage in SQL Server 2008 and SQL Server 2012

November 6-9, Seattle, WA

Surface Area Configuration Changes


Configuration Option: sp_configure awe_enabled SQL Server 2008 R2
Latest release to support awe_enabled option, no effect for 64bit No support for >4GB or Hot Add Memory in 32bit architectures Exists in 32bit for use of Locked pages (not needed for 64bit) AWE exposure in 32bit no longer valid (DMVs/PerfMon) 64bit usage of AWE for Locked Pages unchanged Windows Server 2008 R2 is only 64bit, dwindling new 32bit SQL Server deployments on large machines, and most commodity hardware is now 64bit

SQL Server 2012

Main reasons behind AWE deprecation

Surface Area Configuration Changes


Startup Option: g memory_to_reserve (32bit) SQL Server 2008 R2
Specifies amount of VAS SQL Server would leave for memory allocations in process made outside of the Buffer Pool Direct Window Allocations >8K, CLR, and thread stacks Default value is 256MB and relevant only for 32bit systems where VAS is limited

SQL Server 2012


Specifies the amount of VAS SQL Server would leave for memory allocations in process made outside of Memory Manager Direct Windows Allocations & thread stacks Memory Manager now manages >8K and CLR allocations Default value is 256MB and relevant only for 32bit systems where VAS is limited

Surface Area Changes - Exposures


Consolidation of single and multipage allocator data Standardize unit of memory reported (KB) where possible
sys.dm_os_memory_nodes SQL Server 2012 pages_kb foreign_committed_kb SQL Server 2008 R2 single_pages_kb + multi_pages_kb -

sys.dm_os_sys_info SQL Server 2012 physical_memory_kb virtual_memory_kb committed_kb committed_target_kb visible_target_kb SQL Server 2008 R2 physical_memory_in_bytes virtual_memory_in_bytes bpool_committed bpool_commit_target bpool_visible

Surface Area Changes - Exposures


sys.dm_os_memory_cache_counters SQL Server 2012 pages_kb pages_in_use_kb sys.dm_os_memory_cache_entries SQL Server 2012 pages_kb sys.dm_os_memory_clerks SQL Server 2012 pages_kb page_size_in_bytes sys.dm_os_memory_objects SQL Server 2012 pages_in_bytes max_pages_in_bytes SQL Server 2008 R2 pages_allocated_count max_pages_allocated_count SQL Server 2008 R2 single_pages_kb + multi_pages_kb page_size_bytes SQL Server 2008 R2 pages_allocated_count SQL Server 2008 R2 single_pages_kb + multi_pages_kb single_pages_in_use_kb + multi_pages_in_use_kb

Surface Area Changes - Exposures


SQL Server 2012 Memory Manager \ Large Pages Allocated Memory Manager \ Emergency Memory Memory Manager \ Emergency Memory In Use Memory Manager \ Target Committed (KB) Memory Manager \ Current Committed (KB) Memory Manager \ Pages Allocated (KB) Memory Manager \ Pages Reserved (KB) Memory Manager \ Pages Free (KB) Memory Manager \ Pages In Use Memory Manager \ Page Alloc Potential (KB) Memory Manager \ NUMA Growth Phase Memory Manager \ Last OOM Factor Memory Manager \ Last OS Error SQL Server 2008 R2 Memory Manager \ Reserved Memory Memory Manager \ Reserved Memory In Use Buffer Pool \ Target (Pages) Buffer Pool \ Committed (Pages) Buffer Pool \ Stolen (Pages) + Buffer Pool \ Database (Pages) Buffer Pool \ Reserved (Pages) Buffer Pool \ Free (Pages) Buffer Pool \ Stolen Potential (Pages) Buffer Pool \ Last OOM Factor -

Surface Area Changes - Exposures


SQL Server 2012 Memory node Id = n \ Pages Allocated Memory node Id = n \ Target Committed Memory node Id = n \ Current Committed Memory node Id = n \ Foreign Committed Memory node Id = n \ Away Committed Memory Clerks \ Pages Allocated SQL Server 2008 R2 Memory node Id = n \ MultiPage Allocator + Memory node Id = n \ SinglePage Allocator Memory Clerks \ SinglePage Allocator + Memory Clerks \ MultiPage Allocator

Surface Area Changes - Exposures


SQL Server 2012 Object - SQLServer:Memory Manager Database Cache Memory (KB) Free Memory (KB) Reserved Server Memory (KB) Stolen Server Memory (KB) Target Server Memory (KB) Total Server Memory (KB) SQL Server 2008 R2 Object - SQLServer:Buffer Manager Database pages Free pages Reserved pages Stolen pages Target pages Total pages AWE lookup maps / sec AWE stolen maps / sec AWE write maps / sec AWE unmap calls / sec AWE unmap pages / sec

Surface Area Changes - Exposures


SQL Server 2012 Object - SQLServer:Memory Node Database Node Memory (KB) Free Node Memory (KB) Foreign Node Memory (KB) Stolen Node Memory (KB) Target Node Memory (KB) Total Node Memory (KB) SQL Server 2008 R2 Object - SQLServer:Buffer Node Database pages Free pages Foreign pages Stolen pages Target pages Total pages

Surface Area Changes - Exposures


Total Physical memory and the memory model SQL Server is configured to use (conventional, locked, large)

Demo
Troubleshooting Memory Errors in SQL Server 2008 R2 and SQL Server 2012

November 6-9, Seattle, WA

What else changed? Or didnt


CPU affinity configuration works as before Continue to use the DDL ALTER SERVER CONFIGURATION SET PROCESS AFFINITY
No changes in Resource Governor behavior except that it now controls all page allocations VAS commitment for CLR now classified and charged against the internal memory pool Database cache pages are still not governed by Resource Governor

New Memory Manager Benefits


Predictable sizing and governing of memory consumption
max server memory limits all memory committed by SQL Server Resource Governor governs all SQL memory consumption

Improved performance & scalability of complex queries and operations making greater than 8KB allocations
Improved CPU and NUMA locality for memory accesses

Advantage of a single Memory Manager that services all size page allocations requests
Consistent out-of-memory handling & management across different internal components

Sizing the Memory Manager


Setting max server memory
Can be set on a dedicated server, but not necessary Must leave enough memory for OS and SQL Server worker thread stacks (~2MB/thread on x64) For multi-instance and virtual environments Set when using Large Pages memory model To guarantee a necessary amount of memory To make the memory model static

Setting min server memory

Locked Pages for stability should not be necessary on deployments using Windows Server 2008 and beyond

Multi-Instance Consolidation Scenarios


Run workloads, observe characteristics and understand the baseline set of requirements for an instance Determine the processor and memory requirements for each instance Isolate the processors and memory for each instance
ALTER SERVER CONFIGURATION SET PROCESS AFFINITY Do not set affinity from Task Manager Keep instances within node boundaries Always set max server memory when using affinity Avoid using more memory than available in nodes Better to change configuration with idle server

Multi-Instance Consolidation Example


Machine: 12 LPs - 48 GB RAM Node 0 (16GB) Node 1 (16GB) Node 2 (16GB)

LPs: 8 Memory: 32GB LP = Logical Processor: Computing engine in the OS, application and driver view

LPs: 2
Mem: 12GB

LPs: 2
Mem: 4GB

References
Locked pages KB918483 CPU affinity Books Online Topic AWE deprecation announce in SQL 2008 R2 Performance Troubleshooting whitepaper SQL Consolidation prescriptive guidance

Thank you
for attending this session and the 2012 PASS Summit in Seattle

[Session Code]

November 6-9, Seattle, WA

You might also like