Re: Atomic ops for unlogged LSN - Mailing list pgsql-hackers

From Michael Paquier
Subject Re: Atomic ops for unlogged LSN
Date
Msg-id ZG09kSRxOdvz5TVv@paquier.xyz
Whole thread Raw
In response to Atomic ops for unlogged LSN  (John Morris <john.morris@crunchydata.com>)
Responses Re: Atomic ops for unlogged LSN
List pgsql-hackers
On Tue, May 23, 2023 at 08:24:45PM +0000, John Morris wrote:
> This is a short patch which cleans up code for unlogged LSNs. It
> replaces the existing spinlock with atomic ops.  It could provide a
> performance benefit for future uses of unlogged LSNS,  but for now
> it is simply a cleaner implementation.

Seeing the code paths where gistGetFakeLSN() is called, I guess that
the answer will be no, still are you seeing a measurable difference in
some cases?

-   /* increment the unloggedLSN counter, need SpinLock */
-   SpinLockAcquire(&XLogCtl->ulsn_lck);
-   nextUnloggedLSN = XLogCtl->unloggedLSN++;
-   SpinLockRelease(&XLogCtl->ulsn_lck);
-
-   return nextUnloggedLSN;
+   return pg_atomic_fetch_add_u64(&XLogCtl->unloggedLSN, 1);

Spinlocks provide a full memory barrier, which may not the case with
add_u64() or read_u64().  Could memory ordering be a problem in these
code paths?
--
Michael

Attachment

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: memory leak in trigger handling (since PG12)
Next
From: "Jonathan S. Katz"
Date:
Subject: Re: PG 16 draft release notes ready