Clay might have found out a problem with copying data directly to the user in read A note I should have included earlier: Meaning of "static" when applied outside functions in C Should we mark functions static in kernel modules? Some people do Seems hard to make a good case for it for our demos! What if it wasn't actually a kernel module? A lot of names might actually be really common in the kernel bob and fred demo The Page Cache: The page cache caches pages of files in main memory It might be in L1, L2, or L3 (remember, those are a hardware thing) Remember: milli, micro, nano Block device contains the backing store Cache miss = access to a page not in the cache Cache hit = access a page that is in the cache 1 disk block *might* be 1 page Could also be different than that They're pages of files Read caching: Simple Write caching: Simple: Just update block device, invalidate cache write-through: Update both write-back (or copy-back or write-behind): Update cache, mark updated pages dirty Update the block device when we get around to it Note that by "write" we mean put a write into the block device's queue Cache Eviction: Nothing voluntarily leaves the cache! Ideal strategy: Remove page that is least used in the future LRU: Pretty good generally Remember: We're not deleting anything forever Even in my house, it's a decent metric Two-list (what Linux actually does): "inactive" and "active" lists 1 access: Into inactive more access will move pages into the active queue If the active queue is too big, pages move to inactive By reference here, not actual copying Structures: Cache page comes from a file A file may be stored in a variety of ways The address_space struct stores information about stuff in the cache radix tree: Did you cover these in 311? I haven't covered them in 311 trie A trie doesn't store keys in the nodes Think of a thing to store a dictionary for spell check Wikipedia pictures of this stuff The radix piece: Merge single children with parents Might eliminate most of the nodes Can be more branchy than binary Flusher threads and Writeback: When we need more free memory, and evict a dirty page When data is older than some threshold On sync() or fsync() Laptop mode: Flush if disk spins up for some other reason Set writeback behaviour to be slow I didn't look up if this is still at thing with SSD Don't run out of battery! In /proc/sys/vm There are multiple flusher threads these days For multiple hard drives. If you don't want to use the page cache, use O_DIRECT