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 1vQQId-007Aph-1C for pgsql-hackers@arkaria.postgresql.org; Tue, 02 Dec 2025 13:20: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 1vQQIc-007ugT-1S for pgsql-hackers@arkaria.postgresql.org; Tue, 02 Dec 2025 13:20:10 +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 1vQQIb-007ugJ-2L for pgsql-hackers@lists.postgresql.org; Tue, 02 Dec 2025 13:20:10 +0000 Received: from fout-a8-smtp.messagingengine.com ([103.168.172.151]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vQQIZ-002juu-1g for pgsql-hackers@postgresql.org; Tue, 02 Dec 2025 13:20:09 +0000 Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfout.phl.internal (Postfix) with ESMTP id 07C48EC052B; Tue, 2 Dec 2025 08:20:06 -0500 (EST) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Tue, 02 Dec 2025 08:20:06 -0500 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=fm1; t=1764681606; x=1764768006; bh=ATXrbJc8Yy VbomFJ0SS/rogVDIxhdrlSIp72m6m45BE=; b=DlfMgA19IGmiACWXlz5JJcZ0zK ht1eyR5zXX02jVSfHUGBlXtYZXNIiqTKiVbauyUaLhsADiqMKQT7WX3l0Fiyxth4 Ywyxkl78KOvDkvg4BXb9S+FnzI9BSL2ZLT4x5gyT4FDuXa27MjgKy2wCJ0Os28ux 56DYXBCw4/7RAFkzsF7Y6Kez6Eiw4+VoSgS1mBI5hCV7SrUI5TLy2J80bTw/cRe2 Fg8XXS/RsM0g0A6Kz8DpXHWitcLNjgU7Xd8oa+a+3DHURTDNKCfjj0iBIz94VgwB dfNnR6L9MlNyj6VvCcq3DDHEIEGMN4zE8bl+PQD30TFvgbTiEyHXJM6JJA1A== 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=fm1; t= 1764681606; x=1764768006; bh=ATXrbJc8YyVbomFJ0SS/rogVDIxhdrlSIp7 2m6m45BE=; b=Rk8xg+ZwtU1UwQDr4c5N6tFbxsgX9oZMYkhGIhi4gsz0d/GOHwE p7V8BWivis7UbYIKf4mFSzPSigmGTJAExFfE/dbLicpdkwsdlVJElKiGzT2k6hiE 3x3qVGG1tYCeFusi9pb38oYgG38k95wJ13hndxrnnffPurSty1kzsWyV84k5Yxxx /S1GvNc1RT39283fN7HmLQqbb8uBJ+4TvA2y8gF/anmGKD68fyUO/zstIqIBUPuC xGTnxOrEmHT3QIN1+s/9quxKbAg97IRtGJN3igk5FNzQRH6mUdLBL3Tzh8RJp4nF jj53y3qkmJHjXFMD0T6m6RhFMODNFiPS2eg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddvvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegrihhl ohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpe ffhffvvefukfhfgggtuggjsehttdfstddttddvnecuhfhrohhmpeetnhgurhgvshcuhfhr vghunhguuceorghnughrvghssegrnhgrrhgriigvlhdruggvqeenucggtffrrghtthgvrh hnpeeffffgledvffegtdevlefgtdeggffhvdekgfegteeiveejkeetudelveejhfeugeen ucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrnhgurh gvshesrghnrghrrgiivghlrdguvgdpnhgspghrtghpthhtohepkedpmhhouggvpehsmhht phhouhhtpdhrtghpthhtohepsghovghkvgifuhhrmhdophhoshhtghhrvghssehgmhgrih hlrdgtohhmpdhrtghpthhtohepmhgvlhgrnhhivghplhgrghgvmhgrnhesghhmrghilhdr tghomhdprhgtphhtthhopehmihgthhgrvghlrdhprghquhhivghrsehgmhgrihhlrdgtoh hmpdhrtghpthhtoheprhhosggvrhhtmhhhrggrshesghhmrghilhdrtghomhdprhgtphht thhopehthhhomhgrshdrmhhunhhrohesghhmrghilhdrtghomhdprhgtphhtthhopehhlh hinhhnrghkrgesihhkihdrfhhipdhrtghpthhtohepnhhorghhsehlvggruggsohgrthdr tghomhdprhgtphhtthhopehpghhsqhhlqdhhrggtkhgvrhhssehpohhsthhgrhgvshhqlh drohhrgh X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 2 Dec 2025 08:20:05 -0500 (EST) Date: Tue, 2 Dec 2025 08:20:03 -0500 From: Andres Freund To: Heikki Linnakangas Cc: Melanie Plageman , Matthias van de Meent , pgsql-hackers@postgresql.org, Thomas Munro , Noah Misch , Robert Haas , Michael Paquier Subject: Re: Buffer locking is special (hints, checksums, AIO writes) Message-ID: References: <3je3ahgf7rrmmurxo6hnlhg5d3ffwfrtjwjxd6jm5srlv5iebp@vxqk5qtgmowr> <3w7v3w6a57jnssokap4k7thoekig72flnyhd4wp3yftzdd7lm7@f6lpcfen6hr7> <6rgb2nvhyvnszz4ul3wfzlf5rheb2kkwrglthnna7qhe24onwr@vw27225tkyar> <3nce7i72ayzkunai6mkz24ckbxk74jodz4ua2chcdrwppxlxcd@w6x5kfkjrkru> 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 2025-12-02 10:01:06 +0200, Heikki Linnakangas wrote: > On 25/11/2025 22:46, Andres Freund wrote: > > > > > diff --git a/src/backend/storage/freespace/fsmpage.c > > > > > b/src/backend/storage/freesp> > > > > > /* > > > > > * Update the next-target pointer. Note that we do this even if we're only > > > > > * holding a shared lock, on the grounds that it's better to use a shared > > > > > * lock and get a garbled next pointer every now and then, than take the > > > > > * concurrency hit of an exclusive lock. > > > > > > > > > > We appear to avoid the garbling now? > > > > > > > > I don't think so. Two backends concurrently can do fsm_search_avail() and > > > > one backend might set a hint to a page that is already used up by the other > > > > one. At least I think so? > > > > > > Maybe I don't know what it meant by garbled, but I thought it was > > > talking about two backends each trying to set fp_next_slot. If they > > > now have to have a share-exclusive lock and they can't both have a > > > share-exclusive lock at the same time, then it seems like that > > > wouldn't be a problem. It sounds like you may be talking about a > > > backend taking up the freespace of a page that is referred to by the > > > fp_next_slot? > > > > Yes, a version of the latter. The value that fp_next_slot will be set to can > > be outdated by the time we actually set it, unless we do all of > > fsm_search_avail() under some form of exclusive lock - clearly not something > > desirable. > > I'm pretty sure the "garbled" in the comment means the former, not the > latter. I.e. it means that the pointer itself might become garbage. Would be > good to update the comment if that's no longer possible. Hm. I thought we had always assumed that 4byte values can be read/written tear-free. Hence thinking that garbled couldn't refer to reading entire garbage due to a concurrent write. > But speaking of that: why do we not allow two processes to concurrently set > hint bits on a page anymore? It'd make the locking a lot more complicated without much of a benefit. The new share-exclusive lock mode only requires one additional bit of lock state, for the single allowed holder. If we wanted a new lockmode that prevented the page from being written out concurrently, but could be held multiple times, we'd need at least MAX_BACKENDS bits for the lock level allowing hint bits to be set and another lock level to acquire while writing out the buffer. At the same time, there seems to be little benefit in setting hint bits on a page concurrently. A very common case is that the same hint bit(s) would be set by multiple backends, we don't gain anything from that. And in the cases where hint bits were intended to be set for different tuples, the window in which that is not allowed is very narrow, and the cost of not setting right in that moment is pretty small and the cost of not setting the hint bit right then and there isn't high. Makes sense? Greetings, Andres Freund