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 1oSgzf-0005im-I6 for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Aug 2022 15:48:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oSgv5-00072f-OJ for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Aug 2022 15:43:23 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oSgv5-00072W-Fn for pgsql-hackers@lists.postgresql.org; Mon, 29 Aug 2022 15:43:23 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oSgv0-0005q6-KA for pgsql-hackers@lists.postgresql.org; Mon, 29 Aug 2022 15:43:20 +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 27TFhEZk3209706; Mon, 29 Aug 2022 11:43:14 -0400 From: Tom Lane To: Tomas Vondra cc: Amit Kapila , David Rowley , Andres Freund , Robert Haas , Yura Sokolov , PostgreSQL Developers Subject: Re: Reducing the chunk header sizes on all memory context types In-reply-to: References: <20220809184410.g6yzu6pvttuphag5@awork3.anarazel.de> <3137572.1661780863@sss.pgh.pa.us> <3205803.1661786437@sss.pgh.pa.us> Comments: In-reply-to Tomas Vondra message dated "Mon, 29 Aug 2022 17:27:02 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3209704.1661787794.1@sss.pgh.pa.us> Date: Mon, 29 Aug 2022 11:43:14 -0400 Message-ID: <3209705.1661787794@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Tomas Vondra writes: > I suspect it's a pre-existing bug in Slab allocator, because it does this: > #define SlabBlockGetChunk(slab, block, idx) \ > ((MemoryChunk *) ((char *) (block) + sizeof(SlabBlock) \ > + (idx * slab->fullChunkSize))) > and SlabBlock is only 20B, i.e. not a multiple of 8B. Which would mean > that even if we allocate block and size the chunks carefully (with all > the MAXALIGN things), we ultimately slice the block incorrectly. Right, same conclusion I just came to. But it's not a "pre-existing" bug, because sizeof(SlabBlock) *was* maxaligned until David added another field to it. I think adding a padding field to SlabBlock would be a less messy solution than your patch. regards, tom lane