pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alexander Korotkov <akorotkov@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Avoid locking when an LSN waiter is already removed
Date: Tue, 18 Aug 2026 12:02:13 +0000
Message-ID: <E1wwIWC-000000013YP-2AIz@gemulon.postgresql.org> (raw)

Avoid locking when an LSN waiter is already removed

WaitLSNWakeup() removes each selected waiter from its heap and clears
its inHeap flag before setting its latch.  When such a waiter later
calls deleteLSNWaiter(), it acquires WaitLSNLock exclusively only to
discover that there is nothing left to remove.  Waking many waiters can
therefore make them serialize on the lock for no useful work.

Check inHeap before acquiring WaitLSNLock.  A lockless false value is
conclusive because only the owning backend can change inHeap from false
to true.  A concurrent waker can only clear it.  A stale true value
falls through to the existing recheck under the lock.

WaitLSNCleanup() performed the same lockless check before calling
deleteLSNWaiter().  Drop it there, as it is now redundant.

Author: Xuneng Zhou <xunengzhou@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
Discussion: https://postgr.es/m/CABPTF7UtW_cAa%3DQh4RDfKiUqu3pJJE22ai9tbWJVERbeRyssLw%40mail.gmail.com
Backpatch-through: 19

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/0c8dd518a58fb7b65c992d3bb6ce21aa3f4fa9fb

Modified Files
--------------
src/backend/access/transam/xlogwait.c | 27 +++++++++++++++++----------
1 file changed, 17 insertions(+), 10 deletions(-)



view thread (2+ messages)  latest in thread

Message-ID: <E1wwIWC-000000013YP-2AIz@gemulon.postgresql.org>
Permalink:  ../E1wwIWC-000000013YP-2AIz@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1wwIWC-000000013YP-2AIz@gemulon.postgresql.org

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: akorotkov@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Avoid locking when an LSN waiter is already removed
  In-Reply-To: <E1wwIWC-000000013YP-2AIz@gemulon.postgresql.org>

* 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