Microsoft SQL Server IO Internals
Microsoft SQL Server IO Internals
by Bob Dorr, Microsoft SQL Server Principle Escalation Engineer, 1994 Present
Built: Jan 2008
Areas Covered
WAL Protocol
Synchronous vs
Asynchronous I/O
Overlapped
Event
Completion Port
SQL Server
and HasOverlappedIoCompleted
Network Layers Use Completion Port
dm_io_pending_io_request
s
Overlapped Structure
Async Processing ~=
CPU
Package vs Phone
Memory
Consolidates or Distributes
APIs
Scatter
Gather
Disk
ReadFileScatter
WriteFileGather
Increases Efficiency
Used by SQL I/O Paths
Used by Windows Page File
Old Design: 6.x Sorting
AWE Availability
WriteMultiple
# of 8K Pages
Forward and
Backward
Buffer Pool Ramp-up
Sector Alignment
Block Alignment
Alignment:
http://support.microsoft.com/kb/929491
To verify that an existing partition is aligned, divide the size of the stripe unit by
the starting offset of the RAID disk group. Use the following syntax: ((Partition
offset) * (Disk sector size)) / (Stripe unit size)
Example of alignment calculations in bytes for a 256-KB stripe unit size:
(63 * 512) / 262144 = 0.123046875
(64 * 512) / 262144 = 0.125
(128 * 512) / 262144 = 0.25
(256 * 512) / 262144 = 0.5
(512 * 512) / 262144 = 1
Double Touch
Rewrites
Defragment
4K Sectors
Latch
Memory (Data
Pages)
BUF
Array
BUF
Status
Latch
Database*
PageId
Hash *
User Mode
UMS/SQLOS Aware
Optimized FIFO Ordering
Flushed &
Rollback
Latch Timeout
Sub-latch
Reading A Page
0:000>
0:000> uf
uf ZwWriteFile
ZwWriteFile
mov
mov r10,rcx
r10,rcx
mov
mov eax,5
eax,5
Syscall
Syscall
Kernel
Kernel
Transition
Transition
ret
ret
kernel
kernel transition
transition Stuck
Stuck I/O?
I/O?
ntdll!ZwWriteFile+0xa
ntdll!ZwWriteFile+0xa
kernel32!WriteFile+0xf6
kernel32!WriteFile+0xf6
sqlservr!DiskWriteAsync+0xee
sqlservr!DiskWriteAsync+0xee
Page Audits
Read retry
Stalled I/O Warnings
Error raised at Acquire
Shared (SH) waiters
PAGE_IO* vs PAGE*
Latch
Writing A Page
dbTest.MDF
dbTest.NDF
Vol
#2
Create Database
Workers Assigned by Volume
ID
Work
er #4
dbTest.LDF
Work
er #5
Work
er #1
Serial Plan
select * from
dbTest.dbo.tblTest
Primary = dbTest.MDF
Secondary =
dbTest.NDF
Log = dbTest.LDF
Work
er #3
Work
er #2
Parallel Plan
select * from
dbTest.dbo.tblTest
Queue
I/O Targets
.LDF Usage Triggers
Alternate Triggers (Backup, Restore, )
Scatter/Gather Usage (WriteMultiple)
Checkpoint
Assignments
By Ordinal Sweep
Stalled I/O LW #0
I/O Queue Depth > 2
/PAE in Boot.ini
Boots Kernel with 36 bit addressing
Physical Memory > 4GB
Virtual Address Unchanged (/2gb or /3GB)
Automatic for Hot Add Memory Computers
Data Pages-Only
Locked Pages
Windows Paging
Windows 2000
Bugs
Read Ahead
Usage
Online DBCC
Snapshot Databases
Buffer Pool:
PrepareToDirty
File Control Block (FCB)
Chaining
Sparse Allocation
FCB Tracking
Windows Limits
New Page
Allocations
Advanced Protection
What is a Scribbler?
Data Page Audits
None
Torn Bits
Checksum
REFERENCES
Overview
Subsystems
Diagnostics
KB826433 Additional SQL Server Diagnostics Added to Detect Unrepo
rted I/O Problems
KB897284 SQL Server 2000 SP4 diagnostics help detect stalled and s
tuck I/O operations
(applies to SQL Server2005)
KB828339 Error message 823 may indicate hardware problems or sy
stem problems in SQL Server
KB167711 - Understanding Bufwait and Writelog
Timeout Messages
KB815436 Use Trace Flag 3505 to Control SQL Server Checkpoint Beh
avior
Certification Policy
KB913945Microsoft does not certify that third-par
ty products will work with Microsoft SQL
Server
KB841696 Overview of the Microsoft third-party st
orage software solutions support policy
Utilities
Download - SQLIOStress
utility to stress disk subsystem
(applies to SQL Server7.0, 2000, and
2005 - replaced with SQLIOSim and
SQL Server 2008 installed in BINN)
Blog Content
SQL Server Urban Legends Discussed
http://blogs.msdn.com/psssql/archive/2007/02/21/sql-server-urban-legends-discussed.aspx
How It Works: SQL Server Checkpoint (FlushCache) Outstanding I/O Target
http://blogs.msdn.com/psssql/archive/2008/04/11/how-it-works-sql-server-checkpoint-flushcache-outstanding-i-o-target.aspx
How It Works: SQL Server Page Allocations
http://blogs.msdn.com/psssql/archive/2008/04/08/how-it-works-sql-server-page-allocations.aspx
How It Works: Shapshot Database (Replica) Dirty Page Copy Behavior (NewPage)
http://blogs.msdn.com/psssql/archive/2008/03/24/how-it-works-shapshot-database-replica-dirty-page-copy-behavior-newpage.aspx
How It Works: SQL Server 2005 I/O Affinity and NUMA Don't Always Mix
http://blogs.msdn.com/psssql/archive/2008/03/18/how-it-works-sql-server-2005-i-o-affinity-and-numa-don-t-always-mix.aspx
How It Works: Debugging SQL Server Stalled or Stuck I/O Problems - Root Cause
http://blogs.msdn.com/psssql/archive/2008/03/03/how-it-works-debugging-sql-server-stalled-or-stuck-i-o-problems-root-cause.aspx
How It Works: SQL Server 2005 Database Snapshots (Replica)
http://blogs.msdn.com/psssql/archive/2008/02/07/how-it-works-sql-server-2005-database-snapshots-replica.aspx
How It Works: File Stream the Before and After Image of a File
http://blogs.msdn.com/psssql/archive/2008/01/15/how-it-works-file-stream-the-before-and-after-image-of-a-file.aspx
Using SQLIOSim to Diagnose SQL Server Reported Checksum (Error 824/823) Failures
http://blogs.msdn.com/psssql/archive/2008/12/19/using-sqliosim-to-diagnose-sql-server-reported-checksum-error-824-823-failures.a
spx
How to use the SQLIOSim utility to simulate SQL Server activity on a disk subsystem
http://support.microsoft.com/kb/231619
Should I run SQLIOSim? - An e-mail follow-up from SQL PASS 2008
http://blogs.msdn.com/psssql/archive/2008/11/24/should-i-run-sqliosim-an-e-mail-follow-up-from-sql-pass-2008.aspx
What do I need to know about SQL Server database engine I/O?
http://blogs.msdn.com/psssql/archive/2006/11/27/what-do-i-need-to-know-about-sql-server-database-engine-i-o.aspx
SQLIOSim is "NOT" an I/O Performance Tuning Tool
http://blogs.msdn.com/psssql/archive/2008/04/05/sqliosim-is-not-an-i-o-performance-tuning-tool.aspx
How It Works: SQLIOSim - Running Average, Target Duration, Discarded Buffers ...
http://blogs.msdn.com/psssql/archive/2008/11/12/how-it-works-sqliosim-running-average-target-duration-discarded-buffers.aspx
How It Works: SQLIOSim [Audit Users] and .INI Control File Sections with User Count Options
http://blogs.msdn.com/psssql/archive/2008/08/19/how-it-works-sqliosim-audit-users-and-ini-control-file-sections-with-user-count-opt
ions.aspx
The Gurus Guide to SQL Server Architecture and Internals ISBN 0201-70047-6
Written by Ken after he joined Microsoft SQL Server Support
Many chapters reviewed by developers and folks like myself