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 1vgAR7-008w9n-0t for pgsql-hackers@arkaria.postgresql.org; Wed, 14 Jan 2026 23:38: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 1vgAR6-00DdH9-1V for pgsql-hackers@arkaria.postgresql.org; Wed, 14 Jan 2026 23:38:00 +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.96) (envelope-from ) id 1vgAR5-00DdH0-16 for pgsql-hackers@lists.postgresql.org; Wed, 14 Jan 2026 23:38:00 +0000 Received: from fout-a7-smtp.messagingengine.com ([103.168.172.150]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vgAR2-000TDp-2i for pgsql-hackers@postgresql.org; Wed, 14 Jan 2026 23:37:58 +0000 Received: from phl-compute-08.internal (phl-compute-08.internal [10.202.2.48]) by mailfout.phl.internal (Postfix) with ESMTP id B0C6DEC024B; Wed, 14 Jan 2026 18:37:55 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Wed, 14 Jan 2026 18:37:55 -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=1768433875; x=1768520275; bh=Cp+NUwrCwPHWvM7WfkNKY5j70NgXNy0oGhdB3bZURIY=; b= UBAjHayrH1plMfq5rMMPw+GuBSnFowdr/llpdj9Rg4+huCUbsojMXCBz5AzJQ4ve /zTzu096HfZDFBoQXkQ2U6jPEGbNTX8Eji5EI9AOZHtL/lr0ow9mOte3sM5LxXsD +EqhWZaIk0mdPCNWTvMnkK02QJlt988sctww199qxbgICP7QoOhNOJqkmfEDV18t RYA1stfc99iouIMWpO6MhU3ECmfNIlaU5kajoYBzfTnjxMpw61YotAIWdX1FYhYL jtJ6ORhb/C8j04CMaYq+iwtE89NfSvWbeoGKSj0lXBLZLK1GNiSzDwxddA0Ngmio onZJqvfHIhYO2ELD23P8pQ== 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=1768433875; x= 1768520275; bh=Cp+NUwrCwPHWvM7WfkNKY5j70NgXNy0oGhdB3bZURIY=; b=n QN1j3dDEYntBB3LELNyi7xe9VDm9fPiqlMpa6JuBZowpEM8Bq1VaZkzMJrk69kbm mP/PilVKeRK2Kgh+aS3Tlug9VpIl8NquQzykc1+zsp9r9Bz9rbISq6CDGup17aDI 7ROEpTQBRj3th9ZYw8by9+hXYk21Zrpl3hWp9ZerHK1mbPz4oMCt0bywkDsaXKrt 9jEwZGrsDsR2S30rxuZ/Oix6osxXNc77mZDZ2Z3hMq6LBLWDERxHGJeKviNlPZN4 3zv6BQnptfxTY1t21f8G/XTNbNSDMIUJS8IiUGXwE4z6Ck9aP8eIDSCQVBGdg8bs /GvhgomXSKmQ36Tabw9MA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdduvdeghedvucetufdoteggodetrf 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 18:37:54 -0500 (EST) Date: Wed, 14 Jan 2026 18:37:54 -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: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2026-01-15 07:20:27 +0800, Chao Li wrote: > > On Jan 15, 2026, at 00:30, Andres Freund wrote: > > 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? > > Because I saw the comment in buf_internals.h: > ``` > * NB: A future commit will use a significant portion of the remaining bits to > * implement buffer locking as part of the state variable. > ``` > That seems to indicate all the significant 32 bits will be used for buffer locking. A significant portion != all. As the above excerpt from the comment shows, the locking uses 20 bits. We could increase max backends by 5 bits without running out of bits (we'd need space both in the refcount bitspace as well as the share-lock bitspace). > Also, there is an assert that concretes the impression: > ``` > StaticAssertDecl(BUF_REFCOUNT_BITS + BUF_USAGECOUNT_BITS + BUF_FLAG_BITS == 32, > "parts of buffer state space need to equal 32"); > ``` You can see that being relaxed in the subsequent commit, when we start to use more bits. Greetings, Andres Freund