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:15 +0000
Message-ID: <E1wwIWE-000000013ZL-0TJs@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
------
REL_19_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/58c48b4ec42583c69b3a7e9c6cf7649b38fc8151
Modified Files
--------------
src/backend/access/transam/xlogwait.c | 27 +++++++++++++++++----------
1 file changed, 17 insertions(+), 10 deletions(-)
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: <E1wwIWE-000000013ZL-0TJs@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