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 1vVU0i-004K3A-17 for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Dec 2025 12:18:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vVU0h-006LXL-00 for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Dec 2025 12:18:35 +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 1vVU0f-006LXC-32 for pgsql-hackers@lists.postgresql.org; Tue, 16 Dec 2025 12:18:35 +0000 Received: from fout-b5-smtp.messagingengine.com ([202.12.124.148]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vVU0d-0012cl-12 for pgsql-hackers@lists.postgresql.org; Tue, 16 Dec 2025 12:18:34 +0000 Received: from phl-compute-02.internal (phl-compute-02.internal [10.202.2.42]) by mailfout.stl.internal (Postfix) with ESMTP id 577CB1D000F5; Tue, 16 Dec 2025 07:18:28 -0500 (EST) Received: from phl-frontend-02 ([10.202.2.161]) by phl-compute-02.internal (MEProxy); Tue, 16 Dec 2025 07:18:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eisentraut.org; h=cc:cc:content-transfer-encoding:content-type:content-type :date:date:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:subject:subject:to:to; s=fm3; t=1765887508; x=1765973908; bh=QLy9mTWqtdp3pafNRSJk/eUIwhXcOVU8 SenR+2/yT4E=; b=eOhPB0TOik/fKb39I/Wslp0g1ZhNtjB6PDQT3BGNq24DeDim iWbe4wCrxeu2OLM1aCUltTvJqDNraSnE1wEL5/zYjappyhUk171cp8XUTL0TU1am Oj9WkcRby8IE70ckqi9HyjqNQ/ecUbqjB9afcpDnnEe8piLAE43bTPYLVsLG8a2p kQC3WrTChnkufJsKM4OSJl9gu5fAififoNPbrP408hAlTgUaaB3TvqHZv0KJEGBf HYBHM/I5/VsmUuupaFADprSXOUOj2QlgZeIkvzJVdUyUqfiwmOD2BPM2W48E4HRb DvzIa1zdCJA/eXPpv4W/q9OgnVFfHOyL2tBgAw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1765887508; x= 1765973908; bh=QLy9mTWqtdp3pafNRSJk/eUIwhXcOVU8SenR+2/yT4E=; b=F 9GfcnnzHO08tX+OIn1y5530C/BxlehBlXO3QxxQyVDGv+Z6fl7zKc332JqYb55RP BVOUzgmgpipqj5grgGRRwn+Br1lamrk9I/gW8s1dPRRLq6EVUTKFsNEYj9XT/Pj5 mh54F8GqDh+Ek6hcX6NMuICP/8sH1ZAvkuApNEN1ticTvUwGctCMXGwLfSwntJHd te7M1zgO4k7y7ORJEOeUalgYD0zFp33ncRoFLt2rciR10fuv3XVEPDUXZ1DSjhbk N5RM38rg4RqN3mNVNgxywfeW3ZIqxZKzvF9FzPiTlONhN5hO2jXfdqYElP4fjQlb gWED7iwhbNW1Wb7FFzgCQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdefleeiiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefkffggfgfuvfevfhfhjggtgfesthekredttddvjeenucfhrhhomheprfgvthgvrhcu gfhishgvnhhtrhgruhhtuceophgvthgvrhesvghishgvnhhtrhgruhhtrdhorhhgqeenuc ggtffrrghtthgvrhhnpeejhfevhedttefgfffhhfeffefggffhffelgfeiueeukeehvdeh vdefheffvdefueenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfh hrohhmpehpvghtvghrsegvihhsvghnthhrrghuthdrohhrghdpnhgspghrtghpthhtohep jedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepmhgvlhgrnhhivghplhgrghgvmh grnhesghhmrghilhdrtghomhdprhgtphhtthhopegrnhgurhgvshesrghnrghrrgiivghl rdguvgdprhgtphhtthhopehrohgsvghrthhmhhgrrghssehgmhgrihhlrdgtohhmpdhrtg hpthhtohepgiegmhhmmheshigrnhguvgigqdhtvggrmhdrrhhupdhrtghpthhtohepphhg shhqlhdqhhgrtghkvghrsheslhhishhtshdrphhoshhtghhrvghsqhhlrdhorhhgpdhrtg hpthhtohephhhlihhnnhgrkhgrsehikhhirdhfihdprhgtphhtthhopehrvghshhhkvghk ihhrihhllhesghhmrghilhdrtghomh X-ME-Proxy: Feedback-ID: ie0a040ee:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 16 Dec 2025 07:18:26 -0500 (EST) Message-ID: Date: Tue, 16 Dec 2025 13:18:25 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: eliminate xl_heap_visible to reduce WAL (and eventually set VM on-access) To: Melanie Plageman Cc: Andres Freund , Robert Haas , Andrey Borodin , PostgreSQL Hackers , Heikki Linnakangas , Kirill Reshke References: <2wk7jo4m4qwh5sn33pfgerdjfujebbccsmmlownybddbh6nawl@mdyyqpqzxjek> Content-Language: en-US From: Peter Eisentraut In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 15.12.25 22:05, Melanie Plageman wrote: > On Sat, Dec 13, 2025 at 8:59 AM Peter Eisentraut wrote: >> >> On 20.11.25 18:19, Melanie Plageman wrote: >>> + prstate->deadoffsets = (OffsetNumber *) presult->deadoffsets; >> >> In your patch >> v22-0001-Split-heap_page_prune_and_freeze-into-helpers.patch, the >> assignment above casts away the const qualification of the function >> argument presult: > > Yea, this code (prune_freeze_setup() with a const-qualified > PruneFreezeResult parameter) is actually already in master -- not just > in this patchset. > >> +static void >> +prune_freeze_setup(PruneFreezeParams *params, >> + TransactionId new_relfrozen_xid, >> + MultiXactId new_relmin_mxid, >> + const PruneFreezeResult *presult, >> + PruneState *prstate) >> >> (The cast is otherwise unnecessary, since the underlying type is the >> same on both sides.) >> >> Since prstate->deadoffsets is in fact later modified, this makes the >> original const qualification invalid. > > I didn't realize I was misusing const here. What I meant to indicate > by defining the prune_freeze_setup() parameter, as const, is that the > PruneFreezeResult wouldn't be modified by prune_freeze_setup(). I did > not mean to indicate that no members of PruneFreezeResult would ever > be modified. I'm not sure there is a difference between these two statements. The struct won't be modified is the same as none of its fields will be modified. > deadoffsets is not modified in prune_freeze_setup(). So, > are you saying that I can't define a parameter as const if even the > caller modifies it? You are not modifying deadoffsets in prune_freeze_setup(), but you are assigning its address to a pointer variable that is not const-qualified, and so it could be used to modify it later on. A caller to prune_freeze_setup() that sees the signature const PruneFreezeResult *presult could pass a pointer to a PruneFreezeResult object that is notionally in read-only memory. But through the non-const-qualified pointer you could later modify the pointed-to memory, which would be invalid. The point of propagating the qualifiers is to prevent that at compile time. If what you want is something like, "prune_freeze_setup() does not change any of the fields of what presult points to, but it does record a pointer to one of its fields with the intention of modifying it later after prune_freeze_setup() is finished", then I think C cannot represent that with this API. Here is a simplified example: #include // corresponds to PruneFreezeResult struct foo { int offsets[5]; }; // corresponds to PruneState struct bar { int *offsets; }; static void setup(const struct foo *f) { struct bar *b = malloc(sizeof(struct bar)); b->offsets = f->offsets; // warning } This produces a warning: test.c:20:20: warning: assignment discards 'const' qualifier from pointer target type The reason is that what "f" points to is const, which means that all its fields are const. The fix is to remove the const from the function argument declaration. One of the possible sources of confusion here is that one struct uses an array and the other a pointer, and these sometimes behave similarly and sometimes not.