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 1oSg7q-0002DM-I5 for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Aug 2022 14:52:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oSg7p-0007og-CU for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Aug 2022 14:52:29 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oSg7o-0007oU-Jq for pgsql-hackers@lists.postgresql.org; Mon, 29 Aug 2022 14:52:29 +0000 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oSg7k-0005Rb-Qg for pgsql-hackers@lists.postgresql.org; Mon, 29 Aug 2022 14:52:28 +0000 Received: by mail-ej1-x62a.google.com with SMTP id kk26so16169953ejc.11 for ; Mon, 29 Aug 2022 07:52:24 -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=aJiDwxm+2NZBwgPXFY7DNTl/bLQ2XKJGI1rIQTpttbY=; b=Q1Ww6vec0T+4IsZrRVGet/bRD8IPTj/Cdi6sNWK3+/UE1VfcEaWUeBF4RVvCWHYoUB 48h/bffkievlEGFinsfVELCAccR+Fj4l426UZM0aNL8Wu7U/x2e4euQF3s7lJ2RiLaZL k0zge4xbpaPTCH90FhvPgDW/N6WBmWN/EtuqnFBvQ2s4+kSQ/twgsgzz2ANRrBYwGS0W LsYD5BB6xErcC50t/WPHk0sEWoNVp1WXCR8zkw9Hyd8NdTgqU55UpaWwTgPY17Sz209f /yrE6NnWP8yY2AsAQdNOhZwZxjtELmffBKIq8zyo25lHN7/OMwZo3istQAqth8TusLEz 81Ow== 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=aJiDwxm+2NZBwgPXFY7DNTl/bLQ2XKJGI1rIQTpttbY=; b=sr70ibQQmtqhyuV5Ay+DrOEkyQQ5OF/hFr0R5HXjblstQhMLCO2aY9CPlCOjGKPy+L Obkmz0oBJEWc6tBp3kdxltmw9nOZfmpbGwLhlJGWFevgnmXiJurux+lurqv4o3vpYqAp a/EMza+/Sd6AUzjX1FaC6vXb6XiDcv5cgZ3Xg0a617FsSJF3H3WFBkhS664HpUW7m9ct UZlbDFzhaDqusbNd3+ZehjXR9H32RLD5EbhF2FZHz1UYnwMRWgp304HSgMCtBBFCQj+q Wdx2juXsDVoysDuOqMc6v63y+cMomh011C74oIHiXBV95Tg2mUsFB3s1LZD0JAThDmtc Mvkw== X-Gm-Message-State: ACgBeo0zvCfQRcXYhjL6pqVzc4peRnAN+DRuY78TS7zsvnVylw3X8wHq +AmTATLXGrmOMvuJ9S+AqA1BebK4JOsAiXVMGg22Xv18aVDUfY9/HRPpG41NQc+uy9CnN07dGGO FFMUFrMJTr+YxL7VIMDLwPvzmIWziXG7mvG6pGXjfOUOdIFG1vRnQ18QOJ6TqXP1xiCs3m9bi1k lSqxo4y/ppodMoVcqvo/6fPEuPzu0vvUWVXkI7m/nx1NXTtg1ZDgh9 X-Google-Smtp-Source: AA6agR55FWQrMts/mli80iVHyKnDORHsUyR6gesY7vNt22yXTVtLM8ZXYHQFgWeh1SggZ1TXoUIPcQ== X-Received: by 2002:a17:907:84a:b0:733:735:2b1a with SMTP id ww10-20020a170907084a00b0073307352b1amr13674596ejb.290.1661784743150; Mon, 29 Aug 2022 07:52:23 -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 r1-20020a1709061ba100b00731745a7e62sm4530676ejg.28.2022.08.29.07.52.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 29 Aug 2022 07:52:22 -0700 (PDT) Message-ID: Date: Mon, 29 Aug 2022 16:52:20 +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: Amit Kapila , Tom Lane Cc: David Rowley , Andres Freund , Robert Haas , Yura Sokolov , PostgreSQL Developers References: <20220809184410.g6yzu6pvttuphag5@awork3.anarazel.de> <3137572.1661780863@sss.pgh.pa.us> From: Tomas Vondra In-Reply-To: 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 16:02, Amit Kapila wrote: > On Mon, Aug 29, 2022 at 7:17 PM Tom Lane wrote: >> >> David Rowley writes: >>> I suspect, going by all 3 failing animals being 32-bit which have a >>> MAXIMUM_ALIGNOF 8 and SIZEOF_SIZE_T of 4 that this is due to the lack >>> of padding in the MemoryChunk struct. >>> AllocChunkData and GenerationChunk had padding to account for >>> sizeof(Size) being 4 and sizeof(void *) being 8, I didn't add that to >>> MemoryChunk, so I'll do that now. >> >> Doesn't seem to have fixed it. IMO, the fact that we can get through >> core regression tests and pg_upgrade is a strong indicator that >> there's not anything fundamentally wrong with memory context >> management. I'm inclined to think the problem is in d2169c9985, >> instead ... though I can't see anything wrong with it. >> > > Yeah, I also thought that way but couldn't find a reason. I think if > David is able to reproduce it on one of his systems then he can try > locally reverting both the commits one by one. > I can reproduce it on my system (rpi4 running 32-bit raspbian). I can't grant access very easily at the moment, so I'll continue investigating do more debugging on perhaps I can grant access to the system. So far all I know is that it doesn't happen on d2169c9985 (so ~5 commits back), and then it starts failing on c6e0fe1f2a. The extra padding added by df0f4feef8 makes no difference, because the struct looked like this: struct MemoryChunk { Size requested_size; /* 0 4 */ /* XXX 4 bytes hole, try to pack */ uint64 hdrmask; /* 8 8 */ /* size: 16, cachelines: 1, members: 2 */ /* sum members: 12, holes: 1, sum holes: 4 */ /* last cacheline: 16 bytes */ }; and the padding makes it look like this: struct MemoryChunk { Size requested_size; /* 0 4 */ char padding[4]; /* 4 8 */ uint64 hdrmask; /* 8 8 */ /* size: 16, cachelines: 1, members: 2 */ /* sum members: 12, holes: 1, sum holes: 4 */ /* last cacheline: 16 bytes */ }; so it makes no difference. I did look at the pointers in GetMemoryChunkMethodID, and it looks like this (p1 is result of MAXALIGN(pointer): (gdb) p pointer $1 = (void *) 0x1ca1d2c (gdb) p p1 $2 = 0x1ca1d30 "" (gdb) p p1 - pointer $3 = 4 (gdb) p (long int) pointer $4 = 30022956 (gdb) p (long int) p1 $5 = 30022960 (gdb) p 30022956 % 8 $6 = 4 So the input pointer is not actually aligned to MAXIMUM_ALIGNOF (8B), but only to 4B. That seems a bit strange. >> Another possibility is that there's a pre-existing bug in the >> logical decoding stuff that your changes accidentally exposed. >> > > Yeah, this is another possibility. No idea. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company