pgsql: Move deadlock and other interrupt handling in proc.c out of sign - Mailing list pgsql-committers

From Andres Freund
Subject pgsql: Move deadlock and other interrupt handling in proc.c out of sign
Date
Msg-id E1YIltm-0007KD-Sy@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Move deadlock and other interrupt handling in proc.c out of signal handlers.

Deadlock checking was performed inside signal handlers up to
now. While it's a remarkable feat to have made this work reliably,
it's quite complex to understand why that is the case. Partially it
worked due to the assumption that semaphores are signal safe - which
is not actually documented to be the case for sysv semaphores.

The reason we had to rely on performing this work inside signal
handlers is that semaphores aren't guaranteed to be interruptable by
signals on all platforms. But now that latches provide a somewhat
similar API, which actually has the guarantee of being interruptible,
we can avoid doing so.

Signalling between ProcSleep, ProcWakeup, ProcWaitForSignal and
ProcSendSignal is now done using latches. This increases the
likelihood of spurious wakeups. As spurious wakeup already were
possible and aren't likely to be frequent enough to be an actual
problem, this seems acceptable.

This change would allow for further simplification of the deadlock
checking, now that it doesn't have to run in a signal handler. But
even if I were motivated to do so right now, it would still be better
to do that separately. Such a cleanup shouldn't have to be reviewed a
the same time as the more fundamental changes in this commit.

There is one possible usability regression due to this commit. Namely
it is more likely than before that log_lock_waits messages are output
more than once.

Reviewed-By: Heikki Linnakangas

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/6753333f55e1d9bcb9da4323556b456583624a07

Modified Files
--------------
src/backend/storage/lmgr/proc.c   |  131 +++++++++++++++++--------------------
src/backend/utils/init/postinit.c |    2 +-
src/include/storage/proc.h        |    2 +-
3 files changed, 63 insertions(+), 72 deletions(-)


pgsql-committers by date:

Previous
From: Andres Freund
Date:
Subject: pgsql: Don't allow immediate interrupts during authentication anymore.
Next
From: Andres Freund
Date:
Subject: pgsql: Remove the option to service interrupts during PGSemaphoreLock()