Re: WAL Insertion Lock Improvements

From: Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Andres Freund <andres(at)anarazel(dot)de>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Nathan Bossart <nathandbossart(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: WAL Insertion Lock Improvements
Date: 2023-07-22 07:38:49
Message-ID: CALj2ACWcJvqqWmzawyw_=ycSHty06H+EAAjzSQ5Hfq8kvpaJFA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Jul 21, 2023 at 11:29 AM Michael Paquier <michael(at)paquier(dot)xyz> wrote:
>
> + /* Reading atomically avoids getting a torn value */
> + value = pg_atomic_read_u64(valptr);
>
> Should this specify that this is specifically important for platforms
> where reading a uint64 could lead to a torn value read, if you apply
> this term in this context? Sounding picky, I would make that a bit
> longer, say something like that:
> "Reading this value atomically is safe even on platforms where uint64
> cannot be read without observing a torn value."
>
> Only xlogprefetcher.c uses the term "torn" for a value by the way, but
> for a write.

Done.

> 0001 looks OK-ish seen from here. Thoughts?

Yes, it looks safe to me too. FWIW, 0001 essentially implements what
an existing TODO comment introduced by commit 008608b9d5106 says:

/*
* Read value using the lwlock's wait list lock, as we can't generally
* rely on atomic 64 bit reads/stores. TODO: On platforms with a way to
* do atomic 64 bit reads/writes the spinlock should be optimized away.
*/

I'm attaching v10 patch set here - 0001 has modified the comment as
above, no other changes in patch set.

--
Bharath Rupireddy
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

Attachment Content-Type Size
v10-0001-Optimize-WAL-insertion-lock-acquisition-and-rele.patch application/octet-stream 7.0 KB
v10-0002-Improve-commets-in-and-around-LWLockWaitForVar-c.patch application/octet-stream 3.6 KB
v10-0003-Have-a-quick-exit-for-LWLockUpdateVar-when-there.patch application/octet-stream 1.3 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2023-07-22 10:32:45 Re: doc: improve the restriction description of using indexes on REPLICA IDENTITY FULL table.
Previous Message Tatsuo Ishii 2023-07-22 06:14:46 Re: Row pattern recognition