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 1pmHZr-0006fT-2K for pgsql-hackers@arkaria.postgresql.org; Tue, 11 Apr 2023 17:14:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pmHZo-0002GI-JI for pgsql-hackers@arkaria.postgresql.org; Tue, 11 Apr 2023 17:14:40 +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 1pmHZo-0002G9-8K for pgsql-hackers@lists.postgresql.org; Tue, 11 Apr 2023 17:14:40 +0000 Received: from mail1.dalibo.net ([51.159.93.128] helo=mail.dalibo.com) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pmHZl-002GiU-Oz for pgsql-hackers@lists.postgresql.org; Tue, 11 Apr 2023 17:14:39 +0000 Received: from karst (larco.ioguix.net [78.202.0.6]) by mail.dalibo.com (Postfix) with ESMTPSA id 704891FA8D; Tue, 11 Apr 2023 19:14:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=dalibo.com; s=a; t=1681233265; bh=lHViKJDSEd+0ZqwUxyxSdY4ANyVLY/bxGfqOnFabw6Y=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=XB8pIFEjROTc5FuT7tyMrgmiJmuraWkZehw+gtCeEmix6IgaF0khEiOc/CutpAwci qGBZZ3SoDme+SGUwsw10HpkFGftBLTrSzI16A6ZQTwu0EZFuTahxMOp+P9J0B1XNrs sVW57KWLyXJuukDAX3VR37dsM5OnHSjJE/Wn5SCw= Date: Tue, 11 Apr 2023 19:14:24 +0200 From: Jehan-Guillaume de Rorthais To: Tomas Vondra Cc: Melanie Plageman , pgsql-hackers@lists.postgresql.org Subject: Re: Memory leak from ExecutorState context? Message-ID: <20230411191424.56e9acfe@karst> In-Reply-To: <20230408020119.32a0841b@karst> References: <3013398b-316c-638f-2a73-3783e8e2ef02@enterprisedb.com> <20230302001827.66e95dc3@karst> <41c5766d-ed71-b70c-bbbc-d3396c462d62@enterprisedb.com> <20230302130838.717e888d@karst> <77a96d42-00cb-2448-465a-aa1e92d00cac@enterprisedb.com> <20230302191530.781909fe@karst> <20230310195114.6d0c5406@karst> <20230317091834.22e97642@karst> <455abe0e-91b2-f428-6f4c-b95c7c8dfb52@enterprisedb.com> <20230320151234.38b2235e@karst> <20230327231323.08277083@karst> <20230328151745.0f6061f8@karst> <20230331140611.3695d30d@karst> <20230408020119.32a0841b@karst> Organization: Dalibo MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sat, 8 Apr 2023 02:01:19 +0200 Jehan-Guillaume de Rorthais wrote: > On Fri, 31 Mar 2023 14:06:11 +0200 > Jehan-Guillaume de Rorthais wrote: > > [...] > > After rebasing Tomas' memory balancing patch, I did some memory measures > to answer some of my questions. Please, find in attachment the resulting > charts "HJ-HEAD.png" and "balancing-v3.png" to compare memory consumption > between HEAD and Tomas' patch. They shows an alternance of numbers > before/after calling ExecHashIncreaseNumBatches (see the debug patch). I > didn't try to find the exact last total peak of memory consumption during the > join phase and before all the BufFiles are destroyed. So the last number > might be underestimated. I did some more analysis about the total memory consumption in filecxt of HEAD, v3 and v4 patches. My previous debug numbers only prints memory metrics during batch increments or hash table destruction. That means: * for HEAD: we miss the batches consumed during the outer scan * for v3: adds twice nbatch in spaceUsed, which is a rough estimation * for v4: batches are tracked in spaceUsed, so they are reflected in spacePeak Using a breakpoint in ExecHashJoinSaveTuple to print "filecxt->mem_allocated" from there, here are the maximum allocated memory for bufFile context for each branch: batches max bufFiles total spaceAllowed rise HEAD 16384 199966960 ~194MB v3 4096 65419456 ~78MB v4(*3) 2048 34273280 48MB nbatch*sizeof(PGAlignedBlock)*3 v4(*4) 1024 17170160 60.6MB nbatch*sizeof(PGAlignedBlock)*4 v4(*5) 2048 34273280 42.5MB nbatch*sizeof(PGAlignedBlock)*5 It seems account for bufFile in spaceUsed allows a better memory balancing and management. The precise factor to rise spaceAllowed is yet to be defined. *3 or *4 looks good, but this is based on a single artificial test case. Also, note that HEAD is currently reporting ~4MB of memory usage. This is by far wrong with the reality. So even if we don't commit the balancing memory patch in v16, maybe we could account for filecxt in spaceUsed as a bugfix? Regards,