sql 2005 memory module

27
SQL Server 2005 Memory Management

Upload: fabricio-catae

Post on 21-Feb-2017

101 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: SQL 2005 Memory Module

SQL Server 2005Memory Management

Page 2: SQL 2005 Memory Module

Lesson 1

• Description– Operating System and SQL Server

• Learning Goals:– Physical Memory (RAM) – Virtual Address Space (VAS)– Interaction between SQL Server and

Operating System– Resource monitor

Page 3: SQL 2005 Memory Module

Windows Operating System

• Windows Memory Manager– Abstracts the concept of memory to the applications– Switches data from RAM to Paging File or vice-versa

• Trimming Memory

• Different Platform Versions– 32/64-bit Implementations

Page 4: SQL 2005 Memory Module

Windows Applications

• Process– Virtual Address Space– Threads– Other resources

• Virtual Address Space– 32-bit Native: 2-3GB– 64-bit Compatibility: 4GB– 64-bit Native: 16TB

Page 5: SQL 2005 Memory Module

SQL Server Process• Virtual Address Space

– SQL Engine– Buffer Pool

• SQL Engine– Executable (SQLSERVR.EXE)– Libraries (DLL)– Thread Structures

• Buffer Pool– Sized accordingly to RAM– Limited by VAS

SQLSERVR.EXE

Buffer Pool

SQL Engine

Page 6: SQL 2005 Memory Module

Resource Monitor• Low Memory Conditions

– Buffer Pool– Virtual Address Space– Windows Memory Manager

• Resource Monitor– Background Tasks– Monitor memory pressure– Log the status– Broadcast to other components

SQLSERVR.EXE

Buffer Pool

SQL Engine

Other

Other

Paging FileRAM

Windows Memory Manager

Page 7: SQL 2005 Memory Module

Notification Example<Record id="1701" type="RING_BUFFER_RESOURCE_MONITOR" time="149740267"> <ResourceMonitor> <Notification>RESOURCE_MEMPHYSICAL_LOW</Notification> <Indicators>2</Indicators> <NodeId>0</NodeId> </ResourceMonitor> <MemoryNode id="0"> <ReservedMemory>1646380</ReservedMemory> <CommittedMemory>432388</CommittedMemory> <SharedMemory>0</SharedMemory> <AWEMemory>0</AWEMemory> <SinglePagesMemory>26592</SinglePagesMemory> <MultiplePagesMemory>17128</MultiplePagesMemory> <CachedMemory>17624</CachedMemory> </MemoryNode> <MemoryRecord> <MemoryUtilization>50</MemoryUtilization> <TotalPhysicalMemory>3833132</TotalPhysicalMemory> <AvailablePhysicalMemory>3240228</AvailablePhysicalMemory> <TotalPageFile>5732340</TotalPageFile> <AvailablePageFile>5057100</AvailablePageFile> <TotalVirtualAddressSpace>2097024</TotalVirtualAddressSpace> <AvailableVirtualAddressSpace>336760</AvailableVirtualAddressSpace> <AvailableExtendedVirtualAddressSpace>0</AvailableExtendedVirtualAddressSpace> </MemoryRecord> </Record>

Notification

Memory Node

Operating System

SQL Server Process

Page 8: SQL 2005 Memory Module

Lesson 2• Description

– Buffer Pool and Database Caching– Memory Clerks Concepts

• Objectives– Check the performance related to Buffer Pool – Identify memory dedicated for database cache– Extend the database cache with AWE– Identify the memory usage by components– Find who is stealing memory from Buffer Pool

Page 9: SQL 2005 Memory Module

Database Caching

• Data Unit– Pages = 8Kb

• Accessing Data– Logical Reads– Physical Reads

- SQL Server:Buffer Manager – Page Lookups/sec- SQL Server:Buffer Manager – Page Reads/sec- SQL Server:Buffer Manager – Readahead Pages/sec- SQL Server:Buffer Manager – Page Life Expectancy

Disks

Buffer PoolMemory

PhysicalRead

LogicalRead

Page 10: SQL 2005 Memory Module

Buffer Pool Size• Configuration

– Minimum and Maximum Limits

• Static Memory Management– Define a fixed amount of memory

• Dynamic Memory Management– SQL Server dynamically adjust the amount of memory used

- SQL Server:Buffer Manager – Total Pages- SQL Server:Buffer Manager – Target Pages

Page 11: SQL 2005 Memory Module

Memory Distribution• Data Pages

– Cache Database Pages

• Stolen Pages– Internal SQL components

(eg, Optimizer)

• Free Pages

- SQL Server:Buffer Manager – Database Pages- SQL Server:Buffer Manager – Stolen Pages- SQL Server:Buffer Manager – Free Pages

STOLEN

FREE

DATA

Buffer P

ool

Page 12: SQL 2005 Memory Module

Buffer Pool Extension• AWE

– Going beyond VAS– Only used for Data

Cache

• Comparison– 3GB x AWE– Can I use both

together?

STOLEN

FREE

DATA

SQL Server

Operating System

2GB

8GB

Page 13: SQL 2005 Memory Module

Aging Buffers

• Two purposes: – Tries to keep a minimum number of free

buffers (freeing dirty buffers requires I/O)– Keeps enough physical memory free on the

machine to avoid paging• Sweeps across BUFs to “age” them• Many things that it can’t remove

Page 14: SQL 2005 Memory Module

Demo

• Who’s using my memory?

Page 15: SQL 2005 Memory Module

Internal SQL Server Allocations

ProcedureCache CLR

SQL Memory Node

MC MCMC MCMemory Clerks

Page 16: SQL 2005 Memory Module

Allocation Statistics

SQL Memory Node

MC MCMC

Single Page AllocatorMulti Page AllocatorVirtual Memory InterfaceShared Memory Interface

CACHESTORE_OBJCP

CACHESTORE_SQLCP

CACHESTORE_PHDR

ProcedureCache

Page 17: SQL 2005 Memory Module

Memory Allocation

SQL Memory Node

Single Page Allocator

Multi Page AllocatorVirtual Memory InterfaceShared Memory Interface

SQLSERVR.EXE

Buffer Pool

SQL Engine

Page 18: SQL 2005 Memory Module

Demo

• Who’s stolen my memory?• CLR consuming memory• SQL Plans growing

Page 19: SQL 2005 Memory Module

ENDThe following slides have ideas for

the next workshop update

Page 20: SQL 2005 Memory Module

Lesson 3

• Description– Memory Clerks Concepts

• Objectives– Understand the concept of Memory Clerks– Identify the memory usage by components– Find who is stealing memory from Buffer Pool

Page 21: SQL 2005 Memory Module

Memory Clerk

• Allocates the memory as needed• React differently to Memory Pressure• Sys.dm_os_memory_clerks

MEMORYCLERKResource Monitor

Page 22: SQL 2005 Memory Module

Controlling Memory Usage

• Specifics Types – Custom Memory Clerk– Cache and User Store– Object Store

CUSTOMMEMORY

CLERK

CACHESTORE

USERSTORE

OBJECTSTORE

Page 23: SQL 2005 Memory Module

Custom Memory Clerk

• Each Memory Clerk implements the action to the notification

• Examples– General– CLR– Full Text

Page 24: SQL 2005 Memory Module

Object Store

• Free half of the entries• sys.dm_os_memory_pools

Page 25: SQL 2005 Memory Module

Cache and User Store

• Remove the cheapest items • Use Clock hands algorithm• sys.dm_os_memory_cache_counters

Page 26: SQL 2005 Memory Module

Clock Hand

• External– Resource Monitor

• Internal– Internal Limits / Boundaries (INTERNAL)

• sys.dm_os_memory_cache_clock_hand

Page 27: SQL 2005 Memory Module

Memory Broker