pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Yuhang Qiu <iamqyh@gmail.com>
To: Alexandre Felipe <o.alexandre.felipe@gmail.com>
Cc: Andres Freund <andres@anarazel.de>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: [PATCH] bufmgr: tighten LWLock:BufferMapping on InvalidateBuffer
Date: Tue, 25 Aug 2026 18:37:11 +0800
Message-ID: <C3EB5EF4-4F93-4715-837B-F45C20A3F57C@gmail.com> (raw)
In-Reply-To: <CAE8JnxMkTbEFTfLpa1+6yAJpxih8QOLTLpAvscATHLEjCOR4Mg@mail.gmail.com>
References: <CAE8JnxOR9cJtXGG-3Ki33zHyh5oEcuVeRqeToEvu-44T+R-DnA@mail.gmail.com>
	<hsnzvaqgbcy5z273m3ha773xhvinvdvxbssl6bz67w4spgg2h3@zv77ylqbly5m>
	<CAE8JnxN38Ms3N+2NAVk+hoNiZty4hLAWajNo1nitCXhhjqAbvA@mail.gmail.com>
	<CAE8JnxN5Ot8HN3x=7vqo8NdwJux51=UQ5ArW5E-Dq=tKEtZMcg@mail.gmail.com>
	<wgdm7wmxmw4bprczss5adlrw523n4k7sb6imqir2ffculhj5lr@lkbykmjlkzsl>
	<CAE8JnxP0HJ53Z7t0-vUh23We04GAZ658pa8=K-mVY90PoUhH8Q@mail.gmail.com>
	<B9C99A9B-E480-411E-BFC8-4343195B3EAA@gmail.com>
	<CAE8JnxMv=Di26-XYhVGTcpEUKRaygvcdQMbTx8noa=poYkUjFA@mail.gmail.com>
	<lp2wqvtafhtyxxy3tr27haf7shgq2qhtq2rfsfihpg56zmb6nw@5zvkv7upyctk>
	<CAE8JnxMkTbEFTfLpa1+6yAJpxih8QOLTLpAvscATHLEjCOR4Mg@mail.gmail.com>

Hi Alexandre,

Thanks for sharing the experiments. I have a few concerns.

The benchmark runs in a single backend. This mainly measures instruction and
branch overhead. Saving a few nanoseconds here does not necessarily result
in a measurable end-to-end improvement.

The patch also adds more interfaces and makes the locking code harder to use
and maintain. Some changes seem to move costs rather than remove them.

In 0002, LWLockAcquire is declared as a non-static inline function, while its
external definition is removed, when the compiler does not inline it, for
example with -O0, this whill leave an unresolved LWLockAcquire symbol and
causes a link failure: 
```C
inline bool LWLockAcquire(LWLock *lock, LWLockMode mode)
```

In 0005, queued is not initialized and is never set to true after queueing,
This can cause repeated queueing, incorrect dequeueing, or prevent the backend
from reaching the normal sleep path:
```C
bool queued;

if (!queued)
{
LWLockQueueSelf(lock, mode);
continue;
}
```

I think it would be more useful to reduce unnecessary LWLock acquisitions or 
contention in higher-level code paths, such as buffer mapping and WAL buffers.
For LWLock itself, the important part are atomic operations and cache-line
contention (though there might be no lock contention, but at CPU level, emmm),
wait-list contention, sleep/wakeup mechanism, and fairness...

Best Regards,
Yuhang Qiu.







view thread (13+ messages)  latest in thread

Message-ID: <C3EB5EF4-4F93-4715-837B-F45C20A3F57C@gmail.com>
Permalink:  ../C3EB5EF4-4F93-4715-837B-F45C20A3F57C@gmail.com/
Also on:    postgresql.org/message-id/C3EB5EF4-4F93-4715-837B-F45C20A3F57C@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: iamqyh@gmail.com, o.alexandre.felipe@gmail.com, andres@anarazel.de
  Subject: Re: [PATCH] bufmgr: tighten LWLock:BufferMapping on InvalidateBuffer
  In-Reply-To: <C3EB5EF4-4F93-4715-837B-F45C20A3F57C@gmail.com>
  References: <CAE8JnxOR9cJtXGG-3Ki33zHyh5oEcuVeRqeToEvu-44T+R-DnA@mail.gmail.com> <hsnzvaqgbcy5z273m3ha773xhvinvdvxbssl6bz67w4spgg2h3@zv77ylqbly5m> <CAE8JnxN38Ms3N+2NAVk+hoNiZty4hLAWajNo1nitCXhhjqAbvA@mail.gmail.com> <CAE8JnxN5Ot8HN3x=7vqo8NdwJux51=UQ5ArW5E-Dq=tKEtZMcg@mail.gmail.com> <wgdm7wmxmw4bprczss5adlrw523n4k7sb6imqir2ffculhj5lr@lkbykmjlkzsl> <CAE8JnxP0HJ53Z7t0-vUh23We04GAZ658pa8=K-mVY90PoUhH8Q@mail.gmail.com> <B9C99A9B-E480-411E-BFC8-4343195B3EAA@gmail.com> <CAE8JnxMv=Di26-XYhVGTcpEUKRaygvcdQMbTx8noa=poYkUjFA@mail.gmail.com> <lp2wqvtafhtyxxy3tr27haf7shgq2qhtq2rfsfihpg56zmb6nw@5zvkv7upyctk> <CAE8JnxMkTbEFTfLpa1+6yAJpxih8QOLTLpAvscATHLEjCOR4Mg@mail.gmail.com> <C3EB5EF4-4F93-4715-837B-F45C20A3F57C@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox