Buffer Pools

Table of Contents

Buffer Pools

Prev: database-storage-ii Next: hash-tables

Locks vs Latches

Locks

  • Protect the database’s logical contents from other transactions.
  • Held for the duration of the transaction.
  • Need to be able to rollback changes.

Latches

  • Protects the critical section of the DBMS’ internal data structures from other threads.
  • Held for operation duration.
  • No need to rollback

Buffer Pool

The buffer pool is an in-memory cache of pages read from disk.

Each region of memory is organized as an array of fixed size pages, where each entry is called a frame. When a DBMS requests a page, a copy is placed in one of these frames.

The buffer pool maintains some metadata:

Optimizations:

Allocation Policies:

Replacement Policies

LRU: - LRU maintains a timestamp of when each page was last accessed. - Evicts the page with the oldest timestamp.

CLOCK: - Approximates LRU, with only one bit per timestamp. - Each page has a reference bit, when a page is accessed, set to 1.

On eviction: go in a clockwise order, check if a page’s bit is set to 1. If so, then set to 0, otherwise evict and save a cursor to the position.

Alternatives

LRU and CLOCK are both susceptible to sequential flooading, where scanning disk with a query larger than the buffer pool makes the caches useless (only pure overhead).

Some better solutions include:

  • LRU-K: Take into account history of the last K references.
  • Priority hints: have a way to tell the buffer pool whether each page is important or not.

Prev: database-storage-ii Next: hash-tables