DEV Community

Pawan Kukreja
Pawan Kukreja

Posted on • Edited on

[Summary] Chapter#08 "The Internals of PostgreSQL" Buffer Manager(Part-02)

Buffer Manager Locks:

Buffer Table Locks
BufMappingLock protect data integrity and buffer table and it is light weight lock that used in shared and exclusive modes, and it split into partitions to reduce contention in the buffer table.

Lock for Each Buffer Descriptor
It uses two light-weight locks.
Content Locks
This lock enforces access limits, and it can be used in shared and exclusive modes.
io_in_progress_lock
It is used to wait for I/O on a buffer to complete, process holds exclusive io_in_progress lock of the corresponding descriptor while accessing the storage.

How the Buffer Manager Works

Backend process want to access a desired page, it calls the ReadBufferExtended function.

Accessing a Page Stored in the Buffer Pool
Buffer Manager performs the following steps:

  • Create the buffer _tag of the desired page and compute the hash bucket slot.
  • Aquire the BufMappingLock partition that covers the obtained has bucket slot in shared mode.
  • Look up entry whose tag is Tag-C and obtain the buffer_id from the entry.
  • Pin the buffer descriptor for buffer_id
  • Release the BufMappingLock
  • Access the buffer pool slot with buffer_id

Page Replacement Algorithm: Clock Sweep
This Algorithm is Not Frequently Used with low overhead and it selects less frequently used pages efficiently.

Ring Buffer
The ring buffer is a small and temporary buffer area, following list that should be satisfied a ring buffer is allocated to shared memory.

  • Bulk Ringing
  • Bulk Writing
  • Vacuum Processing

Flushing Dirty Pages
It is used to store background writer process and replace victim pages. Both have same functions but different roles and behaviours.
when checkpointing starts, checkpoint process writes a checkpoint record to WAL segment file.
Role of background writer is to reduce the influence of intensive writing of checkpointing. The background writer continues to flush dirty pages little by little with minimal impact on database activity.

Reference

Top comments (0)