Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Restructured shared buffer mapping table (PostgreSQL)

This repository holds a single self-contained change to PostgreSQL's shared buffer mapping table, published independently of the full source tree.

What the change does

It replaces the dynahash-based shared buffer lookup table with a flat, index-linked open-chaining hash table built from two shared-memory arrays:

  • buckets[num_buckets] — one chain head per hash bucket
  • entries[NBuffers] — one entry per buffer, indexed by buf_id

Each buffer slot i permanently owns entry slot i, so no freelist is needed: bufmgr always removes a buffer's old mapping (BufTableDelete) before inserting a new tag for that same buf_id. num_buckets is a power of two and a multiple of NUM_BUFFER_PARTITIONS, so every tag in a bucket maps to a single partition and the caller's BufMappingLock fully serializes each chain — the same guarantee the dynahash table relied on.

It also reorders the unlock/delete in InvalidateVictimBuffer (bufmgr.c): the buffer header is now unlocked after the mapping entry is deleted, to avoid a race where a concurrent GetVictimBuffer() could reinsert an entry for the same buffer and corrupt the chain.

Files

Path Description
restructured_shared_buffer_table.patch The change as a git diff (2 files).
src/backend/storage/buffer/buf_table.c The rewritten flat hash table (patched state).
src/backend/storage/buffer/bufmgr.c The InvalidateVictimBuffer unlock/delete reorder (patched state).

Only the two modified source files are included, in their post-patch state, at their original tree paths. The rest of the PostgreSQL source is not vendored here.

Applying the patch

The patch applies on top of upstream PostgreSQL commit 4abf411e2328f57fd2547b5c2187a2159e97a606 ("pg_stat_io: Don't flag extends by autovacuum launcher"):

git clone https://git.postgresql.org/git/postgresql.git
cd postgresql
git checkout 4abf411e2328f57fd2547b5c2187a2159e97a606
git apply /path/to/restructured_shared_buffer_table.patch

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages