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

From Andres Freund
Subject Re: Atomic ops for unlogged LSN
Date
Msg-id 20231108011811.elqq3e67burgik7x@awork3.anarazel.de
Whole thread Raw
In response to Re: Atomic ops for unlogged LSN  (John Morris <john.morris@crunchydata.com>)
List pgsql-hackers
Hi,

On 2023-11-07 00:57:32 +0000, John Morris wrote:
> I found the comment about cache coherency a bit confusing. We are dealing
> with a single address, so there should be no memory ordering or coherency
> issues. (Did I misunderstand?) I see it more as a race condition.

IMO cache coherency covers the value a single variable has in different
threads / processes.

In fact, the only reason there effectively is a guarantee that you're not
seeing an outdated unloggedLSN value during shutdown checkpoints, even without
the spinlock or full barrier atomic op, is that the LWLockAcquire(), a few
lines above this, would prevent both the compiler and CPU from moving the read
of unloggedLSN to much earlier.  Obviously that lwlock has a different
address...


If the patch just had done the minimal conversion, it'd already have been
committed...  Even if there'd be a performance reason to get rid of the memory
barrier around reading unloggedLSN in CreateCheckPoint(), I'd do the
conversion in a separate commit.

Greetings,

Andres Freund



pgsql-hackers by date:

Previous
From: Kyotaro Horiguchi
Date:
Subject: Re: Add new option 'all' to pg_stat_reset_shared()
Next
From: Andres Freund
Date:
Subject: Re: Show WAL write and fsync stats in pg_stat_io