pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Avoid locking when an LSN waiter is already removed
2+ messages / 1 participants
[nested] [flat]

* pgsql: Avoid locking when an LSN waiter is already removed
@ 2026-08-18 12:02  Alexander Korotkov <akorotkov@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Alexander Korotkov @ 2026-08-18 12:02 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* pgsql: Avoid locking when an LSN waiter is already removed
@ 2026-08-18 12:02  Alexander Korotkov <akorotkov@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Alexander Korotkov @ 2026-08-18 12:02 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2026-08-18 12:02 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-08-18 12:02 pgsql: Avoid locking when an LSN waiter is already removed Alexander Korotkov <akorotkov@postgresql.org>
2026-08-18 12:02 pgsql: Avoid locking when an LSN waiter is already removed Alexander Korotkov <akorotkov@postgresql.org>

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