<div dir="ltr">Hello,<div><br></div><div>In the allocator snapshot you sent me it's possible to see that the apparent memory leak has to do with memory fragmentation. </div><div><br></div><div>About a week ago I sent a patch to upstream recon to include the mbcs pool in the calculation of total used memory. With this patch (that is now part of the master branch for recon) we can see that the utilization of the binary allocators is very low. </div>
<div><br></div><div><div>34> recon_alloc:fragmentation(current).</div><div>[{{binary_alloc,10},</div><div>  [{sbcs_usage,0.9663911159624771},</div><div>   {mbcs_usage,0.00851128256381634},</div><div>   {sbcs_block_size,12975432},</div>
<div>   {sbcs_carriers_size,13426688},</div><div>   {mbcs_block_size,8594792},</div><div>   {mbcs_carriers_size,1009811616}]},</div><div> {{binary_alloc,21},</div><div>  [{sbcs_usage,0.9576609472490074},</div><div>   {mbcs_usage,0.02275766909139376},</div>
<div>   {sbcs_block_size,69155072},</div><div>   {sbcs_carriers_size,72212480},</div><div>   {mbcs_block_size,21489512},</div><div>   {mbcs_carriers_size,944275616}]},</div><div> {{binary_alloc,4},</div><div>  [{sbcs_usage,0.9769352091165413},</div>
<div>   {mbcs_usage,0.013649233045825031},</div><div>   {sbcs_block_size,26610152},</div><div>   {sbcs_carriers_size,27238400},</div><div>   {mbcs_block_size,12115776},</div><div>   {mbcs_carriers_size,887652512}]},</div>
<div> {{binary_alloc,8},</div><div>  [{sbcs_usage,0.9620084547199639},</div><div>   {mbcs_usage,0.01384863563143117},</div><div>   {sbcs_block_size,26172048},</div><div>   {sbcs_carriers_size,27205632},</div><div>   {mbcs_block_size,10651864},</div>
<div>   {mbcs_carriers_size,769163424}]},</div><div> {{binary_alloc,20},</div><div>  [{sbcs_usage,0.9607166148513436},</div><div>   {mbcs_usage,0.022427188875552406},</div><div>   {sbcs_block_size,34412408},</div><div>   {sbcs_carriers_size,35819520},</div>
<div>   {mbcs_block_size,15121920},</div><div>   {mbcs_carriers_size,674267296}]},...]</div></div><div><br></div><div>So you have a "classic" memory fragmentation problem. The reason why you are seeing it in 17.0 and not in R16 is probably because we have changed the default allocation strategy from "best fit" to "address order first fit carrier best fit". </div>
<div><br></div><div>To fix this I would first try to change the allocation strategy for binaries to "address order first fit carrier address order best fit" (+MBas aoffcaobf) and see if that helps. </div><div><br>
</div><div>If that does not work you could always disable the mbcs pool (+MBacul 0), which would make the allocators run very similar to how they worked in R16. But you loose the nice mbcs pool :(</div><div><br></div><div>
<div>One thing to keep in mind here is that maybe you don't have to fix it at all? The memory is not lost, it just not used at the moment and cannot be released to the OS because some binaries are still present in them. So unless you crash with out of memory I would not change anything. </div>
</div><div><br></div><div>Lukas</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Apr 29, 2014 at 5:17 PM, Max Lapshin <span dir="ltr"><<a href="mailto:max.lapshin@gmail.com" target="_blank">max.lapshin@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_extra">(<a href="mailto:flussonic@127.0.0.1" target="_blank">flussonic@127.0.0.1</a>)3> recon_alloc:snapshot_get().</div>
<div class="gmail_extra">{[{total,2201115696},</div><div class="gmail_extra">
  {processes,140618848},</div><div class="gmail_extra">  {processes_used,140254568},</div><div class="gmail_extra">  {system,2060496848},</div><div class="gmail_extra">  {atom,561761},</div><div class="gmail_extra">  {atom_used,551696},</div>

<div class="gmail_extra">  {binary,1939374344},</div><div class="gmail_extra">  {code,17258778},</div><div class="gmail_extra">  {ets,85224424}],</div><div class="gmail_extra"> [{{sys_alloc,0},</div><div class="gmail_extra">

   [{options,[{e,true},{m,libc},{tt,131072},{tp,0}]}]},</div><div class="gmail_extra">  {{mseg_alloc,0},</div><div class="gmail_extra">   [{memkind,[{name,"all memory"},</div><div class="gmail_extra">              {status,[{cached_segments,0},</div>

<div class="gmail_extra">                       {cache_hits,79},</div><div class="gmail_extra">                       {segments,19,20,20},</div><div class="gmail_extra">                       {segments_size,35913728,36175872,36175872},</div>

<div class="gmail_extra">                       {segments_watermark,19}]},</div><div class="gmail_extra">              {calls,[{mseg_alloc,0,104},</div><div class="gmail_extra">                      {mseg_dealloc,0,85},</div>

<div class="gmail_extra">                      {mseg_realloc,0,0},</div><div class="gmail_extra">                      {mseg_create_resize,0,0},</div><div class="gmail_extra">                      {mseg_create,0,25},</div>

<div class="gmail_extra">                      {mseg_destroy,0,7},</div><div class="gmail_extra">                      {mseg_recreate,0,0},</div><div class="gmail_extra">                      {mseg_clear_cache,0,0},</div>

<div class="gmail_extra">                      {mseg_check_cache,0,6}]}]},</div><div class="gmail_extra">    {options,[{amcbf,4194304},{rmcbf,20},{mcs,10},{scs,0}]},</div><div class="gmail_extra">    {version,"0.9"}]},</div>

<div><br></div><div>.....</div><div><br></div><div><br></div><div><br></div><div><div>(<a href="mailto:flussonic@127.0.0.1" target="_blank">flussonic@127.0.0.1</a>)6> ets:foldl(fun(T,Sum) -> erlang:external_size(T) + Sum end, 0, live_streams_attrs).</div>

<div>1749128853</div></div><div><br></div><div><div>(<a href="mailto:flussonic@127.0.0.1" target="_blank">flussonic@127.0.0.1</a>)9> lists:sum([ ets:foldl(fun(T,Sum) -> erlang:external_size(T) + Sum end, 0, T) || T <- ets:all(), is_atom(T)]).</div>

<div>1758913413</div></div><div><br></div><div><br></div><div>So, it looks like only 2G are really used. Where could leak the rest?  Is it possible that data is leaking or accumulating somewhere in network buffers?</div>
<div>
<br></div><div>Version on R16 doesn't have such problems.</div><div><br></div><div><br></div></div></div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div>