[erlang-questions] high memory consumption in crash.dump

Salikhov Dinislam Dinislam.Salikhov@REDACTED
Tue Feb 12 17:44:00 CET 2019


Hello.

My VM (OTP-20.2) crashed with out of memory error.
I noticed that some processes have unexpectedly high memory consumption.
One of them is a long living process:
=proc:<0.483.0>
State: Waiting
Name: periodic_checker
Spawned as: proc_lib:init_p/5
Spawned by: <0.284.0>
Started: Fri Jan 18 20:37:49 2019
Message queue length: 0
Number of heap fragments: 0
Heap fragment data: 0
Link list: [<0.284.0>]
Reductions: 7015535411
Stack+heap: 1199557
OldHeap: 0
Heap unused: 313695
OldHeap unused: 0
Memory: 9597520
Program counter: 0x000000086de82df8 (gen_server:loop/7 + 632)
CP: 0x0000000000000000 (invalid)
arity = 0
Internal State: ACT_PRIO_NORMAL | USR_PRIO_NORMAL | PRQ_PRIO_NORMAL | ON_HEAP_MSGQ
=proc_dictionary:<0.483.0>
HED872D078
HED872D090
=proc_stack:<0.483.0>
0x0000000ed9053df8:SReturn addr 0x4368ACB0 (proc_lib:init_p_do_apply/3 + 72)
y0:N
y1:A8:infinity
y2:I600000
y3:A10:periodic_checker
y4:N
y5:A10:periodic_checker
y6:P<0.284.0>
0x0000000ed9053e38:SReturn addr 0xA2E048 (<terminate process normally>)
y0:N
y1:SCatch 0x4368ACD0 (proc_lib:init_p_do_apply/3 + 104)
=proc_heap:<0.483.0>
ED872D078:t2:AD:$initial_call,HED872D0D0
ED872D0D0:t3:A10:periodic_checker,A4:init,I1
ED872D090:t2:AA:$ancestors,HED872D0F0
ED872D0F0:lAC:ejabberd_sup|HED872D110
ED872D110:lP<0.203.0>|N

The process is a gen_server that once per 10 minutes searches a process with the longest message queue:
init(_) ->
     ets:new(periodic_checker, [named_table, {read_concurrency, true}]),
     ets:insert(periodic_checker, {max_process_mq_len, get_self_mq_len()}),
     {ok, [], 0}.
handle_call(_, _, State) ->
     {reply, undefined, State, 600000}.
handle_cast(_, State) ->
     {noreply, State, 600000}.
handle_info(timeout, State) ->
     update_max_process_mq_len(),
     {noreply, State, 600000};
handle_info(_, State) ->
     {noreply, State, 600000}.
get_self_mq_len() ->
     Pid = self(),
     {_, MQ_len} = process_info(Pid, message_queue_len),
     {Pid, MQ_len}.
update_max_process_mq_len() ->
     MaxMQ_len = lists:foldl(fun(Pid, Acc = {_, AccSize}) ->
             case process_info(Pid, message_queue_len) of
                 undefined -> Acc;
                 {_, MQ_len} ->
                     if MQ_len > AccSize ->
                         {Pid, MQ_len};
                     true ->
                         Acc
                     end
             end
     end, get_self_mq_len(), processes()),
     ets:insert(periodic_checker, {max_process_mq_len, MaxMQ_len}).

The thing that looks very suspicious is that the process consumed 9Mb of memory. For instance, on working node the 
process takes only ~88Kb.
There are more such processes in crash.dump, this one is the simplest.
Is there a way to find out what led to such high memory consumption?
Any ideas are appreciated.

Thanks in advance,
Dinislam Salikhov



More information about the erlang-questions mailing list