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 1rTQ9g-002nsy-1a for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Jan 2024 17:38:16 +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 1rTQ9e-000jDl-C9 for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Jan 2024 17:38:14 +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 1rTQ9d-000jDd-PF for pgsql-hackers@lists.postgresql.org; Fri, 26 Jan 2024 17:38:14 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rTQ9Y-003rOA-CO for pgsql-hackers@lists.postgresql.org; Fri, 26 Jan 2024 17:38:10 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id DE3825C0465; Fri, 26 Jan 2024 12:38:06 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Fri, 26 Jan 2024 12:38:06 -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=fm3; t=1706290686; x= 1706377086; bh=8wYPlFSIS+ZW2ecfZS7XOhMLLU+W4g4WcAKzubMxbK0=; b=P 1KuEc/0xgWRR0+p1rvvqjzKPXhJsXT8A4QZ1TIWOZLv9O3sUKGSW6T57PEUg7Sta hDUzoWFA2jKgjPCwgPfdLWIHBhoA5RZjiC3Zpb6D3mZDvf16mRF7cejvWu9yYzdD hsXr72AIMmoeffKv/52Tmqf2bkyYvp38jL+e8Y7G8+UtzY512IJyAMN+e+s5Gx5Y R+8c2VJurCYPSm7RBvNWMT12vsK3tjaelfYuRUn1pdql9Vk2UYG6Iv/Sb7shAB9j wxsX24wRxudKXTMW3oBq2nKz+8xXSyDzKkNlbspClb8iYTtKcqfWzeRTH+NwkA96 0ZJE6HibRQB7eG8KtjqBQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvdeljedguddtudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfggtggugfgjsehtkeertddttdejnecuhfhrohhmpeetlhhv rghrohcujfgvrhhrvghrrgcuoegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorh hgqeenucggtffrrghtthgvrhhnpedvkedtffduffdtffffheffhfejjefhgfeiueeukeej keffgfdufffhudffffeuveenucffohhmrghinhepvghnthgvrhhprhhishgvuggsrdgtoh hmnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghl vhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 26 Jan 2024 12:38:06 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1706290684; bh=vX3LIhDLSflUeIdePMx+h0p3uvJt6fZva4qJ7IwizL0=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=qFUHLL6GE9oev5P/yKXagS0Ol5tptc6VtlRI+OciRlG48U0bVzdypvGy8Q0tprKfo wmp65DeY1SQHHQsWwKR97xdafqsn/OP/SAsvbF9niva1x8SmXtbUB0iXkxoL8Z4nov O28ZXnXFUCVR8Mf+Ylptxfg43CksZ/QkcH16elm6ebSMrNhrV8ST27qu6Pzo3LpnVf KBszVGGhNRHVD0d5+p54gYry2jr32BhPB31afPfJbZxL4pdglm3S1+t5fOAlNsbom7 7yWqZHzsbimJmorrvJaIxfdahArpkddJ+j2VFEOoSrpAvoezU5jUtru88M3qlR3mpj VNDipTeCtza4w== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id 6BA449B0; Fri, 26 Jan 2024 18:38:04 +0100 (CET) Date: Fri, 26 Jan 2024 18:38:04 +0100 From: Alvaro Herrera To: Dilip Kumar Cc: tender wang , PostgreSQL Hackers Subject: Re: SLRU optimization - configurable buffer pool and partitioning the SLRU lock Message-ID: <202401261738.zf2evzaborgt@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk I've continued to review this and decided that I don't like the mess this patch proposes in order to support pg_commit_ts's deletion of all files. (Yes, I know that I was the one that proposed this idea. It's still a bad one). I'd like to change that code by removing the limit that we can only have 128 bank locks in a SLRU. To recap, the reason we did this is that commit_ts sometimes wants to delete all files while running (DeactivateCommitTs), and for this it needs to acquire all bank locks. Since going above the MAX_SIMUL_LWLOCKS limit is disallowed, we added the SLRU limit making multiple banks share lwlocks. I propose two alternative solutions: 1. The easiest is to have DeactivateCommitTs continue to hold CommitTsLock until the end, including while SlruScanDirectory does its thing. This sounds terrible, but considering that this code only runs when the module is being deactivated, I don't think it's really all that bad in practice. I mean, if you deactivate the commit_ts module and then try to read commit timestamp data, you deserve to wait for a few seconds just as a punishment for your stupidity. AFAICT the cases where anything is done in the module mostly check without locking that commitTsActive is set, so we're not slowing down any critical operations. Also, if you don't like to be delayed for a couple of seconds, just don't deactivate the module. 2. If we want some refinement, the other idea is to change SlruScanDirCbDeleteAll (the callback that SlruScanDirectory uses in this case) so that it acquires the bank lock appropriate for all the slots used by the file that's going to be deleted. This is OK because in the default compilation each file only has 32 segments, so that requires only 32 lwlocks held at once while the file is being deleted. I think we don't need to bother with this, but it's an option if we see the above as unworkable for whatever reason. The only other user of SlruScanDirCbDeleteAll is async.c (the LISTEN/ NOTIFY code), and what that does is delete all the files at server start, where nothing is running concurrently anyway. So whatever we do for commit_ts, it won't affect async.c. So, if we do away with the SLRU_MAX_BANKLOCKS idea, then we're assured one LWLock per bank (instead of sharing some lwlocks to multiple banks), and that makes the code simpler to reason about. -- Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/ "In fact, the basic problem with Perl 5's subroutines is that they're not crufty enough, so the cruft leaks out into user-defined code instead, by the Conservation of Cruft Principle." (Larry Wall, Apocalypse 6)