Possible memory leak with a NIF

I’m trying to track down what seems to be a memory leak in one of our platforms.

‘system’ memory just keeps growing, leading me to think it’s a NIF causing the issue.

Could anyone tell me if the following output from instrument:allocations/0 looks off?
This is in a VM which has only been running for a couple of hours and is already using over 1.5GB of memory.

My primary suspect is the erlfdb_nif, but I’m not certain what the histogram is actually telling me here.

(smd@localhost)49> instrument:allocations().
{ok,{128,511965312,
     #{asn1rt_nif =>
           #{drv_binary => {132,549,268,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0}},
       crypto =>
           #{drv_binary => {319,5,143,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0}},
       erlfdb_nif =>
           #{binary => {72,85,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
             driver_mutex =>
                 {2240960,206493,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
             driver_tid => {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
             drv_binary => {107,1717,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
             nif_internal => {0,0,0,21,0,0,0,0,0,0,0,0,0,0,0,0,0,0}},
       prim_buffer =>
           #{binary => {0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
             nif_internal => {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}},
       prim_file =>
           #{binary => {0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
             drv_binary => {0,0,0,5,6,1,1,0,0,0,0,0,0,0,0,0,0,0}},
       rocksdb =>
           #{binary => {0,40,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
             drv_binary => {12,4,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0}},
       system =>
           #{binary => {1,54,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
             driver => {0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
             driver_cond => {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
             driver_mutex => {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
             driver_rwlock => {41,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
             driver_tsd => {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
             drv_binary =>
                 {1994,1520,405,10338,3051,10,1,1,1,0,1,0,0,0,0,0,0,1},
             drv_internal => {0,0,101,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
             microstate_accounting =>
                 {1,44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
             nif_internal => {29,14,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
             port => {0,0,104,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
             port_data_lock => {2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}},
       tcp_inet =>
           #{driver_tid => {8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
             driver_tsd => {8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
             drv_binary => {0,0,243,95,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
             drv_internal => {52,8,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
             port => {0,0,13,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}},
       udp_inet =>
           #{drv_binary => {0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}}}}}

2 Likes

The erlfdb_nif entry is telling you that currently there are 2240960 mutexes that are smaller than 128 bytes allocated and 206493 mutexes that are between 128 bytes and 146 bytes. So I would assume that somewhere enif_mutex_create is called without destroy being called.

4 Likes

Thanks. I’ll open an issue with the project.

Thanks @garazdawi

2 Likes