Cache Manager

Download Report

Transcript Cache Manager

Lecture 14 Cache Manager
xlanchen@05/27/2005
计算机系•信息处理实验室
Cache Manager
Key Features of the Windows 2000 Cache
Manager
Cache Structure
Cache Size
Cache Data Structures
Cache Operation
Cache Support Routines
xlanchen@05/27/2005
Understanding the Inside of
Windows2000
计算机系 2
信息处理实验室
Cache Manager
A set of kernel-mode functions and system
threads
Provide data caching for all 2K FS drivers
Both local and network
Cooperate with the memory manager
Cache
the purpose of a cache is to keep a subset of
frequently accessed data in physical memory as a
way to improve I/O performance
xlanchen@05/27/2005
Understanding the Inside of
Windows2000
计算机系 3
信息处理实验室
Key Features of 2K Cache Manager
Supports all file system types (both local and
network)
Uses the memory manager to control what parts
of what files are in physical memory
Caches data on a virtual block basis
Supports "hints" passed by applications at file
open time (such as random versus sequential
access, temporary file creation, and so on)
Supports recoverable file systems
xlanchen@05/27/2005
Understanding the Inside of
Windows2000
计算机系 4
信息处理实验室
Single, Centralized System Cache
Some operating systems rely on each individual
file system to cache data
2K offers a centralized caching facility
caches all externally stored data
local hard disks, floppy disks, network file servers,
or CD-ROMs
user data streams or file system metadata
xlanchen@05/27/2005
Understanding the Inside of
Windows2000
计算机系 5
信息处理实验室
The memory manager
Cache held in virtual (no phys) memory
Cache manager can’t tell what’s in phys mem
Files mapped by Section Objects
Cc copies data to/from Section Object (ref I/O
system)
MM pages data in and flushes it out
Each section logically n * (256-byte) views
Maintained until all handles for file x closed
xlanchen@05/27/2005
Understanding the Inside of
Windows2000
计算机系 6
信息处理实验室
The memory manager
Cache manager
Virtual memory
Memory manager
Physical
pages
xlanchen@05/27/2005
Understanding the Inside of
Windows2000
计算机系 7
信息处理实验室
Cache coherency
Must ensure that any process accessing cached
data will get the most recent version of that data
Example:
Process 1, open/read/write
Process 2, map into its address space
xlanchen@05/27/2005
Understanding the Inside of
Windows2000
计算机系 8
信息处理实验室
Coherent caching
scheme
xlanchen@05/27/2005
Understanding the Inside of
Windows2000
计算机系 9
信息处理实验室
Virtual Block Caching
Logical blocks
Keeps track of which blocks of a disk partition are
in the cache
Novell NetWare, OpenVMS, OS/2, and older
UNIX systems
Virtual block caching
Keeps track of which parts of which files are in
the cache
xlanchen@05/27/2005
Understanding the Inside of
Windows2000
计算机系 10
信息处理实验室
Virtual block caching
Benefits
Opens up the possibility of doing intelligent readahead
Allows the I/O system to bypass going to the file
system for requests for data that is already in the
cache (fast I/O)
xlanchen@05/27/2005
Understanding the Inside of
Windows2000
计算机系 11
信息处理实验室
Stream-Based Caching
Stream caching vs. file caching
A stream is a sequence of bytes within a file
Some file systems allow a file to contain more than
one stream
NTFS
Stream caching: caching each stream
independently
xlanchen@05/27/2005
Understanding the Inside of
Windows2000
计算机系 12
信息处理实验室
Recoverable File System Support
Recoverable file systems
Can reconstruct the disk volume structure after a
system failure
A log file is maintained
NTFS
xlanchen@05/27/2005
Understanding the Inside of
Windows2000
计算机系 13
信息处理实验室
Recoverable File System Support
The cache manager and the file system must work
together
The file system writes a log file record documenting the
volume update it intends to make.
The file system calls the cache manager to flush the log file
record to disk.
The file system writes the volume update to the cache; that
is, it modifies its cached metadata.
The cache manager flushes the altered metadata to disk,
updating the volume structure. (Actually, log file records are
batched before being flushed to disk, as are volume
modifications.)
xlanchen@05/27/2005
Understanding the Inside of
Windows2000
计算机系 14
信息处理实验室
Cache structure
Cache manager caches data on a virtual basis
A region of system virtual address spaces is
divided into views
View: 256KB slots
See System cache address space
xlanchen@05/27/2005
Understanding the Inside of
Windows2000
计算机系 15
信息处理实验室
System cache address space
xlanchen@05/27/2005
Understanding the Inside of
Windows2000
计算机系 16
信息处理实验室
Round-robin
xlanchen@05/27/2005
Understanding the Inside of
Windows2000
计算机系 17
信息处理实验室
Cache Size
how Windows 2000 computes the size of the
system cache ?
Cache Virtual Size ?
Cache Physical Size ?
xlanchen@05/27/2005
Understanding the Inside of
Windows2000
计算机系 18
信息处理实验室
Cache Virtual Size
Default size : 64 MB
If physical memory is more than 16 MB :
128 MB + (64 MB - 16 MB) / 4 MB * PMEM = 896 MB
Size and Location of System Data Cache
Platform
Address Range
Min/Max
Virtual Size
x86 2-GB system
space
0xC1000000-E0FFFFFF,
0xA4000000-BFFFFFFF
64-960 MB
x86 1-GB system space
0xC1000000-DBFFFFFF
64-432 MB
x86 1-GB system space
with Terminal Services
0xC1000000-DCFFFFFF
64-448 MB
xlanchen@05/27/2005
Understanding the Inside of
Windows2000
计算机系 19
信息处理实验室
Cache Physical Size
The Windows 2000 Task Manager doesn't report
the size of the system cache
xlanchen@05/27/2005
Understanding the Inside of
Windows2000
计算机系 20
信息处理实验室
Some Confused concepts
system cache
system cache working set
system working set
A part
Some System Variables
Memory: System Cache Resident Bytes
MmSystemCachePage
Memory: Cache Bytes
MmSystemCacheWs.WorkingSetSize
Memory: Cache Bytes Peak
MmSystemCacheWs.Peak
Memory: Cache Faults/Sec
MmSystemCacheWs.PageFaultCount
xlanchen@05/27/2005
Understanding the Inside of
Windows2000
计算机系 21
信息处理实验室
Cache data structure
to keep track of cached files
A virtual address control block
For each 256-KB slot in the system cache
A private cache map
For each separately opened cached file
A single shared cache map structure
For mapped views of the cached file
xlanchen@05/27/2005
Understanding the Inside of
Windows2000
计算机系 22
信息处理实验室
Systemwide Cache Data Structures
system cache and virtual address control blocks
(VACBs)
VACB structure
xlanchen@05/27/2005
256KB
Understanding the Inside of
Windows2000
计算机系 23
信息处理实验室
Per-File Cache Data Structures
File Handle
xlanchen@05/27/2005
Understanding the Inside of
Windows2000
计算机系 24
信息处理实验室
If read file
Is the file in the cache?
VACB index arrays
If so, which VACB, if any, refers
to the requested location?
xlanchen@05/27/2005
Understanding the Inside of
Windows2000
计算机系 25
信息处理实验室
Cache Operation
Write-Back Caching and Lazy Writing
Intelligent Read-Ahead
xlanchen@05/27/2005
Understanding the Inside of
Windows2000
计算机系 26
信息处理实验室
Write-Back Caching and Lazy Writing
Data written to files is first stored in memory in
cache pages and then written to disk later
Flush timing
Cache manager Memory manager
Demand for physical memory exceeds supply
System thread—the lazy writer
Created once per second
1/8 of the dirty pages in the system cache or more
to be written to disk
xlanchen@05/27/2005
Understanding the Inside of
Windows2000
计算机系 27
信息处理实验室
Dirty Page Threshold
The number of pages that the system cache
keeps in memory before waking up the lazy writer
Calculating the Dirty Page Threshold
System Memory Size
Small
Medium
Large
xlanchen@05/27/2005
Dirty Page Threshold
Physical pages/8
Physical pages/4
Sum of the above two
Understanding the Inside of
Windows2000
计算机系 28
信息处理实验室
Disabling Lazy Writing for a File
Win32 CreateFile function
Specifies FILE_ATTRIBUTE_TEMPORARY to
create a temporary file
The lazy writer won't write dirty pages to the
disk unless there is a severe shortage of physical
memory or the file is closed
To improve system performance
xlanchen@05/27/2005
Understanding the Inside of
Windows2000
计算机系 29
信息处理实验室
Write Through Caching
Win32 CreateFile function
Specifies FILE_FLAG_WRITE_THROUGH flag
Or, Win32 FlushFileBuffers function
xlanchen@05/27/2005
Understanding the Inside of
Windows2000
计算机系 30
信息处理实验室
Flushing Mapped Files
xlanchen@05/27/2005
Understanding the Inside of
Windows2000
计算机系 31
信息处理实验室
xlanchen@05/27/2005
Understanding the Inside of
Windows2000
计算机系 32
信息处理实验室
xlanchen@05/27/2005
Understanding the Inside of
Windows2000
计算机系 33
信息处理实验室
xlanchen@05/27/2005
Understanding the Inside of
Windows2000
计算机系 34
信息处理实验室
xlanchen@05/27/2005
Understanding the Inside of
Windows2000
计算机系 35
信息处理实验室
Cache support routines
File read/write
File map
Process
File System Driver
Memory
Manager
Cached file read
Page fault
Noncached file read
File write
CcInitializeCacheMap
Per file
structure
User space
Copy read
Device Driver
Pin
data
Phys. Mem.
access
I/O
Device
xlanchen@05/27/2005
Map
System
cache
Cache manager
Understanding the Inside of
Windows2000
计算机系 36
信息处理实验室
Copying to and from the Cache
Process
address
space
User
space
Kernel-Mode Functions
for Copying to and from
the Cache
Process
address
space
…
System address space
User
space
System
cache
xlanchen@05/27/2005
CcCopyRead
CcFastCopyRead
O
CcCopyWrite
CcFastCopyWrite
Understanding the Inside of
Windows2000
计算机系 37
信息处理实验室
Mapping and Pinning
Functions for Finding
Metadata Locations
CcMapData
CcPinRead
Kernel mode
File
system
driver
CcPreparePinWrite
metadata
System
cache
CcPinMappedData
CcSetDirtyPinnedData
CcUnpinData
xlanchen@05/27/2005
Understanding the Inside of
Windows2000
计算机系 38
信息处理实验室
DMA
Kernel mode
Phys.
Mem.
Network
file
system
DMA
VMPM
DMA
System
cache
Network
device
MDL:
Memory
descriptor
list
MDL
Functions That Create the DMA Interface
CcMdlRead
CcMdlReadComplete
CcMdlWrite
CcMdlWriteComplete
xlanchen@05/27/2005
Understanding the Inside of
Windows2000
计算机系 39
信息处理实验室
Write Throttling
Write throttling: cache manager’s lazy writer
Upgrade system performance for large write
operation
Useful for network redirectors transmitting data
over slow communication line
Example: writes a large amount of data to a remote
file system over a 9600-baud line
xlanchen@05/27/2005
Understanding the Inside of
Windows2000
计算机系 40
信息处理实验室