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 1ogYrf-0004ZH-EX for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Oct 2022 21:57:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ogYre-0002Ez-3K for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Oct 2022 21:57:10 +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 1ogYrd-0002EN-QP for pgsql-hackers@lists.postgresql.org; Thu, 06 Oct 2022 21:57:09 +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 1ogYrb-0006fy-FT for pgsql-hackers@lists.postgresql.org; Thu, 06 Oct 2022 21:57:08 +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 296Lv1cW2975023; Thu, 6 Oct 2022 17:57:02 -0400 From: Tom Lane To: David Rowley cc: Andres Freund , Julien Rouhaud , Robert Haas , Yura Sokolov , PostgreSQL Developers Subject: Re: Reducing the chunk header sizes on all memory context types In-reply-to: <2963487.1665086713@sss.pgh.pa.us> References: <555399.1663636988@sss.pgh.pa.us> <1693074.1664825870@sss.pgh.pa.us> <1913788.1664898906@sss.pgh.pa.us> <2869610.1665077908@sss.pgh.pa.us> <2910981.1665080361@sss.pgh.pa.us> <20221006190058.rgk4gxa34d6rg77o@awork3.anarazel.de> <2921309.1665083444@sss.pgh.pa.us> <20221006191454.yviucagfzayak3x6@awork3.anarazel.de> <2922295.1665084196@sss.pgh.pa.us> <2963487.1665086713@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Thu, 06 Oct 2022 16:05:13 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2975021.1665093421.1@sss.pgh.pa.us> Date: Thu, 06 Oct 2022 17:57:01 -0400 Message-ID: <2975022.1665093421@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk I wrote: > I also avoided using 001: based on my work with converting guc.c to use > palloc [1], it seems that pfree'ing a malloc-provided pointer is likely > to see 001 a lot, at least on 64-bit glibc platforms. I poked at this some more by creating a function that intentionally does pfree(malloc(N)) for various values of N. RHEL8, x86_64: the low-order nibble of the header is consistently 0001. macOS 12.6, arm64: the low-order nibble is consistently 0000. FreeBSD 13.0, arm64: Usually the low-order nibble is 0000 or 1111, but for some smaller values of N it sometimes comes up as 0010. NetBSD 9.2, amd64: results similar to FreeBSD. I still haven't looked into anybody's source code, but based on these results I'm inclined to leave both 001 and 010 IDs unused for now. That'll help the GUC malloc -> palloc transition tremendously, because people will get fairly clear errors rather than weird assertions and/or memory corruption. That'll leave us in a situation where only one more context ID can be assigned without risk of reducing our error detection ability, but I'm content with that for now. regards, tom lane