Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nWjiH-00014l-HC for pgsql-hackers@arkaria.postgresql.org; Tue, 22 Mar 2022 18:58:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nWjiE-0003Jm-F9 for pgsql-hackers@arkaria.postgresql.org; Tue, 22 Mar 2022 18:58:34 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nWjiD-0003Jb-CT for pgsql-hackers@lists.postgresql.org; Tue, 22 Mar 2022 18:58:34 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nWji6-0001Ep-4V for pgsql-hackers@lists.postgresql.org; Tue, 22 Mar 2022 18:58:32 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 1EF805C045F; Tue, 22 Mar 2022 14:58:25 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Tue, 22 Mar 2022 14:58:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=oxVU8pC9CkxDJKFW9vqnxk5+aflwvrjWuyxyv6QOjds=; b=n1GTR+qr U1WPz3KNL3iZPvbyDiyY/kQO3S8U00ivgDydRRyKqOq7/wlk3Tz9V6zsL06lOl+J ym9QaPbHG6x9XQxbDyxhB8ugpahrTxf15tyw34gve/eT/SaMSNgOIv//oqWXDx2k 6XFupH7+gsNjpsL/260OO4CaQS44R0eTcpg8i5m7BkuPZAQDyYtwgdwfU82IB7A1 +GeZyH2GmBLjsmoAY+PEdflqueAMqkECFa40lGL2KdzfIs0j2jkSNtEhldi18yd/ GPyFGL8YuCsGjuOErYxAb9nSim//5FNGY+yWUCyzC1KuPydQwx0YA9TxbkoChAz/ mgtLA5BpPr0bOg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudeghedgudduiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvuffkgggtugfgjgesthekredttddtjeenucfhrhhomheptehlvhgr rhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh eqnecuggftrfgrthhtvghrnhepudejveejffejveduudetvdekieeuiedtvdeileefkeev jedufeeguedvjefhueelnecuffhomhgrihhnpegvnhhtvghrphhrihhsvggusgdrtghomh enucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhv hhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 22 Mar 2022 14:58:24 -0400 (EDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 910A52A0663; Tue, 22 Mar 2022 15:58:34 -0300 (-03) Date: Tue, 22 Mar 2022 19:58:34 +0100 From: Alvaro Herrera To: Tom Lane Cc: Andres Freund , pgsql-hackers@lists.postgresql.org, Jaime Casanova Subject: Re: LogwrtResult contended spinlock Message-ID: <202203221858.vx3ssvehtkfj@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <202203221611.hqbjdinzsbu2@alvherre.pgsql> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk So I've been wondering about this block at the bottom of XLogWrite: /* * Make sure that the shared 'request' values do not fall behind the * 'result' values. This is not absolutely essential, but it saves some * code in a couple of places. */ { SpinLockAcquire(&XLogCtl->info_lck); if (XLogCtl->LogwrtRqst.Write < LogwrtResult.Write) XLogCtl->LogwrtRqst.Write = LogwrtResult.Write; if (XLogCtl->LogwrtRqst.Flush < LogwrtResult.Flush) XLogCtl->LogwrtRqst.Flush = LogwrtResult.Flush; SpinLockRelease(&XLogCtl->info_lck); } I just noticed that my 0001 makes the comment a lie: it is now quite possible that 'result' is advanced beyond 'request'. Before the patch that never happened because they were both advanced in the region locked by the spinlock. I think we could still maintain this promise if we just moved this entire block before the first pg_atomic_monotonic_advance_u64 setting XLogCtl->LogwrtResult.Write. Or we could halve the whole block, and put one acquire/test/set/release stanza before each monotonic increase of the corresponding variable. However, I wonder if this is still necessary. This code was added in 4d14fe0048c (March 2001) and while everything else was quite different back then, this hasn't changed at all. I can't quite figure out what are those "couple of places" that would need additional code if this block is just removed. I tried running the tests (including wal_consistency_checking), and nothing breaks. Reading the code surrounding the other accesses of XLogCtl->LogwrtRqst, there's nothing that looks to me like it depends on these values not lagging behind LogwrtResult. -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/ "If you have nothing to say, maybe you need just the right tool to help you not say it." (New York Times, about Microsoft PowerPoint)