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 1vg3lh-007j3p-0r for pgsql-hackers@arkaria.postgresql.org; Wed, 14 Jan 2026 16:30:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vg3lg-00Bb3q-1g for pgsql-hackers@arkaria.postgresql.org; Wed, 14 Jan 2026 16:30:48 +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 1vg3lg-00Bb3i-0l for pgsql-hackers@lists.postgresql.org; Wed, 14 Jan 2026 16:30:48 +0000 Received: from fout-b3-smtp.messagingengine.com ([202.12.124.146]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vg3le-000SaW-1V for pgsql-hackers@postgresql.org; Wed, 14 Jan 2026 16:30:48 +0000 Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfout.stl.internal (Postfix) with ESMTP id CD6ED1D0014A; Wed, 14 Jan 2026 11:30:44 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-04.internal (MEProxy); Wed, 14 Jan 2026 11:30:45 -0500 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=fm2; t=1768408244; x=1768494644; bh=J5+uRyRqRWBZ3XSg4q1l4XQndRgr73FjcxPKYmsx2XI=; b= XVRIlXYcyh0NiAOfU9Gos82MVhTQtLtmcT+EP/h1N6MpJi/pJnKARamhKPvcUqqv uaSQ4T2eyBRI8X8eDIXss2zOi2g3U2pLc7g2z1+8vKw52SCBY2lWReOa3kR9/z7u r7Tp8H7TP1Wk8ghUXRMFJIWonsR/YrxqCYBXr9sCkg/P1eNfSxBU8KmdON/y0Oy6 Xdb3tlZ5DLvvg7qhP87nY1bxv/alPQW+g8i9SQl99hdY3QNnuLr597wgZB4OwGob kCBYPrdaMh0aNrXvAZXXUW+sAQoj6Y7fUv+lcqg5IF/TWrW12hCjDRxRMAT4or5P yAd95ozOeKMEoB8SC6giBg== 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=fm2; t=1768408244; x= 1768494644; bh=J5+uRyRqRWBZ3XSg4q1l4XQndRgr73FjcxPKYmsx2XI=; b=b Bggr6q7HK9Op7xgjKlez8y3IQ9ZzpavfhkPY8+ZyQmB4twp4+d2qRT/5aMx1LHLA D18DsiCR6zNy/Hh5wfsb4P3ZWrFIzxtQwvG7mT30oGKG3tVAf4JxxXz0Z/GRlYbR FBtFoae2eN0R+DSV3eGzVVUc4KAOtMu3Yi4URl+TSyzOEk5IWchefZfM3ORVilRb NbInabF7KHRf0TZuchrf7Sdu/XAFUJFvCH1S3UXqGIMmKfWB46Yx3E1QuKN9mNDA CoR0pcn4PuDlfFHpm5UbGUXqB5pTT+/esnBAO09Ye+OJh2BughKjxMBcBo2IXSJi MWPxPwyOuHYVNB1rDlTzw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdduvdefieeiucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepfffhvfevuffkfhggtggugfgjsehtkefstddttdejnecuhfhrohhmpeetnhgurhgv shcuhfhrvghunhguuceorghnughrvghssegrnhgrrhgriigvlhdruggvqeenucggtffrrg htthgvrhhnpedtleelvdfgjedvffeiueekfeeuleffhfegfffhgfffkeevueehieehhfei gffhvdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe grnhgurhgvshesrghnrghrrgiivghlrdguvgdpnhgspghrtghpthhtohepuddtpdhmohgu vgepshhmthhpohhuthdprhgtphhtthhopegsohgvkhgvfihurhhmodhpohhsthhgrhgvsh esghhmrghilhdrtghomhdprhgtphhtthhopehlihdrvghvrghnrdgthhgrohesghhmrghi lhdrtghomhdprhgtphhtthhopehmvghlrghnihgvphhlrghgvghmrghnsehgmhgrihhlrd gtohhmpdhrtghpthhtohepmhhitghhrggvlhdrphgrqhhuihgvrhesghhmrghilhdrtgho mhdprhgtphhtthhopehrvghshhhkvghkihhrihhllhesghhmrghilhdrtghomhdprhgtph htthhopehrohgsvghrthhmhhgrrghssehgmhgrihhlrdgtohhmpdhrtghpthhtohepthhh ohhmrghsrdhmuhhnrhhosehgmhgrihhlrdgtohhmpdhrtghpthhtohephhhlihhnnhgrkh grsehikhhirdhfihdprhgtphhtthhopehnohgrhheslhgvrggusghorghtrdgtohhm X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 14 Jan 2026 11:30:44 -0500 (EST) Date: Wed, 14 Jan 2026 11:30:43 -0500 From: Andres Freund To: Chao Li Cc: Kirill Reshke , Heikki Linnakangas , 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: <1108f18d-cf7c-4f17-b29c-a119fe42f7e5@iki.fi> <5dwlfu2jyzkyf3nrlzxxblxctb6xio5es73ptgsahjnmfu5miu@772rc764hfhi> <4csodkvvfbfloxxjlkgsnl2lgfv2mtzdl7phqzd4jxjadxm4o5@usw7feyb5bzf> <9C2494E1-F446-42DF-B070-7E231B8E6221@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <9C2494E1-F446-42DF-B070-7E231B8E6221@gmail.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2026-01-14 11:41:19 +0800, Chao Li wrote: > Basically, code changes in 0003 is straightforward, just a couple of small comments: > > 1 > ``` > - * refcounts in buf_internals.h. This limitation could be lifted by using a > - * 64bit state; but it's unlikely to be worthwhile as 2^18-1 backends exceed > - * currently realistic configurations. Even if that limitation were removed, > - * we still could not a) exceed 2^23-1 because inval.c stores the ProcNumber > - * as a 3-byte signed integer, b) INT_MAX/4 because some places compute > - * 4*MaxBackends without any overflow check. We check that the configured > - * number of backends does not exceed MAX_BACKENDS in InitializeMaxBackends(). > + * refcounts in buf_internals.h. This limitation could be lifted, but it's > ``` > > Before this patch, there was room for lifting the limitation. With this > patch, state is 64bit already, but the significant 32bit will be used for > buffer locking as stated in buf_internals.h, in other words, there is no > room for lifting the limitation now. If that’s true, then I think we can > remove the statements about lifting limitation. I'm not following - there's plenty space for more bits if we need that: * State of the buffer itself (in order): * - 18 bits refcount * - 4 bits usage count * - 12 bits of flags * - 18 bits share-lock count * - 1 bit share-exclusive locked * - 1 bit exclusive locked That's 54 bits in total. Which part is in the lower and which in the upper 32bit isn't relevant for anything afaict? > 2. By searching for “LockBufHdr”, I found one place missed to update in contrib/pg_prewarm/autoprewarm.c at line 706: > ``` > for (num_blocks = 0, i = 0; i < NBuffers; i++) > { > uint32 buf_state; <=== line 706, should change to uint64 > > CHECK_FOR_INTERRUPTS(); > > bufHdr = GetBufferDescriptor(i); > > /* Lock each buffer header before inspecting. */ > buf_state = LockBufHdr(bufHdr); > ``` Good catch! I didn't find any other similar omissions... > I will continue reviewing 0004 tomorrow. Cool. I'd like to push bufmgr: Change BufferDesc.state to be a 64-bit atomic bufmgr: Implement buffer content locks independently of lwlocks pretty soon, so that we then can concentrate on Require share-exclusive lock to set hint bits and to flush and then subsequently on WIP: bufmgr: Don't copy pages while writing out as there are other patches that have this work as a dependency... Greetings, Andres Freund