This repository holds a single self-contained change to PostgreSQL's shared buffer mapping table, published independently of the full source tree.
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 bucketentries[NBuffers]— one entry per buffer, indexed bybuf_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.
| 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.
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