Buffer Pool & Page Cache

Difficulty
Importance

The problem

Reading from disk on every single query would make even simple lookups unacceptably slow — a database needs to keep frequently accessed data in memory, deciding intelligently what to keep and what to evict as memory fills up, without simply running out of RAM.

Why now

Virtual memory already established that the OS manages a page cache mediating between fast RAM and slow disk; a database's buffer pool is that same idea, implemented a second time at the application level because the database can make smarter, workload-aware eviction decisions than a general-purpose OS cache can.

Mental model

A buffer pool is a fixed-size cache of disk pages held in memory, with an eviction policy (commonly a variant of least-recently-used) deciding what to discard when it's full and new data needs to be loaded — the exact cache/eviction tradeoff virtual memory already introduced for OS-level paging, just re-implemented with database-specific knowledge of which pages are actually likely to be reused soon.

Requires

Used in

Projects

  • Run the same query twice — once against a cold buffer pool (just after restart) and once warm — and measure the latency difference directly
  • Tune a database's buffer pool size for a given working data set size and explain the reasoning using cache hit ratio

Examples

  • A query that reads 10,000 pages already sitting in the buffer pool completes almost instantly; the same query against a cold cache pays a disk read cost for every single page
  • A buffer pool sized smaller than the actively-queried working set causes constant eviction and reload — thrashing, the same failure mode virtual memory already named for OS-level paging

Resources

Mastery checklist