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.94.2) (envelope-from ) id 1rt8fZ-00CWqd-HK for pgsql-hackers@arkaria.postgresql.org; Sat, 06 Apr 2024 16:13:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rt8fY-00DqBS-LD for pgsql-hackers@arkaria.postgresql.org; Sat, 06 Apr 2024 16:13:28 +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.94.2) (envelope-from ) id 1rt8fX-00DqBK-AN for pgsql-hackers@lists.postgresql.org; Sat, 06 Apr 2024 16:13:28 +0000 Received: from fout7-smtp.messagingengine.com ([103.168.172.150]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rt8fU-001EkJ-5T for pgsql-hackers@lists.postgresql.org; Sat, 06 Apr 2024 16:13:26 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.nyi.internal (Postfix) with ESMTP id 9F49C13800AB; Sat, 6 Apr 2024 12:13:22 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Sat, 06 Apr 2024 12:13:22 -0400 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 :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1712420002; x= 1712506402; bh=e3qopoP0wcZuzJs1uHSENgn31ab1pzaqS/uCtwtgnes=; b=W q4djBXAg3ZS4pOaeojJXWyXa74Gjg9QugBQmotWKcddGDhZmQUpToChzTkusnet0 fWOFiYIw9vDI338gvMX6DeaAJs6EHc7fkktbsIjsldLSpsNOiQqhcC27VOvzvXD2 sxHvdg6Kq4kKrUMPJ26M3VmEaklTfyH8kky9QdEkXlt7N1PErEvnNg3EPKK5zSsr 3FZXZGB96/31CCQGPHD5GoAEuzaJVOKbKFAmQkNE06Ov1Y/IR0yEIGI/MVx/ANhD /9B3a9fyCChre9DRieGZPkH+LCGj4m4A9la61C2pU/0efMdc6pdDigWOwZxEbPpd bmYRqKHE0UpypL2oH079g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudegvddgleelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkgggtugfgjgesthekredttddtjeenucfhrhhomheptehlvhgr rhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh eqnecuggftrfgrthhtvghrnhepvdektdffudfftdffffehfffhjeejhffgieeuueekjeek fffgudffhfduffffueevnecuffhomhgrihhnpegvnhhtvghrphhrihhsvggusgdrtghomh enucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhv hhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 6 Apr 2024 12:13:21 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1712419999; bh=KGjpmmPPrFpMups36l525iIWKjXIpk5pLbZNfprIGVo=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=MaoHG77maobiKmI8OVtOEit6M/Tdk6BoMzOykWwV92GShDYVY3k8y/wuah4AaL9xW rBUyndxLvDRrNClnq/srEFP/oh7qTYC5jlEyq9oENZKKPtKgWUKAM3tzcYeCv/v2bX AMKUroSg+R9R/Hb9vlc5lWem66jof4LMgNwwpM997r6fkEbclQQpJDQ8H1MZN2dOiv E5pRpzMhM/coef7WaHIzbE4TFmDgdB1zh6eXO+J9r6OaUgq2Xha8OjHwjlrZAaI6V9 qzf2aDx7a219CxiddCJzgErkpNAQwOuxbwh+FClkj0dWD9DAFxlsv6ytVp3eoLUplS /ucki3xFWAFRg== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id EF07A46F; Sat, 6 Apr 2024 18:13:19 +0200 (CEST) Date: Sat, 6 Apr 2024 18:13:19 +0200 From: Alvaro Herrera To: Jeff Davis Cc: Bharath Rupireddy , Tom Lane , Andres Freund , pgsql-hackers@lists.postgresql.org, Jaime Casanova Subject: Re: LogwrtResult contended spinlock Message-ID: <202404061613.g24s435wqigh@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <43269689137ce4f80224b58a4e162fb891a6fc4e.camel@j-davis.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2024-Apr-05, Jeff Davis wrote: > Minor comments: > * Also, I assume that the Max() call in > pg_atomic_monotonic_advance_u64() is just for clarity? Surely the > currval cannot be less than _target when it returns. I'd probably just > do Assert(currval >= _target) and then return currval. Uhh ... my understanding of pg_atomic_compare_exchange_u64 is that *expected is set to the value that's stored in *ptr prior to the exchange. Its comment * Atomically compare the current value of ptr with *expected and store newval * iff ptr and *expected have the same value. The current value of *ptr will * always be stored in *expected. is actually not very clear, because what does "current" mean in this context? Is the original "current" value, or is it the "current" value after the exchange? Anyway, looking at the spinlock-emulated code for pg_atomic_compare_exchange_u32_impl in atomics.c, /* perform compare/exchange logic */ ret = ptr->value == *expected; *expected = ptr->value; if (ret) ptr->value = newval; it's clear that *expected receives the original value, not the new one. Because of this behavior, not doing the Max() would return the obsolete value rather than the one we just installed. (It would only work correctly without Max() when our cmpxchg operation "fails", that is, somebody else incremented the value past the one we want to install.) Another reason is that when I used pg_atomic_monotonic_advance_u64 with the Write and Flush pointers and did not have the Max(), the assertion failed pretty quickly :-) -- Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/ Al principio era UNIX, y UNIX habló y dijo: "Hello world\n". No dijo "Hello New Jersey\n", ni "Hello USA\n".