pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Heikki Linnakangas <heikki.linnakangas@iki.fi>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Split ProcSleep function into JoinWaitQueue and ProcSleep
Date: Mon, 04 Nov 2024 16:02:36 +0000
Message-ID: <E1t7zXI-0009xX-I2@gemulon.postgresql.org> (raw)

Split ProcSleep function into JoinWaitQueue and ProcSleep

Split ProcSleep into two functions: JoinWaitQueue and ProcSleep.
JoinWaitQueue is called while holding the partition lock, and inserts
the current process to the wait queue, while ProcSleep() does the
actual sleeping. ProcSleep() is now called without holding the
partition lock, and it no longer re-acquires the partition lock before
returning. That makes the wakeup a little cheaper. Once upon a time,
re-acquiring the partition lock was needed to prevent a signal handler
from longjmping out at a bad time, but these days our signal handlers
just set flags, and longjmping can only happen at points where we
explicitly run CHECK_FOR_INTERRUPTS().

If JoinWaitQueue detects an "early deadlock" before even joining the
wait queue, it returns without changing the shared lock entry, leaving
the cleanup of the shared lock entry to the caller. This makes the
handling of an early deadlock the same as the dontWait=true case.

One small user-visible side-effect of this refactoring is that we now
only set the 'ps' title to say "waiting" when we actually enter the
sleep, not when the lock is skipped because dontWait=true, or when a
deadlock is detected early before entering the sleep.

This eliminates the 'lockAwaited' global variable in proc.c, which was
largely redundant with 'awaitedLock' in lock.c

Note: Updating the local lock table is now the caller's responsibility.
JoinWaitQueue and ProcSleep are now only responsible for modifying the
shared state. Seems a little nicer that way.

Based on Thomas Munro's earlier patch and observation that ProcSleep
doesn't really need to re-acquire the partition lock.

Reviewed-by: Maxim Orlov
Discussion: https://www.postgresql.org/message-id/7c2090cd-a72a-4e34-afaa-6dd2ef31440e@iki.fi

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/3c0fd64fec8ed6fa3987c33f076fcffbc3f268c3

Modified Files
--------------
src/backend/storage/lmgr/lock.c | 216 +++++++++++++++++++++-------------------
src/backend/storage/lmgr/proc.c | 144 +++++++++++++--------------
src/backend/tcop/postgres.c     |   2 +-
src/include/storage/lock.h      |   2 +
src/include/storage/proc.h      |   7 +-
5 files changed, 185 insertions(+), 186 deletions(-)



Message-ID: <E1t7zXI-0009xX-I2@gemulon.postgresql.org>
Permalink:  ../E1t7zXI-0009xX-I2@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1t7zXI-0009xX-I2@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: heikki.linnakangas@iki.fi, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Split ProcSleep function into JoinWaitQueue and ProcSleep
  In-Reply-To: <E1t7zXI-0009xX-I2@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