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 1lHiKE-0003QB-GM for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Mar 2021 07:23:10 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lHiKD-0003D7-9a for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Mar 2021 07:23:09 +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 1lHiKD-0003D0-0Y for pgsql-hackers@lists.postgresql.org; Thu, 04 Mar 2021 07:23:09 +0000 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lHiKA-0001KR-Qz for pgsql-hackers@lists.postgresql.org; Thu, 04 Mar 2021 07:23:07 +0000 Received: by mail-pf1-x433.google.com with SMTP id 18so3438500pfo.6 for ; Wed, 03 Mar 2021 23:23:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=PufTnKJn6dytcrSBFJoO+S2ydAUMkrph3lCCtRZaTBA=; b=qGtltdIiv7NsFjZWgEwWVJlHdSH3Af/ItOYfY/4+5+MC7e48fDJRNiyNkveYbJDNs/ y4uaSaPKtMEg161J7HiO0ZFm50evxoi1HCSm5pvYH6PWiLzhbq4xpd1dku/M8VJAdoqZ GomWmFkBKVXUH2Js22nzO+zm66GncbKWMB7PhZi+mUf5KZ2L9laCes/5hJlJm7dODTuM w6oPYdP/fBrhQ8DxRHEwgholotsrkW6OuASZ+i3TVWBPMluFHrMokEPcv1yPBGp+UFod CTO2oi8lQfHi4zbysawZoGXbt/zy54ADOpRRVZUhOgelZjZadxV4r2Nwl11KYWuXlONd KLKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=PufTnKJn6dytcrSBFJoO+S2ydAUMkrph3lCCtRZaTBA=; b=Icc/7s5sTSj99Gv61CsLxmulsxDSxXfaqenrDgpX4UYoGbNca2oybM9df1dQGlGYyb c9hD046ScHUxghnI2ZioJxvEgxNUne3gALYa1FQ3EECiSSdbC6KnMLuj6t2yAj2Qchs4 Rg2R3yrvKHLRaHfyrp8LguPKhoWy+7pGQaO6qwn3uXwCGuWNUZZxG+safd0GUSfDFFaY KPq2jiYezao9jGYxHoVMeThv8CZLffJBTCRnhaceAC2UpTEE6BhvIUKJ6Xr72m2fxvu2 YOb5o7yRO5myrYq7UVRrnIRQS6Y9O1XC9xi/JdXHlE0q+7QP7nJjLK0EpDggWqqCORGl UELg== X-Gm-Message-State: AOAM531UtGdvFh+Hab2Jn9AL2xkoZAGaxDC17F3vbY685Xp8xUvA2MtH uYvwHGXM3Q29+ukQFgK/Uvw= X-Google-Smtp-Source: ABdhPJx4IdJjvivPeIHcnmt6h3AMURRgIrQ6HZ+Z6cdJOABXD4Kh+BcMmYW6vd4LshummBls6ilqYA== X-Received: by 2002:a63:484b:: with SMTP id x11mr2660080pgk.2.1614842585153; Wed, 03 Mar 2021 23:23:05 -0800 (PST) Received: from nol (2001-b011-0008-945f-8e19-0880-613b-abb9.dynamic-ip6.hinet.net. [2001:b011:8:945f:8e19:880:613b:abb9]) by smtp.gmail.com with ESMTPSA id w188sm26784805pfw.177.2021.03.03.23.23.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Mar 2021 23:23:04 -0800 (PST) Date: Thu, 4 Mar 2021 15:23:33 +0800 From: Julien Rouhaud To: Michael Paquier Cc: Tom Lane , Georgios , Julien Rouhaud , PostgreSQL Hackers , "robertmhaas@gmail.com" Subject: Re: Shared memory size computation oversight? Message-ID: <20210304072333.4yydog47md7cfrda@nol> References: <20210227080815.jryyhy6lrn6gahkm@nol> <1183451.1614788634@sss.pgh.pa.us> <20210303164052.f336wina7qpchabd@nol> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Mar 04, 2021 at 04:05:10PM +0900, Michael Paquier wrote: > On Thu, Mar 04, 2021 at 12:40:52AM +0800, Julien Rouhaud wrote: > > On Wed, Mar 03, 2021 at 11:23:54AM -0500, Tom Lane wrote: > >> I have not looked at this patch, but I think the concern is basically that > >> if we have space-estimation infrastructure that misestimates what it is > >> supposed to estimate, then if that infrastructure is used to estimate the > >> size of any of the "big hog" data structures, we might misestimate by > >> enough that the slop factor wouldn't hide it. > > > > Exactly. And now that I looked deeper I can see that multiple estimates are > > entirely ignoring the padding alignment (e.g. ProcGlobalShmemSize()), which can > > exceed the 6kB originally estimated by Robert. > > We are going to have a hard time catching up all the places that are > doing an incorrect estimation, and have an even harder time making > sure that similar errors don't happen in the future. Should we add a > {add,mul}_shmem_size() to make sure that the size calculated is > correctly aligned, that uses CACHELINEALIGN before returning the > result size? I was also considering adding new (add|mull)_*_size functions to avoid having too messy code. I'm not terribly happy with xxx_shm_size(), as not all call to those functions would require an alignment. Maybe (add|mull)shmemalign_size? But before modifying dozens of calls, should we really fix those or only increase a bit the "slop factor", or a mix of it? For instance, I can see that for instance BackendStatusShmemSize() never had any padding consideration, while others do. Maybe only fixing contribs, some macro like PredXactListDataSize that already do a MAXALIGN, SimpleLruShmemSize and hash_estimate_size() would be a short patch and should significantly improve the estimation.