From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D66F03858C74; Tue, 2 Apr 2024 09:56:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D66F03858C74 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1712051763; bh=qSKUcVdG35PyO/brCjHYBJpkaGVoi8Dpgnmhrsu3V+s=; h=From:To:Subject:Date:In-Reply-To:References:From; b=YIGwpOvIGZ8SPJMVqlYHgr41ZpltUk0Bf436rT5fdVIu47qEBfEShVLtE/b7lxhPe 1bLOlwDAYw1Knrhy4/55A9RTZC8Ro1HQ2EpexJoyahOj/ytiAq4AwkvyfFDiV8ji5b 9MMMy1VfGyYcGIkElTgPCOuRPgSwTJAmyk9bjHRk= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/114557] ehcleanup cleanup_empty_eh_merge_phis eats a lot of memory Date: Tue, 02 Apr 2024 09:56:02 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: compile-time-hog, memory-hog X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_status cf_reconfirmed_on everconfirmed Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D114557 Richard Biener changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Last reconfirmed| |2024-04-02 Ever confirmed|0 |1 --- Comment #1 from Richard Biener --- The main reason is that the "large" PHI nodes are never re-used for large allocations and that the GTY ((deletable (""))) for the free_phinodes array doesn't seem to be effective for this testcase. diff --git a/gcc/tree-phinodes.cc b/gcc/tree-phinodes.cc index ddd731323e1..44dc345a3b7 100644 --- a/gcc/tree-phinodes.cc +++ b/gcc/tree-phinodes.cc @@ -223,6 +223,12 @@ release_phi_node (gimple *phi) delink_imm_use (imm); } + if (len - 2 >=3D NUM_BUCKETS - 2) + { + ggc_free (phi); + return; + } + bucket =3D len > NUM_BUCKETS - 1 ? NUM_BUCKETS - 1 : len; bucket -=3D 2; vec_safe_push (free_phinodes[bucket], phi); cuts memory usage to 10GB. The free_phinodes buckets are also badly designed - we always allocate power-of-two overall PHI node memory through ideal_phi_node_len but have buckets for [2, ..., 10] actual PHI nodes which likely makes us have exactly a single (maybe two) free PHI node buckets ... After ehcleanup (and with the above patch) we have (gdb) p/r free_phinodes $5 =3D {0x0, 0x0, 0x7ffff668e000, 0x0, 0x0, 0x0, 0x0, 0x7ffe8b3df000} so as I said. Two slots are used only. (gdb) p/r (free_phinodes)[2].m_vecpfx $7 =3D {m_alloc =3D 524287, m_using_auto_storage =3D 0, m_num =3D 265598} (gdb) p/r (free_phinodes)[7].m_vecpfx $8 =3D {m_alloc =3D 65535, m_using_auto_storage =3D 0, m_num =3D 59610} After the next collection the array is actually empty: (gdb) p/r free_phinodes $9 =3D {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0} but memory usage doesn't shrink, likely either due to fragmentation or due to stale references. Maybe the 'deleteable' only gets effective upon next collection but we do not collect anymore after hitting 10GB, likely because we no longer expand the heap (hitting this peak is the bug anyway). We do re-collect in final(), but that doesn't reduce the memory. We do have a lot of blocks and edges and thus PHIs.=