Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uf44j-001gDb-6B for pgsql-hackers@arkaria.postgresql.org; Thu, 24 Jul 2025 22:06:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uf44i-00BoSJ-AA for pgsql-hackers@arkaria.postgresql.org; Thu, 24 Jul 2025 22:06:04 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uf44h-00BoS8-Dl for pgsql-hackers@lists.postgresql.org; Thu, 24 Jul 2025 22:06:04 +0000 Received: from fout-a7-smtp.messagingengine.com ([103.168.172.150]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uf44d-000fqa-0p for pgsql-hackers@postgresql.org; Thu, 24 Jul 2025 22:06:03 +0000 Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfout.phl.internal (Postfix) with ESMTP id 9FE1DEC0212; Thu, 24 Jul 2025 18:05:57 -0400 (EDT) Received: from phl-imap-03 ([10.202.2.93]) by phl-compute-04.internal (MEProxy); Thu, 24 Jul 2025 18:05:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=compiler.org; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1753394757; x=1753481157; bh=IL+KBwBNJ/UnGghxG+d3AHHip8dbCLOWPcIO1yhPEF4=; b= qo1fzz/GCC0z3Lr34578O9ubJV6tFh6jZ8dT6/A/VGrCgMF2K/ASABkaTFeFDiFL g8tTSLy6PPWhcC4J0B7bxkW+WZ1Vy08Nr44OP3NOTQvuQHAJmel4fR1FuEI0HWHf 7k3t3uUSp+8z4kpdeTOVm4ucp+rgEqkbr+aCzrFH4rGFKLiGfAhpHsvIDP5YienY QGwYGjV0qY3gECprzvFdTPdBCa8CfGRkv/Ii87abJKWQ0yTfWMmjayu9eqE/Bmfa m70evQEQzivdeyi4shIv0ATbLUyoxbVi992hp98Z1hghRe9+4bg5MRPeHUOfd1O0 rJCWER0qrPhRKqUjtX7CMw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1753394757; x= 1753481157; bh=IL+KBwBNJ/UnGghxG+d3AHHip8dbCLOWPcIO1yhPEF4=; b=R 13luktGUzv2D9a3Sh0wKDVav0vVGYqes6uagxHoygpxiHkyUf+86qDHgVDyMh3uo Yuj/rR1sJJBjiAZ+Gt9F9WSvrzBXKmKihZgY2CiecfPCF+64+nKuNj3M04AHzARb W+ewoCFyUtfl3BoDy+TneRdVOvk5cMF+o/eqNvQPyDp3gDbbfmkyL67AFmPwjNNc lvbezs1Z64MRblvWOkE/qL+8ktfgE/nTIvzj1Sudr6mgXoS8eKBScKNg4qY5JHj+ SZ5Kx3ohUUbf5APFD4pTdVXJNp/IKUBYYBvMeH0ngbVCB1b/+MOVbo1tIFjX7Ssd o33JfG210cNfOSccSqnVQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdekudekudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefoggffhffvvefkjghfufgtgfesthhqredtredtjeenucfhrhhomhepfdflohgvlhcu lfgrtghosghsohhnfdcuoehjohgvlhestghomhhpihhlvghrrdhorhhgqeenucggtffrrg htthgvrhhnpefgtdfffeejgeekgeekhedtvdfhffeigfffuefglefftdetieehtdekhfej tedvleenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgnecuvehluhhsthgvrh fuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepjhhovghlsegtohhmphhilhgv rhdrohhrghdpnhgspghrtghpthhtohepjedpmhhouggvpehsmhhtphhouhhtpdhrtghpth htoheprghnughrvghssegrnhgrrhgriigvlhdruggvpdhrtghpthhtohepmhgrshgrohdr fhhujhhiihesghhmrghilhdrtghomhdprhgtphhtthhopehrohgsvghrthhmhhgrrghsse hgmhgrihhlrdgtohhmpdhrtghpthhtohepthhhohhmrghsrdhmuhhnrhhosehgmhgrihhl rdgtohhmpdhrtghpthhtohephhhlihhnnhgrkhgrsehikhhirdhfihdprhgtphhtthhope hmihgthhgrvghlsehprghquhhivghrrdighiiipdhrtghpthhtohepphhgshhqlhdqhhgr tghkvghrshesphhoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: ic6394509:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 3876318E0063; Thu, 24 Jul 2025 18:05:57 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface MIME-Version: 1.0 X-ThreadId: Tbc993bc5b4253b09 Date: Fri, 25 Jul 2025 00:04:31 +0200 From: "Joel Jacobson" To: "Heikki Linnakangas" , "Andres Freund" , "Thomas Munro" Cc: "Michael Paquier" , "Robert Haas" , "Fujii Masao" , pgsql-hackers Message-Id: <21a544b7-febe-41ee-a702-8a68e0cf0010@app.fastmail.com> In-Reply-To: References: <8a0ff52f-de8e-49d2-a3af-ea5bc12f5b97@iki.fi> <4ddab51d-e932-40c5-b6fa-18c52db0e082@iki.fi> <08382e5c-a820-4aca-90ac-fab50cd4599c@iki.fi> Subject: Re: Interrupts vs signals Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Jul 23, 2025, at 09:42, Joel Jacobson wrote: > Great work in this thread. I'll try to help, definitively benchmarking, > but will also try to load the new design into my brain, to get the > correct mental model of it, so I can hopefully help with code review as > well. First, my apologies for joining this long-running discussion late. Following up on my email in the "Optimize LISTEN/NOTIFY" thread [1], I wanted to elaborate on the architectural pattern my patches demonstrate, as I believe it's highly complementary to the work being done here. The fundamental distinction is between decoupled vs. combined state management. The v7 patch set creates a new Interrupt system where the wakeup mechanism and the 'pending' state for all subsystems are combined into a single, centralized atomic bitmask. My work explores an alternative: decoupling the two. The insight is that many of our legacy subsystems were designed to be stateless because they lacked the atomics and WaitEventSet abstractions we have today. The signal was a workaround for this state management limitation. This suggests a powerful, three-step migration pattern: Step 1: Decouple state management with a lock-free atomic FSM. Each subsystem should be empowered to manage its own state. My first patch for async.c [1] demonstrates this by introducing a lock-free, atomic finite state machine (FSM). Using a subsystem-specific atomic integer and CAS operations, async.c now robustly manages its own IDLE, SIGNALLED, PROCESSING states without any locks. This solves the state synchronization problem directly and eliminates the vast majority of redundant wakeups. Step 2: Trivialize the wake-up with a generic poke. Once state is managed reliably, the expensive kill(pid, SIGUSR1) syscall can be trivially replaced with a direct SetLatch, as shown in my second patch [1]. This is a simple and effective intermediate step that leverag= es the existing WaitEventSet infrastructure to make the wakeup much cheaper. Step 3: Decouple event dispatch with specific interrupts. The final goal is to replace the generic poke with SendInterrupt using a specific reason (e.g., INTERRUPT_ASYNC_NOTIFY). This lets the event loop wait on a bitmask of interrupt reasons and, on wakeup, dispatch only to the relevant subsystem handler=E2=80=94fully decoupling event handling f= rom subsystem details. This three-step, vertical migration strategy (subsystem by subsystem) seems to offer a powerful alternative to a horizontal, layer-by-layer replacement. It allows each subsystem's logic to be self-contained and avoids constraints on a single global interrupt mask. The core WaitEventSet is kept simple: its only job is to provide the efficient, multiplexed wait. I believe the ideal architecture uses your unified Interrupt system as the low-level primitive, while encouraging key subsystems to adopt these decoupled FSMs to determine *when* to call SendInterrupt. I'm happy to help with this effort in any way I can. /Joel [1] https://www.postgresql.org/message-id/0b4d402a-9ac2-4aa8-acf8-8231db= e579ea%40app.fastmail.com