Unaccounted memory usage...

Matthias Lang matthias@REDACTED
Mon Mar 10 17:46:43 CET 2003


Shawn Pearce writes:
 > Can someone help me explain this a little?  My beam process is 
 > currently at a little over 200 MB resident heap size.  

Nice to see a real problem concerning code which actually exists. Just
for a change.

It's reasonably easy to see where CPU time is going in Erlang, but
sometimes it's frustratingly difficult to figure out where the memory
is going. Gut feeling tends to be misleading.

Something which often helps is using an instrumented emulator (start
it with -instr) to figure out where memory is going. Take a look at

  http://www.erlang.org/doc/r9b/lib/tools-2.1/doc/html/instrument.html

Don't be afraid to hack instrument.erl to help you figure out what's
going on, e.g. you may want to sum memory areas by type. Here's a hack
I needed to diagnose my previous problem---memory fragmentation. It
gives you a list you can sum instead of just printing out holes:

   holes([]) ->
       ok;
   holes([E | L]) ->
       holes(E, L).
   
   holes(E1, []) -> [];
   holes(E1, [E2 | Rest]) ->
       {_,P1,S1,_} = E1,
       {_,P2,S2,_} = E2,
       End = P1+S1,
       Hole = P2 - (End + ?INFO_SIZE),
       if
   	Hole =< 7 ->
   	    holes(E2, Rest);
   	true ->
   	    [Hole|holes(E2, Rest)]
       end.

Matt



More information about the erlang-questions mailing list