Re: Buffer locking is special (hints, checksums, AIO writes)

From: Andres Freund <andres(at)anarazel(dot)de>
To: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
Cc: Melanie Plageman <melanieplageman(at)gmail(dot)com>, Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, Noah Misch <noah(at)leadboat(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
Subject: Re: Buffer locking is special (hints, checksums, AIO writes)
Date: 2025-12-17 14:54:32
Message-ID: q3ybyaiownp4ivt6xfy55s5llvtq6vqsd4zbt5kn6hacxdcpp4@2ngd4h4bev5d
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On 2025-12-17 11:25:50 +0200, Heikki Linnakangas wrote:
> On 03/12/2025 02:47, Andres Freund wrote:
> > On 2025-11-25 11:54:00 -0500, Andres Freund wrote:
> > > Thanks a lot for that detailed review! A few questions and comments, before I
> > > try to address the comments in the next version.
> >
> > Here's that new new version, with the following changes
> >
> > - Some more micro-optimizations, most importantly adding a commit that doesn't
> > initialize the delay in LockBufHdr() unless needed. With those I don't see a
> > consistent slowdown anymore (slight speedup on one workstation, slight
> > slowdown on another, in an absurdly adverse workload)
>
> +1
>
> I'm comparing the patched LockBufHdr() with LWLockWaitListLock(), which does
> pretty much the same thing, and LWLockWaitListLock() already did the
> initialization of the delay that way. But there are some small differences:
>
> - LockBufHdr() uses unlikely() in the initial attempt, LWLockWaitListLock()
> does not

I think we probably ought to do that in LWLockWaitListLock() too.

> - LWLockWaitListLock() uses pg_atomic_read_u32() after spinning,
> LockBufHdr() retries directly with pg_atomic_fetch_or_u32().

I think here LWLockWaitListLock() is likely right - but it seems like a change
to LockBufHdr() that I would probably make in a separate commit?

> Are there reasons for the differences, or is it just that they were
> developed separately and ended up looking slightly different?

I think it's just the latter...

Thanks for reviewing,

Andres Freund

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2025-12-17 15:00:01 Re: Flaky 003_start_stop.pl test
Previous Message Peter Eisentraut 2025-12-17 14:51:58 Re: Add sanity check for duplicate enum values in GUC definitions