Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uJB8z-000ItJ-Ur for pgsql-bugs@arkaria.postgresql.org; Sun, 25 May 2025 13:12:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uJB8y-00HKHf-Ai for pgsql-bugs@arkaria.postgresql.org; Sun, 25 May 2025 13:11:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uIr19-00CS4m-Ml for pgsql-bugs@lists.postgresql.org; Sat, 24 May 2025 15:42:35 +0000 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uIr16-000lHA-21 for pgsql-bugs@lists.postgresql.org; Sat, 24 May 2025 15:42:34 +0000 Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-441d437cfaaso4023455e9.1 for ; Sat, 24 May 2025 08:42:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=deepbluecap-com.20230601.gappssmtp.com; s=20230601; t=1748101352; x=1748706152; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=zI6HQiBgHXsbxxLdZGYknFm58syu8I2PF/dFCzB+osU=; b=Touw4zTE2Ypbk/xJiflGH+UjZd+e4VgT14h7U/0vSDFsn1cW5ahrSEkNaGqU3j0iLH 83qIhVTy2mv5vC4GprXWjdS2MgIGFPRoAE/JDEBDX2HHmRjxGqbvRH/qjHqafLUWEVm5 UM2syZ1/6olUam0fzAgBVVMXHv8OTrq2pciJHICg9WvIcsFBA1+leNO7nZa7U+F++umI ZYYhs4yvIhNFKyw5YxMZffu9TWVS7uNKmmNwk+MjN1QI6LGgM6TLaLLWVLo3UMTWZTcu H0TRd0SMGBJGBuOFEPHrNPrzenzA/fpRV2mQkFj9Yqy4wf6wIESbp5KHbFDOiUpmczNi zr6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748101352; x=1748706152; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zI6HQiBgHXsbxxLdZGYknFm58syu8I2PF/dFCzB+osU=; b=KgumVtAXULXovZrKtRJiTydwjhBn4pWaCG3Hm0DNbEPeXIwOCoVDrZn2sFnGasSuzd DIaY90Mf5OHfGOtsAYwXxj7FCw05lvxR+bR5EnHUdHOaJC9n1lPY7XXHfDDL8o/4zjv3 gJabD2xRFh+sFHg3edNGK+qxZ6rUA25LEPen1B1+tU5N9NbDhOX8qGy7wp/0x6jg8/GK 4mSWC56FnHXaBSkXAg7yJGTPH/XJrNb5eeshUlChFFnmABJcbym8pNdF3KhE0+QwdVbR RTcJMdRpzh0sI120Bafbt/Qrg5yy+EM1HBXSf/gvOp9ORA4Hqz8h4yMEpNrj4xP4QmZV 2Krg== X-Gm-Message-State: AOJu0YxC8wyN+DyQ7aF2zVZPOFgBMmnHocSRIJq/2dvqPrgi3rxy0WkC E7jEG+KyiU0wPdaNlLywNQJ7PJo7U4HqywIP9v0B0czQAEIsyTu+bR7aQ5zruJs+4DY= X-Gm-Gg: ASbGncujtStb0E1x1vcE+p2Xc27/0v440ct9aKLplvv06enpvVp35kFmTBEwrd1u8ow b0R2BwyekTOk0T8K3qh2Of5VtmgUqVxxawvyBctTuTeyieD8X6SMkdLt9RX0MsHn3j+0zA7o+s5 nCBSf3n72F2YKD9xZzsLlEmo3J0J8nmR0RWbB1T+86hvqzv4AFWn7tLsZeLPyTZMoNPvsbZzCn9 pRnwrjJQCRSfQuTjBbCP8QGCu53VDUHBLAE6/b8CFIWWpEiG4Wv7RG8+PTpBxiKDGF99bPcEg8n Z+mM+Pw3Fv2WmCHu0GRg681C6mcJqJsjI5N6pOLqxYdyNy11O4uMKTu6XRWjz+3mUscKDHKjudb 3401U7FQ37tcfmA2+BCd9buALN7f23Q== X-Google-Smtp-Source: AGHT+IHYSwxNbthbwfEzEe8J9PMrOTKJZ5v3zMgqHDtUYFzGYrsADxL+e4c9ZAZgXL6hJPVJYTYX1w== X-Received: by 2002:a05:600c:1f91:b0:442:dc6f:7a21 with SMTP id 5b1f17b1804b1-44c9301653bmr34858515e9.3.1748101351615; Sat, 24 May 2025 08:42:31 -0700 (PDT) Received: from ?IPV6:2a01:e0a:255:1000:4ac2:93fd:6818:ec6? ([2a01:e0a:255:1000:4ac2:93fd:6818:ec6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-447f7d975cfsm186592975e9.38.2025.05.24.08.42.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 24 May 2025 08:42:31 -0700 (PDT) Message-ID: <6bc28291-b212-4a84-925a-e6e5ef2fb72c@deepbluecap.com> Date: Sat, 24 May 2025 17:42:30 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Logical replication 'invalid memory alloc request size 1585837200' after upgrading to 17.5 To: "Hayato Kuroda (Fujitsu)" , 'Amit Kapila' Cc: "pgsql-bugs@lists.postgresql.org" , Sawada Masahiko References: <680bdaf6-f7d1-4536-b580-05c2760c67c6@deepbluecap.com> Content-Language: en-US From: Duncan Sands In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Dear Hayato Kuroda, thank you so much for working on this problem. Your patch PG17-0001-Avoid-distributing-invalidation-messages-several-tim.patch solves the issue for me. Without it I get an invalid memory alloc request error within about twenty minutes. With your patch, 24 hours have passed with no errors. Best wishes, Duncan. On 21/05/2025 13:48, Hayato Kuroda (Fujitsu) wrote: > Dear hackers, > >> I think the problem here is that when we are distributing >> invalidations to a concurrent transaction, in addition to queuing the >> invalidations as a change, we also copy the distributed invalidations >> along with the original transaction's invalidations via repalloc in >> ReorderBufferAddInvalidations. So, when there are many in-progress >> transactions, each would try to copy all its accumulated invalidations >> to the remaining in-progress transactions. This could lead to such an >> increase in allocation request size. However, after queuing the >> change, we don't need to copy it along with the original transaction's >> invalidations. This is because the copy is only required when we don't >> process any changes in cases like ReorderBufferForget(). I have >> analyzed all such cases, and my analysis is as follows: > > Based on the analysis, I created a PoC which avoids the repalloc(). > Invalidation messages distributed by SnapBuildDistributeSnapshotAndInval() are > skipped to add in the list, just queued - repalloc can be skipped. Also, the function > distributes messages only in the list, so received messages won't be sent again. > > Now a patch for PG17 is created for testing purpose. Duncan, can you apply this and > confirms whether the issue can be solved? > > Best regards, > Hayato Kuroda > FUJITSU LIMITED >