Does REFC-biniaries count to process_info(Pid, memory)?

Hi!
I am trying to measure memory consumption on a program implemented with either binaries or lists for handling Strings.

So i was wondering:
When calling process_info(Pid, memory). Does the memory used for an REFC-binary get counted to the memory used by the process?

If yes, since REFC-binaries are stored in process-shared memory, will two processes that have access to the same binary both count it as memory used and thus “overcount”?

If no, is there another way to see it?

Thank you in advance!
// Chef

process_info(Pid, memory). does not track off heap binary memory. You can use erlang:process_info(Pid, binary) or erlang:process_info(Pid, garbage_collection_info) to get that information.

See the inline comments in this example for details:

2> erlang:process_info(self(), memory).
{memory,142848} %% Original memory
3> <<0:(1024*1024)>>. %% Create a 131072 byte binary
<<0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  0,...>>
4> erlang:process_info(self(), memory).
{memory,142848} %% memory stays the same
5> erlang:process_info(self(), [binary]).
[{binary,[{105025994150080,10,1},
          {105025994149712,78,1},
          {136391456522688,131072,2}, %% This is our binary
          {105025994152344,68,1}]}]
6> erlang:process_info(self(), [garbage_collection_info]).
[{garbage_collection_info,[{old_heap_block_size,10958},
                           {heap_block_size,6772},
                           {mbuf_size,0},
                           {recent_size,137},
                           {stack_size,26},
                           {old_heap_size,3126},
                           {heap_size,6743},
        %% It is also part of the below, but in words not bytes, so 131072 / 8 = 16384.0
                           {bin_vheap_size,16409},
                           {bin_vheap_block_size,98315},
                           {bin_old_vheap_size,72},
                           {bin_old_vheap_block_size,46422}]}]
1 Like

Thank you! This was a very clear and easy-to-understand answer!

1 Like