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 1x3zBp-006oHb-0U for pgsql-hackers@arkaria.postgresql.org; Tue, 08 Sep 2026 17:00:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1x3zBm-008nTv-2t for pgsql-hackers@arkaria.postgresql.org; Tue, 08 Sep 2026 17:00:54 +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 1x3zBm-008nTn-1l for pgsql-hackers@lists.postgresql.org; Tue, 08 Sep 2026 17:00:54 +0000 Received: from mail-ua1-x932.google.com ([2607:f8b0:4864:20::932]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1x3zBk-00000004d6p-39W3 for pgsql-hackers@postgresql.org; Tue, 08 Sep 2026 17:00:53 +0000 Received: by mail-ua1-x932.google.com with SMTP id a1e0cc1a2514c-977258a75d9so3458033241.3 for ; Tue, 08 Sep 2026 10:00:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788886852; x=1789491652; 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=dAgW2040p0CZPoZ8Z8szi+ryT3D1TKQGLJt1eRrrd4Y=; b=JiNW7Joq2g25WrwmosNanVlLN+1uuDJyhN3lENCUGHingClL4NuzzS5A/wYLaphUeD ErxOWc3l76hdf1KE+l6aoVZ22pDtO+kMfKxhWWLeylHMGE4WoKU2hkKaIQgo6eqPEHFu 8q5VOVN6q8QR7KeAaIpsZH/OZa0aPt6b2KMXlnEJOM99Ap/MY5DjvgfClguo3FKqdRc7 k1kDnJlTWmnAqaqR8FHzMFq1JDA8C4zlj4KoHxoB4n/69A+5osO2+3dxTsyiPmixuqLo aaGWLRLTb/N4uQyB2VuLvE9syxAvaQ6wB3Y2QqeT2/xrxHlhWWvk4qZs3F1uCKjxlMXV +r6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788886852; x=1789491652; 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=dAgW2040p0CZPoZ8Z8szi+ryT3D1TKQGLJt1eRrrd4Y=; b=mb7rxZSdGQQGB1ssp+xyJpY1DhGHHAFtDdMXDm/tcVDdYe9PKYpkeTlftwQuT9hDB2 UhFGs/1WoMDLFWtgqXTLCFwNNew32Q7wLmwLUXMZRQSLTPRFzVnSPxTIbo1KXjl7q5PE 6QkZT73clnXDmiegMSHyRfq9dARJKnch4PV2/19U6z2lIJCDFWnc0PDxSZm/C5hUGPHx ouItSuMovr3oTiy+uKgKVWVu4J9RW3z3OfClgX9kRAoGY0tcV2ZNKllJZwGtR7BuMxsp gv7tmZq9uNQXzvoAWuxh8D532ibcZWw2K7zjPZA1r6cVVQ69G3vmnVrjprTEUF1DuIJD iYug== X-Forwarded-Encrypted: i=1; AKwUvBylLiE7anC76xDyj0wHSrmwinTR2FHkzJ/FrUBXCHcGf9poWyhjzTXSUZValAzedVlTPPYS1lD3mf4DzRSh@postgresql.org X-Gm-Message-State: AFuF++kPm60BF+b5BHlj5b0VhlWUljI1Z6xXWEVJTZnEbRBpImAl8CXb 4v1sSa0rJBWnMa915128v/O4SnTLP2WbxdpW0T1sH/TKUsRJptHbpT/D X-Gm-Gg: AYBFou146cCsrcFSXFpR+mQQnoytWmj97FUbuaM+CqXNGMtMhX7J+NvCDJtkcUUJM3x D7Eb69YG03u0NjX4YD4z2ZR9W/ieJ+LPf2xTFZ2RoyPbAqScSbbUiAEP1vHXY3U5pvcq4L3gUyQ Blx4E2621KcIiiaDgN9hhl0J24JLTHfPpSY0eZTYttcaJoCtnpQa/Ngm4SmQEL/eqeix+VQc+9T 5OcyX+hD4qyjjyAsYEmQI/0DM5nXJg7LIDnfr9/8xSSJeQT0FWXo/GNLEx9Lw8USPvBbDGuGeAW IwOrpntuYde+mLowQpU9Kwxp7ksGw9/2fuvIMMxbmf8cit1fbRKqVNZOrXyKlFKzBED/a1hQffc K1Zm/fZZN0ptH85RqAtmx/pXwQ9UAB2aQvMuKjis1Wz4hdQGJdPemLweWmKcnSpWMS2iBeXCO5N 6wit2s5iHVIBxRef6IC4bI8T4Kdv9kTTgXNCd+HY5l3jocMZgy9Htta1L0S6vNXBKZ3JS18MzCu 2LXaGdcFgcfhdjRcdLk9C2N+Sjlh3hWFQ7uIcUY3aLmBE0oeg+gFkmt7gtTswdxLtKujk5WmSRQ 9RZ63hC08EdSRn1o X-Received: by 2002:a05:6102:f8a:b0:786:c86c:8fe4 with SMTP id ada2fe7eead31-78a4ab73095mr14126112137.13.1788886851592; Tue, 08 Sep 2026 10:00:51 -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-9397fb566a8sm1201271085a.25.2026.09.08.10.00.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2026 10:00:50 -0700 (PDT) Date: Tue, 8 Sep 2026 12:00:47 -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 I committed v2-{0003,0004,0008,0009}, and I looked closer at the signed versus unsigned mismatches and determined the following: * v2-0001: We are changing a variable from signed to unsigned, but the code goes out of its way to avoid negative values and signed integer overflow, so I don't think there are any real problems here. The only atomic arithmetic operation is in SICleanupQueue() where we subtract MSGNUMWRAPAROUND, which IIUC should never produce a negative value. That being said, I don't think it would be too disruptive to switch all relevant variables to uint32 as a prerequisite patch. I don't see any particular reason for those variables to be signed, anyway. * v2-0002: The variable in question stores a value from the SharedBitmapState enum. There's no atomic arithmetic involved: we just write and compare-exchange. At a glance, I didn't see any existing examples of using enum values for an atomic variable, but I think it's fine. I believe the C standard guarantees the enum values will be 0, 1, 2, etc., and even if we did set some enumeration constants to negative values, it wouldn't matter because we aren't doing arithmetic with it (and are probably unlikely to anytime soon). So, IMHO this one is fine as-is. * v2-0005: Since 0004 is committed, startupBufferPinWaitBuf is now a Buffer. Buffer is still a signed integer, but since we don't set startupBufferPinWaitBuf to a local buffer (only to a shared buffer or InvalidBuffer (0)), it'll always be >= 0. Furthermore, we don't do any sort of atomic arithmetic with this variable; it's hidden behind setter and getter functions. I think this one is fine. * v2-0006: The variables in this one are only ever incremented by 1, and they track the number of workers for a given operation, which I can't imagine approaches anything even close to overflowing an integer. Not to mention that we're using signed integers for all the relevant variables today... I don't see any risk here, but I'll try to switch the relevant variables to unsigned as a prerequisite and see how it looks. If it's too invasive, it's probably not worth worrying about. * v2-0007: I think this one already does all the work to avoid any signed versus unsigned mismatches. The Assert() in SharedFileSetOnDetach() looks bogus, though, so I'll fix that. I guess there could be some risk of overflow in the "refcnt + 1" in SharedFileSetAttach(), but we don't handle that at all today, so I don't think we need to worry about it. (In theory this patch actually reduces the overflow risk by switching to unsigned, anyway.) -- nathan