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 1mESw1-0007kA-QG for pgsql-hackers@arkaria.postgresql.org; Fri, 13 Aug 2021 08:53:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mESw0-0005NZ-Hr for pgsql-hackers@arkaria.postgresql.org; Fri, 13 Aug 2021 08:53:00 +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 1mESvz-0005M4-Nc for pgsql-hackers@lists.postgresql.org; Fri, 13 Aug 2021 08:53:00 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mESvw-0000dw-CA for pgsql-hackers@lists.postgresql.org; Fri, 13 Aug 2021 08:52:58 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id D52D45C0136; Fri, 13 Aug 2021 04:52:54 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Fri, 13 Aug 2021 04:52:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; bh=iG6kswtL8ctDMmT0jtao/qeDOoiSSaQHeyMSIPiE2 6A=; b=jujYP99maTzxV6ZYUXpL8nYZf9qhTg0N8nIZAFEualxLfzQt+f63VImtx fE/VaxpE781oGlXdvPW181uW9I49cqc1XRuLOWDPQvqeumI0Uc/0mOjppBWdY3lQ pBdhbMaXifRaFH3dg+ptkFGd8HPRSkwihVf5z8dzLSMdn5Cj0i7bsFa/EPbXy1Re 3jJc3yzOJVewXm7Mr+gG3oVi90gNIRB13619OARDJL7Qi+KkKoa7qHZqx1ke6VJ6 gz3jlS2ix1KGYsP+rGVqID1575o74GpOKqR8V71R1vSrtnVGcR4wr0LltuKvBzj6 xcj+67vDJphdCuxGI6IajP5leVSSw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrkeehgddtkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefuvfhfhffkffgfgggjtgfgsehtjeertddtfeejnecuhfhrohhmpefrvghtvghr ucfgihhsvghnthhrrghuthcuoehpvghtvghrrdgvihhsvghnthhrrghuthesvghnthgvrh hprhhishgvuggsrdgtohhmqeenucggtffrrghtthgvrhhnpeelveehheeuieduieetiedt keeuteelfeetjeffieffudegvdffvdfftdeivdeukeenucevlhhushhtvghrufhiiigvpe dtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpvghtvghrrdgvihhsvghnthhrrghuthes vghnthgvrhhprhhishgvuggsrdgtohhm X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 13 Aug 2021 04:52:52 -0400 (EDT) Subject: Re: Shared memory size computation oversight? To: Julien Rouhaud Cc: PostgreSQL Hackers , Robert Haas References: <20210227080815.jryyhy6lrn6gahkm@nol> From: Peter Eisentraut Message-ID: Date: Fri, 13 Aug 2021 10:52:50 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 12.08.21 16:18, Julien Rouhaud wrote: > On Thu, Aug 12, 2021 at 9:34 PM Peter Eisentraut > wrote: >> >> On 27.02.21 09:08, Julien Rouhaud wrote: >>> PFA a patch that fixes pg_prewarm and pg_stat_statements explicit alignment to >>> CACHELINEALIGN, and also update the alignment in hash_estimate_size() to what I >>> think ShmemInitHash will actually consume. >> >> For extensions, wouldn't it make things better if >> RequestAddinShmemSpace() applied CACHELINEALIGN() to its argument? >> >> If you consider the typical sequence of RequestAddinShmemSpace(mysize()) >> and later ShmemInitStruct(..., mysize(), ...), > > But changing RequestAddinShmemSpace() to apply CACHELINEALIGN() would > only really work for that specific usage only? If an extension does > multiple allocations you can't rely on correct results. I think you can do different things here to create inconsistent results, but I think there should be one common, standard, normal, straightforward way to get a correct result. >> Btw., I think your patch was wrong to apply CACHELINEALIGN() to >> intermediate results rather than at the end. > > I'm not sure why you think it's wrong. It's ShmemInitStruct() that > will apply the padding, so if the extension calls it multiple times > (whether directly or indirectly), then the padding will be added > multiple times. Which means that in theory the extension should > account for it multiple time in the amount of memory it's requesting. Yeah, in that case it's probably rather the case that there is one CACHELINEALIGN() too few, since pg_stat_statements does two separate shmem allocations.