Master the fundamental concepts of file systems through this focused micro-challenge.
Block caches keep recently used disk blocks in RAM, keyed by (device, block number). Reads hit RAM; misses fetch from media and insert with eviction policy (LRU or clock).
Fields per entry:
For example, scanning a 1 MB file with 4 KB blocks touches 256 distinct block IDs; a 64-entry cache captures hot sequential reuse on second pass.
The hash-table-plus-LRU-list design here is exactly how Linux's unified page cache accelerates every file read, and the clock algorithm mentioned is what the kernel actually uses instead of strict LRU to keep overhead low at scale. Mixing up write-through and write-back semantics is a real source of data-loss bugs: one is safe but slow, the other is fast but loses dirty data on a crash.
Before you call the implementation done, walk failure modes on purpose. Test empty structures, single-element edge cases, maximum concurrency, and errno paths that must not crash the program. OS code usually fails in production when happy-path tests pass but invariants break under contention or memory pressure.
Keep structures small and name fields after kernel counterparts when possible. That lets you read man pages and kernel source side by side while you work. Print observable events during development; remove noisy logs once tests pass reliably.
You will implement get/put with clock eviction and write-back on flush. The task asks you to count cache hits vs misses on repeated reads of the same file.
Implement block cache with LRU replacement.
Requirements:
Test:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github