Do not lock in BufferGetLSNAtomic() on archs with 8 byte atomic reads
Tomas Vondra <tomas.vondra@postgresql.org>
Author:
Tomas Vondra <tomas.vondra@postgresql.org>
Date: 2026-03-11T18:46:08Z
Releases:
19 (unreleased)
Do not lock in BufferGetLSNAtomic() on archs with 8 byte atomic reads On platforms where we can read or write the whole LSN atomically, we do not need to lock the buffer header to prevent torn LSNs. We can do this only on platforms with PG_HAVE_8BYTE_SINGLE_COPY_ATOMICITY, and when the pd_lsn field is properly aligned. For historical reasons the PageXLogRecPtr was defined as a struct with two uint32 fields. This replaces it with a single uint64 value, to make the intent clearer. To prevent issues with weak typedefs the value is still wrapped in a struct. This also adjusts heapfuncs() in pageinspect, to ensure proper alignment when reading the LSN from a page on alignment-sensitive hardware. Idea by Andres Freund. Initial patch by Andreas Karlsson, improved by Peter Geoghegan. Minor tweaks by me. Author: Andreas Karlsson <andreas@proxel.se> Author: Peter Geoghegan <pg@bowt.ie> Reviewed-by: Andres Freund <andres@anarazel.de> Reviewed-by: Tomas Vondra <tomas@vondra.me> Discussion: https://postgr.es/m/b6610c3b-3f59-465a-bdbb-8e9259f0abc4@proxel.se
Files
| Path | Change | +/− |
|---|---|---|
| contrib/pageinspect/heapfuncs.c | modified | +3 −10 |
| contrib/pageinspect/rawpage.c | modified | +3 −5 |
| src/backend/access/common/bufmask.c | modified | +1 −1 |
| src/backend/storage/buffer/bufmgr.c | modified | +30 −19 |
| src/include/access/gist.h | modified | +2 −2 |
| src/include/storage/bufpage.h | modified | +37 −10 |
Discussion
- Remove header lock BufferGetLSNAtomic() on architectures with 64 bit atomic operations 12 messages · 2025-11-23 → 2026-03-11