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 1x3zOY-006oQk-2X for pgsql-hackers@arkaria.postgresql.org; Tue, 08 Sep 2026 17:14:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1x3zOW-008sDy-2R for pgsql-hackers@arkaria.postgresql.org; Tue, 08 Sep 2026 17:14:04 +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 1x3zOW-008sDq-1U for pgsql-hackers@lists.postgresql.org; Tue, 08 Sep 2026 17:14:04 +0000 Received: from mail-qv1-xf2a.google.com ([2607:f8b0:4864:20::f2a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1x3zOU-00000004dDj-3v4p for pgsql-hackers@postgresql.org; Tue, 08 Sep 2026 17:14:03 +0000 Received: by mail-qv1-xf2a.google.com with SMTP id 6a1803df08f44-90cd96389efso59748236d6.3 for ; Tue, 08 Sep 2026 10:14:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788887642; x=1789492442; darn=postgresql.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=llP6MEuq6rH9TSiNolYI9fcSbr660Vx9mUXAFcKgnhM=; b=BFT60R2O1nUXLSC7yNqmnBLCz+Y9Kt4Lo+wY7BJ9h49ElSMJ5OIahY/aO2UgWrpXhI SgL5Y5OQBb1IivUXbb2x1kC1DlIJzHNIb+qL+DIzHxYjVsZl+7Db79IzCW5edZ4VP/80 3276VzuTOOFkQgCP1CzZKlJJA+kXg4oIf3g5XpEADnw9b+Oh3qpKW4irsnYeCsdcVpM2 9nlH/q0NOACXGQFVG0DskyDFzieB9aE+PTwYnVs7FJZW977DwGqRuADF0UElshDSyePx MjbwjcrmiToqVEzbGoBCb0m5YNOzvvvc82oBCuBFFuTnxxjkJ1WP/+igVHaniWbeoV8l b3cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788887642; x=1789492442; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=llP6MEuq6rH9TSiNolYI9fcSbr660Vx9mUXAFcKgnhM=; b=pB9k9O3LKmgCuJQDR5bsnm9LYU0CofnRUMwDhEa3JT0rC4TYTUSMmIzNKxUScc97s/ 0dkosIjmn+JHC8wqJuEDn3NRDRl9k4OeCEXO9BDzXqAFskTb7VI8kff4n1vpGV/F9of1 kzMsDM1WuBgkVIc9b15bctgCGS+NlEPAawskc2LxLVchaGh1l3KmJ+ly3pmg5e/pCIDZ guAKjRPKg142EdJz+ArdlXGfWBLLqD0XXxMR44xY3LJfQKd4kFaMds1xq3AMQXXfAqcT eYjRQu+LFrGgtgjEWhEPDw2m8UHuTHzNzZD7glK4xY0fvYpKUceFD1bOBEzwszXJ3YOL JfUA== X-Forwarded-Encrypted: i=1; AKwUvBzZFJQ/BZKyXS7AtFVzzk9xCU3+OECXyQpnLYqQxmNtbVuTeiNCY9OlMuCAXqbNrMXCOgS4PqQCTRJtIJ33@postgresql.org X-Gm-Message-State: AFuF++mPR/hlpujp5vMO4qTrvc514VRoeqVW7LS9aAFoYjIVIyQBK1vZ zfh2PqBPDOJ0D/e+j2YH1Z87ipgwTb1fGwichcHs7yuy3a82AnvlngJT X-Gm-Gg: AYBFou0pgnz2Q6fB+KhU04o6uH9BlZAOIA1iMnSWO2v15tUc24ZcxseVvA9EbMz/wfg D25IjUKtwrE7x35Q6z7fcfNDRKBXfYjR3Y6s/QoquNQyPA425uxxCSJbbjrreFkD7q/ZKXdywAa BxcCh1Ev9rl84n993dWWyi6JW/myxU7IoNt/f8z5m50fjuYHxWFvSdZtqJak1ZjxEK5F6oA8zhY MJDQk70bY5s/X2tSIizuNxBASe0puXV6RnKZFXQgt3ptuwEZz2Bze6CfrFzL4papFwZKxh+iSaJ sgwGNpyM0tGSTjNXQxt6CCOnVH2R3J+IBlfAoAzjJ4ZXUX3lKnhShgfbSN42C8LS8Ns+bZiB/Uy 9plYh4cK1plHcW8JUhPwCLJK13tmxZ6wQhaVNeOtI4YB6u2vrcsxKFlXrjLnh8oy1yjPEO9fMIE IUgLwCmtXEnfJFXMIZk8pOSE1qlbID0c3CGYxpUzFI4nJU03ryUaofjhbBTIfoT27i0QNGtw+W8 yq39xMqAm2gW5irJMS2NFXRejOerOLrLXOH+snGO6HMS19Wobs/1mtSy2NaOA33k/kXcc3CQmnn tlCtAE1x5z832NWaGWKL7bZEoQ== X-Received: by 2002:a05:620a:390e:b0:939:2670:befd with SMTP id af79cd13be357-9398040023cmr3614918685a.26.1788887641867; Tue, 08 Sep 2026 10:14:01 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id af79cd13be357-9397fbe31c6sm1194847085a.46.2026.09.08.10.13.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2026 10:13:59 -0700 (PDT) Date: Tue, 8 Sep 2026 12:13:57 -0500 From: Nathan Bossart To: Heikki Linnakangas Cc: Andres Freund , Peter Eisentraut , pgsql-hackers@postgresql.org Subject: Re: convert various variables to atomics Message-ID: References: <9d8c317d-d933-46c7-b675-4b9308eaca2b@eisentraut.org> <207c0bfb-6e06-4358-bb2f-c961915efc36@eisentraut.org> <3856d1cf-53a8-414b-98d9-829d5a455a86@iki.fi> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3856d1cf-53a8-414b-98d9-829d5a455a86@iki.fi> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Aug 06, 2026 at 11:37:46AM +0300, Heikki Linnakangas wrote: > On 04/08/2026 17:32, Andres Freund wrote: >> I'm quite hesitant to do that, at least without a lot more clear cut examples >> where it actually would make the code better. I think it's rarely a good idea >> to use signed variables for atomics, because you get undefined behaviour on >> overflow, there's problems with bit masking, etc. IME most data in atomically >> modified should actually be unsigned and probably should have been unsigned >> before the conversion to atomics. > > We could provide pg_atomic_read/write_i32() and > pg_atomic_compare_exchange_i32() but leave out fetch-and-add and other such > instructions that have overflow or bit masking issues. I would do both of these, i.e., first try switching to unsigned, and if that's not an option for whatever reason, use signed atomics. If those existed, I'd use them for v2-0002, which uses an atomic variable for an enum value, and v2-0005, which uses an atomic variable for a Buffer. Neither needs to do any sort of atomic arithmetic on the value, so the lack of fetch-and-add, etc., isn't a problem. That being said, adding signed atomics just for these small patches seems rather extreme, so unless we see ourselves using them quite a bit more down the road, my feeling is that the juice isn't worth the squeeze. I'm curious how others feel about this. -- nathan