| From: | Andres Freund <andres(at)anarazel(dot)de> |
|---|---|
| To: | Nathan Bossart <nathandbossart(at)gmail(dot)com> |
| Cc: | pgsql-hackers(at)lists(dot)postgresql(dot)org |
| Subject: | Re: pgsql: Add pg_atomic_unlocked_write_u64 |
| Date: | 2025-12-04 15:56:12 |
| Message-ID: | 6a7i4g5rroen3jyok4jxpd76tpg7nkicq4o75cdprp5thdlkbn@dfwr7ts43rsm |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers pgsql-hackers |
Hi,
On 2025-12-04 09:51:10 -0600, Nathan Bossart wrote:
> On Wed, Dec 03, 2025 at 11:40:47PM +0000, Andres Freund wrote:
> > Add pg_atomic_unlocked_write_u64
> >
> > The 64bit equivalent of pg_atomic_unlocked_write_u32(), to be used in an
> > upcoming patch converting BufferDesc.state into a 64bit atomic.
>
> I noticed that this new function was defined as
>
> ptr->value = val;
>
> and couldn't figure out why that was safe. Above
> pg_atomic_unlocked_write_u32(), I see this comment:
>
> * The write is guaranteed to succeed as a whole, i.e. it's not possible to
> * observe a partial write for any reader. ...
>
> But the new 64-bit version doesn't seem to be surrounded by a check for
> PG_HAVE_8BYTE_SINGLE_COPY_ATOMICITY, and I found no discussion about it in
> the commit message or the linked thread. Am I missing something here?
The whole point of the _unlocked_ function is to use it for modifying an
atomic that doesn't need to actually be atomic when modified by that
function. The current use-case for it is to to modify BufferDesc->state for
temporary table buffers. Those obviously can't be shared across processes and
therefore don't need an atomic operation to be modified. In the referenced
thread I'm working on converting BufferDesc->state to be a 64bit atomic, hence
the need for pg_atomic_unlocked_write_u64().
I didn't notice that the comment for pg_atomic_unlocked_write_u32() makes that
claim about partial writes not being visible. I think we should just remove
that claim.
Greetings,
Andres Freund
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Nathan Bossart | 2025-12-04 16:03:22 | Re: pgsql: Add pg_atomic_unlocked_write_u64 |
| Previous Message | Nathan Bossart | 2025-12-04 15:51:10 | Re: pgsql: Add pg_atomic_unlocked_write_u64 |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Nathan Bossart | 2025-12-04 16:03:22 | Re: pgsql: Add pg_atomic_unlocked_write_u64 |
| Previous Message | Amit Langote | 2025-12-04 15:54:29 | Re: Batching in executor |