← Lessons

quiz vs the machine

Silver1060

Databases

The Buffer Pool and Page Cache

Databases keep hot pages in RAM so most reads never touch the disk.

4 min read · intro · beat Silver to climb

Memory In Front Of Disk

A database stores data on disk in fixed size pages, but disk is slow. To stay fast it keeps a large region of RAM called the buffer pool holding copies of recently used pages. A read first checks the pool, and only on a miss does it fetch the page from disk.

How It Works

  • When a query needs a row, the engine looks up the page in the pool by page id.
  • A hit returns the page from memory immediately.
  • A miss reads the page from disk, places it in the pool, and may evict an old page to make room.
  • Eviction usually follows a least recently used policy so cold pages leave first.

Dirty Pages

A page changed in memory but not yet written back to disk is dirty. The buffer pool delays these writes and flushes them in batches, turning many small random writes into fewer efficient ones.

Key idea

The buffer pool caches pages in RAM so the working set is served from memory, and dirty pages are flushed lazily to keep writes efficient.

Check yourself

Answer to earn rating on the learn ladder.

1. What happens on a buffer pool miss?

2. What is a dirty page?