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 1vgABm-008tb4-0k for pgsql-hackers@arkaria.postgresql.org; Wed, 14 Jan 2026 23:22:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vgAAm-00DVB8-0N for pgsql-hackers@arkaria.postgresql.org; Wed, 14 Jan 2026 23:21:08 +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 1vgAAl-00DVAz-21 for pgsql-hackers@lists.postgresql.org; Wed, 14 Jan 2026 23:21:08 +0000 Received: from mail-dy1-x1329.google.com ([2607:f8b0:4864:20::1329]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vgAAi-000T4Z-15 for pgsql-hackers@postgresql.org; Wed, 14 Jan 2026 23:21:06 +0000 Received: by mail-dy1-x1329.google.com with SMTP id 5a478bee46e88-2ad70765db9so706781eec.1 for ; Wed, 14 Jan 2026 15:21:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768432864; x=1769037664; darn=postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=unPPCAZEh73caDr+fmaYC5aGtCM99Qi6CdGd7p6agik=; b=TFfFwC+Rv6Kz0Lydi06MnnC7O6VZ8PZUxLy1+bD5sU88mcKpSH7ckJGD86AfnEfz8a NkKCgkOrgIXp5bV0SDpbF3leatmWj3PFPf8B1JTnej5D55y+Y9RcjwZPsj6SYN1Z+Xga InbrzpDXwmrwnaq/nY5i0yo3coLYzJi7AQ7WTjk7t5iZSzaYDILlPVtFYTc5LuMkF/9Y KzC/6ysS3jhrZ+xA15M1FsRpJ+x4jxzAbeNbjBrHnMtxtvd/WCujYW3Kdwg84FqqGr8O m39ut9giiK/c2MJQZtZAAcZS1iMNyI74fDb2L70FuPLwZXFokpi3M8zsCQU4PSsf7q8Z r1vQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768432864; x=1769037664; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=unPPCAZEh73caDr+fmaYC5aGtCM99Qi6CdGd7p6agik=; b=MVZ4nAvla9pO2ifaT3zRZ/3wCi66HrGXtASgwNAoPyKycs4TGYyfkjJ0MTRcco1FvD fcR1tbJyfHsfYpx5jOZdg1rfL2CbPthZkNirNZZ1bFpuG62wB6FxrL/eGldwYvuLGVz5 wIzLFzFWoTm6ahgQdd3JPJOF8R+4CO7MqKMRTwH+4cCsMP3qsy5nis3GScttGTxLkNYq uesK/gf+lqUwFOdfoV6/AZD+fJGjgAroJafzS2E3dqOzNibaHHJ20rguqalI9vt5kHzX fioiSSr9vd28X0R6YPV1a+UPmRrEy+4O9M6DwfOVg5wqswVPnzbQBXz4AoiEo1xdF7VT j1xw== X-Forwarded-Encrypted: i=1; AJvYcCW549I7xmzCPoD///vuQ3MVXza2YJP15vchukq7gH5doypWknqZ61Krnr++GMnIyd9m5/ppnTQ7Sb0wE1Al@postgresql.org X-Gm-Message-State: AOJu0Yx8jUbZ6d2w6YWHKZGw+C7hg3A6oZ4TFKWCXziscolLwDbHFPaD sSPzvaW26yS+qhVrzV8e4eEzKTvgIkLMb2dE+7K/TxaH3uI4/iyclmcI X-Gm-Gg: AY/fxX69WPKt1Fj52/FK1HDdChN83nLP4nBuDwvSDP/7rXpV3ERkrSp92TGejCLCNeN IYc6FItseVh5HQt1Wo8gtv75NSCVgbnnA6qW/0UVJexRCoILYqAX3Yz23OZpMGwXo1WqI9hsSXj tRYTtOGUuOxRuqAYiZ7+Hit5Lw5AQCb0MhsPZfbAHisiJRKYXD4tqnQH7qTr1uO6weXN/b/gSDq IsJBBAaZBORV/vxCHd28ajoZyDOypGLjlVvU8PqVaW0QzKNSTlH4pD79B/fkw8Km9vuiBWVG7jF cRBRKTcgl0UOJ2k2vxxLLih5LSVgex3hnjiI6hjMKyBbBdqvw4Vq01Iy679Aq9IDdlBgU8tASTG 2li0QWMlTps/t4EWnveFTgH0/eaCEq3WwhoU5AueS7YdI7kjnpj4jOXyCM4xY0dM1DKZGYxdXKD 5CtKQFBtoWrKUmmxmamZxv X-Received: by 2002:a05:7301:2f8a:b0:2ac:1a21:841d with SMTP id 5a478bee46e88-2b486de5907mr5465167eec.16.1768432864117; Wed, 14 Jan 2026 15:21:04 -0800 (PST) Received: from smtpclient.apple ([142.171.105.12]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2b1706a53cdsm20565081eec.11.2026.01.14.15.21.01 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Jan 2026 15:21:03 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81.1.4\)) Subject: Re: Buffer locking is special (hints, checksums, AIO writes) From: Chao Li In-Reply-To: Date: Thu, 15 Jan 2026 07:20:27 +0800 Cc: Kirill Reshke , Heikki Linnakangas , Melanie Plageman , Matthias van de Meent , pgsql-hackers@postgresql.org, Thomas Munro , Noah Misch , Robert Haas , Michael Paquier Content-Transfer-Encoding: quoted-printable Message-Id: References: <1108f18d-cf7c-4f17-b29c-a119fe42f7e5@iki.fi> <5dwlfu2jyzkyf3nrlzxxblxctb6xio5es73ptgsahjnmfu5miu@772rc764hfhi> <4csodkvvfbfloxxjlkgsnl2lgfv2mtzdl7phqzd4jxjadxm4o5@usw7feyb5bzf> <9C2494E1-F446-42DF-B070-7E231B8E6221@gmail.com> To: Andres Freund X-Mailer: Apple Mail (2.3826.700.81.1.4) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Jan 15, 2026, at 00:30, Andres Freund wrote: >=20 > Hi, >=20 > On 2026-01-14 11:41:19 +0800, Chao Li wrote: >> Basically, code changes in 0003 is straightforward, just a couple of = small comments: >>=20 >> 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 >> ``` >>=20 >> 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=E2=80=99s true, then I = think we can >> remove the statements about lifting limitation. >=20 > I'm not following - there's plenty space for more bits if we need = that: >=20 > * 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 >=20 > 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. Also, there is an assert that concretes the impression: ``` StaticAssertDecl(BUF_REFCOUNT_BITS + BUF_USAGECOUNT_BITS + BUF_FLAG_BITS = =3D=3D 32, "parts of buffer state space need to equal 32"); ``` So, I thought we can explain 18bit refcount is good enough without = mentioning =E2=80=9Clifting=E2=80=9D that potentially adds confusion to = readers. But anyway, this is not a strong opinion. I won=E2=80=99t = insist on this comment. >=20 >=20 >> 2. By searching for =E2=80=9CLockBufHdr=E2=80=9D, I found one place = missed to update in contrib/pg_prewarm/autoprewarm.c at line 706: >> ``` >> for (num_blocks =3D 0, i =3D 0; i < NBuffers; i++) >> { >> uint32 buf_state; <=3D=3D=3D line 706, should change to uint64 >>=20 >> CHECK_FOR_INTERRUPTS(); >>=20 >> bufHdr =3D GetBufferDescriptor(i); >>=20 >> /* Lock each buffer header before inspecting. */ >> buf_state =3D LockBufHdr(bufHdr); >> ``` >=20 > Good catch! I didn't find any other similar omissions... I saw you have added this occurrence to v11. >=20 >=20 >> I will continue reviewing 0004 tomorrow. >=20 > Cool. >=20 > I'd like to push >=20 > bufmgr: Change BufferDesc.state to be a 64-bit atomic > bufmgr: Implement buffer content locks independently of lwlocks >=20 > pretty soon, so that we then can concentrate on Other than the =E2=80=9Clifting=E2=80=9D comment, v11 LGTM. But that=E2=80= =99s not a strong opinion. I explained more above, if you consider = that=E2=80=99s not a problem, I am totally fine. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/