SQL Server Memory Architecture Sumit Sarabhai Microsoft Corp.

Slides:



Advertisements
Similar presentations
Advanced Troubleshooting with Debug Diagnostics on IIS 6
Advertisements

Paging: Design Issues. Readings r Silbershatz et al: ,
OS Components and Structure
More on File Management
Part IV: Memory Management
The Linux Kernel: Memory Management
Memory management.
Windows Kernel Internals User-mode Heap Manager
File Systems.
© Neeraj Suri EU-NSF ICT March 2006 Budapesti Műszaki és Gazdaságtudományi Egyetem Méréstechnika és Információs Rendszerek Tanszék Zoltán Micskei
Mobile Handset Memory Management
CE6105 Linux 作業系統 Linux Operating System 許 富 皓. Chapter 2 Memory Addressing.
Memory Management 1 CS502 Spring 2006 Memory Management CS-502 Spring 2006.
CS-3013 & CS-502, Summer 2006 Memory Management1 CS-3013 & CS-502 Summer 2006.
MEMORY MANAGEMENT By KUNAL KADAKIA RISHIT SHAH. Memory Memory is a large array of words or bytes, each with its own address. It is a repository of quickly.
Basics of Operating Systems March 4, 2001 Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard.
 Demand Technology Software, Inc. 32-bit Virtual Memory Constraints in Windows 2000 and 2003 Mark Friedman Demand Technology 1020 Eighth Avenue South,
SQL Server memory architecture and debugging memory Issues
 Demand Technology Software, Inc. Memory Leaks Demand Technology 1020 Eighth Avenue South, Suite 6, Naples, FL phone: (941) fax: (941)
Oracle Memory Configuration on Windows Server Configuring Large Memory for Oracle on 32-bit and 64-bit Windows.
© 2011 IBM Corporation 11 April 2011 IDS Architecture.
Module 8: Server Management. Overview Server-level and instance-level resources such as memory and processes Database-level resources such as logical.
Windows 2000 Memory Management Computing Department, Lancaster University, UK.
Real-Time Concepts for Embedded Systems Author: Qing Li with Caroline Yao ISBN: CMPBooks.
Chapter 8 Windows Outline Programming Windows 2000 System structure Processes and threads in Windows 2000 Memory management The Windows 2000 file.
 Demand Technology Software, Inc. 32-bit Virtual Memory Constraints in Windows: an Update Mark Friedman Demand Technology 1020 Eighth Avenue South,
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Database Performance Tuning and Query Optimization.
Key Perf considerations & bottlenecks Windows Azure VM characteristics Monitoring TroubleshootingBest practices.
Win32 Programming Lesson 16: Virtual Memory. Where are we?  We’ve covered the theory of Windows memory, and poked around some  Now let’s use how to.
8.4 paging Paging is a memory-management scheme that permits the physical address space of a process to be non-contiguous. The basic method for implementation.
Chapter 3.5 Memory and I/O Systems. 2 Memory Management Memory problems are one of the leading causes of bugs in programs (60-80%) MUCH worse in languages.
Lecture Topics: 11/17 Page tables TLBs Virtual memory flat page tables
Windows Memory Architecture 井民全製作. A Process ’ s Virtual Address Space Every Process has its own private virtual address 32-bits processes  4 GB address.
1 Linux Operating System 許 富 皓. 2 Memory Addressing.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 12: File System Implementation File System Structure File System Implementation.
Win32 Programming Lesson 14: Introducing Windows Memory (C Rox…)
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Virtual Memory Hardware.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition File System Implementation.
Review °Apply Principle of Locality Recursively °Manage memory to disk? Treat as cache Included protection as bonus, now critical Use Page Table of mappings.
Troubleshooting SQL Server Performance: Tips &Tools Amit Khandelwal.
TOP 10 Thinks you shouldn’t do with/in your database
COMP091 – Operating Systems 1 Memory Management. Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address.
3 Copyright © 2004, Oracle. All rights reserved. Database Architecture Comparison.
Get the Most out of SQL Server Standard Edition Or How to be a SQL Miser.
A deep dive into SQL Server Plan Cache Management.
CMSC 611: Advanced Computer Architecture
FileSystems.
143A: Principles of Operating Systems Lecture 6: Address translation (Paging) Anton Burtsev October, 2017.
Chapter 8: Main Memory.
Configuring SQL Server
Lecture 14 Virtual Memory and the Alpha Memory Hierarchy
CS399 New Beginnings Jonathan Walpole.
Turbo-Charged Transaction Logs
Microsoft Virtual Academy
Configuring SQL Server
Virtual Memory Hardware
Oracle Memory Configuration on Windows Server
CSE 451: Operating Systems Autumn 2005 Memory Management
Transaction Log Internals and Performance David M Maxwell
CSE451 Virtual Memory Paging Autumn 2002
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
OS Components and Structure
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
Paging and Segmentation
Buddy Allocation CS 161: Lecture 5 2/11/19.
COMP755 Advanced Operating Systems
Inside the Database Engine
Chapter 8 & 9 Main Memory and Virtual Memory
Inside the Database Engine
Inside the Database Engine
Presentation transcript:

SQL Server Memory Architecture Sumit Sarabhai Microsoft Corp.

C:/>whoami 9+ years in MSFT SQL vNext Complex Problems Product Group Engagement SQL vNext Complex Problems Product Group Engagement Speaker in UG Meets, SQL Talks and SSGAS conference Speaker in UG Meets, SQL Talks and SSGAS conference Expert in SQL Engine Currently learning Azure viz.HDInsight, SQL Azure, NoSQL and BI Expert in SQL Engine Currently learning Azure viz.HDInsight, SQL Azure, NoSQL and BI Customer Obsession

Agenda Virtual Memory Virtual Address Space SQL Server OS Architecture Changes in SQL 2012 Architecture Some Troubleshooting – if time permits!

Memory Allocations Virtual Memory Virtual memory is best used for managing large arrays or collections of objects or structures of varying sizes. It is the primary mechanism by which SQL Server allocates memory. Heap A heap is a memory region consisting of one or more pages of reserved space that can be suballocated into smaller pieces by the heap manager. Heaps are most useful for allocating large numbers of similarly sized, relatively small objects and structures

Difference between 32 bit and 64 bit

32 (x86) vs 64 (x64) null 64Gb User 2Gb Kernel 2Gb User 2-3Gb Kernel 1-2Gb 4Gb PAE increase userva (/3gB) AWE null 16EB User 2Gb-8TB Kernel 8TB …and (alot) of room to grow user (…someday) Kernel 8TB …and (alot) of room to grow user (…someday) 2TB Physical Memory Limit BCDEdit. exe User 4Gb WoW Address Windowing Extensions

Trivia What is committed memory? What is Working set? What is private bytes? What is Total Server Memory and Target Server Memory?

SQL Server 32 bit Bpool and MTL //(By default 256 MB and can be controlled by -g) Stack size =512 KB per thread for 32 Bit SQL Server MTL= (256 *512 KB) + 256MB =384MB MTL = (Stack size * max worker threads) + Additional space BPool = Min (Physical memory, (User address space – MTL)) – BUF structures

Start Your 32bit BPool Engines 16Gb RAM User Mode Address space Bpool Reserves ~2Gb- Bpool Reserves ~2Gb- MemToLeave Kernel 2Gb Kernel 2Gb 4Gb Address Space Limit Bpool Committed Memory If AWE enabled, Bpool can allocate here Bpool Committed Memory 16Gb RAM with /3Gb User Mode Address space Bpool Reserves ~3Gb- Bpool Reserves ~3Gb- MemToLeave Kernel 1Gb Kernel 1Gb Bpool Committed Memory Stack size * “max worker threads” + -g startup parameter Stack size * “max worker threads” + -g startup parameter 256 <=4 procs Add 8 for every proc after <=4 procs Add 8 for every proc after 4 Default of 256Mb Capped at 50% of VAS A bigger MemToLeave A bigger MemToLeave WoW gives you all 4Gb BPool does not commit its target memory at startup

64 bit SQL Server SQL Server calculates the size of RAM during the startup and reserve it, minimum of (reserved space, “Max server memory”) is used as Bpool. Remaining all is Non BPOOL Memory Models: Conventional Locked Large

Memory Models VirtualAlloc API Typically used to allocate large chunks of memory You manage it With NUMA, local memory is attempted first AWE API Created to extend memory for 32bit but works on 64bit Not part of your working set (not pageable by OS or “locked”) Requires “Locked Pages in Memory” privilege NUMA API specific support Large Pages Use VirtualAlloc with MEM_LARGE_PAGES Typically in 2Mb or greater sizes Allocation is slowwwwww Requires “Locked Pages in Memory” privilege 11 Use a heap if you want OS to manage it

Memory Fundamentals Memory Node Memory Allocators Memory Clerks Memory Objects

Here Come the Clerks Track Usage by Component Interface for allocators System to Respond to Pressure Caching Infrastructure Brokerage System for Large Users Generic Buffer Pool (BPool) CLROptimizerXEvent Cache Store Proc Cache System Rowset User Store Token Perm Metadata Pool Locks SNI Network Packets OBJECTSTORE Simple cache of like equal objects We don’t use SOS cache or store framework We have hash tables and clocks for pressure Similar to cache store without hash tables

SQL Server Memory Model Memory Clerk Memory Object Memory Node Memory Allocators Cache Store User Store Memory Pool Generic I’m a heap I understand NUMA Shared Memory Virtual Page I know Windows APIs I provide pages I need memory Single, Multi, Large Brought to you by SQLOS Windows API

How do I Really Get Memory? Buffer Pool Buffer Pool Memory Node Memory Allocators Single Page Allocator I know Window s APIs Memory Object Memory Clerk Multi Page Allocator Multi Page Allocator Virtual Allocator Virtual Allocator VirtualAlloc and AWE APIs VirtualAlloc and AWE APIs Backup Buffers Backup Buffers Plan Cache Database Page Cache Why am I both a clerk and an allocator? Because I’m good at managing a cache of 8Kb pages Most SQL memory comes from the Buffer Pool But I also need to respond to external pressure Optimizer I cache memory I use and release

SQLOS 2012 Memory Management 16 SQLOS doesn’t know anything about the Buffer Pool and database pages. Buffer Pool Memory Clerk Buffer Pool Memory Clerk Memory Node Memory Allocators Memory Object Memory Clerk VirtualAlloc and AWE APIs VirtualAlloc and AWE APIs Backup Buffers Backup Buffers Plan Cache Database Page Cache Optimizer Workspaces Virtual Allocator Fragment Manager Block Allocator There is no single vs multi-page concept

What about the 64bit BPool? No MemToLeave issues No initial big reservation of VAS When using AWE, map as you commit when growing visible always equals target Differences from 32bit Memory allocated with AWE not part of working set so cannot be trimmed If Lock Pages in Memory/EE SKU, then most BPool commits use AWE Private Bytes does not show memory allocated with AWE APIs Not all SQL memory is locked (thread stacks, Multi-page and Virtual allocators The AWE/”Lock Pages” mystery Poorly designed DLLs may get more memory because not VAS limited VAS errors could be now virtual memory error or slow perf due to paging Any effects of this design? 17 BPool does not commit its target memory at startup But it may look that way after startup due to initial growth Large Pages Exception

Remain Calm…There is a Memory Pressure Alert 18 Resource Monitor Task Resource Monitor Task Low Physical Memory Low Physical Memory User and Object Stores Cache Stores Buffer Pool CLR Clerk Recalc target, We could shrink BPool Garbage Collection Garbage Collection External Clock hand moves, entries may be removed External Clock hand moves, up to store to remove entry CPU Node Clerk End idle worker threads Low VAS We can’t reserve 4Mb Use Windows Memory Notification APIs sys.dm_os_ring_buffers We also recognize working set trim External Pressure sys.dm_os_proccess_memory sys.dm_os_memory_cache_clock_hands

Internal Pressure: Keeping Ourselves Trim 19 Memory Brokers User Stores Cache Stores Internal Clock hand moves, entries may be removed Internal Clock hand moves, up to store to remove entry Buffer Pool Target Change ‘max server memory’ change Near fixed limit Procedure Cache Stores Procedure Cache Stores Optimizer Memory Query Execution Memory MEMORYBROKER_F OR_CACHE Move internal clock hand which may result in removal of proc cache objects MEMORYBROKER_F OR_CACHE Move internal clock hand which may result in removal of proc cache objects MEMORYBROKER_F OR_STEAL Gateways modified. Compiles may wait MEMORYBROKER_F OR_STEAL Gateways modified. Compiles may wait MEMORYBROKER_FO R_RESERVE Thresholds lowered. Sorts/hashes may wait MEMORYBROKER_FO R_RESERVE Thresholds lowered. Sorts/hashes may wait sys.dm_os_memory_cache_clock_hands sys.dm_os_memory_brokers LazyWrites We won’t go below ‘min server memory’

Knowledge Check SQL Server is leaking memory. SQL is Culprit AWE is not used on 64bit SQL Server never allocates > ‘max server memory’ PAE required for SQL 32bit to use AWE on 64bit Windows SQL Server allocates all of its memory at startup ‘Lock pages’ guarantees nothing for SQL is trimmed My application will run faster when I go from 32 to 64bit No one truly understands all of this stuff Just because private bytes increases doesn’t mean we are leaking FALSE Only Large Pages FALSE This may be true

Thank you for attending Tech Unite