From: Tomas Vondra <tomas.vondra@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Do not lock in BufferGetLSNAtomic() on archs with 8 byte atomic
Date: Wed, 11 Mar 2026 18:48:07 +0000
Message-ID: <E1w0ObH-003VWH-0A@gemulon.postgresql.org> (raw)
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
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/943e881733ca62ea2e1ceb20e79b3d149379755d
Modified Files
--------------
contrib/pageinspect/heapfuncs.c | 13 +++-------
contrib/pageinspect/rawpage.c | 8 +++---
src/backend/access/common/bufmask.c | 2 +-
src/backend/storage/buffer/bufmgr.c | 49 +++++++++++++++++++++++--------------
src/include/access/gist.h | 4 +--
src/include/storage/bufpage.h | 47 +++++++++++++++++++++++++++--------
6 files changed, 76 insertions(+), 47 deletions(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-committers@postgresql.org
Cc: tomas.vondra@postgresql.org, pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Do not lock in BufferGetLSNAtomic() on archs with 8 byte atomic
In-Reply-To: <E1w0ObH-003VWH-0A@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox