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 1pSofc-00088d-CZ for pgsql-hackers@arkaria.postgresql.org; Fri, 17 Feb 2023 00:32:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pSofb-0006cg-6M for pgsql-hackers@arkaria.postgresql.org; Fri, 17 Feb 2023 00:32:11 +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 1pSofa-0006cW-Sx for pgsql-hackers@lists.postgresql.org; Fri, 17 Feb 2023 00:32:10 +0000 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pSofY-0007HC-IU for pgsql-hackers@lists.postgresql.org; Fri, 17 Feb 2023 00:32:10 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 90D8932003C0; Thu, 16 Feb 2023 19:32:06 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Thu, 16 Feb 2023 19:32:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm1; t=1676593926; x=1676680326; bh=/T2Ln6g9wQ VyLzKS17Jq8+or1NLHGTdK/i8Xvdm8t6Y=; b=eUADR+SJ5L5lFkClJjG5lVdeqw CgTDgAfwURR3CflN5AuC9EPjLP53i4/e4MbdA1edKNh0Nik0Mb7uMlU9OL3ccMJ6 6KWIp3ynP15f76KuFh3BhQZL+zz0XHEbH3REBWTsUMJYaVVCU8lMl4th4Zj07Gx+ Rarawddn6Edoj5zkmGT25LbXJiRXJWd9deE0r6pZRlkyvMPof98elITE0Z067SAh 2IF6ming48BLJhyWTNFInKcM0IA45q8DLqEKcxcAS1Qm+IuwSQiUdhUcx5JjZOIC CwiL6ymz49RBsYGj4hR4oj+wt9G0BkKo5TSfWnb2dvkLcgnqZV+p/tAnJHYw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1676593926; x=1676680326; bh=/T2Ln6g9wQVyLzKS17Jq8+or1NLH GTdK/i8Xvdm8t6Y=; b=YhiUUWjpkAZi9LxoTc2XmNAO+ndBTL78NF+cn5F13b+R iA77IKKA7p4xuREtjmgbK7pdg6FkUfvAI0IRiohO49gc6ufj+yLdNytGJWNiOHXN KFKVcqIA1Yawl9Fl87744c4m5M8iqC3azLCncUmyAQYqh3sy7drqPmEgOyhV1bhs y78bUQrQYR7GUI2IX235/00ruYppxrsrk8M3AzKGHPBPnYKL2uublRPHhKkM/eEr 5WWnl/BLYcZlnYNHbr4SA+MEu6jR6L7NHAk9P+Etgf7O5o2OSQf6mk4zn0xdfAkw iPic1yCFP4VE3mohk9L6dn+VLjjymHsPvOUA5EqRbg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrudeikedgvdefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomheptehnughr vghsucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgiivghlrdguvgeqnecuggftrf grthhtvghrnhepvdfffeevhfetveffgeeiteefhfdtvdffjeevhfeuteegleduheetvedu ieettddunecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh eprghnughrvghssegrnhgrrhgriigvlhdruggv X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 16 Feb 2023 19:32:05 -0500 (EST) Date: Thu, 16 Feb 2023 16:32:04 -0800 From: Andres Freund To: "Jonah H. Harris" Cc: PostgreSQL Hackers Subject: Re: Reducing System Allocator Thrashing of ExecutorState to Alleviate FDW-related Performance Degradations Message-ID: <20230217003204.cx5zu2aocjbwz5ns@awork3.anarazel.de> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2023-02-16 16:49:07 -0500, Jonah H. Harris wrote: > I've been working on a federated database project that heavily relies on > foreign data wrappers. During benchmarking, we noticed high system CPU > usage in OLTP-related cases, which we traced back to multiple brk calls > resulting from block frees in AllocSetReset upon ExecutorEnd's > FreeExecutorState. This is because FDWs allocate their own derived > execution states and required data structures within this context, > exceeding the initial 8K allocation, that need to be cleaned-up. What PG version? Do you have a way to reproduce this with core code, e.g. postgres_fdw/file_fdw? What is all that memory used for? Is it possible that the real issue are too many tiny allocations, due to some allocation growing slowly? > Increasing the default query context allocation from ALLOCSET_DEFAULT_SIZES > to a larger initial "appropriate size" solved the issue and almost doubled > the throughput. However, the "appropriate size" is workload and > implementation dependent, so making it configurable may be better than > increasing the defaults, which would negatively impact users (memory-wise) > who aren't encountering this scenario. > > I have a patch to make it configurable, but before submitting it, I wanted > to hear your thoughts and feedback on this and any other alternative ideas > you may have. This seems way too magic to expose to users. How would they ever know how to set it? And it will heavily on the specific queries, so a global config won't work well. If the issue is a specific FDW needing to make a lot of allocations, I can see adding an API to tell a memory context that it ought to be ready to allocate a certain amount of memory efficiently (e.g. by increasing the block size of the next allocation by more than 2x). Greetings, Andres Freund