Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eI5SY-0003jD-SD for pgsql-committers@arkaria.postgresql.org; Fri, 24 Nov 2017 04:19:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eI5SX-0005d8-Qm for pgsql-committers@arkaria.postgresql.org; Fri, 24 Nov 2017 04:19:25 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eI5SX-0005cy-M8 for pgsql-committers@lists.postgresql.org; Fri, 24 Nov 2017 04:19:25 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eI5SU-0006a5-LZ for pgsql-committers@postgresql.org; Fri, 24 Nov 2017 04:19:25 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id vAO4JENp031256; Thu, 23 Nov 2017 23:19:15 -0500 From: Tom Lane To: Tomas Vondra cc: Andres Freund , Simon Riggs , pgsql-committers , Andrew Dunstan Subject: Re: pgsql: Generational memory allocator In-reply-to: References: <20171123001649.y2nf7422iay6cw3v@alap3.anarazel.de> <20171123193936.fncfnar5wkpx56mw@alap3.anarazel.de> <21043.1511467602@sss.pgh.pa.us> <20171123214636.unwkrkunr7m2bkii@alap3.anarazel.de> <13547.1511474676@sss.pgh.pa.us> Comments: In-reply-to Tomas Vondra message dated "Thu, 23 Nov 2017 23:51:03 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <31254.1511497154.1@sss.pgh.pa.us> Date: Thu, 23 Nov 2017 23:19:14 -0500 Message-ID: <31255.1511497154@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Tomas Vondra writes: > On 11/23/2017 11:04 PM, Tom Lane wrote: >> I pushed a patch that computes how much padding to add and adds it. >> (It might not really work if size_t and void * are different sizes, >> because then there could be additional padding in the struct; but >> that seems very unlikely.) > Thanks. Do we need to do something similar to the other memory contexts? > I see Slab does not do this at all (assuming it's not necessary), and > AllocSet does this in a different way (which seems a bit strange). Hm ... the coding in AllocSet is ancient and I have to say that I don't like it as well as what I put into generation.c. We could not have done it in that way at the time, because (IIRC) we did not have constant macros for SIZEOF_SIZE_T, and maybe not SIZEOF_VOID_P either --- and you need constant macros in order to do the #if calculation, because sizeof() does not work in preprocessor expressions. But we have 'em now, so I'm tempted to change aset.c to match generation.c. As for SlabChunk, I think that's fine as-is (except I wonder why the "block" field is declared "void *" rather than "SlabBlock *"). Since the contents are fixed at two pointer fields, it's impossible that there's any unexpected padding in there --- the struct size is basically guaranteed to be 2 * sizeof(pointer). Which makes it either 8 or 16 bytes, either one of which is certain to be a multiple of MAXALIGN. So I think the StaticAssert that that's true is plenty sufficient in that case. regards, tom lane