Is there an existing proposal for this?
Is your feature request related to a problem?
It seems that memray currently reports the different "kinds" of allocations based on which libc function was called (malloc, mmap...). (*) However, third-party allocators such as mimalloc and jemalloc are growing in use because of their desirable performance characteristics. When those are used instead of the system allocator, allocations which are logically malloc-like are reported as mmap calls with very large allocation sizes.
There is an example in this issue report where a bunch of 64MiB blocks are reported by memray as allocated (one per thread, roughly), resulting in a large reported footprint of more than 1GiB, while those are the page reservations by mimalloc and the corresponding allocations on the application side are tiny (1kiB each).
This is a problem that is bound to produce many user reports of memory leaks or overconsumption, while actually the program is operating at normal.
(*) I may be wrong in this interpretation of mine, in which case please do correct me.
Describe the solution you'd like
Ideally, memray would also detect calls to third-party allocator routines and report a mi_malloc(1024) as allocating 1024 bytes, not 64 MiB :-)
Several technical solutions can be considered and I'm not an expert in the field. Here are two that comes to mind:
-
Hard-code support for the most popular 3rd-party allocators, by looking at their respective API names. This seems conceptually easy but will have limited benefits, because those allocators are often privately vendored and sometimes their symbols are mangled to avoid symbol clashes. Also, this means that less popular allocators will not get any coverage.
-
Devise some sort of runtime protocol where the allocator themselves may tag API functions (how? I have no idea :-)) as being malloc-like, realloc-like, etc. This is obviously more complex technically and requires cooperation to come up with a suitable protocol, but would work better in the long term.
Alternatives you considered
No response
Is there an existing proposal for this?
Is your feature request related to a problem?
It seems that memray currently reports the different "kinds" of allocations based on which libc function was called (
malloc,mmap...). (*) However, third-party allocators such as mimalloc and jemalloc are growing in use because of their desirable performance characteristics. When those are used instead of the system allocator, allocations which are logically malloc-like are reported as mmap calls with very large allocation sizes.There is an example in this issue report where a bunch of 64MiB blocks are reported by memray as allocated (one per thread, roughly), resulting in a large reported footprint of more than 1GiB, while those are the page reservations by mimalloc and the corresponding allocations on the application side are tiny (1kiB each).
This is a problem that is bound to produce many user reports of memory leaks or overconsumption, while actually the program is operating at normal.
(*) I may be wrong in this interpretation of mine, in which case please do correct me.
Describe the solution you'd like
Ideally, memray would also detect calls to third-party allocator routines and report a
mi_malloc(1024)as allocating 1024 bytes, not 64 MiB :-)Several technical solutions can be considered and I'm not an expert in the field. Here are two that comes to mind:
Hard-code support for the most popular 3rd-party allocators, by looking at their respective API names. This seems conceptually easy but will have limited benefits, because those allocators are often privately vendored and sometimes their symbols are mangled to avoid symbol clashes. Also, this means that less popular allocators will not get any coverage.
Devise some sort of runtime protocol where the allocator themselves may tag API functions (how? I have no idea :-)) as being malloc-like, realloc-like, etc. This is obviously more complex technically and requires cooperation to come up with a suitable protocol, but would work better in the long term.
Alternatives you considered
No response