Professional Documents
Culture Documents
Singapore WindowsKernelOverview
Singapore WindowsKernelOverview
Overview
9 October 2006
Singapore
Security refmon I/O Manager Memory Manger Procs & threads Win32 GUI
Drivers
• Kernel extensions (devices, file systems, network)
L“Global??” L“C:”
<symbolic link>
\Device\HarddiskVolume1
L“\” \Device\HarddiskVolume1
Access checks
Name lookup
Object
Kernel Manager
Returns ref’d ptr
Code
Kernel
Data Object
Ref’d ptr used until deref
user kernel
Mapping
handle mechanism
Data
structure
Thread
Files Virtual
Process’ Thread
Address
Events Handle Table
Descriptors Thread
Devices
Memory Thread
Drivers Manager
read(handle) Structures Thread
user-mode execution
v3 © Microsoft Corporation 2006 21
Handle Table
– NT handles allow user code to reference
kernel data structures (similar, but more
general than UNIX file descriptors)
– NT APIs use explicit handles to refer to
objects (simplifying cross-process operations)
– Handles can be used for synchronization,
including WaitMultiple
– Implementation is highly scalable
File Sys
File System Fills in File object
OBJECT BODY
[with optional DISPATCHER_HEADER]
SignalState
WaitListHead.flink
WaitListHead.blink
Private Unused
Process
Space
Virtual Allocations
Heaps
0x0000FFFF
v3 © Microsoft Corporation 2006 34
0x00000000 No access region
Process/Thread structure
Any Handle Object Process
Table Manager Object
Thread
Thread
Files Virtual
Process’ Thread
Address
Events Handle Table
Descriptors Thread
Devices
Memory Thread
Drivers Manager
Structures Thread
Control Area
Section
Object
Handle Page
Directory Proto
PTEs
Shared
Cache Map Subsection
Subsection
VAD
Cache
Access,
Page Noncached
Flush, Fault IO
Purge
PD PT page DATA
CR3
GetPteAddress:
0xe4321000
PD PT => 0xc0390c84
0x300 0x321
0x390 PTE
Modified
Standby Modified
Page-
List List
writer
MM Low
Memory Physical Page State
Changes
Hardfault Zerofault
(DISK) (FILL)
executable
Image
c-o-w
Standby List
Free List
Data
SQL db
Modified List
File
Application Phys
Data
datafile
File
Data
pagefile
Data Modified
Page Writer
v3 © Microsoft Corporation 2006 53
CPU
Processes versus Threads
Lighterweight multi-threading
CPU scheduling
CPU mechanisms:
APCs, ISRs/DPCs, system worker threads
Thread
Files Virtual
Process’ Thread
Address
Events Handle Table
Descriptors Thread
Devices
Thread
Drivers
Thread
ready block
IPC callee
v3 © Microsoft Corporation 2006 59
Scheduling
Windows schedules threads, not processes
Scheduling is preemptive, priority-based, and round-robin at the
highest-priority
16 real-time priorities above 16 normal priorities
Scheduler tries to keep a thread on its ideal processor/node to
avoid perf degradation of cache/NUMA-memory
Threads can specify affinity mask to run only on certain processors
Each thread has a current & base priority
Base priority initialized from process
Non-realtime threads have priority boost/decay from base
Boosts for GUI foreground, waking for event
Priority decays, particularly if thread is CPU bound (running at
quantum end)
Scheduler is state-driven by timer, setting thread priority,
thread block/exit, etc
Priority inversions can lead to starvation
balance manager periodically boosts non-running runnable threads
v3 © Microsoft Corporation 2006 60
ed
pp
a
Sw
Ready
Scheduler
Blocked
Running
Object Pointer R
Object: RefCnt: R + 1 + N
Object Pointer 3
Reference Dereference
Object Pointer 2
IopParseDevice IoCallDriver
complete
I/O I/O I/O I/O I/O I/O
K K
complete
complete
complete
U U
request
request
request
request
request
request
thread
thread
thread
thread
thread
thread
thread
thread
normal completion I/O completion ports
Kernel32 / ntdll
user
kernel
NT I/O Manager