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 1oSgfP-0004We-KP for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Aug 2022 15:27:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oSgfO-0002Ou-Dj for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Aug 2022 15:27:10 +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 1oSgfO-0002Ol-4u for pgsql-hackers@lists.postgresql.org; Mon, 29 Aug 2022 15:27:10 +0000 Received: from mail-ed1-x529.google.com ([2a00:1450:4864:20::529]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oSgfL-0005iO-HH for pgsql-hackers@lists.postgresql.org; Mon, 29 Aug 2022 15:27:09 +0000 Received: by mail-ed1-x529.google.com with SMTP id 2so10611888edx.2 for ; Mon, 29 Aug 2022 08:27:07 -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=u2JLs0VNFY2hEPFLnqI+HWW1PXW73md152yeSpJ0E7Y=; b=kgP1YOzn0qGCTdIHrJxD6ABanbnyoxV9FkMzIuDsw9RLYEV06uiqw6X4uBkg4jZIjs T1LJAIBCQvLPC1D0FO0BBrNmDRSMfr4fFNsf2T8J9J1rdAInrBa3/pgK13+8X7Pkgx05 /tURh7HwidEe4HdUywZcDO3pYcKoKKfnwjYxhoYxdoCIc7kbaDYSnew3qSpjL+IISsnD EMMpZLdLggiK1CseqQj+ZS/B3h4JzUU2RYjygak6xfJ+LhgbRazB2mQAOFH1qxuI57th 3fKjNKMBzOsRgn70Tu6dzrP7/VusDavdQpdJOUYhvQQbEP28HW2O2AHgrALSDJiv+3ZI HknQ== 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=u2JLs0VNFY2hEPFLnqI+HWW1PXW73md152yeSpJ0E7Y=; b=ZqWZ+StMCYMi40chRc9+Fd1h/2YF3XBf5NADgNHsIhIU5A+RV0dTnOGUtYITf0jNHi K4WdrWQftriGvaSzctzrXOlKv+rChbpg7WO+8mZlFqixhNpCmDRcmGOCaDqD++r2rrTY aVx53kkz/u35AwzYeA0dlZsBqjnuP2989+QC4ZD/RMQloCbgRtEiLqALnWKFXgW5O/EL tu+EwigP+FdJYF/RomGBeCzbkwOa2TlkTpH29a56zuofZhomvVQOergWmq8SmL8AH/o0 piezbFZXd3aL4cZvx6i+yQsoa+ZWwRozTFxpAG8MGWduRStN++SFnOkc3gr4vOXFYdeM 7tuA== X-Gm-Message-State: ACgBeo2aZEkFMblK6iSuQ3R2uL6LxEJSbpHw23X2APLGaKfwPq+lPflB c4vA+I1OhvXT8GoTeFjZJmrRFXkCPLo51yHAt4glL2NawBc1s6tsJRWRtK/z1sjb1k6x9KXRAJK XmcYUSQSaDr8B4x9A49kkB1HIbS8Zke2/SyPDEqk0r1RzcDFXXlr/hU0wR+nbdJr1JLSh0Aa2B3 kZIbQAofJfx8egWGirIidIYDmuYLh3msGevb0V/a0kOIqwlI68XY/O X-Google-Smtp-Source: AA6agR4tiRUZ3MQUu5kGbx/kd+FLaa9LfEIKgiv7/nECZh7EkWf5CjudlKziwYBRammRgANTXb/u8Q== X-Received: by 2002:a05:6402:2547:b0:448:6c4c:b3e with SMTP id l7-20020a056402254700b004486c4c0b3emr4717949edb.288.1661786825146; Mon, 29 Aug 2022 08:27:05 -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 d5-20020a056402400500b004466f5375a5sm2606284eda.53.2022.08.29.08.27.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 29 Aug 2022 08:27:04 -0700 (PDT) Message-ID: Date: Mon, 29 Aug 2022 17:27:02 +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> From: Tomas Vondra In-Reply-To: <3205803.1661786437@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:20, Tom Lane wrote: > 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 = (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