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 1oSgZE-00049O-Gn for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Aug 2022 15:20:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oSgZC-0005Dn-Vp for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Aug 2022 15:20:46 +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 1oSgZC-0005De-MZ for pgsql-hackers@lists.postgresql.org; Mon, 29 Aug 2022 15:20:46 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oSgZA-0008KK-Gl for pgsql-hackers@lists.postgresql.org; Mon, 29 Aug 2022 15:20:45 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 27TFKbs63205804; Mon, 29 Aug 2022 11:20:37 -0400 From: Tom Lane To: Tomas Vondra cc: Amit Kapila , David Rowley , Andres Freund , Robert Haas , Yura Sokolov , PostgreSQL Developers Subject: Re: Reducing the chunk header sizes on all memory context types In-reply-to: References: <20220809184410.g6yzu6pvttuphag5@awork3.anarazel.de> <3137572.1661780863@sss.pgh.pa.us> Comments: In-reply-to Tomas Vondra message dated "Mon, 29 Aug 2022 16:52:20 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3205802.1661786437.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 29 Aug 2022 11:20:37 -0400 Message-ID: <3205803.1661786437@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Tomas Vondra writes: > I can reproduce it on my system (rpi4 running 32-bit raspbian). Yeah, more or less same as what I'm testing on. Seeing that the complaint is about pfree'ing a non-maxaligned ReorderBufferChange pointer, I tried adding diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend= /replication/logical/reorderbuffer.c index 89cf9f9389..dfa9b6c9ee 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -472,6 +472,8 @@ ReorderBufferGetChange(ReorderBuffer *rb) change =3D (ReorderBufferChange *) MemoryContextAlloc(rb->change_context, sizeof(ReorderBuffe= rChange)); = + Assert(change =3D=3D (void *) MAXALIGN(change)); + memset(change, 0, sizeof(ReorderBufferChange)); return change; } and this failed! (gdb) f 3 #3 0x003cb888 in ReorderBufferGetChange (rb=3D0x24ed820) at reorderbuffer= .c:475 475 Assert(change =3D=3D (void *) MAXALIGN(change)); (gdb) p change $1 =3D (ReorderBufferChange *) 0x24aaa14 So the bug is in fact in David's changes, and it consists in palloc sometimes handing back non-maxaligned pointers. I find it mildly astonishing that we managed to get through core regression tests without such a fault surfacing, but there you have it. This machine has MAXALIGN 8 but 4-byte pointers, so there's something wrong with that situation. regards, tom lane