23. File System Caching and Consistency Flashcards
How do we make a big, slow thing look fast?
Use a cache! (Put a smaller, faster thing in front of it)
What is a buffer cache?
The memory used to cache file system data.
Memory serves as the smaller, faster thing (compared to disk) that we use to make a big, slow thing (disk) look faster.
What are two ways that operating systems use memory?
- As memory (duh)
2. To cache file data in order to improve performance
When the OS splits memory use into main mem and file system buffer cache, what are the consequences of allocating a big buffer cache and a small main memory?
With a big buffer cache and a small main memory, file access is fast, but there is an increased potential for thrashing in the memory subsystem.
When the OS splits memory use into main mem and file system buffer cache, what are the consequences of allocating a small buffer cache and a large main memory?
With a small buffer cache and a large main memory, little swapping occurs (good), but file access is extremely slow.
What does the swappiness Linux kernel parameter do?
It controls how aggressively the operating system prunes unused process memory pages and hence the balance between memory and buffer cache.
Describe what happens for open, read, write, and close operations for “above the file system” placement of the buffer cache.
Open - Pass down to the underlying file system
Read
- If the file is not in the buffer cache, pass down to underlying file system and load contents into the buffer cache
- If the file is in the cache, return the cached contents
Write
- If file is not in the buffer cache, pass load contents into the buffer cache and then modify them
- If the file is in the cache, modify the cached contents
Close
- Remove from the cache (if necessary) and flush contents through the file system
Describe the pros and cons of “above the file system” placement of the buffer cache.
Pros:
- Buffer cache sees file operations and may lead to better prediction or performance
Cons:
- Hides many file operations from the file system, preventing it form providing consistency guarantees
- Can’t cache file system metadata: inodes, superblocks, etc
With the “above the file system” implementation of the buffer cache, what do we cache?
Entire files and directories!
What is the buffer cache interface for “above the file system” implementation?
open, close, read, and write
Same as the file system call interface
With the “below the file system” implementation of the buffer cache, what do we cache?
Disk blocks!
What is the buffer cache interface for “below the file system” implementation?
readblock and writeblock
Same as the disk interface
Describe the pros and cons of “below the file system” placement of the buffer cache.
Pros:
- Can cache all blocks including file system data structures, inodes, superblocks, etc
- Allows file system to see all file operations even if they eventually hit the cache
Cons:
- Cannot observe file semantics or relationships
Do modern operating systems place the buffer cache “above” the file system or “below” the file system?
Below the file system
To understand why, think above each of the pros of placing it below the file system
How can the cache cause consistency problems?
Objects in the cache are lost on failures (like loss of power)