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 1uyIGX-006AyK-Ue for pgsql-hackers@arkaria.postgresql.org; Mon, 15 Sep 2025 23:05:46 +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 1uyIGU-00E9At-U7 for pgsql-hackers@arkaria.postgresql.org; Mon, 15 Sep 2025 23:05:43 +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 1uyIGU-00E9Aj-Fs for pgsql-hackers@lists.postgresql.org; Mon, 15 Sep 2025 23:05:43 +0000 Received: from fhigh-a7-smtp.messagingengine.com ([103.168.172.158]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uyIGQ-0011Xw-1A for pgsql-hackers@postgresql.org; Mon, 15 Sep 2025 23:05:42 +0000 Received: from phl-compute-12.internal (phl-compute-12.internal [10.202.2.52]) by mailfhigh.phl.internal (Postfix) with ESMTP id 7586D14001B8; Mon, 15 Sep 2025 19:05:38 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-12.internal (MEProxy); Mon, 15 Sep 2025 19:05:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1757977538; x=1758063938; bh=Z3nYdI4epr 0BdSk7mnX5AFvpkFPI1Wf9hx4bt7yE6JI=; b=NkmXnHb+l1E1NxugLNmjgR8B79 WI3Ve9k4oI8TzvodKDv2v/okwvC8sUMUZ0izbE0TQTg27+6R8+v08Oq5ZKnGmIAW TSop6gpYhzIhB48t14eGTnkKKm+UZWoou/ji4OAnSZYeMGcV0m9H7iafPhar5qwf qt0Ef3D9a+qvuydApiG8wge9p2V5te9CdX4zQlnqu0MDo7r4PbgvK4dd8EAhbIzJ YcwSsc1zLcOjGjdbIhkYpEbmQfWv7UlMaGkmUkTQCg/ci47TakdYNfNCnFVYTdyj IIxkY7PRabPLMlAGvwGTVy1u76tNEmVQJ9QgJKRjunrsS4RsSxBBeeaMs/VA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1757977538; x=1758063938; bh=Z3nYdI4epr0BdSk7mnX5AFvpkFPI1Wf9hx4 bt7yE6JI=; b=b4BznTAiu5Z5Euv2wT9WEiirm1jVE32Ub6ARCM6t7jqh3ff7CRF 8EZvTkLZLBX5IgBtHMboHoxWCIJVZ8gLWMUFTG7jb5UaH0NHeyK4n3UCaM5KCEFc RzJe61xaLOcN+qpSNaSyjYIWzMYl5eJbiV4FPPpIeGbXKS+71QYloheohQoOhLnn wJ+VfyMeM1CcmdVpE5cCtDvjjUvUakNffeRc829GczKop2m/4Ld8eeDoBGysmCPu h3SGsfKRisoOm+j4SaVSPU9PRChpdU8QQCkUqBGUgsPg3O7tcHkEuf0QA+xnqW6a 80lsM5jtDPYL61KWQZKWvKf+kwV3kdoetDQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggdefkeeljecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpeffhffvuffkfhggtggujgesmhdtsfertddtvdenucfhrhhomheptehnughrvghsucfh rhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgiivghlrdguvgeqnecuggftrfgrthhtvg hrnhepffevhfekveetvdeukefhuedvueegtdfgueegfeevgeekveduieeggffhueevueej necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghnug hrvghssegrnhgrrhgriigvlhdruggvpdhnsggprhgtphhtthhopeejpdhmohguvgepshhm thhpohhuthdprhgtphhtthhopehmvghlrghnihgvphhlrghgvghmrghnsehgmhgrihhlrd gtohhmpdhrtghpthhtohepmhhitghhrggvlhdrphgrqhhuihgvrhesghhmrghilhdrtgho mhdprhgtphhtthhopehrohgsvghrthhmhhgrrghssehgmhgrihhlrdgtohhmpdhrtghpth htohepthhhohhmrghsrdhmuhhnrhhosehgmhgrihhlrdgtohhmpdhrtghpthhtohephhhl ihhnnhgrkhgrsehikhhirdhfihdprhgtphhtthhopehnohgrhheslhgvrggusghorghtrd gtohhmpdhrtghpthhtohepphhgshhqlhdqhhgrtghkvghrshesphhoshhtghhrvghsqhhl rdhorhhg X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 15 Sep 2025 19:05:37 -0400 (EDT) Date: Mon, 15 Sep 2025 19:05:37 -0400 From: Andres Freund To: pgsql-hackers@postgresql.org, Melanie Plageman , Thomas Munro , Heikki Linnakangas , Noah Misch , Robert Haas , Michael Paquier Subject: Re: Buffer locking is special (hints, checksums, AIO writes) Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="i6vpoucf45injzqw" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --i6vpoucf45injzqw Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, On 2025-08-22 15:44:48 -0400, Andres Freund wrote: > The hardest part about this change is that everything kind of depends on each > other. The changes are large enough that they clearly can't just be committed > at once, but doing them over time risks [temporary] performance regressions. > > > > > The order of changes I think makes the most sense is the following: > > 1) Allow some modifications while holding the buffer header spinlock > > 2) Reduce buffer pin with just an atomic-sub > > This needs to happen first, otherwise there are performance regressions > during the later steps. Here are the first few cleaned up patches implementing the above steps, as well as some cleanups. I included a commit from another thread, as it conflicts with these changes, and we really should apply it - and it's arguably required to make the changes viable, as it removes one more use of PinBuffer_Locked(). Another change included is to not return the buffer with the spinlock held from StrategyGetBuffer(), and instead pin the buffer in freelist.c. The reason for that is to reduce the most common PinBuffer_locked() call. By definition PinBuffer_locked() will become a bit slower due to 0003. But even without 0003 it 0002 is faster than master. And the previous approach also just seems pretty unclean. I don't love that it requires the new TrackNewBufferPin(), but I don't really have a better idea. I invite particular attention to the commit message for 0003 as well as the comment changes in buf_internals.h within. I'm not sure I like the TODOs added in 0003 and removed in 0004, but squashing the changes doesn't really seem better either. Greetings, Andres Freund --i6vpoucf45injzqw Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v3-0001-Improve-ReadRecentBuffer-scalability.patch"