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 1v0one-000w8h-UA for pgsql-hackers@arkaria.postgresql.org; Mon, 22 Sep 2025 22:14:23 +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 1v0ond-002RY1-FS for pgsql-hackers@arkaria.postgresql.org; Mon, 22 Sep 2025 22:14:21 +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 1v0onc-002RXr-7W for pgsql-hackers@lists.postgresql.org; Mon, 22 Sep 2025 22:14:21 +0000 Received: from fhigh-b3-smtp.messagingengine.com ([202.12.124.154]) by makus.postgresql.org with smtp (Exim 4.96) (envelope-from ) id 1v0onX-001plL-10 for pgsql-hackers@postgresql.org; Mon, 22 Sep 2025 22:14:19 +0000 Received: from phl-compute-02.internal (phl-compute-02.internal [10.202.2.42]) by mailfhigh.stl.internal (Postfix) with ESMTP id 4F93F7A020A; Mon, 22 Sep 2025 18:14:14 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-02.internal (MEProxy); Mon, 22 Sep 2025 18:14:14 -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=1758579254; x=1758665654; bh=Q9PriBADQb V8YCNvc+sW28fd75gsgCXKa+wR4wOJCio=; b=ARW43rQng+p8pbJIdk9ya9Gw8n jhUAoXu7/tKRj4QfJWMpxRzIdVJcAxBmbADcy0YDXKjA67xeLcvjXG+BLUKNg+VZ YjxAM/o7WT/7x+LXKKB5TxhNbFvC9B7qETJsqcOrx6pcq7Cty/2EATH2MrCaNJtf FRqxyYFSA8bj0oWeGuDndIuTn+saOnpofCEq2o4vlIpmi265r4ufiOFsy6HjJII+ ciBZ5IiChQiwRUuKVv8PXlo1e3uCjlFmzyUAVqPfCa7nfb3vDP+qROoCSrY3N0Nt AJLFzF6c/0neHwlsWOTP3tU0iIFPL5WBs2lzR/4Z+1c2HTaU2OXWCbtDCwZQ== 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= 1758579254; x=1758665654; bh=Q9PriBADQbV8YCNvc+sW28fd75gsgCXKa+w R4wOJCio=; b=ZfCxaWhTHldS5bdO3/INQeGOo+2pos7fEGq9fZ8F3YmObeJ2e50 vJ2/TlAyMCOl8aYiyXnLo5vv8nmMSYaL5O17Lne1E04zecuvhUXrkFn00LYlyUOS 5xDVnCK5MzDwiXXdOdZZlCXwGBJHobFt3ZllnOAj/d8xQSZ+GnbTJen497V15Ngc gdb/SRd86CTqG/FlZ7V1OA0f8ljc01nixbHkHH1Vth92TdGnRoGb9xea5CVhBJrB JKYl9Yh3jQOkTR4/5AAuESwK6Nr6PuCArWrJamJTkdsw0eKSrrvDfPz8dwCV9r2y +3FY703sVruBX0YAN3xxINxoolQ2r36ihbw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggdehledtvdcutefuodetggdotefrod 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, 22 Sep 2025 18:14:13 -0400 (EDT) Date: Mon, 22 Sep 2025 18:14:12 -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: <6kmid26do57ykqfpvq6iieniy4djsymhrypkjccazq5g4bbe6a@2y6owwv7qpex> References: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="al7hvfxknuxztweg" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --al7hvfxknuxztweg Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, On 2025-09-15 19:05:37 -0400, Andres Freund wrote: > 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. Robert looked at the patches while we were chatting, and I addressed his feedback in this new version. Changes: - Updated patch description for 0002, giving a lot more background - Improved BufferDesc comments a fair bit more in 0003 - Reduced the size of 0003 a bit, by using UnlockBufHdrExt() instead of a CAS loop in buffer_stage_common() and reordering some things in TerminateBufferIO() - Made 0004 only use the non-looping atomic op in UnpinBufferNoOwner(), not MarkBufferDirty(). I realized the latter would take additional complexity to make safe (a CAS loop in TerminateBufferIO()). I am somewhat doubtful that there are workloads where it matters... Greetings, Andres Freund --al7hvfxknuxztweg Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v4-0001-Improve-ReadRecentBuffer-scalability.patch"