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 1vfqay-005SOt-1s for pgsql-hackers@arkaria.postgresql.org; Wed, 14 Jan 2026 02:26:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vfqaw-007YpD-2R for pgsql-hackers@arkaria.postgresql.org; Wed, 14 Jan 2026 02:26:50 +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 1vfqaw-007Yp5-1J for pgsql-hackers@lists.postgresql.org; Wed, 14 Jan 2026 02:26:50 +0000 Received: from mail-dy1-x1331.google.com ([2607:f8b0:4864:20::1331]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vfqau-000Kxx-0I for pgsql-hackers@postgresql.org; Wed, 14 Jan 2026 02:26:50 +0000 Received: by mail-dy1-x1331.google.com with SMTP id 5a478bee46e88-2b04a410f42so7299097eec.0 for ; Tue, 13 Jan 2026 18:26:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768357605; x=1768962405; darn=postgresql.org; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=2380MCURCeutZNCIPt2EwnfgJAgdse6nLMjlDEGs7BE=; b=EyIWd5KoqGTfjSpXGn00qTurikHqEfXWXu+lTKgj/cwUZS5F4ynoegUTcB2aB6blgW /fWlkoa9oWET6Zrz1/DjPNsoDgaqUk5uYJA7869/puY35V4DtW6zYkNPkwLMM3OocZ2T IqVGEXMV9tP9t2aXdVPUPCw/oo+b+o3wBi94KSIFIY+NpLCaZnKZ14KnX82vBTYOVNxe BhNDdalt9E8wJDsvXVCjZ/ZHc7gCQgsvFncH/N6YhqjqRcz6o6mYDl9sxHONypw0aP4r lMNXA3Xtsyph8MsGTiH0bMqM8Y+OJzK42mO+hv3ZnvKhdTHlghRenknORy3I2pefBJfj sZ2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768357605; x=1768962405; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=2380MCURCeutZNCIPt2EwnfgJAgdse6nLMjlDEGs7BE=; b=hegowcASYSNbJXVkgV1ZEWBKDUC3qVZQ/mq1knhhOukaxsZazVt/K6zInidMJiRKH/ S7BhSbWGaMQAZ7x0A3FDcBDXTvJ6lJ8Omu8h65n/fjmEtCpW69POV/evH9MQAJ1wAHDt 70LDjAXsudK6xua0L3prF7Lj64XfRJQedqSXxxRgO/nnnpBe9MHMqv+mBzqeRTbV5dLz jpoxf/3QKOpSUvTC3saqPgVRSHGxx/1t7SDmh+RGnWwswOcZnogjdYziVTBRx+vDCqCe Hf2jNoRidf4qo2I7oJmxdwSELY4L9ZcXkykqBZ1PXBkfkLsvLq099SJLbSl/TN7c56uC Tf4g== X-Forwarded-Encrypted: i=1; AJvYcCUiRW1aS469sKQMgQwWGtHr5YTSs0DwP5kkLwgoBdl6leJluswGuF1SXyhLlrmRqsx7ZL4ANcByFziT/7Qv@postgresql.org X-Gm-Message-State: AOJu0Ywsb/b5ZYjktNvyJKvcV6wm1aS+1EsGeGX/d7w0g4MoNw4dXAkX +5VxnWIpt53Z9YJh/BxtVyyDstVPtRHkPE4jeImcs39i0gO2cIfm1fi7 X-Gm-Gg: AY/fxX44bQrDSLfBa1fydcIayoSkmA3vvtTcKdofG1lVrL3LZte9fzQqLZRuN2CFYeV 9mw/aM77zUVkaNfiLZ1UL1H0rrzJpP1A6ESDKenA8J5oyB3SCETQ7pfm+g+A+qPvMgNf5Uq5JTG dpVZmW1vwAZ0r4+s/7QpuQVkWfiu5zYFtz5zcQ/XlbGA9jHgDfj7f0HwbvTDW170Jf0pzJ7JwiI i2RhRWFiNWXnIqolTj/CrI1JwAwqCznIhWDaZSpl6kp4vYPHbygT7bA8reLIjlLKpyrGfkQ9Hgn giHfVClnSbiIaVqQfAWCGF7UjsZ92ZLnugRR1QOP2KlHhCK/KpCBuwfX/rBtu+Sf2rZXJqWUhiU IhAyCnFGJSgvFBMaXRDTfXdesdo9Ac+a4da77gjsL/JxQbP4Pvi3OvBfQKRUSXw2PgZIpZ36qAg nSb2tEssMwIVV7fK1ZrHRp X-Received: by 2002:a05:7301:3f13:b0:2b0:52f5:18d1 with SMTP id 5a478bee46e88-2b486c9b208mr1236510eec.11.1768357605148; Tue, 13 Jan 2026 18:26:45 -0800 (PST) Received: from smtpclient.apple ([142.171.105.12]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2b170673266sm19419682eec.1.2026.01.13.18.26.40 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Jan 2026 18:26:44 -0800 (PST) From: Chao Li Message-Id: Content-Type: multipart/mixed; boundary="Apple-Mail=_FFEB6AA3-0D2D-4781-BC67-A5F276E1E243" 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) Date: Wed, 14 Jan 2026 10:26:07 +0800 In-Reply-To: Cc: Kirill Reshke , Heikki Linnakangas , Melanie Plageman , Matthias van de Meent , pgsql-hackers@postgresql.org, Thomas Munro , Noah Misch , Robert Haas , Michael Paquier To: Andres Freund References: <1108f18d-cf7c-4f17-b29c-a119fe42f7e5@iki.fi> <5dwlfu2jyzkyf3nrlzxxblxctb6xio5es73ptgsahjnmfu5miu@772rc764hfhi> <4csodkvvfbfloxxjlkgsnl2lgfv2mtzdl7phqzd4jxjadxm4o5@usw7feyb5bzf> 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 --Apple-Mail=_FFEB6AA3-0D2D-4781-BC67-A5F276E1E243 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Jan 13, 2026, at 08:33, Andres Freund wrote: >=20 > Hi, >=20 > On 2026-01-12 12:45:03 -0500, Andres Freund wrote: >> I'm doing another pass through 0003 and will push that if I don't = find >> anything significant. >=20 > Done, after adjust two comments in minor ways. >=20 >=20 >> Also working on doing comment polishing of the later patches, found a = few >> things, but not quite enough to be worth reposting yet. >=20 > Here are the remaining commits, with a bit of polish: >=20 > - fixed references to old names in some places (lwlocks, release_ok) >=20 > - Aded an assert that we don't already hold a lock in = BufferLockConditional() >=20 > - typo and grammar fixes >=20 > - updated the commit message of the LW_FLAG_RELEASE_OK, as "requested" = by > Melanie. I hope this explains the situation better. >=20 > - added a commit that renames ResOwnerReleaseBufferPin to > ResOwnerReleaseBuffer (et al), as it now also releases content locks = if held >=20 > I kept this separate as I'm not yet sure about the new name, = partially due > to there also being a "buffer io" resowner. I tried "buffer = ownership" for > the resowner that tracks pins and locks, but that was long and not = clearly > better. >=20 > Greetings, >=20 > Andres Freund > = Hi Andres, So far I=E2=80=99ve only reviewed 0001 and 0002. I=E2=80=99m not very = familiar with this area, so the review has been a bit slow. Overall, 0001 looks good to me. It renames LW_FLAG_RELEASE_OK to = LW_FLAG_WAKE_IN_PROGRESS and inverts the meaning, which makes sense. I = only have a small nit on naming: the local variable = =E2=80=9Cnew_release_in_progress". I see that it=E2=80=99s inherited = from the old name and was updated from =E2=80=9C_ok" to = =E2=80=9C_in_progress", but now that the flag itself is renamed, would = it make sense to rename the variable as well? Something like = =E2=80=9Cwake_in_progress" or =E2=80=9Cnew_wake_in_progress" might = better reflect the new flag name. In 0002, a bunch of new macros are introduced. My initial impression = wasn=E2=80=99t great, mostly due to the amount of line wrapping. Looking = a bit closer, I also noticed some duplication, for example, = "BUF_REFCOUNT_BITS + BUF_USAGECOUNT_BITS" appears more than once; and a = small inconsistency between BUF_STATE_GET_REFCOUNT and = BUF_STATE_GET_USAGECOUNT (even though the former doesn=E2=80=99t = actually need a shift). I tried a small refactor of the macro definitions in the attached diff = to see if things could be made a bit more regular. It introduces a = helper macro MASK() and a BUF_REFCOUNT_SHIFT constant, and removes a bit = of duplication. If you like it, feel free to take it; otherwise, please = just ignore it. Note that, the diff is based on 0002. (I actually hesitated to attach a diff, because if you=E2=80=99ve = already created a CF entry, the attached diff could break the CI tests. = If that happens, sorry about that.) Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/ --Apple-Mail=_FFEB6AA3-0D2D-4781-BC67-A5F276E1E243 Content-Disposition: attachment; filename=buf_internals_h.diff Content-Type: application/octet-stream; x-unix-mode=0644; name="buf_internals_h.diff" Content-Transfer-Encoding: 7bit diff --git a/src/include/storage/buf_internals.h b/src/include/storage/buf_internals.h index 2f607ea2ac5..34e6c6cd54f 100644 --- a/src/include/storage/buf_internals.h +++ b/src/include/storage/buf_internals.h @@ -49,28 +49,26 @@ StaticAssertDecl(BUF_REFCOUNT_BITS + BUF_USAGECOUNT_BITS + BUF_FLAG_BITS == 32, "parts of buffer state space need to equal 32"); -/* refcount related definitions */ -#define BUF_REFCOUNT_ONE 1 -#define BUF_REFCOUNT_MASK \ - ((1U << BUF_REFCOUNT_BITS) - 1) +#define BUF_REFCOUNT_SHIFT 0 +#define BUF_USAGECOUNT_SHIFT (BUF_REFCOUNT_SHIFT + BUF_REFCOUNT_BITS) +#define BUF_FLAG_SHIFT (BUF_USAGECOUNT_SHIFT + BUF_USAGECOUNT_BITS) + +/* mask generator */ +#define MASK(bits) ((1U << (bits)) - 1) +/* refcount related definitions */ +#define BUF_REFCOUNT_ONE 1U +#define BUF_REFCOUNT_MASK (MASK(BUF_REFCOUNT_BITS) << BUF_REFCOUNT_SHIFT) /* usage count related definitions */ -#define BUF_USAGECOUNT_SHIFT \ - BUF_REFCOUNT_BITS -#define BUF_USAGECOUNT_MASK \ - (((1U << BUF_USAGECOUNT_BITS) - 1) << (BUF_USAGECOUNT_SHIFT)) -#define BUF_USAGECOUNT_ONE \ - (1U << BUF_REFCOUNT_BITS) +#define BUF_USAGECOUNT_ONE (1U << BUF_USAGECOUNT_SHIFT) +#define BUF_USAGECOUNT_MASK (MASK(BUF_USAGECOUNT_BITS) << BUF_USAGECOUNT_SHIFT) /* flags related definitions */ -#define BUF_FLAG_SHIFT \ - (BUF_REFCOUNT_BITS + BUF_USAGECOUNT_BITS) -#define BUF_FLAG_MASK \ - (((1U << BUF_FLAG_BITS) - 1) << BUF_FLAG_SHIFT) +#define BUF_FLAG_MASK (MASK(BUF_FLAG_BITS) << BUF_FLAG_SHIFT) /* Get refcount and usagecount from buffer state */ #define BUF_STATE_GET_REFCOUNT(state) \ - ((state) & BUF_REFCOUNT_MASK) + (((state) & BUF_REFCOUNT_MASK) >> BUF_REFCOUNT_SHIFT) #define BUF_STATE_GET_USAGECOUNT(state) \ (((state) & BUF_USAGECOUNT_MASK) >> BUF_USAGECOUNT_SHIFT) @@ -81,8 +79,7 @@ StaticAssertDecl(BUF_REFCOUNT_BITS + BUF_USAGECOUNT_BITS + BUF_FLAG_BITS == 32, * entry associated with the buffer's tag. */ -#define BUF_DEFINE_FLAG(flagno) \ - (1U << (BUF_REFCOUNT_BITS + BUF_USAGECOUNT_BITS + (flagno))) +#define BUF_DEFINE_FLAG(flagno) (1U << (BUF_FLAG_SHIFT + (flagno))) /* buffer header is locked */ #define BM_LOCKED BUF_DEFINE_FLAG( 0) --Apple-Mail=_FFEB6AA3-0D2D-4781-BC67-A5F276E1E243--