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.96) (envelope-from ) id 1vU8iT-000JOr-1H for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Dec 2025 19:22:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vU8iS-009613-0t for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Dec 2025 19:22:13 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vU8iR-00960u-19 for pgsql-hackers@lists.postgresql.org; Fri, 12 Dec 2025 19:22:12 +0000 Received: from fhigh-b6-smtp.messagingengine.com ([202.12.124.157]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vU8iQ-000MJw-13 for pgsql-hackers@lists.postgresql.org; Fri, 12 Dec 2025 19:22:11 +0000 Received: from phl-compute-02.internal (phl-compute-02.internal [10.202.2.42]) by mailfhigh.stl.internal (Postfix) with ESMTP id 7F9BE7A016A; Fri, 12 Dec 2025 14:22:08 -0500 (EST) Received: from phl-imap-14 ([10.202.2.87]) by phl-compute-02.internal (MEProxy); Fri, 12 Dec 2025 14:22:08 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=burd.me; 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=fm1; t=1765567328; x=1765653728; bh=55ZgCH1dBYNBFtvBNC9w39X0xy6QlXS2BceE1jzJEV8=; b= gD9wCgzjDtChpywPCtpO8Pw2Ls8wi0CmSw4PRUIT2laS2dVKz+6RMkrMCosCBljh WpxbURNQ5xDFc+nZ4PqcKjxB+VyZ49zmb838gEjFmT50pOiFkm9ruAzTIm0L4NYJ nKM9fDGmpd/G+EXWxzLe480XfYeAaG9fdcHkLbn70UaO0uNLkjU9SCTkay6dt3oU i4q2vjd5aBBatFLj4PJCmLjdb3z1Ibfzb+uFx2qPUjhgAI9viMxYALb06kJr7HD9 /NlYqKomDCt8SlkAuv48F4rp2KBaFxnb0kvK2RvwGwy3AK1V0u98SJfgJOsnCdB3 VoxP8ZqQDNfu0rX2qPRuLg== 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=fm1; t=1765567328; x= 1765653728; bh=55ZgCH1dBYNBFtvBNC9w39X0xy6QlXS2BceE1jzJEV8=; b=v CMVlrBPOSGqGabzmeoajh5mbidOrmO0X0bZsGzj/WO9v72EKGZJ2b2mcjOSF8Zyh NIMn73e8e5u6SjPKSA0sXbQvtED/bCRpTrQ0SJUuM6UwA3jxyp2fIqAovw7y1Amz 32cCO/CK4TQqSq+CUMNliEIPz3Z7me4PEqbSDptm4DLRgEaR0VrYdst0aADSVqGl ebBueRJ031y3KPDyBfoUWmudMDb9ew8uT6wOcj8Lj+UprRMg3eANAJVubgFRWyNJ TAHFiFkFStXZjDNepCbcYxBkygi/XBi2VVu/c7kBXKNlKjDKNatNZ2bgk2po8I5Q 5fY5rqvXqbaHf6I0nlDLw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddvledtudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefoggffhffvvefkjghfufgtgfesthejredtredttdenucfhrhhomhepfdfirhgvghcu uehurhgufdcuoehgrhgvghessghurhgurdhmvgeqnecuggftrfgrthhtvghrnhephfelud eggfekjeetgeefveetffduvdehheejveehtedugfelvdduffeiheetheejnecuffhomhgr ihhnpehmihgtrhhoshhofhhtrdgtohhmpdhpohhsthhgrhgvshhqlhdrohhrghenucevlh hushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehgrhgvghessghu rhgurdhmvgdpnhgspghrtghpthhtohepiedpmhhouggvpehsmhhtphhouhhtpdhrtghpth htoheprghnughrvghssegrnhgrrhgriigvlhdruggvpdhrtghpthhtohepphgvthgvrhes vghishgvnhhtrhgruhhtrdhorhhgpdhrtghpthhtohepuggrvhgvtghrrghmvghrsehgmh grihhlrdgtohhmpdhrtghpthhtohepnhgrthhhrghnuggsohhsshgrrhhtsehgmhgrihhl rdgtohhmpdhrtghpthhtohepthhhohhmrghsrdhmuhhnrhhosehgmhgrihhlrdgtohhmpd hrtghpthhtohepphhgshhqlhdqhhgrtghkvghrsheslhhishhtshdrphhoshhtghhrvghs qhhlrdhorhhg X-ME-Proxy: Feedback-ID: i675e48f3:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 0DCDBC4006D; Fri, 12 Dec 2025 14:22:08 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface MIME-Version: 1.0 X-ThreadId: Atr_W4N1XYlB Date: Fri, 12 Dec 2025 14:21:47 -0500 From: "Greg Burd" To: "Nathan Bossart" Cc: "Thomas Munro" , "PostgreSQL Hackers" , "Peter Eisentraut" , "Dave Cramer" , "Andres Freund" Message-Id: <8e926f26-0a97-434f-a665-8bb6f9159b08@app.fastmail.com> In-Reply-To: References: <386595D6-0373-4E08-BC00-D8F17F5F7CAE@greg.burd.me> <63d07b91-a55a-4c5f-bf62-d3506acfdb5b@app.fastmail.com> <5e169c16-9e54-4325-8027-1f52a5bb5c1e@app.fastmail.com> <1c2a29b8-5b1e-44f7-a871-71ec5fefc120@app.fastmail.com> Subject: Re: [PATCH] Fix ARM64/MSVC atomic memory ordering issues on Win11 by adding explicit DMB ?barriers Content-Type: text/plain Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Dec 12, 2025, at 11:03 AM, Nathan Bossart wrote: > +/* > + * _InterlockedExchange() generates a full memory barrier (or release > + * semantics that ensures all prior memory operations are visible to > + * other cores before the lock is released. > + */ > +#define S_UNLOCK(lock) (InterlockedExchange(lock, 0)) Nathan, thanks for looking at the patch! > This seems to change the implementation from > > #define S_UNLOCK(lock) \ > do { _ReadWriteBarrier(); (*(lock)) = 0; } while (0) > > in some cases, but I am insufficiently caffeinated to figure out what > platforms use which implementation. In any case, it looks like we are > changing it for some currently-supported platforms, and I'm curious why. This change is within _MSC_VER, but AFAICT this intrinsic is available across their supported platforms. The previous implementation of S_UNLOCK() boils down to a no-op because the _ReadWriteBarrier()[1] is a hint to the compiler and does not emit any instruction on any platform and it's also deprecated. So, on MSVC S_UNLOCK is an unguarded assignment and then a loop that will be optimized out, not really what we wanted I'd imagine. My tests with godbolt showed this to be true, no instruction barriers emitted. I think it was Andres[2] who suggested replacing it with _InterlockedExchange()[3]. So, given that _ReadWriteBarrier() is deprecated I decided not to specialize this change to only the ARM64 platform, sorry for not making that clear in the commit or email. My buildfarm animal for this platform was just approved and is named "unicorn", I'm not making that up. :) best. -greg > Perhaps there's some way to make the #ifdefs a bit more readable, too > (e.g., a prerequisite patch that rearranges things). > > The rest looks generally reasonable to me. > > -- > nathan [1] https://learn.microsoft.com/en-us/cpp/intrinsics/readwritebarrier [2] https://www.postgresql.org/message-id/beirrgqo5n5e73dwa4dsdnlbtef3bsdv5sgarm6przdzxvifk5%40whyuhyemmhyr [3] https://learn.microsoft.com/en-us/cpp/intrinsics/interlockedexchange-intrinsic-functions