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 1ur0mB-00Gn9z-P9 for pgsql-hackers@arkaria.postgresql.org; Tue, 26 Aug 2025 21:00:21 +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 1ur0mB-00AEWZ-3F for pgsql-hackers@arkaria.postgresql.org; Tue, 26 Aug 2025 21:00:19 +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 1ur0mA-00AEVS-2E for pgsql-hackers@lists.postgresql.org; Tue, 26 Aug 2025 21:00:19 +0000 Received: from fout-b6-smtp.messagingengine.com ([202.12.124.149]) by makus.postgresql.org with smtp (Exim 4.96) (envelope-from ) id 1ur0m8-001u9V-0N for pgsql-hackers@postgresql.org; Tue, 26 Aug 2025 21:00:17 +0000 Received: from phl-compute-03.internal (phl-compute-03.internal [10.202.2.43]) by mailfout.stl.internal (Postfix) with ESMTP id 688651D00184; Tue, 26 Aug 2025 17:00:15 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-03.internal (MEProxy); Tue, 26 Aug 2025 17:00:15 -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=1756242015; x=1756328415; bh=C5eH07ySYtqlURdmNCR1xz6FiHDBoDe2unn3ojw8bb8=; b= QnKFq2Auk1rfK2lEc/AKJCMGrwSfaya5lha/O4ZsSu6IABbwy7tn8E65/ArTZGMJ BYDIh0lKLGjsHx/LGxYPA6XyBtGf6ZONEP7dAPKhXO1BCxp/iHeVyNxPSkhXVQ2o Xlb8zqbrbXmhtrzeCHm/DUB6HthT0tHHohRw+7vM8XQxfgHYdux+qoebWwWNDsfH CywF5/nGpcPZI1Zz7q+kfhwkjgoxWyl0Lzx+I+z6g8UuXHOz3UTxiJ6+UjQNqIik 5acmLtnun5L5cti+uvf6FbRScELH8m1/rY/DlF15s0irLflZd4Akl80BXx/IwN0L z+lkrQujg/DcSsm4jO/yxA== 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=1756242015; x= 1756328415; bh=C5eH07ySYtqlURdmNCR1xz6FiHDBoDe2unn3ojw8bb8=; b=X CRuZTVw/NT9wFPXZuMcSXW8sUXm6p/eK4842ixGgV+8zvwoqL2e4B+oflIWqPuaF 3VSltbCY/Z6X6X4+XIdFwvGwa0nffs8kEhZb/yOZbXuD80iHXPT0s82G+85fqBdf zhLzeofNpxkVOWMdeaVD9ukUnDkUXAa8Zfz9lv64k/Z25uTfRJ1aK8T2c4ynapYt NT+knzV0p6+RIKwk+pXOQquTuxQ+N0gH2GHBP+JdwpHEgslYEmb6GT4GR+dhx5MZ KQSpwPItA27MEykGiNBJQ01U9oxgACD5G7K+QkH3u3h5T0Z56J4kWNQ7bUB5rzvf O/5rcC57yDYcYdWhxh0xw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgddujeeivdelucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepfffhvfevuffkfhggtggugfgjsehtkefstddttdejnecuhfhrohhmpeetnhgurhgv shcuhfhrvghunhguuceorghnughrvghssegrnhgrrhgriigvlhdruggvqeenucggtffrrg htthgvrhhnpedtleelvdfgjedvffeiueekfeeuleffhfegfffhgfffkeevueehieehhfei gffhvdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe grnhgurhgvshesrghnrghrrgiivghlrdguvgdpnhgspghrtghpthhtohepiedpmhhouggv pehsmhhtphhouhhtpdhrtghpthhtohepmhgvlhgrnhhivghplhgrghgvmhgrnhesghhmrg hilhdrtghomhdprhgtphhtthhopehrohgsvghrthhmhhgrrghssehgmhgrihhlrdgtohhm pdhrtghpthhtohepthhhohhmrghsrdhmuhhnrhhosehgmhgrihhlrdgtohhmpdhrtghpth htohephhhlihhnnhgrkhgrsehikhhirdhfihdprhgtphhtthhopehnohgrhheslhgvrggu sghorghtrdgtohhmpdhrtghpthhtohepphhgshhqlhdqhhgrtghkvghrshesphhoshhtgh hrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 26 Aug 2025 17:00:14 -0400 (EDT) Date: Tue, 26 Aug 2025 17:00:13 -0400 From: Andres Freund To: Robert Haas Cc: pgsql-hackers@postgresql.org, Melanie Plageman , Thomas Munro , Heikki Linnakangas , Noah Misch Subject: Re: Buffer locking is special (hints, checksums, AIO writes) Message-ID: References: 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 2025-08-26 16:21:36 -0400, Robert Haas wrote: > On Fri, Aug 22, 2025 at 3:45 PM Andres Freund wrote: > > My conclusion from the above is that we ought to: > > > > A) Make Buffer Locks something separate from lwlocks > > B) Merge BufferDesc.state and the content lock > > C) Allow some modifications of BufferDesc.state while holding spinlock > > +1 to (A) and (B). No particular opinion on (C) but if it works well, great. Without it I see performance regressions due to the increased rate of CAS failures due to having more changes to one atomic variable :/ > > 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 > > 3) Widen BufferDesc.state to 64 bits > > 4) Implement buffer locking inside BufferDesc.state > > 5) Do IO while holding share-exclusive lock and require all buffer > > modifications to at least hold share exclusive lock > > 6) Wait for AIO when acquiring an exclusive content lock > > No strong objections. I certainly like getting to (5) and (6) and I > think those are in the right order. I'm not sure about the rest. > I thought (1) and (2) were the same change after reading your email They are certainly related. I thought it'd make sense to split them as outlined above, as (1) is relatively verbose on its own, but far more mechanical. > and it surprises me a little bit that (2) is separate from (4). Without doing 2) first, I see performance/scalability regressions doing (4). Doing (3) without (2) also hurts... > > DOES ANYBODY HAVE A BETTER NAME THAN SHARE-EXCLUSIVE???!? > > AFAIK "share exclusive" or "SX" is standard terminology. While I'm not > wholly hostile to the idea of coming up with something else, I don't > think our tendency to invent our own way to do everything is one of > our better tendencies as a project. I guess it bothers me that we'd use share-exclusive to mean the buffer can't be modified, but for real (vs share, which does allow some modifications). But it's very well plausible that there's no meaningfully better name, in which case we certainly shouldn't differ from what's somewhat commonly used. Greetings, Andres Freund