Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eWXYp-00006S-01 for pgsql-hackers@arkaria.postgresql.org; Wed, 03 Jan 2018 01:09:39 +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 1eWXYo-0006X2-HK for pgsql-hackers@arkaria.postgresql.org; Wed, 03 Jan 2018 01:09:38 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eWXYo-0006Ws-0o for pgsql-hackers@lists.postgresql.org; Wed, 03 Jan 2018 01:09:38 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eWXYk-00045f-QS for pgsql-hackers@lists.postgresql.org; Wed, 03 Jan 2018 01:09:36 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 2C0BD20D39; Tue, 2 Jan 2018 20:09:33 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute5.internal (MEProxy); Tue, 02 Jan 2018 20:09:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=yG3WqRoXE68lcdTXrHHDitvMPR3+U zDN4tfa+br7Cqc=; b=qQOTsnFYTPrFTHJlZsLH3chBarlBJTDWiOluIL4exoL65 JNCqJJMLp6hHAtObNw9Fw0cn2hdCckZJOsym1i0NBXww1csZDVfoBigIz/J5Fp6r 8sKzTcy/N/UDwsTYeKKR36hjZ7YbPRWoeTWz10n/5EgVEjhHMa2RxrBJ4kt5V5uA i06RUReApFKVIo02BJGp+KYNDHwYw7O4ADITb5Ivuh5+G+wmsXc6e63tzDryoBd4 YTnOuhkr1iybZ7nxUJjXygARggld9fqrsh9W6g6mrGP6aesMEgxXKAtbxSmn0l5n LCWrSrBhNWDqXTJ6v3pKOCasPhR9zgw5atFTXy6EA== X-ME-Sender: Received: from intern.anarazel.de (unknown [136.24.76.189]) by mail.messagingengine.com (Postfix) with ESMTPA id CFDD1244E7; Tue, 2 Jan 2018 20:09:32 -0500 (EST) Date: Tue, 2 Jan 2018 17:09:31 -0800 From: Andres Freund To: Tom Lane Cc: Thomas Munro , pgsql-hackers@lists.postgresql.org Subject: Re: Ensuring hash tuples are properly maxaligned Message-ID: <20180103010931.6vsirlb5pdapdroq@alap3.anarazel.de> References: <14483.1514938129@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <14483.1514938129@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, On 2018-01-02 19:08:49 -0500, Tom Lane wrote: > Now, the existing definition of the struct seems safe on all > architectures we support, but it would not take much to break it. > I think we ought to do what we did recently in the memory-context > code: insert an explicit padding calculation and a static assertion > that it's right. Hence, the attached proposed patch (in which > I also failed to resist the temptation to make the two code paths > in dense_alloc() look more alike). Any objections? Generally no objections. > + /* > + * It's required that data[] start at a maxaligned offset. This padding > + * calculation is correct as long as int is not wider than size_t and > + * dsa_pointer is not wider than a regular pointer, but there's a static > + * assertion to check things in nodeHash.c. > + */ But note that dsa_pointer can be wider than a regular pointer on platforms without atomics support. > +#define HASHMEMORYCHUNKDATA_RAWSIZE (SIZEOF_SIZE_T * 3 + SIZEOF_VOID_P) > + > + /* ensure proper alignment by adding padding if needed */ > +#if (HASHMEMORYCHUNKDATA_RAWSIZE % MAXIMUM_ALIGNOF) != 0 > + char padding[MAXIMUM_ALIGNOF - HASHMEMORYCHUNKDATA_RAWSIZE % MAXIMUM_ALIGNOF]; > +#endif > + > char data[FLEXIBLE_ARRAY_MEMBER]; /* buffer allocated at the end */ > } HashMemoryChunkData; Wonder if this specific case wouldn't be easier handled with a union? Greetings, Andres Freund