Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a way to replace default malloc to investigate different allocators #35772

Open
SchrodingerZhu opened this issue May 6, 2020 · 6 comments

Comments

@SchrodingerZhu
Copy link

Hi,
I have seen a previous discussion at #128 and a recent discussion at https://discourse.julialang.org/t/julia-vs-microsofts-rust-inspired-verona-language-and-e-g-snmalloc-allocator/38610.

After investigating a bit at microsoft/snmalloc#176, I think that the error caused by LD_PRELOAD is not the fault of snmalloc(they even tried exposing cfree to fix the problem). Therefore, I think currently there is no appropriate way to intercept low-level memory APIs for Julia correctly (ptrace is not considered here).

Hence, I open this issue hoping to request an investigation on a proper and efficient way to change the global allocator of Julia.

Several years has passed since #128, though memory allocation may not be the first thing to consider in most situations, some modern allocators like snmalloc and mimalloc can considerably improve the performance in some cases (see https://github.com/schrodingerzhu/bench_suite). Especially, these allocators are providing a better support with some special functions for modern languages. Maybe it is not easy to adapt some special features like deferring the memory returning in local free list in mimalloc, but simply apply the allocator can do good directly. Languages like rust also provides some handy interfaces to change the global allocator with a single line of code.

@JeffBezanson
Copy link
Member

It's not clear to me why LD_PRELOAD doesn't work. Looks like something inside libgfortran?

@SchrodingerZhu
Copy link
Author

@JeffBezanson I do not know the exact reason either. libgfortran calls a free in that case, but it is the version within system libc.

@ufechner7
Copy link

Could be useful for example for using Bumper.jl as allocator for a section of code.

@ViralBShah
Copy link
Member

ViralBShah commented Sep 10, 2024

Related: #46298 (jemalloc), #47062 (mimalloc)

@giordano
Copy link
Contributor

This ticket is only about providing a mechanism to change the allocator rather than defaulting to a different one, but in case someone was to suggest using jemalloc as default allocator, issues like the ones described in https://social.treehouse.systems/@marcan/113463801684233089 (e.g. jemalloc/jemalloc#467) make very hard to produce portable applications shipping jemalloc.

@gbaraldi
Copy link
Member

If anyone wants to play with this I started #47062 a while ago with mimalloc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants