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 1vriAi-001yFZ-01 for pgsql-hackers@arkaria.postgresql.org; Sun, 15 Feb 2026 19:52:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vriAg-00260W-1u for pgsql-hackers@arkaria.postgresql.org; Sun, 15 Feb 2026 19:52:46 +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 1vriAg-00260N-0x for pgsql-hackers@lists.postgresql.org; Sun, 15 Feb 2026 19:52:46 +0000 Received: from mail-dy1-x132f.google.com ([2607:f8b0:4864:20::132f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vriAd-00000000mHu-1EXJ for pgsql-hackers@postgresql.org; Sun, 15 Feb 2026 19:52:45 +0000 Received: by mail-dy1-x132f.google.com with SMTP id 5a478bee46e88-2b785801c93so6700677eec.0 for ; Sun, 15 Feb 2026 11:52:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1771185163; x=1771789963; darn=postgresql.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=ORpQQceGFvKOMjnRfjQ6IuEFhPRcHgBtvQdWEfOPz+M=; b=eLaxCbsG997bkebq9loNN+pKQcSEY6PXx/Vd02fW40ATCtFN4uB9jV8Wb98dZx0v8T KeNllLsLJXq87tFjIxSq46GwdR1ejzgY1Mnnj0OcYWcVv3N8jyIt/YX6g7cCShektu7C 6eq2GIg50UGl7GtlM5UcCqlDH+unJlg1iZBfs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771185163; x=1771789963; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=ORpQQceGFvKOMjnRfjQ6IuEFhPRcHgBtvQdWEfOPz+M=; b=roK5hYiU4Hi9M6AVQH8fKLgLkxqixjKP9ryLZ2PuLc4uBr01+7TIdGOga27FKmBel5 yBJNE45pzcPA6hC8MmxhuFJspUVpvgOUPpyL9Dfm85d60eStssIZexQzwpr8kLtR6HZa ApV2tY2NSPVr5PPm7f1ep9MHd2iuD5JMx8f4XSyXtDzw7r8kupLGbeRueBlDcsMwJ+So w669rAd0IMVaSEI7tXDI2MZsBgVdMBCGQlmk7+IJgzDkzkivrFC9axUmcMXep05wGXkZ GFYKGJrBNrLH2yHoSZySoTMPwlS1/rqiyC4m8QWsSjw6QwkTFme3o7e5bdzddDROxdLs J1Ug== X-Forwarded-Encrypted: i=1; AJvYcCUuqGfSG3IwvLTsxLXF1GGWnSxda/fGNRVCn/NPkLwgQV7fWLBUAEKBcY9BWMhR7yDTqMEZHw6vwx5eM4Y/@postgresql.org X-Gm-Message-State: AOJu0YxuQk2pkpoV1Et1WJYWuHyejegGVszLv/vzW4oC5YEGLRhHyfxw m6/r1Gn+XWvvBVz5YseJ7BETv7SlzPIQ2IwK+t8XecV+SUEpMr/EXMcK0LWvjstf4A== X-Gm-Gg: AZuq6aKj7E7yiNtYGDlRfH/PNY4AclKlWjZtBvB/gMVdzrW16L4/5bHdeTY2IZSgad8 3aYd8nNeCWkH0mT5Pj07OJdo33xPDNNS7QqwWHOlFQ0IWHbQFhKPG6t3coBe/xRAEBtUgEZ6vQ+ 9bnlOJokiuZriOyGWwM6WyZYLzMALS7kxvhmtMjiLr/2l16sPb2XIkZTcbEXvxazvOEKHeOWPkw MLBR+MZcNN303oPl8+hlvoOC1KNi70aFuOb3TPZyLBE3n0a86uVkBF4Xzu8pMRB9wjLS3Ag+ho8 qlRTYUdeNqjW5tHwJkXSDqXZnGVFgrcRQ81rLNWvGMAhVYfRcbYPLXzojAA0ODS0kZJ2P3dJUMU tHAdWvSjhTXD4TKA9S9bHTK0NtAK1u0bUrqYvHSsGGWr3iKqReDJeQ6cQseQc7V+rpTDttgBeTq 4UyV+h/tkl7zWPFMo5CNrdsZbV/aHA8Rh/1s3Vur0dRjzJ94y3GC8W8Gg= X-Received: by 2002:a05:7300:d513:b0:2ba:8d12:1ca3 with SMTP id 5a478bee46e88-2bac93569dbmr2336640eec.17.1771185162553; Sun, 15 Feb 2026 11:52:42 -0800 (PST) Received: from microsoft.com (c-73-15-160-255.hsd1.ca.comcast.net. [73.15.160.255]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2bacb6782e5sm6788117eec.29.2026.02.15.11.52.41 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 Feb 2026 11:52:41 -0800 (PST) Date: Sun, 15 Feb 2026 11:52:39 -0800 From: Noah Misch To: Andres Freund , Heikki Linnakangas Cc: Melanie Plageman , Kirill Reshke , Matthias van de Meent , pgsql-hackers@postgresql.org, Thomas Munro , Robert Haas , Michael Paquier Subject: Re: Buffer locking is special (hints, checksums, AIO writes) Message-ID: <20260215195239.ce.noahmisch@microsoft.com> References: <1108f18d-cf7c-4f17-b29c-a119fe42f7e5@iki.fi> <5dwlfu2jyzkyf3nrlzxxblxctb6xio5es73ptgsahjnmfu5miu@772rc764hfhi> <4csodkvvfbfloxxjlkgsnl2lgfv2mtzdl7phqzd4jxjadxm4o5@usw7feyb5bzf> <5ubipyssiju5twkb7zgqwdr7q2vhpkpmuelxfpanetlk6ofnop@hvxb4g2amb2d> <68e89de8-5f6c-4eaf-a800-e16a5e487667@iki.fi> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <68e89de8-5f6c-4eaf-a800-e16a5e487667@iki.fi> User-Agent: Mutt/2.2.12 (2023-09-09) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sat, Feb 07, 2026 at 12:44:25PM +0200, Heikki Linnakangas wrote: > On 03/02/2026 00:33, Andres Freund wrote: > > - The way MarkBufferDirtyHint() operates was copied into > > heap_inplace_update_and_unlock(). Now that MarkBufferDirtyHint() won't work > > that way anymore, it seems better to go with the alternative approach the > > comments already outlined, namely to only delay updating of the buffer > > contents. > > > > I've done this in a prequisite commit, as it doesn't actually depend on any > > of the other changes. Noah, any chance you could take a look at this? v12-0001-heapam-Don-t-mimic-MarkBufferDirtyHint-in-inplac.patch looks good. > Patch 0001 Looks correct to me. However: > > > * ["D" is a VACUUM (ONLY_DATABASE_STATS)] > > * ["R" is a VACUUM tbl] > > * D: vac_update_datfrozenxid() -> systable_beginscan(pg_class) > > * D: systable_getnext() returns pg_class tuple of tbl > > * R: memcpy() into pg_class tuple of tbl > > * D: raise pg_database.datfrozenxid, XLogInsert(), finish > > * [crash] > > * [recovery restores datfrozenxid w/o relfrozenxid] > > * > > * As we hold an exclusive lock - preventing the buffer from being written > > * out once dirty - we can work around this as follows: MarkBufferDirty(), > > * XLogInsert(), memcpy(). > > That last reference to 'memcpy' is a little orphaned now. The comment used > to talk about the stack copy of the page, but now there's no mention of that > except for this reference to memcpy(). To make things worse, the steps have > "memcpy() into pg_class tuple of tbl", so one could think that the "memcpy" > refers to that. "memcpy" does refer to "memcpy() into pg_class tuple of tbl", so I don't see that as orphaned. Nonetheless: > How about this: > > * We avoid that by using a temporary copy of the buffer to hide our > * change from other backends until it's been WAL-logged. We apply our > * change to the temporary copy and WAL-log it before modifying the real > * page. That way any action a reader of the in-place-updated value takes > * will be WAL logged after this change. Either v12 or v12 w/ this edit is fine with me. I find this proposed text redundant with nearby comment "register block matching what buffer will look like after changes", so I mildly prefer v12.