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 1w5VsI-003KFL-2f for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Mar 2026 21:34:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w5VsH-00GhoU-0u for pgsql-hackers@arkaria.postgresql.org; Wed, 25 Mar 2026 21:34:49 +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 1w5VsG-00GhoM-36 for pgsql-hackers@lists.postgresql.org; Wed, 25 Mar 2026 21:34:49 +0000 Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w5VsE-000000018hY-3wfp for pgsql-hackers@postgresql.org; Wed, 25 Mar 2026 21:34:49 +0000 Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-66971ccfcabso356328a12.3 for ; Wed, 25 Mar 2026 14:34:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774474486; cv=none; d=google.com; s=arc-20240605; b=EP9PAXrzXC0OsUC2kthMxokPtUCgpkkgOxMySEbaMPkvyJZJGrqxjRg+LRB//++UrK E/iQGv4NZkKYzQSmIFekupW/9jZ2nm9j8bxP8ioG21jq3BGnqBHuFXgzxvDkp6uU3LPI LUmf8H+Tq1BNzAJ18ooj1vbYl08M7lkCA2AMaAojhL/1EcqfvVn9rXXuYPAb0Wsu5+xW z6cc5ou4X95nDqj1OHJr7Bnacw0P9rTvyemZ3savqy/jZHHZyDQtrE0Dt9xbFeREcHji dkU8lWtcqS5EDcYQLX7LEsg9YB8/3Iw8I2HGJplzyDvXfsvnko8VT+aCW4uT749jfqVL 1hOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=5eiirxYdDJTDsfdTv3rHKH76fuVKz7NjiUijnjSVPUY=; fh=YBZ+kHE+rl8dqyeXMpI3j2CKHoAdtVTzZY0jdEKQIYE=; b=NfT+Jvf54bpymPSXXxbjzXXeCZOk/ZBB8lRqhrC75z01CzANuHmPkBZYBZr+jRjzjO uoEMkN20ZuIGYXn1oNlNpbQGFvLCZ0efC45dEp0UY4Sp3JSxs7IiFN90Aj/qQcQlSwjq uB0rnFrSXb+HFTEhwLwG2ZVH/8Xxm/QemOWIcrncycjk/RNw30JUExbcbuGatKODT4jg XkK6NDMBYzfUHRl9s8HD49fjVD4HVJ1DE6jbv5ZW7oC0gMHnEkttMbFqYcNWnZ9YbFTN JeuLPcSvMOrvzChIefJ6mbN/FDv+1yEMN9uiwor/9J5LGC/Zw6rHonHVoMbjZkHoxfsA aY2A==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774474486; x=1775079286; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=5eiirxYdDJTDsfdTv3rHKH76fuVKz7NjiUijnjSVPUY=; b=faLVKo2UyHPezZa1MdpBU37aQKUCuZjUx4cHNb73P5mBBk6c+QJaSP4aSWrmBFIzt6 4qvmdMyXaVQWytkDNua7ojuwiGA/Jwui4UGcovBQToaCspsmeda3aR9LP9C5yhAnYXgK AbgqR5oEzQjRiA/BHNIz5w9febxuBdgB2udM7Uw8RoBj9DuauPOHaWw4b6l1BnOKb6Rv HCUXXvDhJ+Qqhc0vkrZpD9QEMfZXllQPG3FQTkcZmzPkRnW9DJXHKfZyxIuJ03UFCVBY z9lBfrX+7LTzaDM5fAV4OPrq+jW4w8v5IeLhM2zYa0IbMPePjrgysF3p2QYmizeyg9pf +Bcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774474486; x=1775079286; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=5eiirxYdDJTDsfdTv3rHKH76fuVKz7NjiUijnjSVPUY=; b=kQrG4wwufOpMtSJZrJ8+uRmtoQvPCxGRtfS1W/UlrVAMUa73vKlGBbZVZxCM7x2WJ4 TgPBMD+96kdCQL7mYFPE44S3MhUJr1ZHoNScW20SqTb5PmpqJAlNtD+aZ6GnTC28Gqxc bdGH7UFhvo9gjbEA4HOKhN/Jsfbs5RGXqhZTs1nEhrviQPrlEfWJWYSKii1GonHwOC9p X9nsqWmmB+7Ww+b5tuYb1n/i7xFkBAozaytXCi0mhaFKkv+KvaqvhpAgMa2kbIgfhAzB 3ewxQxkH5Cf0ZXujxCYGG1Oy85aBt/MNvPLmbTkonX1Wtdz8EtnTLDnVAT1GXKO4q2CX 1RJw== X-Forwarded-Encrypted: i=1; AJvYcCWjdiP7l9IsmRq8lDy6VIIBuLnDpvnrayJ3niiIP0DImZ+DNkrr7M9CAjRagpaTKUQvq6wVhT6WPjKrqYzY@postgresql.org X-Gm-Message-State: AOJu0YxC3RAg+DQVTW1qZ94u7C9p/BIE4Jt/KS3RN3ZzibIBGjSmdJPw PQtZgVRDkiwnobHlQG+VFvu+T7Ek0BESKcsu4zJoiEKCAxlcuVBJ0ycTkJkFY/Kl1HLndysUXCG uOHK/oWvw6/vRMfY1PExV7OFKSRjZqBU= X-Gm-Gg: ATEYQzxmpECkRnRu6KZpZgiQHkaDyXx6ZKgKi8/2jlpTzM4Ue3NsFUlovlcROLEClAG D47nYBqO3E6gYSx54gq8JbrsVyZwDcQB0/xH2+9wEcfCK9c2K3IOJ85sUQd/8paP8T03L7f+VW4 DpXJk/5WtiDhULpWwG/jAl0Qk2yC3H1aitzMYkJam32S/fAEpG9NOJbsiGlLcIsvFBLwEM/2LEa YbeVyZmNImGfazPuN7jiW9Z2M3AlZJp2O4qhHNh42hNoyIIfEru2qZasiu1HO6f2s8puy3Kszrc tmmmN1jaiLn5ST/RgeeDV0IJqZYKsYFERh3s/3cJfwTmAofr9lUlCtSRJ25cZ+6nnSqu17GGMIc ZLh9aK+5k X-Received: by 2002:a05:6402:34cf:b0:66a:55eb:1cfa with SMTP id 4fb4d7f45d1cf-66a8262e259mr3189274a12.9.1774474485093; Wed, 25 Mar 2026 14:34:45 -0700 (PDT) MIME-Version: 1.0 References: <5dwlfu2jyzkyf3nrlzxxblxctb6xio5es73ptgsahjnmfu5miu@772rc764hfhi> <4csodkvvfbfloxxjlkgsnl2lgfv2mtzdl7phqzd4jxjadxm4o5@usw7feyb5bzf> <5ubipyssiju5twkb7zgqwdr7q2vhpkpmuelxfpanetlk6ofnop@hvxb4g2amb2d> <68e89de8-5f6c-4eaf-a800-e16a5e487667@iki.fi> <20260215195239.ce.noahmisch@microsoft.com> In-Reply-To: From: Melanie Plageman Date: Wed, 25 Mar 2026 17:34:33 -0400 X-Gm-Features: AQROBzDbG11oHtVAbrefT_FbpZXIrHjoPpvEPUUE4W7wzZL4cXuQnMIEWW66k_8 Message-ID: Subject: Re: Buffer locking is special (hints, checksums, AIO writes) To: Andres Freund Cc: Noah Misch , Heikki Linnakangas , Kirill Reshke , Matthias van de Meent , pgsql-hackers@postgresql.org, Thomas Munro , Robert Haas , Michael Paquier Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Mar 11, 2026 at 6:40=E2=80=AFPM Andres Freund = wrote: > > I pushed this and many of the later patches in the series. Here are upda= ted > versions of the remaining changes. The last two previously were one comm= it > with "WIP" in the title. The first one has, I think, not had a lot of rev= iew - > but it's also not a complicated change. 0001 looks good except for the comment above PageSetChecksum() that says it is only for shared buffers and a stray reference to the no-longer-present bufToWrite variable in a comment around line 4490 in bufmgr.c 0002 diff --git a/src/backend/access/nbtree/nbtpage.c b/src/backend/access/nbtree/nbtpage.c index cc9c45dc40c..ad700e590e8 100644 --- a/src/backend/access/nbtree/nbtpage.c +++ b/src/backend/access/nbtree/nbtpage.c @@ -1011,24 +1011,48 @@ _bt_relandgetbuf(Relation rel, Buffer obuf, BlockNumber blkno, int access) Assert(BlockNumberIsValid(blkno)); if (BufferIsValid(obuf)) - _bt_unlockbuf(rel, obuf); - buf =3D ReleaseAndReadBuffer(obuf, rel, blkno); - _bt_lockbuf(rel, buf, access); + { + if (BufferGetBlockNumber(obuf) =3D=3D blkno) + { + /* trade in old lock mode for new lock */ + _bt_unlockbuf(rel, obuf); + buf =3D obuf; + } + else + { + /* release lock and pin at once, that's a bit more efficient */ + _bt_relbuf(rel, obuf); + buf =3D ReadBuffer(rel, blkno); + } + } + else + buf =3D ReadBuffer(rel, blkno); Not related to this patch, but why do we unlock and relock it when obuf has the block we need? Couldn't we pass lock mode and then just do nothing if it is the right lockmode? Setting that aside, I presume we don't need to check the fork and relfilelocator (as ReleaseAndReadBuffer() did) because this code knows it will be the same? Anyway, LGTM. 0003 AFAICT, this does what you claim. I don't really know what else to look when reviewing it, if I'm being honest. As such, I diligently fed it through AI which suggested you may have lost a VALGRIND_MAKE_MEM_NOACCESS(BufHdrGetBlock(buf), BLCKSZ); which sounds right to me and like something you should fix. Also, I'd say this comment + /* + * Now okay to allow cancel/die interrupts again, were held when the lo= ck + * was acquired. + */ needs a "which" after the comma to read smoothly. - Melanie