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 1x52TY-007Zy2-1b for pgsql-hackers@arkaria.postgresql.org; Fri, 11 Sep 2026 14:43:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1x52TX-00FOD3-15 for pgsql-hackers@arkaria.postgresql.org; Fri, 11 Sep 2026 14:43:35 +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 1x52TW-00FOCt-2q for pgsql-hackers@lists.postgresql.org; Fri, 11 Sep 2026 14:43:35 +0000 Received: from mail.postgrespro.ru ([93.174.132.70]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1x52TT-000000059Ks-1t1w for pgsql-hackers@lists.postgresql.org; Fri, 11 Sep 2026 14:43:33 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1789137807; bh=1zVsmpfCCqsYqoQTM3I3oWXaVctev75m8jVwG+7tUm4=; h=Message-ID:Date:User-Agent:Subject:To:References:From:In-Reply-To: From; b=vEBelAEwhQoq735orvg8dmCqVD9Vw4G8jtK2n83zJZt4bPw1Qa5cWXzYVTz6xVkR+ OVat8lLaE3PKKNg/bz1fFgHn80LUN+kJOmoWDXmAtttkKv7exEPCZEazcrTorSQca/ Vu7PuTP5AsYohXTsy+7XhgZsvq2ikU6ul51t8w98cEnoqv3iBoweCeutj7pByAH8aX fEtz8dA24/0qPpoN5O+1WjnBzy7Xb5HeZh/oPCIzXJmrCUsIg7GwzH6JuuJ7CxfOki ZP25x932ExupDDq/izA242nvak85YHlfLlDBUNMSy0rn2F30lmuVjYsvW20W6aG2hH izwmGl+oHUuXA== Received: from [10.3.12.91] (broadband-188-255-38-164.ip.moscow.rt.ru [188.255.38.164]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: y.sokolov@postgrespro.ru) by mail.postgrespro.ru (Postfix/465) with ESMTPSA id 2869463E04 for ; Fri, 11 Sep 2026 17:43:27 +0300 (MSK) Message-ID: <55e6a615-ec9d-4a57-8f36-7fbd1674da2c@postgrespro.ru> Date: Fri, 11 Sep 2026 17:43:22 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: convert various variables to atomics To: pgsql-hackers@lists.postgresql.org References: <9d8c317d-d933-46c7-b675-4b9308eaca2b@eisentraut.org> <207c0bfb-6e06-4358-bb2f-c961915efc36@eisentraut.org> <3856d1cf-53a8-414b-98d9-829d5a455a86@iki.fi> Content-Language: en-US From: Yura Sokolov In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-KSMG-AntiPhishing: NotDetected, bases: 2026/09/11 13:52:00 X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 3.0.0.9059, bases: 2026/09/11 10:43:00 #28573187 X-KSMG-AntiVirus-Status: NotDetected, skipped X-KSMG-LinksScanning: not scanned, disabled by settings X-KSMG-Message-Action: skipped X-KSMG-Rule-ID: 1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 08.09.2026 22:49, Nathan Bossart пишет: > On Tue, Sep 08, 2026 at 12:00:47PM -0500, Nathan Bossart wrote: >> * 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. > > v3-0001 is the prerequisite patch. This requires some new clamping logic > in SICleanupQueue() for minsig and lowbound, since the subtractions can > produce negative values. I believe this retains the existing behavior, but > need to double-check. Personally, I don't like current implementation of pg_atomic_read_membarrier_u32 because it writes into shared variable. That is why in [1] (thread [2]) I used explicit pg_memory_barrier before and pg_read_barrier after reading segP->maxMsgNum. (pg_memory_barrier writes onto stack - process's private memory, and pg_read_barrier does nothing on x86_64). [1] https://www.postgresql.org/message-id/attachment/174633/v3-0001-sinvaladt.c-use-atomic-operations-on-maxMsgNum.patch [2] https://www.postgresql.org/message-id/flat/30aa0030-f694-44ef-a19d-6ef7ddb69374%40postgrespro.ru -- regards Yura Sokolov aka funny-falcon