Re: Interrupts vs signals

From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de>, Robert Haas <robertmhaas(at)gmail(dot)com>
Subject: Re: Interrupts vs signals
Date: 2024-08-24 17:17:47
Message-ID: 476672e7-62f1-4cab-a822-f3a8e949dd3f@iki.fi
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 07/08/2024 17:59, Heikki Linnakangas wrote:
> I'm also wondering about the relationship between interrupts and
> latches. Currently, SendInterrupt sets a latch to wake up the target
> process. I wonder if it should be the other way 'round? Move all the
> wakeup code, with the signalfd, the self-pipe etc to interrupt.c, and in
> SetLatch, call SendInterrupt to wake up the target process? Somehow that
> feels more natural to me, I think.

I explored that a little, see attached patch set. It's going towards the
same end state as your patches, I think, but it starts from different
angle. In a nutshell:

Remove Latch as an abstraction, and replace all use of Latches with
Interrupts. When I originally created the Latch abstraction, I imagined
that we would have different latches for different purposes, but in
reality, almost all code just used the general-purpose "process latch".
this patch accepts that reality and replaces the Latch struct directly
with the interrupt mask in PGPROC.

This initially defines only two interrupts. INTERRUPT_GENERAL_WAKEUP is
the main one, sending that interrupt to a process replaces setting the
process's generic process latch in PGPROC:

* SetLatch(MyLatch) -> RaiseInterrupt(INTERRUPT_GENERAL_WAKEUP)

* SetLatch(&ProcGlobal->allProcs[procno].procLatch) ->
SendInterrupt(procno, INTERRUPT_GENERAL_WAKEUP

* ResetLatch(MyLatch) -> ClearInterrupt(INTERRUPT_GENERAL_WAKEUP)

* WaitLatch(MyLatch) -> WaitInterrupt(1 << INTERRUPT_GENERAL_WAKEUP)

There was only one extra Latch in addition the process's generic
procLatch, the recoveryWakeupLatch. It's replaced by the second
interrupt bit, INTERRUPT_RECOVERY_WAKEUP.

This is complementary or preliminary work to your patch set. All the
changes to replace ProcSignals with different interrupt bits could go on
top of this.

This patch set is work in progress, I'd love to hear your thoughts on
this before I spent more time on this. (Haven't tested on Windows for
example).

Patches 0001 - 0006 are just little cleanups and minor refactorings that
I think make sense even without the rest of the work, though.

0007 is the main patch.

Patch 0010 addresses the problem discussed at
https://www.postgresql.org/message-id/CALDaNm01_KEgHM1tKtgXkCGLJ5209SMSmGw3UmhZbOz365_%3DeA%40mail.gmail.com.
Other solutions are discussed on that thread, but while working on
these, I realized that with these new interrupts, it's pretty
straightforward to fix by introducing one more interrupt reason.

--
Heikki Linnakangas
Neon (https://neon.tech)

Attachment Content-Type Size
0001-Remove-unused-latch.patch text/x-patch 2.0 KB
0002-Remove-unneeded-include.patch text/x-patch 769 bytes
0003-Rename-SetWalSummarizerLatch-function.patch text/x-patch 2.3 KB
0004-Address-walwriter-and-checkpointer-by-proc-number.patch text/x-patch 4.5 KB
0005-Address-walreceiver-by-procno-not-direct-pointer-to-.patch text/x-patch 6.3 KB
0006-Use-proc-number-for-wakeups-in-waitlsn.c.patch text/x-patch 4.5 KB
0007-Replace-Latches-with-Interrupts.patch text/x-patch 130.1 KB
0008-Replace-ProcSendSignal-ProcWaitForSignal-with-new-in.patch text/x-patch 5.5 KB
0009-Replace-all-remaining-Latch-calls-with-new-Interrupt.patch text/x-patch 69.9 KB
0010-Fix-lost-wakeup-issue-in-logical-replication-launche.patch text/x-patch 3.7 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2024-08-24 18:17:20 Re: Optimize mul_var() for var1ndigits >= 8
Previous Message Michail Nikolaev 2024-08-24 15:52:00 Re: Issues with ON CONFLICT UPDATE and REINDEX CONCURRENTLY