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 1pUeCs-00088A-AP for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Feb 2023 01:46:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pUeCp-0004Dz-Hb for pgsql-hackers@arkaria.postgresql.org; Wed, 22 Feb 2023 01:46:03 +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 1pUeCp-0004Dq-6X for pgsql-hackers@lists.postgresql.org; Wed, 22 Feb 2023 01:46:03 +0000 Received: from mail-oi1-x229.google.com ([2607:f8b0:4864:20::229]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pUeCi-0004PP-NX for pgsql-hackers@lists.postgresql.org; Wed, 22 Feb 2023 01:46:02 +0000 Received: by mail-oi1-x229.google.com with SMTP id bm20so5757039oib.7 for ; Tue, 21 Feb 2023 17:45:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=v8pojkZxXyiHWJCBVyKAYq/ljgHI6sAYBNs7z5XDfBE=; b=fDAyV4Q3QvYigtyeK4wH1QwotEVDmc1slHAtiGNHbuur5BLZhZkqrNYzP8NT8A2wwB 7u4DogNgIv8LW9uxnuLBdC+CfSWGF+jnHtYUA/7d3u/TPQcSBEQe0sDxQDwJ/oI2vvjU HJhRSQ0eiVxSp3yZpa0TYIjE63B8k+RBaiHzjmmyRlaYzK5JDCdZKDxplAO0iJYcoX6/ +W1Lyg7DZLL/cxFVMx+wmahPthdZfdGxXNQb7byV059RNUkzhhZPnPYRbsZ5ZiJfb3Oc 49dSh2fpzFQODbl+RCCDDl6sg2yZJ7rVLa6whXQX1GAiHj61D65n2VUQJ+T+gIjQCJLm 8N7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=v8pojkZxXyiHWJCBVyKAYq/ljgHI6sAYBNs7z5XDfBE=; b=QEpoau0ImtyXk90XCq3Rtf3dueVZFKkSK1kX2PsZyVgesLYL2IBkxG9a7cZkPKjd5I UiZgaWv8piY+KZsGPr5ifQdAQY3GTgWd2jRv4zABf2UWMbJzg21Lt9CVrNyFZNNTJspT u4Tbhp9MCFJXiuVq6yMfmszdldCd8oJOS1Wi8HBFWGHPDXlU76ZjD1Zrcu9MkQCfGTWs AlsejGR+c15S9RHRr43TM8/Oi+2Zzd6ia2MGcSuRFj6EvHHg7kP3cgHdHj6J1QVr0Nr8 MbS42mEdqbrU13QBTqQKHofn7XU34ZIY9HbMK73ZwxcKj4t/kKjVjruApn5koNQJrDG8 n5/w== X-Gm-Message-State: AO0yUKXmc9/1aPLigHkb9P395Pku59TlusFhldN9k9swH0QmIi0I9pHP umET9B6YB0UeZR9cvTldiVMKoomvGUUsS3eS7Tk= X-Google-Smtp-Source: AK7set+zo2yBb+mDyIGfT/9ndTvG7wPC1QO48tlzJ5DoODbyzJSKJAVzzqxJvhVsGWi+TepZncbmthEEdaQIzj9cM54= X-Received: by 2002:a05:6808:2394:b0:378:29a6:b642 with SMTP id bp20-20020a056808239400b0037829a6b642mr794863oib.259.1677030356053; Tue, 21 Feb 2023 17:45:56 -0800 (PST) MIME-Version: 1.0 References: <20230217003204.cx5zu2aocjbwz5ns@awork3.anarazel.de> <20230217034000.ddcklsr6hfdifyqk@awork3.anarazel.de> <20230217175201.lspbj47wnjxhastu@awork3.anarazel.de> In-Reply-To: <20230217175201.lspbj47wnjxhastu@awork3.anarazel.de> From: David Rowley Date: Wed, 22 Feb 2023 14:45:39 +1300 Message-ID: Subject: Re: Reducing System Allocator Thrashing of ExecutorState to Alleviate FDW-related Performance Degradations To: Andres Freund Cc: "Jonah H. Harris" , PostgreSQL Hackers Content-Type: multipart/mixed; boundary="000000000000a6883a05f5400e26" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000a6883a05f5400e26 Content-Type: text/plain; charset="UTF-8" On Sat, 18 Feb 2023 at 06:52, Andres Freund wrote: > And did you increase ALLOCSET_DEFAULT_INITSIZE everywhere, or just passed a > larger block size in CreateExecutorState()? If the latter,the context > freelist wouldn't even come into play. I think this piece of information is critical to confirm what the issue is. > A 8MB max block size is pretty darn small if you have a workload that ends up > with a gigabytes worth of blocks. We should probably review that separately. These kinds of definitions don't age well. The current ones appear about 23 years old now, so we might be overdue to reconsider what they're set to. 2002-12-15 21:01:34 +0000 150) #define ALLOCSET_DEFAULT_MINSIZE 0 2000-06-28 03:33:33 +0000 151) #define ALLOCSET_DEFAULT_INITSIZE (8 * 1024) 2000-06-28 03:33:33 +0000 152) #define ALLOCSET_DEFAULT_MAXSIZE (8 * 1024 * 1024) ... I recall having a desktop with 256MBs of RAM back then... Let's get to the bottom of where the problem is here before we consider adjusting those. If the problem is unrelated to that then we shouldn't be discussing that here. > And the problem also could just be that the default initial blocks size takes > too long to ramp up to a reasonable block size. I think it's 20 blocks to get > from ALLOCSET_DEFAULT_INITSIZE to ALLOCSET_DEFAULT_MAXSIZE. Even if you > allocate a good bit more than 8MB, having to additionally go through 20 > smaller chunks is going to be noticable until you reach a good bit higher > number of blocks. Well, let's try to help Johan get the information to us. I've attached a quickly put together patch which adds some debug stuff to aset.c. Johan, if you have a suitable test instance to try this on, can you send us the filtered DEBUG output from the log messages starting with "AllocSet" with and without your change? Just the output for just the 2nd execution of the query in question is fine. The first execution is not useful as the cache of MemoryContexts may not be populated by that time. It sounds like it's the foreign server that would need to be patched with this to test it. If you can send that in two files we should be able to easily see what has changed in terms of malloc() calls between the two runs. David --000000000000a6883a05f5400e26 Content-Type: text/plain; charset="US-ASCII"; name="aset_debug_hacks.diff" Content-Disposition: attachment; filename="aset_debug_hacks.diff" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_lef0b5jw0 ZGlmZiAtLWdpdCBhL3NyYy9iYWNrZW5kL3V0aWxzL21tZ3IvYXNldC5jIGIvc3JjL2JhY2tlbmQv dXRpbHMvbW1nci9hc2V0LmMKaW5kZXggMDI2ZjU0NTY3Ni4uNTkwNTk1YmYyNSAxMDA2NDQKLS0t IGEvc3JjL2JhY2tlbmQvdXRpbHMvbW1nci9hc2V0LmMKKysrIGIvc3JjL2JhY2tlbmQvdXRpbHMv bW1nci9hc2V0LmMKQEAgLTQyNyw2ICs0MjcsOCBAQCBBbGxvY1NldENvbnRleHRDcmVhdGVJbnRl cm5hbChNZW1vcnlDb250ZXh0IHBhcmVudCwKIAkJCSgoTWVtb3J5Q29udGV4dCkgc2V0KS0+bWVt X2FsbG9jYXRlZCA9CiAJCQkJc2V0LT5rZWVwZXItPmVuZHB0ciAtICgoY2hhciAqKSBzZXQpOwog CisJCQllbG9nKERFQlVHMSwgIkFsbG9jU2V0Q29udGV4dENyZWF0ZUludGVybmFsOiByZWN5Y2xp bmcgY29udGV4dCBmb3IgJXMiLCAoKE1lbW9yeUNvbnRleHQpIHNldCktPm5hbWUpOworCiAJCQly ZXR1cm4gKE1lbW9yeUNvbnRleHQpIHNldDsKIAkJfQogCX0KQEAgLTUyMiw2ICs1MjQsOCBAQCBB bGxvY1NldENvbnRleHRDcmVhdGVJbnRlcm5hbChNZW1vcnlDb250ZXh0IHBhcmVudCwKIAogCSgo TWVtb3J5Q29udGV4dCkgc2V0KS0+bWVtX2FsbG9jYXRlZCA9IGZpcnN0QmxvY2tTaXplOwogCisJ ZWxvZyhERUJVRzEsICJBbGxvY1Nld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