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 1qlXc3-003FyV-Lk for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Sep 2023 16:42:11 +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 1qlXc1-0018Wt-Nb for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Sep 2023 16:42:10 +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 1qlXc1-0018WW-Ch for pgsql-hackers@lists.postgresql.org; Wed, 27 Sep 2023 16:42:09 +0000 Received: from lahtoruutu.iki.fi ([2a0b:5c81:1c1::37]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qlXby-007vJp-M5 for pgsql-hackers@postgresql.org; Wed, 27 Sep 2023 16:42:09 +0000 Received: from [192.168.1.115] (dsl-hkibng22-54f8db-125.dhcp.inet.fi [84.248.219.125]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) (Authenticated sender: hlinnaka) by lahtoruutu.iki.fi (Postfix) with ESMTPSA id 4Rwj7c1b2tz49Q8H; Wed, 27 Sep 2023 19:42:04 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1695832924; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qeAtiphUrYMKvK3l3Gn/WxOGd+Sg/G9PpcpkKXXoAbg=; b=l+v+8HuIWMdNqn5LyuroIz/xt/nY2pq9XNUSmrQm5IA2eTqAcOr7e02HvcyfHJGckyo5BA B/SyMeaA3n2PNsU9F83xSnP3gzp11GOt46booh0XUDjbFDnmsSeYNQT0B9ksjD/FwaOzGn RkMJqS35qI0PqCHEUaRLBqg7U1EczYurixT9x2Il01Bm8GEJIN8sXACkAQtLpBgRqFNuvn Dp4euBaksckUeDZbZgIvUZW9uBqiHQF4GfQY8drkcz3+7cAQZWd/SaqbKYjxSA6f8moryw ++g+BgXAouUsE+lGXLUl1pVk9RaF9RZR6eNGhmCYQjSuvC0+OFizeYPlO4MUKQ== ARC-Seal: i=1; s=lahtoruutu; d=iki.fi; t=1695832924; a=rsa-sha256; cv=none; b=QV62q1HsJ8W2vIvUkdTqkYd+SD8dg20uQzzN8BKMB7v5siLXdpbaxEmn+s/TorTDAkxy8r ulzyVwJLmIhblcFRZ2l0HsNXn1AJTdLF/JflFRj+Coau42nJASgZPDBKIUtvy+a0w4McAS taxBfmTEjh3m3KYQ7DEElp90jTjYCmp5y3wyGFRy8ZzpoNuCqBau/2nd8lphkUwCTrHLfm ya+eQ68M4tVEv+m3nQwxIZMTiMdv3h0RK8rn+kHIbh59TF8H9sc9vVGhhXYwny5+0GCddI fruUT1AweUQlEznItvJOgUXtwYlQYSlOfwNy4mU6+mnRapVSQlP/o0XEBxIpKg== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1695832924; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qeAtiphUrYMKvK3l3Gn/WxOGd+Sg/G9PpcpkKXXoAbg=; b=p8DqbIHCw9URBnFVbvzIcdYO3ItOSJNe8cr0jYAW/Zfbry7oElMiicalNp3FpIAFj6lMwN DPjy7+k+p+/+0CSgpHlvSHs4oJMIsUOcxn5oWt8cr1GQ4uaO2T+gjR6ipXJHtPUQlo9X/i rbGB/x+VB4AKd0tAYxD/C0n979ndmy7evLTXtYpKPgo/YzTgjA8Zv69zvYL+jT0NM4mtG3 gfln4PoG0CthmBlLrzcfbyrv4M6RzG0YX0twuFauP3D5kmJLXHmD+xeVFFbb/07wNJfNbD y6r5MpMyasnkgj913jTBz5OFd2vMZuA4M6uq622RI4x8d5kLWcNKhTrpJ6Q7dQ== Message-ID: <871e80d4-e8cf-a117-ceb2-141586a3bcd2@iki.fi> Date: Wed, 27 Sep 2023 19:42:03 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: Unlinking Parallel Hash Join inner batch files sooner Content-Language: en-US To: Jehan-Guillaume de Rorthais , Thomas Munro Cc: pgsql-hackers References: <20230510230031.4d710fd1@karst> From: Heikki Linnakangas In-Reply-To: <20230510230031.4d710fd1@karst> 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 On 11/05/2023 00:00, Jehan-Guillaume de Rorthais wrote: > On Wed, 10 May 2023 15:11:20 +1200 > Thomas Munro wrote: >> The reason I didn't do this earlier is that sharedtuplestore.c >> continues the pre-existing tradition where each parallel process >> counts what it writes against its own temp_file_limit. At the time I >> thought I'd need to have one process unlink all the files, but if a >> process were to unlink files that it didn't create, that accounting >> system would break. Without some new kind of shared temp_file_limit >> mechanism that doesn't currently exist, per-process counters could go >> negative, creating free money. In the attached patch, I realised >> something that I'd missed before: there is a safe point for each >> backend to unlink just the files that it created, and there is no way >> for a process that created files not to reach that point. > > Indeed. > > For what it worth, from my new and non-experienced understanding of the > parallel mechanism, waiting for all workers to reach > WAIT_EVENT_HASH_GROW_BATCHES_REPARTITION, after re-dispatching old batches in > new ones, seems like a safe place to instruct each workers to clean their old > temp files. Looks good to me too at a quick glance. There's this one "XXX free" comment though: > for (int i = 1; i < old_nbatch; ++i) > { > ParallelHashJoinBatch *shared = > NthParallelHashJoinBatch(old_batches, i); > SharedTuplestoreAccessor *accessor; > > accessor = sts_attach(ParallelHashJoinBatchInner(shared), > ParallelWorkerNumber + 1, > &pstate->fileset); > sts_dispose(accessor); > /* XXX free */ > } I think that's referring to the fact that sts_dispose() doesn't free the 'accessor', or any of the buffers etc. that it contains. That's a pre-existing problem, though: ExecParallelHashRepartitionRest() already leaks the SharedTuplestoreAccessor structs and their buffers etc. of the old batches. I'm a little surprised there isn't aready an sts_free() function. Another thought is that it's a bit silly to have to call sts_attach() just to delete the files. Maybe sts_dispose() should take the same three arguments that sts_attach() does, instead. So that freeing would be nice to tidy up, although the amount of memory leaked is tiny so might not be worth it, and it's a pre-existing issue. I'm marking this as Ready for Committer. -- Heikki Linnakangas Neon (https://neon.tech)