Well, if I have to spend my days (and currently nights!) with Windows cache and memory management, it should at least be good for a blog post ;)
The Windows Cache Manager is a central operating system facility managing the system cache, which transparently supports all Windows filesystems. It is capable of handling file data - including multiple data streams for filesystems that support such - as well as filesystem metadata. Since the operating system provides for a centralized external storage caching mechanism (including support for network and disk based access), filesystems are alleviated of implementing proprietary caching functionality.
The Cache Manager operates on a relatively high level for a kernel mode component, interpreting files as byte streams vs. individual disk blocks on physical storage media. Abstracting away from physical file layout allows for simplified analysis of data access patterns and resulting optimizations for instance in terms of better read-ahead performance.
A segment of the kernel virtual address space is assigned to the system cache by the Windows Memory Manager. The Cache Manager further slices this segment into 256KB chunks to hold cached views of filesystem data.
Mapping file contents from disk into the system cache is 256KB-aligned - that is, when reading 100 bytes from a 1MB file at byte offset 400,000 the Cache Manager will fill up the corresponding 256KB chunk in the system cache starting at byte offset 262144 through 524288-1. Assignment of filesystem mappings into the system cache 256KB slots happens in a round robin fashion.
The filesystem tracks the physical bits of a logical file and the type of I/O requested (buffered vs. unbuffered) within corresponding file objects. Multiple file objects can represent the same file on disk. The former share a "shared cache map" which serves as metadata structure for the file on disk being represented by the file objects. It contains a mapping from file offset for a particular view to system cache virtual address space. The Cache Manager utilizes the shared cache map to ensure cache coherency among the different file objects for the same file - for instance by only caching the same view into the file exactly once. Data relevant to individual file objects alone - that is, access patterns to handle read-ahead - is kept in object-specific private cache maps.
- Fourth Edition of Russinovich's Windows® Internals, Fourth Edition
- an updated version has been released in June 2009, covering the more recent versions of the OS: Windows Internals, Fifth Edition
.
- 2005 MSDN Channel 9 interview with Molly Brown, the engineer responsible for the Vista version of the Windows Cache Manager: part 1 and part 2













gamesTM asked me for a preview of the title which has been published in their latest, i.e. August 2008, issue. The magazine is available at newsstands and bookstores as well as a slick DRM-free PDF online.
It is jam-packed with previews (e.g. Civ IV: Colonization, CoD: World at War, Treyarch's Bond, Dawn of War 2), reviews (Battlefield Bad Company, Alone in the Dark) and a LucasArts Indy retro flashback - well worth shelling out the bucks ;)