Bug 65538 - [5 Regression] Memory leak of ipa_node_params_sum elements
Summary: [5 Regression] Memory leak of ipa_node_params_sum elements
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 5.0
: P3 normal
Target Milestone: 5.0
Assignee: Martin Liška
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-24 09:16 UTC by Jakub Jelinek
Modified: 2015-03-25 12:08 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2015-03-24 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jakub Jelinek 2015-03-24 09:16:38 UTC
Seen recently in valgrind output (e.g. on the pr65533.c testcase):

==19246== 216 (48 direct, 168 indirect) bytes in 1 blocks are definitely lost in loss record 501 of 594
==19246==    at 0x4A070D7: operator new(unsigned long) (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==19246==    by 0xAEBAAE: function_summary<ipa_node_params*>::allocate_new() (symbol-summary.h:106)
==19246==    by 0xAEAF20: function_summary<ipa_node_params*>::get(int) (symbol-summary.h:232)
==19246==    by 0xAE9B97: function_summary<ipa_node_params*>::get(cgraph_node*) (symbol-summary.h:112)
==19246==    by 0xAF9C38: ipa_analyze_node(cgraph_node*) (ipa-prop.c:2386)
==19246==    by 0x15B5578: ipcp_generate_summary() (ipa-cp.c:4449)
==19246==    by 0xC255AF: execute_ipa_summary_passes(ipa_opt_pass_d*) (passes.c:2154)
==19246==    by 0x841202: ipa_passes() (cgraphunit.c:2179)
==19246==    by 0x8415E5: symbol_table::compile() (cgraphunit.c:2295)
==19246==    by 0x841907: symbol_table::finalize_compilation_unit() (cgraphunit.c:2444)
==19246==    by 0x69CEB8: c_write_global_declarations() (c-decl.c:10801)
==19246==    by 0xD1EBAC: compile_file() (toplev.c:608)
==19246== 
==19246== 384 (192 direct, 192 indirect) bytes in 4 blocks are definitely lost in loss record 519 of 594
==19246==    at 0x4A070D7: operator new(unsigned long) (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==19246==    by 0xAEBAAE: function_summary<ipa_node_params*>::allocate_new() (symbol-summary.h:106)
==19246==    by 0xAEAF20: function_summary<ipa_node_params*>::get(int) (symbol-summary.h:232)
==19246==    by 0xAE9B97: function_summary<ipa_node_params*>::get(cgraph_node*) (symbol-summary.h:112)
==19246==    by 0xAF42FC: ipa_initialize_node_params(cgraph_node*) (ipa-prop.c:293)
==19246==    by 0xAE323D: estimate_function_body_sizes(cgraph_node*, bool) (ipa-inline-analysis.c:2518)
==19246==    by 0xAE4F54: compute_inline_parameters(cgraph_node*, bool) (ipa-inline-analysis.c:2951)
==19246==    by 0xAE5051: compute_inline_parameters_for_current() (ipa-inline-analysis.c:2978)
==19246==    by 0xAE50D8: (anonymous namespace)::pass_inline_parameters::execute(function*) (ipa-inline-analysis.c:3008)
==19246==    by 0xC25B24: execute_one_pass(opt_pass*) (passes.c:2328)
==19246==    by 0xC25D5E: execute_pass_list_1(opt_pass*) (passes.c:2380)
==19246==    by 0xC25DCC: execute_pass_list(function*, opt_pass*) (passes.c:2391)

inline summaries are ggc allocated and so not a problem, but the ipa-prop summaries are not, and thus something should arrange that the ipa_node_params class objects allocated by allocate_new are destructed when m_map is destructed.
So, perhaps summary_hashmap_traits needs to implement the remove template method?  Though, it is unclear how it could find out if the hash_map is ggc or not.  Perhaps the decision ggc vs. non-ggc should be done as function_summary template parameter or similar.
Comment 1 Richard Biener 2015-03-24 10:29:29 UTC
Confirmed.
Comment 2 Martin Liška 2015-03-24 10:38:41 UTC
(In reply to Jakub Jelinek from comment #0)
> Seen recently in valgrind output (e.g. on the pr65533.c testcase):
> 
> ==19246== 216 (48 direct, 168 indirect) bytes in 1 blocks are definitely
> lost in loss record 501 of 594
> ==19246==    at 0x4A070D7: operator new(unsigned long) (in
> /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
> ==19246==    by 0xAEBAAE: function_summary<ipa_node_params*>::allocate_new()
> (symbol-summary.h:106)
> ==19246==    by 0xAEAF20: function_summary<ipa_node_params*>::get(int)
> (symbol-summary.h:232)
> ==19246==    by 0xAE9B97:
> function_summary<ipa_node_params*>::get(cgraph_node*) (symbol-summary.h:112)
> ==19246==    by 0xAF9C38: ipa_analyze_node(cgraph_node*) (ipa-prop.c:2386)
> ==19246==    by 0x15B5578: ipcp_generate_summary() (ipa-cp.c:4449)
> ==19246==    by 0xC255AF: execute_ipa_summary_passes(ipa_opt_pass_d*)
> (passes.c:2154)
> ==19246==    by 0x841202: ipa_passes() (cgraphunit.c:2179)
> ==19246==    by 0x8415E5: symbol_table::compile() (cgraphunit.c:2295)
> ==19246==    by 0x841907: symbol_table::finalize_compilation_unit()
> (cgraphunit.c:2444)
> ==19246==    by 0x69CEB8: c_write_global_declarations() (c-decl.c:10801)
> ==19246==    by 0xD1EBAC: compile_file() (toplev.c:608)
> ==19246== 
> ==19246== 384 (192 direct, 192 indirect) bytes in 4 blocks are definitely
> lost in loss record 519 of 594
> ==19246==    at 0x4A070D7: operator new(unsigned long) (in
> /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
> ==19246==    by 0xAEBAAE: function_summary<ipa_node_params*>::allocate_new()
> (symbol-summary.h:106)
> ==19246==    by 0xAEAF20: function_summary<ipa_node_params*>::get(int)
> (symbol-summary.h:232)
> ==19246==    by 0xAE9B97:
> function_summary<ipa_node_params*>::get(cgraph_node*) (symbol-summary.h:112)
> ==19246==    by 0xAF42FC: ipa_initialize_node_params(cgraph_node*)
> (ipa-prop.c:293)
> ==19246==    by 0xAE323D: estimate_function_body_sizes(cgraph_node*, bool)
> (ipa-inline-analysis.c:2518)
> ==19246==    by 0xAE4F54: compute_inline_parameters(cgraph_node*, bool)
> (ipa-inline-analysis.c:2951)
> ==19246==    by 0xAE5051: compute_inline_parameters_for_current()
> (ipa-inline-analysis.c:2978)
> ==19246==    by 0xAE50D8: (anonymous
> namespace)::pass_inline_parameters::execute(function*)
> (ipa-inline-analysis.c:3008)
> ==19246==    by 0xC25B24: execute_one_pass(opt_pass*) (passes.c:2328)
> ==19246==    by 0xC25D5E: execute_pass_list_1(opt_pass*) (passes.c:2380)
> ==19246==    by 0xC25DCC: execute_pass_list(function*, opt_pass*)
> (passes.c:2391)
> 
> inline summaries are ggc allocated and so not a problem, but the ipa-prop
> summaries are not, and thus something should arrange that the
> ipa_node_params class objects allocated by allocate_new are destructed when
> m_map is destructed.
> So, perhaps summary_hashmap_traits needs to implement the remove template
> method?  Though, it is unclear how it could find out if the hash_map is ggc
> or not.  Perhaps the decision ggc vs. non-ggc should be done as
> function_summary template parameter or similar.

I think the correct way is to traverse all items in function_summary<T>::release (in case of GGC-based map) and delete them all.

Working on the patch.

Martin
Comment 3 Martin Liška 2015-03-25 11:47:35 UTC
Author: marxin
Date: Wed Mar 25 11:47:04 2015
New Revision: 221658

URL: https://gcc.gnu.org/viewcvs?rev=221658&root=gcc&view=rev
Log:
Fix PR65538.

	PR tree-optimization/65538
	* symbol-summary.h (function_summary::~function_summary):
	Relese memory for allocated summaries.
	(function_summary::release): New function.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/symbol-summary.h
Comment 4 Martin Liška 2015-03-25 12:08:01 UTC
Fixed in 5.0.0.