Remove header lock BufferGetLSNAtomic() on architectures with 64 bit atomic operations

From: Andreas Karlsson <andreas(at)proxel(dot)se>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Remove header lock BufferGetLSNAtomic() on architectures with 64 bit atomic operations
Date: 2025-11-23 23:10:03
Message-ID: b6610c3b-3f59-465a-bdbb-8e9259f0abc4@proxel.se
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Andres pointed out this possible optimization on Discord so I hacked up
a quick patch which avoids taking a lock when reading the LSN from a
page on architectures where we can be sure to not get a torn value. It
is always nice to remove a lock from a reasonably hot code path.

I thought about using our functions for atomics but did not do so since
I did not want to introduce any extra overhead on platforms which do not
support 64-bit atomic operations.

I decided to just remove the struct to make the code simpler and more
consistent but I can also see an argument for keeping it to get some
degree of type safety.

I have not properly benchmarked it yet but plan to do so when I am back
from my vacation.

I have also included a cleanup patch where I change a macro into an
inline function which I think improves code readability. Feel free to
ignore that one if you want.

--
Andreas
Percona

Attachment Content-Type Size
v1-0001-Do-not-lock-in-BufferGetLSNAtomic-on-archs-with-8.patch text/x-patch 3.3 KB
v1-0002-Convert-PageXLogRecPtrSet-from-macro-to-inline-fu.patch text/x-patch 2.5 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2025-11-23 23:36:09 Re: Issues with ON CONFLICT UPDATE and REINDEX CONCURRENTLY
Previous Message Thomas Munro 2025-11-23 23:03:53 Re: PRI?64 vs Visual Studio (2022)