Notes for v14 of "Interrupts vs signals" ========================================= Host and builds --------------- AWS c7i.8xlarge (32 vCPU, 64 GB), Fedora 44 (ami-0b5ca366db5ab46b6), kernel as shipped, gcc 16.2.1, gp3 root volume. This is a VM, so treat differences under a few percent as noise. THP disabled, governor "performance" where the host allows it. Correctness runs: meson, -Dcassert=true -Ddebug=true -Dtap_tests=enabled -Dinjection_points=true -Dwerror=true. Every commit built on its own; "meson test" at the tip: 398 ok, 0 fail, 30 skipped (ssl, ldap and similar need extra setup). Benchmarks: --buildtype=release, one data directory per build, shared_buffers=8GB, fsync=off, synchronous_commit=off, max_connections=300. "base" is master at the series' base commit, "tip" the series. 1. CHECK_FOR_INTERRUPTS() overhead ---------------------------------- SELECT count(*) FROM cfi WHERE g % 7 = 3 over a 20M-row table, parallel query off (ms, median of 3 per round); pgbench -S -M prepared, 20 s (tps). An A/A round of base first, then 5 interleaved rounds: test base tip diff A/A noise seqscan 20M rows, ms 580.7 561.8 -3.3% 1.1% pgbench -S, 1 client 42,293 42,753 +1.1% 2.7% pgbench -S, 16 686,823 687,571 +0.1% 3.9% pgbench -S, 64 1,752,665 1,753,303 +0.0% 1.5% The volatile holdoff counters in v14 were measured separately, three builds interleaved over 5 rounds, first (cold-cache) round dropped: test base tip (no volatile) tip (v14) seqscan, ms 598.4 606.8 (+1.4%) 600.8 (+0.4%) pgbench -S, 1 41,635 42,117 (+1.2%) 41,140 (-1.2%) pgbench -S, 64 1,673,080 1,663,325 (-0.6%) 1,664,831 (-0.5%) volatile adds 239 bytes of text to the postgres binary. LWLockAcquire() is 138 instructions with and without it. 2. NOTIFY --------- 8 clients running NOTIFY bench_chan, 'x' (pgbench -n, 20 s) while 32 other clients LISTEN on the channel, three listener styles. 3 rounds each, interleaved, medians: listeners (32) sender tps listener tps base tip base tip LISTEN; SELECT pg_sleep(0.001) 78,123 71,194 24,794 27,144 LISTEN; \sleep 1 ms (client side) 56,666 56,632 28,525 28,656 pg_sleep loop, capped -R 20000 75,573 75,539 19,828 19,793 The senders are slower only in the first row, where the listener transactions go up by about the same amount. The two groups share the CPUs and the commit path. perf stat -p on the 32 listener backends, rate-capped, 5 s: epoll_wait returns kill() calls base 3,330,569 1,602,388 tip 1,942,214 0 On master every NOTIFY sets the listener's latch, which wakes it out of pg_sleep() only for it to go back to sleep. With the series, INTERRUPT_ASYNC_NOTIFY isn't in the mask while a query runs, so the listener stays asleep and is notified when it goes idle. With idle or rate-capped listeners, sender throughput is equal. Joel Jacobson saw the same direction on v7 in 2025-07; I believe this is the explanation. 3. Reproducers -------------- a) Single-user SIGCHLD (0001): python3 -c 'import os,signal,sys; signal.signal(signal.SIGCHLD, signal.SIG_IGN); os.execvp(sys.argv[1], sys.argv[1:])' \ postgres --single -D data postgres <<< \ "COPY (SELECT 1) TO PROGRAM 'cat > /dev/null';" master: ERROR: could not close pipe to external command: No child processes v14: no error b) full_page_writes reload during the shutdown checkpoint (0009): shared_buffers=4GB, full_page_writes=on, a 12M-row table updated once so that most buffers are dirty; pg_ctl stop -m fast in the background; once "checkpoint starting: shutdown" is in the log, change full_page_writes to off in postgresql.conf and send SIGHUP to the checkpointer. master: checkpoint completes, then PANIC: cannot make new WAL entries during recovery (Aleksandr Korchak's report from today) v13 rebased: PANIC: concurrent write-ahead log activity while database system is shutting down v14: checkpoint completes, "database system is shut down" c) Deferred recovery conflict spin (0009): Primary with a failover logical slot, standby with sync_replication_slots=on. Once the slot is synced, attach gdb to the slotsync worker and run set var MyProc->pendingRecoveryConflicts.value = (1 << RECOVERY_CONFLICT_LOGICALSLOT) call SendInterrupt(INTERRUPT_RECOVERY_CONFLICT, MyProcNumber) then sample utime+stime from /proc//stat for 5 s. v13 rebased: 479 ticks in 5 s (about 96% of a CPU), worker never exits v14: "ERROR: canceling statement due to conflict with recovery", worker restarts, as on master 4. Compiler output behind the volatile change --------------------------------------------- Release build of the rebased v13, objdump -dr of _hash_doinsert(), the START_CRIT_SECTION() before _hash_pgaddtup(): mov MyPendingInterruptsFlags@GOT,%rsi ... mov ZeroPendingInterruptsFlags@GOT,%rax ... mov CritSectionCount@GOT,%r15 mov %rax,(%rsi) <- MyPendingInterruptsFlags = &Zero... mov %r13d,%esi addl $0x1,(%r15) <- CritSectionCount++ The pointer store comes before the counter increment. A SIGALRM between them sees CritSectionCount == 0, and the RESUME_INTERRUPTS() at the end of handle_sig_alarm() points MyPendingInterruptsFlags back at the real flags, inside the critical section.