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 1rhA4t-009vo5-HG for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Mar 2024 15:18:08 +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 1rhA4r-008wJ2-Pf for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Mar 2024 15:18:06 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rhA4q-008wIV-9p for pgsql-hackers@lists.postgresql.org; Mon, 04 Mar 2024 15:18:05 +0000 Received: from fout6-smtp.messagingengine.com ([103.168.172.149]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rhA4n-002js1-CA for pgsql-hackers@lists.postgresql.org; Mon, 04 Mar 2024 15:18:04 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfout.nyi.internal (Postfix) with ESMTP id 4E8941380058; Mon, 4 Mar 2024 10:18:00 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 04 Mar 2024 10:18:00 -0500 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=fm1; t=1709565480; x= 1709651880; bh=dmMSQUzKWYkJ4T4QdYL0HKcRiM0KSCAeKUXlHBoS1wo=; b=i vxoh+Mq+lmXmTvu6Oq5i9gQ/2sMtjJnUmKSD9KdpCHTB4m64C7qyHw0kA+7UCw11 PbF9pmDGRdxKvBM2wEVkyQaUm6aswNwtNJFpvHiK0EZ3jDOS4DczFtlpVT0V0sxw HXXa57Tp3lYSJ/SSb6p8BluMx+1+qEc73Ojx36vxjgruYx59Y3QRfOmFZHBJk3um labbe7XS1PzngOIF2rY9eFnlqLTdJTB9HbodAotoHE8RSY54Tj5lj3vcRpL/mqQh qXQ48Y+FYzwepczDR0w7wtMAbRwGzEY9VZxgj9rmKEHFWaZMANAoNPzhqy7wpo6j AhV8aKR8gsDBa1J2sFP1g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrheejgdejvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvfevuffkgggtugfgjgesmhekre ertddtjeenucfhrhhomheptehlvhgrrhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgv segrlhhvhhdrnhhoqdhiphdrohhrgheqnecuggftrfgrthhtvghrnhepudelkeekgfdttd ettdekgfduvdeiffelteegjeeihfetheekveeftedtuddvhfeunecuffhomhgrihhnpegv nhhtvghrphhrihhsvggusgdrtghomhenucevlhhushhtvghrufhiiigvpedtnecurfgrrh grmhepmhgrihhlfhhrohhmpegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 4 Mar 2024 10:17:59 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1709565478; bh=8WtfTSCAK6ZyBIlG/MuNwBud2/I+Hdgywrok0UFW7tk=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=eXQgbB6nxz2N/B0zSb8Y6o97ZbzFTLGtA6jUp0DB4vcflgoVro9VzRQdU/Td4SI8b +50Q4zwHsI+W/R8X8oSf3oa6JyYrAmcrMx5dDbl2MjM54lyry5kcLuNFgIrQh3iINu TJZsJjHVQ99VdOKi3x3mm1qYCv2JrGU06A7KGM583PXGstoTyjE6in+r7NnqzEwE77 IfFmuM3tWGE/v1CHORcgQqOa05CM3dEzHeyICeldVO68cyzNjaOcW0v9i7so28ZJZv yu0ZaeCgC+V0/cFjAJlUbC3wHMpTPsuKBS1YWtrhdlTsLYovP5TQQg59SiAX3smytn z4qAdz/s3kMYg== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id 0C815CD5; Mon, 4 Mar 2024 16:17:58 +0100 (CET) Date: Mon, 4 Mar 2024 16:17:58 +0100 From: Alvaro Herrera To: Tom Lane , Dilip Kumar Cc: pgsql-hackers@lists.postgresql.org Subject: Re: pgsql: Improve performance of subsystems on top of SLRU Message-ID: <202403041517.3a35jw53os65@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="gflnge3qfnp343ni" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <3396247.1709500489@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --gflnge3qfnp343ni Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On 2024-Mar-03, Tom Lane wrote: > This is certainly simpler, but I notice that it holds the current > LWLock across the line > > ptr = (MultiXactMember *) palloc(length * sizeof(MultiXactMember)); > > where the old code did not. Could the palloc take long enough that > holding the lock is bad? Hmm, I guess most of the time it shouldn't be much of a problem (if the length is small so we can palloc without malloc'ing); but it could be in the worst case. But the fix is simple: just release the lock before. There's no correctness argument for holding it all the way down. I was just confused about how the original code worked. > Also, with this coding the "lock = NULL;" assignment just before > "goto retry" is a dead store. Not sure if Coverity or other static > analyzers would whine about that. Oh, right. I removed that. On 2024-Mar-04, Dilip Kumar wrote: > I am not sure about the other changes, I mean that makes the code much > simpler but now we are not releasing the 'MultiXactOffsetCtl' related > bank lock, and later in the following loop, we are comparing that lock > against 'MultiXactMemberCtl' related bank lock. This makes code > simpler because now in the loop we are sure that we are always holding > the lock but I do not like comparing the bank locks for 2 different > SLRUs, although there is no problem as there would not be a common > lock address, True. This can be addressed in the same way Tom's first comment is: just release the lock before entering the second loop, and setting lock to NULL. This brings the code to a similar state than before, except that the additional LWLock * variables are in a tighter scope. That's in 0001. Now, I had a look at the other users of slru.c and noticed in subtrans.c that StartupSUBTRANS we have some duplicate code that I think could be rewritten by making the "while" block test the condition at the end instead of at the start; changed that in 0002. I'll leave this one for later, because I want to add some test code for it -- right now it's pretty much test-uncovered code. I also looked at slru.c for uses of shared->bank_locks and noticed a couple that could be made simpler. That's 0003 here. -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/ "If it is not right, do not do it. If it is not true, do not say it." (Marcus Aurelius, Meditations) --gflnge3qfnp343ni Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename="v2-0001-rework-locking-code-in-GetMultiXactIdMembers.patch"