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 1oShBX-0006Jz-LW for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Aug 2022 16:00:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oShBW-00020F-Ii for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Aug 2022 16:00:22 +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 1oShBW-0001yt-8z for pgsql-hackers@lists.postgresql.org; Mon, 29 Aug 2022 16:00:22 +0000 Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oShBT-0000CD-Fo for pgsql-hackers@lists.postgresql.org; Mon, 29 Aug 2022 16:00:21 +0000 Received: by mail-ed1-x535.google.com with SMTP id e18so3216132edj.3 for ; Mon, 29 Aug 2022 09:00:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc; bh=nzIuSwXY4r8zsXUl//u/OK+wF3xZvVML34A4nDKR3D4=; b=BjYlVDNdlN2u9sZEeGhe8xg0eWmQ9kvnf/VgCToGCNBuFURdMZXZQxWSjyDOCCp+IK PY+VlCH3yxDDBiaJTeLRHIBfuD7KPfipFVDUx4KCl6/prY/PXNqWUdkGGeWGWf075WX/ dsiX0sK7BnDgJQMCnS4fBd6wy6/34za82aL8w60HIyM/tNQPv2wcuWT9fbsDYy+k4By9 rCd1SVzjny22wpxztrLOtvtbK9kxzfEIHg2rSBz/eKosISeji4TCWb4mJ22+HoKYKPdt 4Hh7rsOp3FX2Y9guk7VP35yKdl2eZxOEJstTeNghJoD4QW5TORzqwBvMs11c7sra5fRN zL2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc; bh=nzIuSwXY4r8zsXUl//u/OK+wF3xZvVML34A4nDKR3D4=; b=ksNXc/E8gqxFejzl6fNzsmJrTYJseacIOlRt3nzjyC8z8wCMr3yg20EObhkdUbiPFd g33nV4RMCv5Iditxi/rzhsX6MFS2/gakBLc2xl2TFep4R0vas8ZkxK4cn9PIRMV+pKzs GyI6eFk1uj7pyjXVd7Z2IsxwZVURnFe/Brjn2MBi1yrGnGR/wB3otbQ9AdJ+ZzHpb9g9 dbDksWhddP85D3Q3ni9JMdS8YTm+OBNSz1LswKfWz0IP5JaiOJXHD36oQe/21ArND8M3 2uXxf0uMJPBifIeg4MIIV91tyGcfxx7V5Md7UAp62vKraoBGLuT5EmD1fhwEd8dMt0G2 S7YQ== X-Gm-Message-State: ACgBeo2imrU9IGlshnpJrLirpBZhEX0Ys2+wCnmPme1YBvfeYzG5VGPo YBm7grGX9LtnPtc8W+VoBFKd2ePyVVDjTqTQSQ/a2XDRC4pR64+uHaMnhkKRFC0PHJYkD8Snrpm w9/jhiceMoGywR0Wh0OkFoDrTlHY85YBaY9e/lRomoJ9Y7phqIjJtI/1xA+Iz1TzHzXLUY0vCnj KnmRPdpTvRBWS1zklq5giFKD+QxKx0Lm3bGtuJy+X2BtgjnXgFm65C X-Google-Smtp-Source: AA6agR5C4UYXFIh2NqjbkUOVtTsuaK6EBwR8WT6GtDG+sGmwH6oUpuRIlOlgNqV5bqLLkxCQzAxATg== X-Received: by 2002:a05:6402:1945:b0:446:692:8aeb with SMTP id f5-20020a056402194500b0044606928aebmr16780336edz.403.1661788817041; Mon, 29 Aug 2022 09:00:17 -0700 (PDT) Received: from [10.137.0.18] (ip-86-49-229-52.bb.vodafone.cz. [86.49.229.52]) by smtp.gmail.com with ESMTPSA id d13-20020a170906304d00b0073c8d4c9f38sm4681704ejd.177.2022.08.29.09.00.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 29 Aug 2022 09:00:16 -0700 (PDT) Message-ID: <9371f7b2-9062-ac49-606d-8c01e68ef48c@enterprisedb.com> Date: Mon, 29 Aug 2022 18:00:14 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: Reducing the chunk header sizes on all memory context types Content-Language: en-US To: Tom Lane Cc: Amit Kapila , David Rowley , Andres Freund , Robert Haas , Yura Sokolov , PostgreSQL Developers References: <20220809184410.g6yzu6pvttuphag5@awork3.anarazel.de> <3137572.1661780863@sss.pgh.pa.us> <3205803.1661786437@sss.pgh.pa.us> <3209705.1661787794@sss.pgh.pa.us> From: Tomas Vondra In-Reply-To: <3209705.1661787794@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 8/29/22 17:43, Tom Lane wrote: > 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. > Yeah, that's true. Still, there was an implicit expectation the size is maxaligned, but it wasn't mentioned anywhere. I don't even recall if I was aware of it when I wrote that code, or if I was just lucky. > I think adding a padding field to SlabBlock would be a less messy > solution than your patch. Maybe, although I find it a bit annoying that we do MAXALIGN() for a bunch of structs, and then in other places we add padding. Maybe not for Slab, but e.g. for Generation. Maybe we should try doing the same thing in all those places. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company