[erlang-questions] Troubleshooting binary memory usage

Lukas Larsson <>
Mon Feb 13 13:32:55 CET 2017


Hello,

On Fri, Feb 10, 2017 at 12:28 PM, ash <> wrote:

> Hi,
> I've been getting high values for `erlang:memory(binary)` so I've been
> looking at the following:
> (1) `[erlang:process_info(Pid, binary) || Pid <- processes()]`
>

This describes the number of off-heap binaries created by the application
belonging to the specified process.


> (2) `instrument:memory_data/0`
>

This describes the amount of memory used by the allocator type binary.


> (3) `erlang:system_info({allocator, binary_alloc})`
>

This describes the amount of memory allocated into the binary allocator aka
binary_alloc.

None of these will have the same value.

The binary allocator contains all off-heap binaries and other binary like
things (for drivers, nifs and erts things), so it will always be the
largest one.

The binary allocator type is what is used to allocate a off-heap binary.
However all off-heap binaries do not have to below to processes, they could
also belong to ports, nifs or some other VM internal entity. This value
should be smaller then binary_alloc. The pid that you see here is which
process CREATED the binary, the ownership of it may later have been shared
with a port, nif, or other process, or something else.

Lastly process_info describes the binaries currently referenced from the
heap of the given process. This should be smaller then binary_alloc and the
binary allocator type.

Lukas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20170213/1fe5fca7/attachment.html>


More information about the erlang-questions mailing list