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

From: Andres Freund <andres(at)anarazel(dot)de>
To: Melanie Plageman <melanieplageman(at)gmail(dot)com>
Cc: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Kirill Reshke <reshkekirill(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: 2026-01-14 21:20:58
Message-ID: k5j77f3q6ztihnjnx2nqxzyor6fbj2qxcbhzuxhkh2yy63jyfg@p72phigar3n4
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On 2026-01-12 19:33:56 -0500, Andres Freund wrote:
> Here are the remaining commits, with a bit of polish:

I pushed 0001, 0002.

Attached is an updated version of the remaining changes:

- I updated the definition in BUF_DEFINE_FLAG to have a redundant copy of
BUF_FLAG_SHIFT's "contents", as suggested by Chao

- I realized I had forgotten to remove the BufferContent lwlock tranche

- Updated the FIXME comment about using PGPROC->lw* to not be a fixme anymore,
it seems nobody is pushing back against that being ugly-but-reasonable for now

- I renamed ResOwnerReleaseBufferPin etc to ResOwnerReleaseBuffer, as I
suggested nearby.

- Added a commit removing ForEachLWLockHeldByMe, now that it's not used
anymore. I checked in with Noah, who added it, and he's on-board with that
plan.

- Added a commit removing LWLockDisown(), LWLockReleaseDisowned(). They were
added for AIO and AIO doesn't need them anymore, as that's implemented
purely in bufmgr.c now. I don't see a reason to keep them...

- I reflowed the comments / README in "Require share-exclusive lock to set hint bits and to flush"
and removed the FIXME about that

- Removed "FIXME: The start of the comment above needs updating." from the
above commit, I already had rewritten the comment, just hadn't removed the
FIXME yet

I tried putting the new code in a header, as we had discussed, but that turns
out to not work easily: The locking code needs access to the private-refcount
infrastructure and we can't put the private refcount infrastructure into a
header without making PrivateRef* non-static, which in turn causes slightly
worse code generation.

I'm now working on cleaning up the last two commits. The most crucial bit is
to simplify what happens in MarkSharedBufferDirtyHint(), we afaict can delete
the use of DELAY_CHKPT_START etc and just go to marking the buffer dirty first
and then do the WAL logging, just like normal WAL logging. The previous order
was only required because we were dirtying the page while holding only a
shared lock, which did not conflict with the lock held by SyncBuffers() etc.

There are some comments that arguably should be updated in 0005, but will only
be updated in 0006. I don't really see how to address that without squashing
the two commits though - which I think wouldn't be good, as the necessary
changes are decidedly nontrivial.

Greetings,

Andres Freund

Attachment Content-Type Size
v11-0001-bufmgr-Change-BufferDesc.state-to-be-a-64-bit-at.patch text/x-diff 45.5 KB
v11-0002-bufmgr-Implement-buffer-content-locks-independen.patch text/x-diff 51.1 KB
v11-0003-lwlock-Remove-ForEachLWLockHeldByMe.patch text/x-diff 2.2 KB
v11-0004-lwlock-Remove-support-for-disowned-lwlwocks.patch text/x-diff 4.6 KB
v11-0005-Require-share-exclusive-lock-to-set-hint-bits-an.patch text/x-diff 40.8 KB
v11-0006-WIP-bufmgr-Don-t-copy-pages-while-writing-out.patch text/x-diff 11.6 KB
v11-0007-WIP-Make-UnlockReleaseBuffer-more-efficient.patch text/x-diff 3.5 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2026-01-14 21:33:03 Re: AIX support
Previous Message Matheus Alcantara 2026-01-14 21:15:47 Re: how to gate experimental features (SQL/PGQ)