Re: Using WaitEventSet in the postmaster
Andres Freund <andres@anarazel.de>
From: Andres Freund <andres@anarazel.de>
To: Thomas Munro <thomas.munro@gmail.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2022-12-02T01:40:22Z
Lists: pgsql-hackers
Hi, On 2022-12-02 10:12:25 +1300, Thomas Munro wrote: > Here's a work-in-progress patch that uses WaitEventSet for the main > event loop in the postmaster Wee! > with a latch as the wakeup mechanism for "PM signals" (requests from > backends to do things like start a background worker, etc). Hm - is that directly related? ISTM that using a WES in the main loop, and changing pmsignal.c to a latch are somewhat separate things? Using a latch for pmsignal.c seems like a larger lift, because it means that all of latch.c needs to be robust against a corrupted struct Latch. > In order to avoid adding a new dependency on the contents of shared > memory, I introduced SetLatchRobustly() that will always use the slow > path kernel wakeup primitive, even in cases where SetLatch() would > not. The idea here is that if one backend trashes shared memory, > others backends can still wake the postmaster even though it may > appear that the postmaster isn't waiting or the latch is already set. Why is that a concern that needs to be addressed? ISTM that the important thing is that either a) the postmaster's latch can't be corrupted, because it's not shared with backends or b) struct Latch can be overwritten with random contents without causing additional problems in postmaster. I don't think b) is the case as the patch stands. Imagine some process overwriting pm_latch->owner_pid. That'd then break the SetLatch() in postmaster's signal handler, because it wouldn't realize that itself needs to be woken up, and we'd just signal some random process. It doesn't seem trivial (but not impossible either) to make SetLatch() robust against arbitrary corruption. So it seems easier to me to just put the latch in process local memory, and do a SetLatch() in postmaster's SIGUSR1 handler. Greetings, Andres Freund
Commits
-
Remove unneeded volatile qualifiers from postmaster.c.
- 8d2c1913ed3d 16.0 landed
-
Fix WaitEventSetWait() buffer overrun.
- f1821b58fc8d 16.0 landed
- 8a98523a542f 15.2 landed
- 547e60b8317e 14.7 landed
- c159b0383fa6 13.10 landed
- bf388ab82850 12.14 landed
- 1b40710a8c89 11.19 landed
-
Refactor DetermineSleepTime() to use milliseconds.
- 5a26c7b310b6 16.0 landed
-
Use WaitEventSet API for postmaster's event loop.
- 7389aad63666 16.0 landed
-
Allow parent's WaitEventSets to be freed after fork().
- b5d0f8ec01c0 16.0 landed
-
Don't leak a signalfd when using latches in the postmaster.
- 1f0019de2fe3 16.0 landed
-
Add WL_SOCKET_ACCEPT event to WaitEventSet API.
- 30829e52ff1a 16.0 landed
-
From: Phil Thompson <phil@river-bank.demon.co.uk>
- d5bbe2aca55b 7.1.1 cited