It seems that I've found the issue.<div><br></div><div>I have a "process_killer" gen_server where processes can subscribe for periodic GC or kill. Its subscribe functions are called on each message received by some processes to postpone the GC/kill (something like re-arm).</div><div><br></div><div>This process performs an erlang:monitor if not already monitored to catch a dead process and remove it from watch list. If I comment our the re-subscription line on each handled message, "system" area seems to behave normally. That means it is a bug in my process_killer that does leak monitor refs (remember you can call erlang:monitor multiple times and each call creates a reference).</div><div><br></div><div>I was lead to this idea because I've tested a simple module which was calling erlang:monitor in a loop and I have seen ~13 bytes "system" area grow on each call. </div><div><br></div><div>The workers themselves were OK because they would die anyway taking their monitors along with them. There is one long running (starts with the app, stops with the app) process that dispatches all the messages to the workers that was calling GC re-arm on each received message, so we're talking about tens of thousands of monitors spawned per hour and never released.</div><div><br></div><div>I'm writing this answer here for future reference.</div><div><br></div><div>TL;DR; make sure you are not leaking monitor refs on a long running process. </div><div><br>On Thursday, February 7, 2013 6:21:45 PM UTC+2, Matthew Evans wrote:<blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">
<br>Can you kill the VM with a SIGUSR1 and look at the resulting crash dump?
<br>
<br>Start an Erlang shell, start crashdump viewer and poke around:
<br>
<br>crashdump_viewer:start().
<br>
<br>______________________________<wbr>__
<br>> Date: Thu, 7 Feb 2013 08:08:58 -0800 
<br>> From: <a href="javascript:" target="_blank" gdf-obfuscated-mailto="2m7U3YdA-70J">sig...@gmail.com</a> 
<br>> To: <a href="javascript:" target="_blank" gdf-obfuscated-mailto="2m7U3YdA-70J">erlang-pr...@<wbr>googlegroups.com</a> 
<br>> CC: <a href="javascript:" target="_blank" gdf-obfuscated-mailto="2m7U3YdA-70J">erlang-q...@erlang.org</a> 
<br>> Subject: Re: [erlang-questions] Memory growing 
<br>> 
<br>> I've tested NIFs from lists module and they seem to be fine. 
<br>> 
<br>> So, coming back to square one, how can I debug what is allocated in the 
<br>> "system" section of erlang:memory/0 ? 
<br>> 
<br>> Alex 
<br>> 
<br>> On Saturday, February 2, 2013 10:52:04 PM UTC+2, Alex P wrote: 
<br>> Hello, 
<br>> 
<br>> If somebody could help me with an issue, I would be grateful. I'm 
<br>> pulling my hair off trying to figure out why an erlang app keeps 
<br>> growing in memory usage. The erlang:memory() after 3 days shows this: 
<br>> 
<br>> [{total,325732292}, 
<br>> {processes,54520269}, 
<br>> {processes_used,54492115}, 
<br>> {system,271212023}, 
<br>> {atom,932793}, 
<br>> {atom_used,912937}, 
<br>> {binary,2348080}, 
<br>> {code,8288354}, 
<br>> {ets,487392}, 
<br>> {maximum,398189416}] 
<br>> 
<br>> The interesting part is "system" section. All other data is fine 
<br>> (processes goes to few MBs during the night as all the started procs 
<br>> are either hibernated - for long running or they die because of 
<br>> inactivity). 
<br>> 
<br>> There are two issues here: 
<br>> - "system" keeps growing (around 800MB/week) 
<br>> - OS (Linux) shows a significantly different amount of memory usage 
<br>> (almost 2x, 610MB resident in this case) 
<br>> 
<br>> The only case where I've managed to make "system" grow is by calling 
<br>> erlang:monitor() multiple times. It grows with ~13K/call. 
<br>> 
<br>> Erlang release used is R15B03. 
<br>> 
<br>> The questions are: 
<br>> - is there any hidden function to inspect all the active process 
<br>> monitors? (as the single place where I use erlang:monitor looks fine. 
<br>> The spawned kid does its job and dies, so the ref should be garbage 
<br>> collected). 
<br>> - is there any way to inspect "system" section and find out what it 
<br>> contains? Looking at memory chunks in process map got me nowhere 
<br>> 
<br>> Thank you, 
<br>> Alex 
<br>> 
<br>> 
<br>> 
<br>> ______________________________<wbr>_________________ erlang-questions 
<br>> mailing list <a href="javascript:" target="_blank" gdf-obfuscated-mailto="2m7U3YdA-70J">erlang-q...@erlang.org</a> 
<br>> <a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/<wbr>listinfo/erlang-questions</a> 
<br>                                               
<br>______________________________<wbr>_________________
<br>erlang-questions mailing list
<br><a href="javascript:" target="_blank" gdf-obfuscated-mailto="2m7U3YdA-70J">erlang-q...@erlang.org</a>
<br><a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/<wbr>listinfo/erlang-questions</a>
<br></blockquote></div>