Re: [PATCH] bufmgr: tighten LWLock:BufferMapping on InvalidateBuffer

From: Alexandre Felipe <o(dot)alexandre(dot)felipe(at)gmail(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: Yuhang Qiu <iamqyh(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [PATCH] bufmgr: tighten LWLock:BufferMapping on InvalidateBuffer
Date: 2026-08-24 21:01:43
Message-ID: CAE8JnxMkTbEFTfLpa1+6yAJpxih8QOLTLpAvscATHLEjCOR4Mg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Aug 24, 2026 at 1:25 PM Andres Freund <andres(at)anarazel(dot)de> wrote:

> On 2026-08-24 09:16:28 +0100, Alexandre Felipe wrote:
> > I also studied the current LWLock the implementation and there is room to
> > make the no-contention path faster. Is that something worth doing,
> > or is it pointless?
>
> Hard to say without knowing what you're actually going to propose. Of couse
> making the uncontended path faster is attractive, but correctness /
> complexity
> / contended performance all are also not uninmportant.
>

Here I include the experiments. Maybe you don't want to use this
implementation
but it might give you some hints to write a faster version that you like.

There are no algorithmic changes. The changes are about

0002 having two distinct paths for LW_EXCLUSIVE and LW_SHARED,
the rest is diminishing returns. And also added LWLockReleaseLast,
added wrappers as inline functions in lwlock.h that compiles the
current code base replacing the calls
LWLockAcquire(lock, LW_EXCLUSIVE | LW_SHARED) by the
LWLockAcquire(Exclusive|Shared)(lock)

0003 reading the mode from the LWLock state and saving space and time
storing it in the held lwlocks array.
0004 well, bring LWLock(Acquire/Release)X external functions that take
mode as a parameter (a baseline).
0005 Inlined LWLockAttemptLock and folded the loop, placing a single
LWLockAttemptLock at the top of the loop followed by the common logic
(previously at the end bottom of the function), then enqueue and continue
or wait.

Regards,
Alexandre

Attachment Content-Type Size
0002-LWLock-fast-paths.patch application/octet-stream 12.4 KB
0004-mode-as-a-dynamic-parameter.patch application/octet-stream 3.2 KB
0001-Benchmark.patch application/octet-stream 18.0 KB
0003-lwlock-Save-only-pointer.patch application/octet-stream 6.5 KB
0005-Inline-attempt-and-fold-acquire-loop.patch application/octet-stream 4.5 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Nathan Bossart 2026-08-24 21:34:54 Re: problems with toast.* reloptions
Previous Message Mihail Nikalayeu 2026-08-24 20:50:45 Re: Apply worker can pick an invalid index for REPLICA IDENTITY FULL lookups