Pardon me if this is something basic; I don't have much of a C background and seem to have gotten stuck in getting Rust to use jemalloc.
I'm seeing my Rust program crash when run in a Docker container after hitting the memory limit. Running it through heaptrack didn't show any leaks; so I wanted to explore jemalloc to see if this was due to fragmentation and get more information on what is happening.
I followed the tikv-jemallocator readme and added the dependency to Cargo.toml and set the global allocator in main.rs.
[target.'cfg(not(target_env = "msvc"))'.dependencies] tikv-jemallocator = "0.5"
At the beginning of main.rs:
#[cfg(not(target_env = "msvc"))] use tikv_jemallocator::Jemalloc; #[cfg(not(target_env = "msvc"))] #[global_allocator] static GLOBAL: Jemalloc = Jemalloc;
It built successfully, but
ldd didn't show the dependency
$ ldd heapdemo linux-vdso.so.1 (0x00007ffc3c17d000) libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f8352cb6000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f8352c93000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f8352b44000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f8352b3e000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f835294c000) /lib64/ld-linux-x86-64.so.2 (0x00007f835375f000)
I guess it may be statically linked, and proceeded to set the MALLOC_CONF
$ echo $MALLOC_CONF prof:true,prof_active:true,prof_final:true,prof_leak:true,lg_prof_interval:30,lg_prof_sample:0
Running the program didn't produce any extra output from jemalloc, so I'm not really sure whether jemalloc is actually being used or not.
So I tried switching to dynamically linking it so that I could see the dependency in
$ cat .cargo/config.toml rustflags = ["-C", "link-args=-l jemalloc"]
But this made no difference; the ldd output remained same and the program didn't produce any jemalloc output.
Wondering what I might be doing wrong here? Is there any other implied step that I should have done? I tried installing libjemalloc-dev
apt install libjemalloc-dev and that too didn't affect anything.