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 1vgArH-0091Fb-13 for pgsql-hackers@arkaria.postgresql.org; Thu, 15 Jan 2026 00:05:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vgArG-00Dlgp-1q for pgsql-hackers@arkaria.postgresql.org; Thu, 15 Jan 2026 00:05:02 +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 1vgArG-00Dlgg-0t for pgsql-hackers@lists.postgresql.org; Thu, 15 Jan 2026 00:05:02 +0000 Received: from mail-dl1-x1232.google.com ([2607:f8b0:4864:20::1232]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vgArE-000WKQ-0e for pgsql-hackers@postgresql.org; Thu, 15 Jan 2026 00:05:02 +0000 Received: by mail-dl1-x1232.google.com with SMTP id a92af1059eb24-121bf277922so467577c88.0 for ; Wed, 14 Jan 2026 16:04:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768435498; x=1769040298; 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=G75LpbMIxWF9iiZl04KQkA4tZCBDOYanSKBfBYFNz5o=; b=WGy1xaxFYV+uwZG0zKLBvFBCD82ZBrBf5Y/h9AL1wdhY/4JvgTePz12BMSPKUjGRv7 pvepi+lMYB8cUEqq+//sosHZb2No6NjbHogu67NfkKJ1VBgi65m1ihYXOZQYqburMW5S tKUDHP4RR37hHlJKUJmMxZSLvmyyUkgGTs3HACLUEMEbtFJn6nGBKmFPlpATt5b+3Xpd GHmYppSskj4AOZNwCLYna64zSxdircyZukat86sznEslLi902GdIPJ6uj7Y4yKTC+0/m lqi+HBLL/KZWw/rmtTB3/nqjnLAzLAnf8TtPV3uaVqc5jtdRDmHGPo8fhuCiFq2uXl4h CeJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768435498; x=1769040298; 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=G75LpbMIxWF9iiZl04KQkA4tZCBDOYanSKBfBYFNz5o=; b=E/39CssMnwcV2+jFQkAJpZqeVFwU+BeZmlT4V5eihpUv/qdZc2udcf/WKKFQhaWdQ1 GPP6fiwAPDw5b9QxhEtf4u5RNCBWDpOFXjo3fUKt6xah53ynB0U9JrMEyNrNZgiD5Ary FkAxqw2XzhFalYxD2ZZfdB+bgLpy2JraRvuYmr1kNmq2PH2rRrCBCpg+k/b3m4Ck0kUe Zm0AZVO+RFsrbN7nv2BvJWrwXUw0ndKUvDaaqyduq2VCunhMM2WA81taL27wHDI5exED pugweeIXdybOKRlHTG101nnaKY8KuTp2HtzOIJouRGky1Ir4s2Xm4eBXQFWfGYcrmk0i 4icA== X-Forwarded-Encrypted: i=1; AJvYcCWL9WD5DxYfDqadaO8aspdb3K70KMQivqTi3hk92Lp5xm2E6Ltko4+gx2fxTV7YVGZZdkQSF1T5oVsq4f/7@postgresql.org X-Gm-Message-State: AOJu0Yy4QWWGAW4hMH2FcZcDFH+Q7Zq2cugRJkDMBpnzrWYOsQTW+Rfv ypRLj6sSuHePoyUiOWh67SuFIefKuRy9zZ4THom7LUE1pspFdUBMasiu X-Gm-Gg: AY/fxX5ofL2kd0qjHAXEqrHV94SFgVWo4xYFHjcqEj6utHPMp34aNIS/GL1HEFw4qxU R/ioCzKtCr+Sr4fADcEmoq0fQQ77rAsMCx2qyZ+AGKglI7LSL7+oI4ZUecfhgud3gVXfST4bzUN 24uLdiM3xga1hsi05mpWOWFZBXjbUJxvb8rRRs8wCGBGaiPIGizJjrZ3B4g+tgSXCP9oagUrs5/ TjJZ7WCQ5dRvhDO0ofKHmtGj6X3HPMr9NogZHI7EiDr5/75st9wXsWXznQMDr4odlG8fq7Jihxj /MGux78CTEfMm9ocXxZzLsiDcAD8HNI9VAW0/1QspzOdqNUsCy5JE4iwWfCd3B6gOMXtYfzAckF Vxe7uxycBAbq9+sYFrflM0gxbui87gKaQjLgCDvdTEaGewpOGjzT4xZTnZDL69olZECorfAK965 3seQHpeC+CSG17NPhmSMZs X-Received: by 2002:a05:701b:231a:b0:123:3584:de4b with SMTP id a92af1059eb24-12336a8add7mr3022468c88.29.1768435497522; Wed, 14 Jan 2026 16:04:57 -0800 (PST) Received: from smtpclient.apple ([142.171.105.12]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-121f24985d1sm32061198c88.16.2026.01.14.16.04.54 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Jan 2026 16:04:56 -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 08:04:21 +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: <58821140-0182-4FF3-9A4F-5B168DDB9243@gmail.com> 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 07:37, Andres Freund wrote: >=20 > Hi, >=20 > 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: >>>>=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? >>=20 >> 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. >=20 > A significant portion !=3D 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). Make sense. I think I misread the comment. >=20 >=20 >> 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"); >> ``` >=20 > You can see that being relaxed in the subsequent commit, when we start = to use > more bits. >=20 Sure. I plan to review 0003-0005 today. I believe I will get better = understanding. So, 0001 and 0002 LGTM now. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/