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 1w7jSK-005dkB-0F for pgsql-hackers@arkaria.postgresql.org; Wed, 01 Apr 2026 00:29:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w7jSI-00DzqM-2B for pgsql-hackers@arkaria.postgresql.org; Wed, 01 Apr 2026 00:29:11 +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 1w7jSH-00DzqE-29 for pgsql-hackers@lists.postgresql.org; Wed, 01 Apr 2026 00:29:10 +0000 Received: from fhigh-b4-smtp.messagingengine.com ([202.12.124.155]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1w7jSE-00000002GYS-1qBc for pgsql-hackers@postgresql.org; Wed, 01 Apr 2026 00:29:09 +0000 Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfhigh.stl.internal (Postfix) with ESMTP id 5CB237A016D; Tue, 31 Mar 2026 20:29:04 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Tue, 31 Mar 2026 20:29:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc: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=fm2; t=1775003344; x=1775089744; bh=VeWJXT2hZp IPwsB6IfoSTiP5y6Fxi16Ix59EIiYetC4=; b=HIX4cnPcANQqTtTkD3KoNcWOKi zWNuYduixe+dlPa+jQkxUXsPTFqAhCdJtBr2pTfe298Jz+Kdiv1lFB4DskSmT+aF uZAE21vxMaXY55a1t8/jD6FT/5MKlt1a3e/ISxLHqvSYztQlOA2xTCmaKE+WRmBe b/HKKlPNWbfIikfk5BfuoZorAVnO1RLZ+E25jVJuWYBArmvku9q76sGp806l19LA iVyVdvYJsM19uQK+Tra0C9QvrEmuqGhjFFY0o7GirHOUYhu85ZyJG2bfoUaq8dgT pPWzMqRuG0IqS24NSBlszzaskq923XuYw3AUhtdiKeTKBgFwEzPyJIhzUxyg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=fm2; t= 1775003344; x=1775089744; bh=VeWJXT2hZpIPwsB6IfoSTiP5y6Fxi16Ix59 EIiYetC4=; b=QPytOPms/HbjIWAJ54uODLyJS8RsCqVyCVgF+4+yZHN4BGybwC2 kRv5+liRi0KplOqyqteoac3YBbEvAOXcDjPl8l8MTNF3IIcS1pJmkf2RVCNug1L5 tPlfk2vIr8SI3KZzcPWOlVr81Tcmgho6KdUEexZa5Mq5hFf7EvbUJCT1xjTGIo0c nzESghRHS+AzQA2fsnZIFwmy00Mzm9exQYc3dBwiyfsKcJFrpm86zgH+bzJ/+C1z lUfaUNsFKLBRd1/9fRoD+qNoFKfJjVMU1+oFMj+MHFaqknHdwBDue7CiJWndcofK U0AvKXeM2HmPhCz3Aszz4qcVXpiEEZx4WCw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgdduieehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceurghi lhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurh epfffhvfevuffkfhggtggujgesthdtsfdttddtvdenucfhrhhomheptehnughrvghsucfh rhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgiivghlrdguvgeqnecuggftrfgrthhtvg hrnhepfeffgfelvdffgedtveelgfdtgefghfdvkefggeetieevjeekteduleevjefhueeg necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghnug hrvghssegrnhgrrhgriigvlhdruggvpdhnsggprhgtphhtthhopedutddpmhhouggvpehs mhhtphhouhhtpdhrtghpthhtohepsghovghkvgifuhhrmhdophhoshhtghhrvghssehgmh grihhlrdgtohhmpdhrtghpthhtohepmhgvlhgrnhhivghplhgrghgvmhgrnhesghhmrghi lhdrtghomhdprhgtphhtthhopehmihgthhgrvghlrdhprghquhhivghrsehgmhgrihhlrd gtohhmpdhrtghpthhtoheprhgvshhhkhgvkhhirhhilhhlsehgmhgrihhlrdgtohhmpdhr tghpthhtoheprhhosggvrhhtmhhhrggrshesghhmrghilhdrtghomhdprhgtphhtthhope hthhhomhgrshdrmhhunhhrohesghhmrghilhdrtghomhdprhgtphhtthhopehhlhhinhhn rghkrgesihhkihdrfhhipdhrtghpthhtohepnhhorghhsehlvggruggsohgrthdrtghomh dprhgtphhtthhopeihrdhsohhkohhlohhvsehpohhsthhgrhgvshhprhhordhruh X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 31 Mar 2026 20:29:03 -0400 (EDT) Date: Tue, 31 Mar 2026 20:29:02 -0400 From: Andres Freund To: Yura Sokolov Cc: Melanie Plageman , 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: <5ubipyssiju5twkb7zgqwdr7q2vhpkpmuelxfpanetlk6ofnop@hvxb4g2amb2d> <68e89de8-5f6c-4eaf-a800-e16a5e487667@iki.fi> <20260215195239.ce.noahmisch@microsoft.com> <5bf667f3-5270-4b19-a08f-0facbecdff68@postgrespro.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2026-03-31 18:05:46 -0400, Andres Freund wrote: > On 2026-03-31 19:02:33 +0300, Yura Sokolov wrote: > > 27.03.2026 23:00, Andres Freund wrote: > > > On 2026-03-25 18:35:55 -0400, Andres Freund wrote: > > >> Running it through valgrind and then will work on reading through one more > > >> time and pushing them. > > > > > > And done. > > > > > > Phew, this project took way longer than I'd though it'd take. > > > > In addition to bug with BM_IO_ERROR [1] , I found race condition in > > PinBuffer in this lines of code: > > > > if (unlikely(skip_if_not_valid && !(old_buf_state & BM_VALID))) > > return false; > > > > /* > > * We're not allowed to increase the refcount while the buffer > > * header spinlock is held. Wait for the lock to be released. > > */ > > if (old_buf_state & BM_LOCKED) > > old_buf_state = WaitBufHdrUnlocked(buf); > > > > While we waited for buffer header for being unlocked, it may become > > invalid, isn't it? > > Therefore, check related to skip_if_not_valid have to happen after waiting. > > Yea, that does seem wrong. Not sure how it ended up that way. > > I think it may be better to add a continue after the WaitBufHdrUnlocked(), so > that we restart the loop, rather than moving the skip_if_not_valid check. Done that way. Thanks for finding & reporting this, well spotted! Greetings, Andres