Re: Atomic ops for unlogged LSN

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: John Morris <john(dot)morris(at)crunchydata(dot)com>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>, Stephen Frost <sfrost(at)snowman(dot)net>
Subject: Re: Atomic ops for unlogged LSN
Date: 2023-05-23 22:26:25
Message-ID: ZG09kSRxOdvz5TVv@paquier.xyz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jonathan S. Katz 2023-05-23 22:27:23 Re: PG 16 draft release notes ready
Previous Message Tom Lane 2023-05-23 21:39:44 Re: memory leak in trigger handling (since PG12)