<div dir="ltr">Hi,<br><br>Most likely you have temporary  processes that handles binaries that never die<br>holding those binaries referenced and gc cannnot garbage collect them.<br><br>This is a sign o bad process cleanup management logic.<br><br>On Tuesday, November 10, 2015 at 4:59:27 AM UTC+2, 이기탁 wrote:<blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir="ltr">Hello All :)<div><br></div><div><br></div><div>I have a some question about Erlang binary memory management.</div><div><br></div><div>I'm running the application on Erlang VM 17.4</div><div>(Erlang/OTP 17 [erts-6.3] [source-f9282c6] [64-bit] [smp:24:24] [async-threads:10] [hipe] [kernel-poll:false])</div><div><br></div><div>This application is processing many binaries. (relaying some binary packets from A client to B client)</div><div><br></div><div>But A weeks ago, binary metric in system does not drop on base line (like below picture). <br></div><div>Base line of binary memory is about 144 MB but only increased :( </div><div><br></div><div><br></div><div><br></div><p style="text-align:center;clear:both"><a href="https://lh3.googleusercontent.com/-1a_Y6_fLALQ/VkFXvIF_i7I/AAAAAAAAAOg/JHjuVsqqTDk/s1600/is_memory_leak.png" style="margin-left:1em;margin-right:1em" target="_blank" rel="nofollow" onmousedown="this.href='https://lh3.googleusercontent.com/-1a_Y6_fLALQ/VkFXvIF_i7I/AAAAAAAAAOg/JHjuVsqqTDk/s1600/is_memory_leak.png';return true;" onclick="this.href='https://lh3.googleusercontent.com/-1a_Y6_fLALQ/VkFXvIF_i7I/AAAAAAAAAOg/JHjuVsqqTDk/s1600/is_memory_leak.png';return true;"><img origsrc="https://lh3.googleusercontent.com/-1a_Y6_fLALQ/VkFXvIF_i7I/AAAAAAAAAOg/JHjuVsqqTDk/s400/is_memory_leak.png" border="0" height="196" width="400"></a></p><div>So I ran some codes in machine's console</div><div><br></div><div><div>(xxx@node)1> lists:sum([try</div><div>(xxx@node)1>   {_,M} = erlang:process_info(Pid, binary),</div><div>(xxx@node)1>   lists:sum([ByteSize || {_, ByteSize, _} <- M])</div><div>(xxx@node)1> catch</div><div>(xxx@node)1>   _:_ -> 0</div><div>(xxx@node)1> end || Pid <- processes()]).</div><div>151431354</div><div>(xxx@node)2> CS = lists:foldl(</div><div>(xxx@node)2>        fun ({instance, _, L}, Acc) -></div><div>(xxx@node)2>          {value,{_,MBCS}} = lists:keysearch(mbcs, 1, L),</div><div>(xxx@node)2>          {value,{_,SBCS}} = lists:keysearch(sbcs, 1, L),</div><div>(xxx@node)2>          [MBCS,SBCS | Acc]</div><div>(xxx@node)2>        end,</div><div>(xxx@node)2>        [],</div><div>(xxx@node)2>        erlang:system_info({<wbr>allocator_sizes, binary_alloc})),</div><div>(xxx@node)2> lists:foldl(</div><div>(xxx@node)2>   fun(L, Sz0) -></div><div>(xxx@node)2>     {value,{_,Sz,_,_}} = lists:keysearch(blocks_size, 1, L),</div><div>(xxx@node)2>     Sz0+Sz</div><div>(xxx@node)2>   end, 0, CS).</div><div>553821984</div></div><div><br></div><div>Sum of binaries using processes is 144MB, but some of binary allocator is 528MB. </div><div>This is almost same with below binary memory.</div><div><br></div><div><div>(xxx@node)3> erlang:memory().</div><div>[{total,2314432736},</div><div> {processes,1672464336},</div><div> {processes_used,1672334920},</div><div> {system,641968400},</div><div> {atom,2017513},</div><div> {atom_used,2001044},</div><div> {binary,553927480}, <--</div><div> {code,54190392},</div><div> {ets,7211864}]</div></div><div><br></div><div>Maybe GC problem? so I ran GC forcibly.</div><div><br></div><div><div>(xxx@node)4> [erlang:garbage_collect(P) || P <- processes()].</div><div>[true,true,true,true,true,<wbr>true,true,true,true,true,true,</div><div> true,true,true,true,true,<wbr>true,true,true,true,true,true,<wbr>true,</div><div> true,true,true,true,true,<wbr>true|...]</div><div><br></div><div><br></div><div>(xxx@node)5> erlang:memory().</div><div>[{total,2294793888},</div><div> {processes,1654106832},</div><div> {processes_used,1653947192},</div><div> {system,640687056},</div><div> {atom,2017513},</div><div> {atom_used,2001044},</div><div> {binary,552605080}, <--</div><div> {code,54190392},</div><div> {ets,7240816}]</div></div><div><br></div><div>Not resolved... :(</div><div><br></div><div>Moreover this issue is only in production environment, no issue in develop env. I can't reproduce it.</div><div>About 200 machines in production, but about 110 machines has this issue.</div><div><br></div><div>How can I approach this issue to resolve? </div><div><br></div><div>Ah! my sys.config is like this.</div><div>===</div><div><div>+K true<br></div><div>+A 6<br></div><div>+stbt db<br></div><div>+SP 50:50<br></div><div>+P 134217727<br></div><div>-env ERL_FULLSWEEP_AFTER 0<br></div><div>-heart<br></div></div><div>===</div><div><br></div><div><p style="margin-top:1em;margin-bottom:1em;line-height:normal;font-family:arial,sans-serif">Thanks in advance for your advice,</p><p style="margin-top:1em;margin-bottom:1em;line-height:normal;font-family:arial,sans-serif">GiTack, Lee</p></div><div><br></div></div></blockquote></div>