Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oWQOw-0005SW-3G for pgsql-hackers@arkaria.postgresql.org; Thu, 08 Sep 2022 22:53:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oWQOu-0001eb-5z for pgsql-hackers@arkaria.postgresql.org; Thu, 08 Sep 2022 22:53:36 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oWQOt-0001eR-Sy for pgsql-hackers@lists.postgresql.org; Thu, 08 Sep 2022 22:53:35 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oWQOr-0002hp-HS for pgsql-hackers@lists.postgresql.org; Thu, 08 Sep 2022 22:53:34 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 288MrTUH4159948; Thu, 8 Sep 2022 18:53:29 -0400 From: Tom Lane To: Andres Freund cc: David Rowley , Julien Rouhaud , Robert Haas , Yura Sokolov , PostgreSQL Developers Subject: Re: Reducing the chunk header sizes on all memory context types In-reply-to: <20220908221523.c2nsmn7cvsdqvxvn@awork3.anarazel.de> References: <3021143.1662432194@sss.pgh.pa.us> <20220907130552.sfjri7jublfxyyi4@jrouhaud> <3666758.1662563307@sss.pgh.pa.us> <20220908164409.ptv66iogw2kvnwj5@awork3.anarazel.de> <4098200.1662660636@sss.pgh.pa.us> <20220908221523.c2nsmn7cvsdqvxvn@awork3.anarazel.de> Comments: In-reply-to Andres Freund message dated "Thu, 08 Sep 2022 15:15:23 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <4159946.1662677609.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 08 Sep 2022 18:53:29 -0400 Message-ID: <4159947.1662677609@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Andres Freund writes: > On 2022-09-08 14:10:36 -0400, Tom Lane wrote: >> No, I don't think we can get away with that. See int8inc() for a >> counterexample. > What I was suggesting a bit below the bit quoted above, was that we'd co= py > whenever there's no finalfunc or if the finalfunc doesn't take an intern= al > parameter. Hmm, OK, I was confusing this with the optimization for transition functions; but that one is looking for pointer equality rather than checking MemoryContextContains. So maybe this'd work. > This business with interpreting random memory as a palloc'd chunk seems = like a > fundamentally wrong approach worth incurring some pain to fix. I hate to give up MemoryContextContains altogether. The assertions that David nuked in b76fb6c2a had some value I think, and I was hoping to address your concerns in [1] by adding Assert(MemoryContextContains()) to guc_free. But I'm not sure how much that'll help to diagnose you- malloced-instead-of-pallocing if the result is not an assertion failure but a segfault in a not-obviously-related place. The failure at guc_free is already going to be some distance from the scene of the crime. The implementation I suggested upthread would reliably distinguish malloc from palloc, and while it is potentially a tad expensive I don't think it's too much so for Assert checks. I don't have an objection to trying to get to a place where we only use it in Assert, though. regards, tom lane [1] https://www.postgresql.org/message-id/20220905233233.jhcu5jqsrtosmgh5%= 40awork3.anarazel.de