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 1rtRUu-00EnYw-6r for pgsql-hackers@arkaria.postgresql.org; Sun, 07 Apr 2024 12:19:45 +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 1rtRUt-006Sll-2V for pgsql-hackers@arkaria.postgresql.org; Sun, 07 Apr 2024 12:19:43 +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 1rtRUr-006Sla-Mp for pgsql-hackers@lists.postgresql.org; Sun, 07 Apr 2024 12:19:42 +0000 Received: from fhigh7-smtp.messagingengine.com ([103.168.172.158]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rtRUk-001dyG-E4 for pgsql-hackers@lists.postgresql.org; Sun, 07 Apr 2024 12:19:40 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id EBD381140095; Sun, 7 Apr 2024 08:19:32 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Sun, 07 Apr 2024 08:19:32 -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=1712492372; x= 1712578772; bh=gEAMEeKd1KztePIhmzVCfzgDjgwcHKprHcb39OLk01A=; b=q qlSqP2UwOD6afuDv1jPOqyDoKO9J0GMuXdUb6AXHyfT5P9s3XjqQL/R+hfpLOvm9 jQMyCpokp1uvcjoExV+muupKB+LGyJLBg1k+IUaTCLqsKWJHFvV8U8ag2bjkOgyK G28zEpVZ1JSLzATWwG9vDrplqrjYUYGnutT5VLitB+ZuYRp0t/996BRBlpj3lB3C N0aeSP/t6K/elO8mxcV1j6Gw/xfvML1T6T73IhM3c3zTWBqZlqmnaoK5k+iu3EYz UUquMF7kf8AYSyPrZoR80q7MY6295/mvcwmE992u8SrcmAU4ccs7nP/3PxMOcPyS 3UL79IFgWCFY6tDsDAyVQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudeggedghedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkgggtugfgjgesthekredttddtjeenucfhrhhomheptehlvhgr rhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh eqnecuggftrfgrthhtvghrnhepheekueegieeuvefglefgteekheetjeehjeevieejveeg keehheejhfelvdfgudegnecuffhomhgrihhnpegvnhhtvghrphhrihhsvggusgdrtghomh dpshhlrghshhguohhtrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghm pehmrghilhhfrhhomheprghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 7 Apr 2024 08:19:31 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1712492369; bh=wTKTQM0mOnVF1QaSH19Tjum/8DlXHog234mv7sRZYKU=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=DDYKqkgPQnuV667/bil3jkTdX4zaZF63ph9wgXNRLVPdnNUX3i/A9OyV5iNuYRdJ0 aXWxwox4Q9IvYwSgYfUVtcjTzwCvZuk++MQMvVlnU8moSAIScFuen3uUyUeafVqRGy rkG0wg4kGnJmRtSoECbo4y4Tp+HwELEoJS+59yglSkzyIM8Y+FNQZHvmfS40AbKEag tAKZ18eQEFhn+LAvcwEFcK1xGybBhh0kfHQgQXiUR2zouFaxENxQcSjboHy+0nxw+Y ECbf5nly/i1ua+p8PIzP7s+rRqLjIDXbfpIe2Q8gZQTpgC73zJlvQ1o+tzX77N7jSZ Y7n/y/ovNjMCA== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id 8E84046F; Sun, 7 Apr 2024 14:19:29 +0200 (CEST) Date: Sun, 7 Apr 2024 14:19:29 +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: <202404071219.p5qphx7vzxte@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 I pushed the "copy" pointer now, except that I renamed it to "insert", which is what we call the operation being tracked. I also added some comments. One perhaps significant change from what Bharath submitted is that we now use the return value from monotonic advance to return an updated value of finishedUpto from WaitXLogInsertionsToFinish. I think this is a useful optimization: the only caller of WaitXLogInsertionsToFinish which cares about its return value is XLogFlush, which AFAICS benefits from having a more up-to-date value. Also, I did adopt your (Jeff's) idea of using a barrier when reading logInsertResult in WaitXLogInsertionsToFinish. If I understand correctly, this is actually useful: if some other CPU core was also recently busy waiting for xlog insertions and wrote an updated version of logInsertResult that's past what we last saw, we benefit from an updated value because we can skip the spinlock dance and WAL-insert-var stuff altogether. With no barrier, we would potentially see an outdated value of logInsertResult and waste a lot of effort to get it updated. -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/ "Those who use electric razors are infidels destined to burn in hell while we drink from rivers of beer, download free vids and mingle with naked well shaved babes." (http://slashdot.org/comments.pl?sid=44793&cid=4647152)