]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Avoid potential spinlock in a signal handler as part of global barriers.
authorAndres Freund <andres@anarazel.de>
Tue, 16 Jun 2020 01:23:10 +0000 (18:23 -0700)
committerAndres Freund <andres@anarazel.de>
Wed, 17 Jun 2020 19:47:13 +0000 (12:47 -0700)
commit09bff91b316e90bf7f523593c1e8000c772cbe52
tree1dc45e3c734b8f9e833cb5f8f69c3de141ef7c47
parent7f932f77c7eb068772355c76cfa48bc5d0260e2f
Avoid potential spinlock in a signal handler as part of global barriers.

On platforms without support for 64bit atomic operations where we also
cannot rely on 64bit reads to have single copy atomicity, such atomics
are implemented using a spinlock based fallback. That means it's not
safe to even read such atomics from within a signal handler (since the
signal handler might run when the spinlock already is held).

To avoid this issue defer global barrier processing out of the signal
handler. Instead of checking local / shared barrier generation to
determine whether to set ProcSignalBarrierPending, introduce
PROCSIGNAL_BARRIER and always set ProcSignalBarrierPending when
receiving such a signal. Additionally avoid redundant work in
ProcessProcSignalBarrier if ProcSignalBarrierPending is unnecessarily.

Also do a small amount of other polishing.

Author: Andres Freund
Reviewed-By: Robert Haas
Discussion: https://postgr.es/m/20200609193723.eu5ilsjxwdpyxhgz@alap3.anarazel.de
Backpatch: 13-, where the code was introduced.
src/backend/storage/ipc/procsignal.c
src/include/storage/procsignal.h