Re: Interrupts vs signals
Heikki Linnakangas <hlinnaka@iki.fi>
From: Heikki Linnakangas <hlinnaka@iki.fi>
To: Thomas Munro <thomas.munro@gmail.com>
Cc: Michael Paquier <michael@paquier.xyz>, Robert Haas
<robertmhaas@gmail.com>, Fujii Masao <masao.fujii@gmail.com>,
pgsql-hackers <pgsql-hackers@postgresql.org>,
Andres Freund <andres@anarazel.de>
Date: 2024-12-02T10:42:20Z
Lists: pgsql-hackers
On 02/12/2024 09:32, Thomas Munro wrote: > On Sat, Nov 23, 2024 at 10:58 AM Heikki Linnakangas <hlinnaka@iki.fi> wrote: >> Hmm, so this would replace the maybeSleepingOnInterrupts bitmask I >> envisioned. Makes a lot of sense. If it's a single bit though, that >> means that you'll still get woken up by interrupts that you're not >> waiting for. Maybe that's fine. Or we could merge the >> maybeSleepingOnInterrupts and pendingInterrupts bitmasks to a single >> atomic word, so that you would have a separate "maybe sleeping" bit for >> each interrupt bit, but could still use atomic_fetch_or atomically read >> the interrupt bits and announce the sleeping. > > I think one bit is fine for now. At least, until we have a serious > problem with interrupts arriving when you're sleeping but not ready to > service that particular interrupt. The 'interrupt bit already set, > don't try to wake me' stuff discussed earlier would limit the number > of useless wakeups to one, until you eventually are ready and consume > the interrupt. The main case I can think of, if we fast forward to > the all-procsignals-become-interrupts patch (which I'll be rebasing on > top of this when the next version appears), is that you might receive > a sinval catchup request, but you might be busy running a long query. > Sinval catchup messages are only processed between queries, so you > just keep ignoring them until end of query. I think that's fine, and > unlikely. Do you have other cases in mind? Yeah, no, I think one bit is is good enough. Let's go with that. > If there is legitimate use case for a more fine-grained maybe-sleeping > and I've been too optimistic above, I don't think we should give one > whole maybe-sleeping bit to each interrupt reason. We only have 32 > bit atomics (splinlock-based emulation of 64 bit atomics is not good > enough for this, it's not safe in SIGALRM handlers, at least not > without a lot more pain; admittedly the SIGALRM handlers should > eventually be replaced but not for a while) so if we used up two bits > for every interrupt reason we could handle only 16 interrupt reasons, > and that's already not enough. Perhaps we could add maybe-sleeping > bits for classes of interrupt if we ever determine that one bit for > all of them isn't enough? If we run out of bits in a single pendingInterrupt words, we can have multiple words. SendInterrupt and ClearInterrupt would still only need to manipulate one word, the one holding the bit it's setting/clearing. WaitEventSetWait() would need to touch all of them, or at least all the ones that hold bits you want to wait for. That seems OK from a performance point of view. I don't think we need to go there any time soon though, 32 bits should be enough for the use cases we've been discussing. -- Heikki Linnakangas Neon (https://neon.tech)
Commits
-
Ignore SIGINT in walwriter and walsummarizer
- a92b809f9da1 19 (unreleased) landed
-
Split WaitEventSet functions to separate source file
- 393e0d231405 18.0 landed
-
Use ModifyWaitEvent to update exit_on_postmaster_death
- 84e5b2f07a5e 18.0 landed
-
Remove unused ShutdownLatchSupport() function
- a98e4dee63ce 18.0 landed
-
Rename two functions that wake up other processes
- 368d8270c838 18.0 landed
-
Use ProcNumbers instead of direct Latch pointers to address other procs
- a9c546a5a378 18.0 landed
-
Clean up WaitLatch calls that passed latch without WL_LATCH_SET
- f9ecb57a506a 18.0 landed
-
Remove unneeded #include
- 094ae071605d 18.0 landed
-
Remove unused latch
- 6c0c49f7d37d 18.0 landed
-
Remove support for background workers without BGWORKER_SHMEM_ACCESS.
- 80a8f95b3bca 15.0 cited