<div><br></div><div><includetail><div style="font:Verdana normal 14px;color:#000;"><div>Hi,</div><div><br></div><div>My question is about the binary memory usage.</div><div>I implemented a server which accepts Tcp connection. All the Tcp connections use binary options.</div><div><br></div><div>Before I set up 10000 Tcp connections to my server, the memory usage is as below:</div><div><div>(node1@yeshaobo)1> erlang:memory().</div><div>[{total,100311433},</div><div> {processes,24898112},</div><div> {processes_used,24895144},</div><div> {system,75413321},</div><div> {atom,1517705},</div><div> {atom_used,1506108},</div><div> <font color="#ff0000">{binary,3115928},</font></div><div> {code,48956174},</div><div> {ets,3556416},</div><div> {maximum,102757346}]</div></div><div><br></div><div>after I set up 10000 Tcp connections, every connection is hold by one gen_server; the memory usage is as below:</div><div><div>(node1@yeshaobo)5>erlang:memory().          </div><div>[{total,2616776425},</div><div> {processes,92150752},</div><div> {processes_used,92138976},</div><div> {system,2524625673},</div><div> {atom,1517705},</div><div> {atom_used,1506108},</div><div><font color="#ff0000"> {binary,2437117184},</font></div><div> {code,48956174},</div><div> {ets,13264464},</div><div> {maximum,2848153566}]</div></div><div><br></div><div>And I check the binary hold by all the processes on the node with the command below:</div><div>List = [begin {binary, L} = erlang:process_info(P, binary), {P, (lists:foldl(fun({_, I, _}, Acc) -> Acc + I end, 0, L))} end || P <- processes() -- [self()]], lists:foldl(fun({_, A}, Acc) -> A + Acc end, 0, List). </div><div>the result is 23113860.  It is much less than the value <span style="color: rgb(255, 0, 0);">2437117184</span> reported by erlang:memory().</div><div><br></div><div>My question is :</div><div>why does the VM allocate so much memory for binary?</div><div>Does the Tcp ports allocate their send/recv buffer on binary heap?</div><div>Is there any way I can see what are in the binary heap?</div><div><br></div><div>Thanks,</div><div>BRs/Michael</div><div><tincludetail></tincludetail></div></div><!--<![endif]--></includetail></div>