<div>I'm very interested in that too. Last time I asked for help only @Max Lapshin was kind enough to share some feedbacks (today's Daniel).</div><div><br></div><div>I would appreciate if the OTP team can teach us how to debug VM's mem issues, and  how pick the right allocator.</div><div><br></div><div>I'm aware of the excellent recon module. But to be honest, I was never be able to successfully use it to track my mem issue. Maybe not using it correctly. </div><div><br></div><div>Thanks in advance.</div><div><br></div><div>Best,</div><div>/Frank</div><div><br></div><div><div class="gmail_quote"><div>Le sam. 14 janv. 2017 à 21:47, Dániel Szoboszlay <<a href="mailto:dszoboszlay@gmail.com">dszoboszlay@gmail.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_msg">Hi Jack,<div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">I guess the 9 GB is lost due to memory fragmentation. Erlang allocates memory in large chunks called carriers from the OS, then places the blocks your program actually needs on these carriers. A carrier can only be returned to the OS once all the blocks on it have been freed (and even then, the memory allocator may decide to keep it around for a while in case more memory is needed).</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">You can check with <a href="https://ferd.github.io/recon/recon_alloc.html" class="gmail_msg" target="_blank">recon_alloc</a> how much unused memory is lost due to fragmentation in the various allocators.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">The bad news is that you cannot defragment the carriers, and if the selected memory allocator strategy doesn't work well for your application, you cannot change it either without restarting the emulator.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">However, if the memory is wasted in the <font face="monospace" class="gmail_msg">eheap_alloc</font>, you may try to force a GC on all processes a couple of times. As the GC copies the memory, it will allocate new blocks and free up the old heap blocks. So there's a chance the allocators can compact the blocks together on fewer segments. But that's just a guess, it may or may not work at all.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Cheers,</div><div class="gmail_msg">Daniel</div></div><br class="gmail_msg"><div class="gmail_quote gmail_msg"><div class="gmail_msg">On Sat, 14 Jan 2017 at 08:04 Jack Tang <<a href="mailto:himars@gmail.com" class="gmail_msg" target="_blank">himars@gmail.com</a>> wrote:<br class="gmail_msg"></div><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_msg"><span style="font-size:12.8px" class="gmail_msg">Hello list,</span><div style="font-size:12.8px" class="gmail_msg"><br class="gmail_msg"></div><div style="font-size:12.8px" class="gmail_msg">I run one Erlang application on Debian server and today I find the beam process consumes around 35G memory by `top` command.</div><div style="font-size:12.8px" class="gmail_msg"><br class="gmail_msg"></div><div style="font-size:12.8px" class="gmail_msg"><div class="gmail_msg">```</div><div class="gmail_msg">KiB Mem:  99194912 total, 61682656 used, 37512252 free,   397380 buffers</div><div class="gmail_msg">KiB Swap:        0 total,        0 used,        0 free. 18684864 cached Mem</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND</div><div class="gmail_msg">11858 usr1   20   0 36.850g 0.032t   6220 S  73.5 34.4   8038:49 beam.smp</div><div class="gmail_msg">```</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">I connect to the Erlang application using remote shell and find the mem-leaked supervisor tree and run gc on the whole tree. Code looks like blow:</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">```</div><div class="gmail_msg">lists:foreach(fun(E) -> PId = element(2, E), erlang:garbage_collect(PId) end, supervisor:which_children(some_thing_sup)).<br class="gmail_msg"></div><div class="gmail_msg">```</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">and erlang:memory() decreases from 32G to 23G.</div><div class="gmail_msg">```</div><div class="gmail_msg"><div class="gmail_msg">[{total,22982011544},</div><div class="gmail_msg"> {processes,12884182336},</div><div class="gmail_msg"> {processes_used,12884170336},</div><div class="gmail_msg"> {system,10097829208},</div><div class="gmail_msg"> {atom,13828705},</div><div class="gmail_msg"> {atom_used,13796692},</div><div class="gmail_msg"> {binary,170530288},</div><div class="gmail_msg"> {code,16450626},</div><div class="gmail_msg"> {ets,9637717576}]</div></div><div class="gmail_msg">```</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">However, when I input `top` command, the beam process still takes 35G memory. What can I do to release the 9G memory? Thanks</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">BR</div><div class="gmail_msg">-Jack</div></div></div><br><br>_______________________________________________<br class="gmail_msg"><br><br>erlang-questions mailing list<br class="gmail_msg"><br><br><a href="mailto:erlang-questions@erlang.org" class="gmail_msg" target="_blank">erlang-questions@erlang.org</a><br class="gmail_msg"><br><br><a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" class="gmail_msg" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br class="gmail_msg"><br><br></blockquote></div><br><br>_______________________________________________<br class="gmail_msg"><br>erlang-questions mailing list<br class="gmail_msg"><br><a href="mailto:erlang-questions@erlang.org" class="gmail_msg" target="_blank">erlang-questions@erlang.org</a><br class="gmail_msg"><br><a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" class="gmail_msg" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br class="gmail_msg"><br></blockquote></div></div>