| From: | Greg Burd <greg(at)burd(dot)me> |
|---|---|
| To: | Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com> |
| Cc: | pgsql-hackers(at)lists(dot)postgresql(dot)org, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Andres Freund <andres(at)anarazel(dot)de>, Thomas Munro <thomas(dot)munro(at)gmail(dot)com> |
| Subject: | Re: Interrupts vs signals |
| Date: | 2026-11-26 16:24:42 |
| Message-ID: | 179563744102.730.2558622331815624024@burd.me |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Wed, Nov 11, 2026 at 4:05 PM Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com> wrote:
Hi Zsolt,
Thanks for catching the single-user regression from 2e2751e6976. That
sent me back into the series, and the review turned up a few real bugs
in the big patch too.
For anyone joining now: this series replaces latches and most
ProcSignals with per-process interrupt bits in PGPROC. A process waits
for a set of bits with WaitInterrupt(), other processes set them with
SendInterrupt() by ProcNumber, and CHECK_FOR_INTERRUPTS() calls handlers
registered per bit. Heikki posted v13 in June [1] and keeps a rebased
copy on his GitHub; v14 is that rebased onto current master, your fix in
front, and the fixes below folded into the commits they belong to.
Heikki's sinval catchup fix stays as 0002 because 0009 is built on top
of it; it is under review on its own thread [2]. His AI-generated test
for it is left out, since he said there that he doesn't intend to commit
it. For anyone who has read Heikki's branch, the attached
nocfbot-v14-review-fixes.diff shows only my changes to it.
0001 is your patch. I reproduced the failure on master with your script
and confirmed 0001 fixes it. The only change is its comment, which now
points at SetPostmasterChildSignalHandlers(), where 0009 moves the
SIGCHLD reset.
Design changes in 0009:
- Checkpointer and full_page_writes.
v13 ran the checkpointer's config reload from CHECK_FOR_INTERRUPTS(),
and added one at the top of CheckpointWriteDelay(), ahead of the
shutdown checks. So a SIGHUP that turns full_page_writes off during
the shutdown checkpoint wrote XLOG_FPW_CHANGE after the redo pointer,
and the checkpoint failed with "PANIC: concurrent write-ahead log
activity while database system is shutting down".
The checkpointer now disables INTERRUPT_CONFIG_RELOAD once it sees
INTERRUPT_SHUTDOWN_XLOG, which also covers the CHECK_FOR_INTERRUPTS()
in errfinish(). The alternative, moving the CHECK_FOR_INTERRUPTS()
back under the shutdown checks, would leave every other one reachable
from CreateCheckPoint() open.
Master has a milder form of the same bug after the checkpoint
completes; Aleksandr Korchak posted a fix for it today [3]. With 0009
applied, this change covers his case too.
- volatile holdoff counters.
v13 made HOLD_INTERRUPTS() and START_CRIT_SECTION() also store to
MyPendingInterruptsFlags, and dropped volatile from
InterruptHoldoffCount and CritSectionCount. handle_sig_alarm() still
does HOLD/RESUME_INTERRUPTS(), and gcc -O2 does reorder the stores: in
_hash_doinsert() the pointer store comes before the "addl $1" on
CritSectionCount. A SIGALRM between the two would restore the real
flags pointer inside the critical section.
The two counters and the pointer are volatile again. That adds 239
bytes of text, and a CHECK_FOR_INTERRUPTS()-heavy seqscan and pgbench
-S at 1 and 64 clients are within noise of master either way. Dropping
the HOLD/RESUME pair from handle_sig_alarm() would also work, but then
nothing would enforce what its comment promises.
- Deferred recovery conflicts.
When report_recovery_conflict() can't throw because query cancel is
disabled, v13 re-raised INTERRUPT_RECOVERY_CONFLICT. The bit is still
enabled, so every CHECK_FOR_INTERRUPTS() and every wait returned at
once. The slotsync worker never enabled INTERRUPT_QUERY_CANCEL, so a
logical-slot conflict made it spin forever: about 96% CPU in a probe
that injects the conflict with gdb.
Now the conflict is only recorded, and a new
ResumeQueryCancelInterrupt() raises it again where SocketBackend(),
CopyGetData() and the walsender's manifest reader re-enable cancel.
The slotsync worker gets the query-cancel handler, which it had on
master through StatementCancelHandler. With that, the worker in the
probe throws "canceling statement due to conflict with recovery" and
restarts, which is what master's code does.
- SendInterruptWithPid() held ProcArrayLock to keep the PID check and
the send together, but neither ProcKill() nor InitProcess() holds it
when changing pid.
It now checks the PID and sets the bits under freeProcsLock. A new
occupant must pop the slot from the freelist under that lock and then
clears the slot's pending interrupts, so the bits either reach the
intended process or are discarded. The wakeup happens after the lock
is released.
- The postmaster passed notify_proc_number from shared memory straight
to SendInterrupt() in four of the five places it reads it. All five
go through one range-checking helper now.
- RequestAddinInterrupt() handed out bits from a per-process counter, as
Andres pointed out in February, so an extension loaded on demand in
one backend could get the same bit as a different extension in
another.
It now errors unless called from shared_preload_libraries, as
RegisterCustomRmgr() does. There's still no in-tree user; a test
module that uses it would be a good follow-up.
Smaller fixes, all in 0009:
- die() in single-user mode respects INTERRUPTS_CAN_BE_PROCESSED(), as
ProcessInterrupts() did on master.
- The checkpointer's write-delay nap wakes for the shutdown interrupts.
- Four leftover bgw_notify_pid assignments are gone.
- A stale ProcessRecoveryConflictInterrupts() prototype is removed.
- pg_interrupt_handler_t is added to typedefs.list.
Open questions:
1. Heikki: do you want registrants of dynamic background workers to get
INTERRUPT_WAIT_WAKEUP by default, as 0009 does now? It also widens
ForgetUnstartedBackgroundWorkers() to every unstarted dynamic worker,
not only those whose registrant asked to wait. I think yes, and the
docs already say so, but it changes behavior for extensions.
2. Should bgw_notify_pid be removed rather than kept "not used"? An
extension that reads MyBgworkerEntry->bgw_notify_pid to find its
registrant now gets 0 without a compile error. Removing it would make
that a build failure, which seems better than a silent hang.
Results, all on the posted version: every patch builds on its own with
-Werror, and meson test reports 398 passed and 0 failed, on Fedora 44
with gcc 16 and cassert. The fork's CI is green on Linux (autoconf,
meson 32- and 64-bit), Windows MSVC and MinGW, and CompilerWarnings.
GitHub never found a macOS runner for it, so cfbot will be the first
macOS run.
Benchmarks and the NOTIFY analysis are in the attached notes.txt. In
short, NOTIFY senders look 8% slower when the listeners loop on
pg_sleep(), but only because those listeners wake 42% less often and
spend the CPU they save on their own loop. With idle or rate-capped
listeners, sender throughput is the same as master.
v14 attached, rebased onto 4483697be0e.
best.
-greg
[1] https://postgr.es/m/0aac2b1a-ec0f-4bb6-a786-760e6cea4d1d@iki.fi
[2] https://postgr.es/m/42b2c4f9-511e-4b5c-8edd-b474019ddf29@iki.fi
[3] https://postgr.es/m/CAEBMo=D+fQ6vAw_TOpTQyL4h_+jHo1CMEDEuMzapN79-PsnKEw@mail.gmail.com
| Attachment | Content-Type | Size |
|---|---|---|
| v14-0002-Fix-losing-a-sinval-catchup-signal-that-arrives-.patch | text/x-patch | 5.2 KB |
| v14-0001-Reset-SIGCHLD-in-standalone-backends-too.patch | text/x-patch | 1.5 KB |
| v14-0007-Remove-dependency-on-utils-resowner.h-just-for-R.patch | text/x-patch | 3.1 KB |
| v14-0004-Refactor-datachecksums-launcher-worker-comms-to-.patch | text/x-patch | 5.9 KB |
| v14-0003-Refactor-PARALLEL_MESSAGE-procsignal-signaling.patch | text/x-patch | 17.6 KB |
| nocfbot-v14-review-fixes.diff | text/x-patch | 21.5 KB |
| v14-0006-Rename-postmaster-interrupt.c-to-ipc-signal_hand.patch | text/x-patch | 21.3 KB |
| notes.txt | text/plain | 5.7 KB |
| v14-0008-Remove-unnecessary-include-from-tcopprot.h.patch | text/x-patch | 4.5 KB |
| v14-0005-Move-CHECK_FOR_INTERRUPTS-and-friends-to-new-ipc.patch | text/x-patch | 123.4 KB |
| v14-0009-Replace-Latches-with-Interrupts.patch | text/x-patch | 537.7 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Antonin Houska | 2026-11-26 16:33:19 | Re: Allow progress tracking of sub-commands |
| Previous Message | Laurenz Albe | 2026-11-26 16:12:32 | Re: passwordcheck: Make the user name check case-insensitive |