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.96) (envelope-from ) id 1w5WpW-003LD3-2f for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Mar 2026 22:36:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w5WpV-00H8E4-0l for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Mar 2026 22:36:01 +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.96) (envelope-from ) id 1w5WpU-00H8Dv-30 for pgsql-hackers@lists.postgresql.org; Wed, 25 Mar 2026 22:36:01 +0000 Received: from fout-a5-smtp.messagingengine.com ([103.168.172.148]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1w5WpS-000000019Dt-2Ify for pgsql-hackers@postgresql.org; Wed, 25 Mar 2026 22:36:01 +0000 Received: from phl-compute-05.internal (phl-compute-05.internal [10.202.2.45]) by mailfout.phl.internal (Postfix) with ESMTP id BBBB1EC01EF; Wed, 25 Mar 2026 18:35:56 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Wed, 25 Mar 2026 18:35:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-transfer-encoding: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=1774478156; x=1774564556; bh=GN//RNNO3yQH0Kw8vffxNlKMXtsf3nS5qs3z0oVtl0c=; b= Ly6WKNv1+M/LDVSuniuhUtftRVQ1OrGclziW0gici+/YZS+ufTpg2NDd/HP9qd+l Ars358e+IWSkW+Y0tVw9hGazhrtBrpZ2SwBimqttIhCEU/S4JuYzB5yp2+NQ+QDn llf7pv9pMaTU/HXPF9rT6Cc5KerSDqKqIeEDrk5fVTdjGt7ArQYQDz74NUd9H0+A lUDZPvK4zdxZk3n0TRfXGDM34PGvLL3NJydEkr8hnx7qGLzqQxBM3Rw5CZCvEYFu rBe9PzfmAh2QaSL8GZTPvK4DL6NEKyYYCpvZs8WraGIyuBXs+wDtlLnTxmhWYr7t YIPVYI9mYLMDdJkhzZVjVw== 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 :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1774478156; x= 1774564556; bh=GN//RNNO3yQH0Kw8vffxNlKMXtsf3nS5qs3z0oVtl0c=; b=i HIhPm1ioB1ERXYWnyQFUhNGQ6jycNO50yuONFg29RxiKDMfW4vy4dWsf0Th1Y4di jaBzOQeyIjbScoJQPE3M31+G5VBjtTXZpkhetK+4t+Ij040PKctk01szj00aX/1B Wb+WHUyMC8XDnxVwafGUGBu4eh9OLfyNYYQDs0J9OgTtXjPy9w1A0H82yFIu2xwE +bb1nZm3NtInQnw5jtFCOF5QrcHcbJIxW9LSPcOF/NOUqC4xluKoLdSaLSFdzi/V zD3SjeVuxqjrrNBpOtmgSh6qdWHk9/NM+j/T2CJaoKYfOZpNdHS0YK/e+19FgP2I gGGkDMz/SmZTqYE4q9ixw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdefvdehieelucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepfffhvfevuffkfhggtggugfgjsehtkefstddttdejnecuhfhrohhmpeetnhgurhgv shcuhfhrvghunhguuceorghnughrvghssegrnhgrrhgriigvlhdruggvqeenucggtffrrg htthgvrhhnpedtleelvdfgjedvffeiueekfeeuleffhfegfffhgfffkeevueehieehhfei gffhvdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe grnhgurhgvshesrghnrghrrgiivghlrdguvgdpnhgspghrtghpthhtohepledpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtohepsghovghkvgifuhhrmhdophhoshhtghhrvghsse hgmhgrihhlrdgtohhmpdhrtghpthhtohepmhgvlhgrnhhivghplhgrghgvmhgrnhesghhm rghilhdrtghomhdprhgtphhtthhopehmihgthhgrvghlrdhprghquhhivghrsehgmhgrih hlrdgtohhmpdhrtghpthhtoheprhgvshhhkhgvkhhirhhilhhlsehgmhgrihhlrdgtohhm pdhrtghpthhtoheprhhosggvrhhtmhhhrggrshesghhmrghilhdrtghomhdprhgtphhtth hopehthhhomhgrshdrmhhunhhrohesghhmrghilhdrtghomhdprhgtphhtthhopehhlhhi nhhnrghkrgesihhkihdrfhhipdhrtghpthhtohepnhhorghhsehlvggruggsohgrthdrtg homhdprhgtphhtthhopehpghhsqhhlqdhhrggtkhgvrhhssehpohhsthhgrhgvshhqlhdr ohhrgh X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 25 Mar 2026 18:35:56 -0400 (EDT) Date: Wed, 25 Mar 2026 18:35:55 -0400 From: Andres Freund To: Melanie Plageman Cc: Noah Misch , Heikki Linnakangas , Kirill Reshke , Matthias van de Meent , pgsql-hackers@postgresql.org, Thomas Munro , Robert Haas , Michael Paquier Subject: Re: Buffer locking is special (hints, checksums, AIO writes) Message-ID: References: <4csodkvvfbfloxxjlkgsnl2lgfv2mtzdl7phqzd4jxjadxm4o5@usw7feyb5bzf> <5ubipyssiju5twkb7zgqwdr7q2vhpkpmuelxfpanetlk6ofnop@hvxb4g2amb2d> <68e89de8-5f6c-4eaf-a800-e16a5e487667@iki.fi> <20260215195239.ce.noahmisch@microsoft.com> 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 Hi, On 2026-03-25 17:34:33 -0400, Melanie Plageman wrote: > On Wed, Mar 11, 2026 at 6:40 PM Andres Freund wrote: > > > > I pushed this and many of the later patches in the series. Here are updated > > versions of the remaining changes. The last two previously were one commit > > with "WIP" in the title. The first one has, I think, not had a lot of review - > > but it's also not a complicated change. > > 0001 looks good except for the comment above PageSetChecksum() that > says it is only for shared buffers and a stray reference to the > no-longer-present bufToWrite variable in a comment around line 4490 in > bufmgr.c Thanks for catching these. Updated the PageSetChecksum() comment to * Set checksum on a page. * * If the page is in shared buffers, it needs to be locked in at least * share-exclusive mode. ... > 0002 > diff --git a/src/backend/access/nbtree/nbtpage.c > b/src/backend/access/nbtree/nbtpage.c > index cc9c45dc40c..ad700e590e8 100644 > --- a/src/backend/access/nbtree/nbtpage.c > +++ b/src/backend/access/nbtree/nbtpage.c > @@ -1011,24 +1011,48 @@ _bt_relandgetbuf(Relation rel, Buffer obuf, > BlockNumber blkno, int access) > Assert(BlockNumberIsValid(blkno)); > if (BufferIsValid(obuf)) > - _bt_unlockbuf(rel, obuf); > - buf = ReleaseAndReadBuffer(obuf, rel, blkno); > - _bt_lockbuf(rel, buf, access); > + { > + if (BufferGetBlockNumber(obuf) == blkno) > + { > + /* trade in old lock mode for new lock */ > + _bt_unlockbuf(rel, obuf); > + buf = obuf; > + } > + else > + { > + /* release lock and pin at once, that's a bit more efficient */ > + _bt_relbuf(rel, obuf); > + buf = ReadBuffer(rel, blkno); > + } > + } > + else > + buf = ReadBuffer(rel, blkno); > > Not related to this patch, but why do we unlock and relock it when > obuf has the block we need? Couldn't we pass lock mode and then just > do nothing if it is the right lockmode? I think it's very unlikely that it's called at any frequency with the same buffer and lockmode. What would be the point of calling _bt_relandgetbuf() if that's the case. > Setting that aside, I presume we don't need to check the fork and > relfilelocator (as ReleaseAndReadBuffer() did) because this code knows > it will be the same? Yea, it's a single index, so there can't be a different relfilenode. > 0003 > AFAICT, this does what you claim. I don't really know what else to > look when reviewing it, if I'm being honest. As such, I diligently fed > it through AI which suggested you may have lost a > VALGRIND_MAKE_MEM_NOACCESS(BufHdrGetBlock(buf), BLCKSZ); > which sounds right to me and like something you should fix. Good catch Melai. > Also, I'd say this comment > + /* > + * Now okay to allow cancel/die interrupts again, were held when the lock > + * was acquired. > + */ > > needs a "which" after the comma to read smoothly. Fixed. Running it through valgrind and then will work on reading through one more time and pushing them. Greetings, Andres Freund