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 1w10a6-002PW6-2V for pgsql-hackers@arkaria.postgresql.org; Fri, 13 Mar 2026 11:21:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w10a4-003VJ0-33 for pgsql-hackers@arkaria.postgresql.org; Fri, 13 Mar 2026 11:21:25 +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.96) (envelope-from ) id 1w10a4-003VIr-22 for pgsql-hackers@lists.postgresql.org; Fri, 13 Mar 2026 11:21:25 +0000 Received: from mail-oo1-xc36.google.com ([2607:f8b0:4864:20::c36]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w10a2-00000002S2Y-42K0 for pgsql-hackers@postgresql.org; Fri, 13 Mar 2026 11:21:24 +0000 Received: by mail-oo1-xc36.google.com with SMTP id 006d021491bc7-673ee2a98b1so1189791eaf.0 for ; Fri, 13 Mar 2026 04:21:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1773400881; cv=none; d=google.com; s=arc-20240605; b=brEpbwu5UJeJUDmWp6Yz/d2J54IXGdVRtg7sxpYYWO00DLlDdurmCh+Q0vwDRg+3BF 3JZ9kZ4xKVndeQI6CIm8YglizIqGPcuIRreBkFoF9a0JRbHfEaXxZ0sI5QclAY/pGW/7 jh2PxfNMLrjjgp3bXreCowpccLD/KTUfIXsBRMQG5EZsUKDumOtNOdkrO9akyovfPRqm 5aANRG7ZnRfWP38e8CsEggAwfN3u0QUe4JQnJBArsCR0iDXW+mRsUhIbMzbHssmRChvJ gqk4gJ8LfMh4FIqSJb/YkRagJiDBwCHzNfU9pBZA+7lnEKOedKlvKyHvz27YYOqpNTgK PE1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=r6kQZMI9H3L69tJ7Ibro0W2y4TuplXhQByTMvzsn3YE=; fh=hrDv9aZdnx1NkUObliKCmKbmcuqie08VFQirejfrPKc=; b=cxk4eo+R0xpsgoiNTyebULK19RaaKtILKYM2ImtY4VmcvTbTPRaUef1p4SFdAoGILa w6Vx8NDjqNwaFZApRbMhms5a373iUcSy+wDsfh+wvjPvVMMkzsHseQfdJnvpfxMkGF4i 1fgOar8tuDycTQDNAJTDVB1iPWmAOBnze+eXfUnSqywTDrB+WJv4xHYVVISwLg+kBRe9 /F9yMCLhyXPthk41og2ILL5KRgZ192vWCBIJShNTtlpVABOteciSsXla5yoXoqV/zFK6 7bv8R8SJqur4GhEahptb2z7Zc2eM42Gg5WpGB/gYqc9iptcAN/5mXivnFb3BtXEd0Dwh No0A==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773400881; x=1774005681; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=r6kQZMI9H3L69tJ7Ibro0W2y4TuplXhQByTMvzsn3YE=; b=TDrZiMPsyZuJBfKIwrrg6qtSWm2XhFjAT1RiJaXBxNQDD8hccGOKWq3qgfgy0tk+my uvZZDqmHeM7e3ReGDux/FTEq3sg4K0bCDpcR7beO53+umnZJDD0CkMz4vWKfXU865rHp QIoP69mLYBv7r9fiMiZgjMg/b0Ge0ORN5o2EKqqHO8LTUBC3QRbOnwtbY1nbQD/AFMFM 3O0742h1g541QgrIYo5TAep9P12hJKaBEM7O612E2ZcZdK1DPG70AcV0ooZSXEdNYxmj c25eNL7kzWeHHtEgqPK4vUno8neNH7IVaPPXmT2wfRdpf6TNj6gokFki6g1BO7bx/ziu MRHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773400881; x=1774005681; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=r6kQZMI9H3L69tJ7Ibro0W2y4TuplXhQByTMvzsn3YE=; b=WCqU6ggORWaPlE+EfPp8BcierdEGQhVQBQQBKEpF+nFJZPzezpbMWGmp4MHZVJzSpJ nsHAhjZX5Ii7R6s89Y2T8pR7dAEPKqRs6x9WHAJTR4EHDcbz+ye5sh/yknxSfB9Zojr2 6HQXwnqnlwoL+TXmjdeRinkONoZhWWlI99TQXFaKRNHyK3FDjUDMKARqpUc4jcWJaTu9 BUtb1Q8flhHuxymTYCrY8ud8tudIJQzAjXYFMOtwBuA2vg04BnfXpiOQj46A45y5YS5p QqLuxq6KBB6b9cmvdI/ch3B7ftmIIUehgpzAB9qYFRlzby91/PpRvtvPzn8pxYrCIpwd XXZw== X-Gm-Message-State: AOJu0YwLGdbVzbVf7imb7klKlmJD6odNpLKpOj+bvOit231pnyu2kGTF WyzYzww8ld7SqGq+zFb03q9fPHdd07oVG2ubBkuy7ZiGVRzsmSQ7NPuVS6NK0XZNI9Jl9BgytL5 T4pd/IXkjtqgQKTcUP5SqUrLNhJqBbnQF7BsY X-Gm-Gg: ATEYQzx01I9qVrxbAF5vwQAyJvLH5unxTh+D3ieJqWnNjZXhodgcKGumLorW0M+Juu4 7Dalpq3zKXT7c41JG126Lz57LjB0wUBU1Bi01wvzRCEM/DnkM7brggWB6nBpjKEVfeaXuI5i/0d HxWJf/wUtC5CGnwnXRY0PTbMLrQZ35jMBDL4YmkxDlL5mihgn3RnYGUoZKJU+1GVpltWL+X4LEs ZULYH12+2TyQhTPSk07sPqOv3I2ihr872ZfsFcuu3hkaDhY+jZnPOC4FEvc3jA9RKdyK4SeSczO JcRw59GHB2uK2K2zLUtyh4c39XqsbJAPMGviNIUOr0dgwgM3RdxFntOTsPIYfjD2ObownOy3ZAo aPL/oVX8= X-Received: by 2002:a05:6820:3108:b0:67b:a667:f532 with SMTP id 006d021491bc7-67bdaa3871amr1783474eaf.40.1773400881041; Fri, 13 Mar 2026 04:21:21 -0700 (PDT) MIME-Version: 1.0 References: <6ybtypq2v3kvskiqj7izl2rmfrcluilsmbobtpylcnp7moa7vq@2q3cplokvcza> In-Reply-To: From: Alexander Korotkov Date: Fri, 13 Mar 2026 13:21:08 +0200 X-Gm-Features: AaiRm50oARculDx9KmE7Z1z5j-GpazuIvokmcD8uQIoFkBMxYm4q7w_l1QgtPZU Message-ID: Subject: Re: pg_atomic_compare_exchange_*() and memory barriers To: Andres Freund Cc: pgsql-hackers Content-Type: multipart/alternative; boundary="0000000000008f1a0a064ce611a1" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000008f1a0a064ce611a1 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, Mar 8, 2025 at 5:20=E2=80=AFPM Andres Freund w= rote: > On 2025-03-08 17:06:38 +0200, Alexander Korotkov wrote: > > On Sat, Mar 8, 2025 at 3:41=E2=80=AFPM Andres Freund wrote: > > > > > > On 2025-03-08 08:02:41 -0500, Andres Freund wrote: > > > > From the C/C++ standard atomics model it doesn't make sense to say that a > > > > failed CAS has release semantics, as there simply isn't a write that could be > > > > ordered! What their barriers guarantee is ordering between multiple memory > > > > operation, you can't order multiple writes if you don't have multiple > > > > writes... The synchronization in the C/C++ model is only established between > > > > accesses of the same variable and there's no write in the case of a failed > > > > CAS, so there's nothing that could establish a release-acquire ordering. > > > > > > > > Unfortunately that model doesn't mesh well with barriers that aren't attached > > > > to read/modify operations. Which is what we ended up with... > > > > > > Adding a full barrier to failed CAS would be a rather large overhead, > > > undesirable in just about any sane algorithm. As a consequence, I think what > > > we ought to do is to redefine the barrier semantics to only imply an acquire > > > barrier in case CAS fails. > > > > Thank you, I'm good with this solution. Can I leave this on you? I'm > > not feeling myself strong to word this correctly. > > Not in the next ~four weeks. If you ping me afterwards, I can give it a go. It has been more than a year. Probably not perfect moment again. But could you, please, revise that comment? ------ Regards, Alexander Korotkov Supabase --0000000000008f1a0a064ce611a1 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Sat, Mar 8, 2025 at 5:20=E2=80=AFPM Andres Freund <<= a href=3D"mailto:andres@anarazel.de">andres@anarazel.de> wrote:
&= gt; On 2025-03-08 17:06:38 +0200, Alexander Korotkov wrote:
> > On= Sat, Mar 8, 2025 at 3:41=E2=80=AFPM Andres Freund <andres@anarazel.de> wrote:
> > >
&g= t; > > On 2025-03-08 08:02:41 -0500, Andres Freund wrote:
> >= ; > > From the C/C++ standard atomics model it doesn't make sense= to say that a
> > > > failed CAS has release semantics, as = there simply isn't a write that could be
> > > > ordered= !=C2=A0 What their barriers guarantee is ordering between multiple memory> > > > operation, you can't order multiple writes if you= don't have multiple
> > > > writes...=C2=A0 The synchro= nization in the C/C++ model is only established between
> > > &= gt; accesses of the same variable and there's no write in the case of a= failed
> > > > CAS, so there's nothing that could estab= lish a release-acquire ordering.
> > > >
> > > &= gt; Unfortunately that model doesn't mesh well with barriers that aren&= #39;t attached
> > > > to read/modify operations. Which is w= hat we ended up with...
> > >
> > > Adding a full b= arrier to failed CAS would be a rather large overhead,
> > > un= desirable in just about any sane algorithm. As a consequence, I think what<= br>> > > we ought to do is to redefine the barrier semantics to on= ly imply an acquire
> > > barrier in case CAS fails.
> &g= t;
> > Thank you, I'm good with this solution.=C2=A0 Can I lea= ve this on you?=C2=A0 I'm
> > not feeling myself strong to wor= d this correctly.
>
> Not in the next ~four weeks. If you ping = me afterwards, I can give it a go.

It has been more than a year.=C2= =A0 Probably not perfect moment again.=C2=A0 But could you, please, revise = that comment?

------
Regards,
Alexander Korotkov
Supabase --0000000000008f1a0a064ce611a1--