pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tomas Vondra <tomas.vondra@enterprisedb.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Amit Kapila <amit.kapila16@gmail.com>
Cc: David Rowley <dgrowleyml@gmail.com>
Cc: Andres Freund <andres@anarazel.de>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: Yura Sokolov <y.sokolov@postgrespro.ru>
Cc: PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>
Subject: Re: Reducing the chunk header sizes on all memory context types
Date: Mon, 29 Aug 2022 17:27:02 +0200
Message-ID: <fc3a36eb-0767-d915-cdbd-e531983dc1de@enterprisedb.com> (raw)
In-Reply-To: <3205803.1661786437@sss.pgh.pa.us>
References: <CAApHDvpjauCRXcgcaL6+e3eqecEHoeRm9D-kcbuvBitgPnW=vw@mail.gmail.com>
	<CA+TgmoZcHxSZRN1HhHKT-g=FBk2THH60zy1sK3YwB6cB4EQqtQ@mail.gmail.com>
	<20220809184410.g6yzu6pvttuphag5@awork3.anarazel.de>
	<CAApHDvq8Mn8EiK_giG3TQ_=bgzSBvsWTi0KkY0Zv4RrA1kjRQQ@mail.gmail.com>
	<CAApHDvrVppH=3NKzhD0v1XkHyWiT+DkdfOdnQPo=BgauVcL7fw@mail.gmail.com>
	<CAApHDvpuhcPWCzkXZuQQgB8YjPNQSvnncbzZ6pwpHFr2QMMD2w@mail.gmail.com>
	<CAApHDvrCkmvdcnyGBtxq6D8FfM50UiunN3qJquTBwOdUqoKYvg@mail.gmail.com>
	<CAApHDvo3ZaWQNO2AKYiH8y3oGKxWfa2EAkZz9peGBnXvZe2hvA@mail.gmail.com>
	<CAApHDvrbd3y4QxRANd7oFZBXVJ7ZmwUjxSYDLFEMOZY8uyQzRg@mail.gmail.com>
	<CAApHDvrvWMqB6kR-=6qz7n+Jb4Et8VkfnOufwKKLDz5kOm=AEA@mail.gmail.com>
	<CAApHDvociYOk=OTxw0XmO9BR38Covk13M_wg8nt8N7aySWKbLw@mail.gmail.com>
	<3137572.1661780863@sss.pgh.pa.us>
	<CAA4eK1LGx6WW4UPn5-h4KhRCP_NLbNih+si1vpA6KU8TvHgung@mail.gma! il.com>
	<f1d04651-caf9-5c6d-1bf0-c9feac16df10@enterprisedb.com>
	<3205803.1661786437@sss.pgh.pa.us>



On 8/29/22 17:20, Tom Lane wrote:
> Tomas Vondra <tomas.vondra@enterprisedb.com> 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 = (ReorderBufferChange *)
>                 MemoryContextAlloc(rb->change_context, sizeof(ReorderBufferChange));
>  
> +       Assert(change == (void *) MAXALIGN(change));
> +
>         memset(change, 0, sizeof(ReorderBufferChange));
>         return change;
>  }
> 
> and this failed!
> 
> (gdb) f 3
> #3  0x003cb888 in ReorderBufferGetChange (rb=0x24ed820) at reorderbuffer.c:475
> 475             Assert(change == (void *) MAXALIGN(change));
> (gdb) p change
> $1 = (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.
> 

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.

This would explain the 4B difference I reported before, I think. But I'm
just as astonished we got this far in the tests - regular regression
tests don't do much logical decoding, and we only use slab for changes,
but I see the failure in 006 test in src/test/recovery, so the first
five completed fine.


regards

-- 
Tomas Vondra
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company





view thread (152+ messages)  latest in thread

Message-ID: <fc3a36eb-0767-d915-cdbd-e531983dc1de@enterprisedb.com>
Permalink:  ../fc3a36eb-0767-d915-cdbd-e531983dc1de@enterprisedb.com/
Also on:    postgresql.org/message-id/fc3a36eb-0767-d915-cdbd-e531983dc1de@enterprisedb.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: tomas.vondra@enterprisedb.com, tgl@sss.pgh.pa.us, amit.kapila16@gmail.com, dgrowleyml@gmail.com, andres@anarazel.de, robertmhaas@gmail.com, y.sokolov@postgrespro.ru
  Subject: Re: Reducing the chunk header sizes on all memory context types
  In-Reply-To: <fc3a36eb-0767-d915-cdbd-e531983dc1de@enterprisedb.com>
  References: <CAApHDvpjauCRXcgcaL6+e3eqecEHoeRm9D-kcbuvBitgPnW=vw@mail.gmail.com> <CA+TgmoZcHxSZRN1HhHKT-g=FBk2THH60zy1sK3YwB6cB4EQqtQ@mail.gmail.com> <20220809184410.g6yzu6pvttuphag5@awork3.anarazel.de> <CAApHDvq8Mn8EiK_giG3TQ_=bgzSBvsWTi0KkY0Zv4RrA1kjRQQ@mail.gmail.com> <CAApHDvrVppH=3NKzhD0v1XkHyWiT+DkdfOdnQPo=BgauVcL7fw@mail.gmail.com> <CAApHDvpuhcPWCzkXZuQQgB8YjPNQSvnncbzZ6pwpHFr2QMMD2w@mail.gmail.com> <CAApHDvrCkmvdcnyGBtxq6D8FfM50UiunN3qJquTBwOdUqoKYvg@mail.gmail.com> <CAApHDvo3ZaWQNO2AKYiH8y3oGKxWfa2EAkZz9peGBnXvZe2hvA@mail.gmail.com> <CAApHDvrbd3y4QxRANd7oFZBXVJ7ZmwUjxSYDLFEMOZY8uyQzRg@mail.gmail.com> <CAApHDvrvWMqB6kR-=6qz7n+Jb4Et8VkfnOufwKKLDz5kOm=AEA@mail.gmail.com> <CAApHDvociYOk=OTxw0XmO9BR38Covk13M_wg8nt8N7aySWKbLw@mail.gmail.com> <3137572.1661780863@sss.pgh.pa.us> <f1d04651-caf9-5c6d-1bf0-c9feac16df10@enterprisedb.com> <3205803.1661786437@sss.pgh.pa.us> <fc3a36eb-0767-d915-cdbd-e531983dc1de@enterprisedb.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox