I have a huge code spreaded over number of files. This code is currently using normal malloc.
I want to implement Jemalloc in it for better performance and I also want to use Jemalloc's memory profiler to get to know how and where exactly every allocation is happening inside that code.
I am trying this for over 3 weeks. Please help me.
Thanks in advance.
After you build jemalloc
without any prefix, you will have a shared library with all the malloc
family of functions reimplemented.
Assumption: Linux enviroment
You could use LD_PRELOAD
enviroment variable to preload the jemalloc.so
before you run your application, if it runs in a single terminal. Something like:
export LD_PRELOAD=$LD_PRELOAD:/path/to/jemalloc-build/lib/jemalloc.so.1
For all the applications to be affected by the change you can add a new line in the file /etc/ld.so.preload
with the path to your lib. (This works for sure in Debian-based systems, but probably on others too)
I have installed my jemalloc in /usr/local , so he is out of the "normal" library paths.
The installation kindly created a shell for me, to launch programs using the jemalloc library.
In a way, it automates the procedure that Iulius described above, but it uses jemalloc ONLY for the program I want to execute. If this is the intended use, you may do the following:
First, check if that little script exists somewhere in your path:
me@mypc /root #
which jemalloc.sh
/usr/local/bin/jemalloc.sh
If it exists, you may simply execute your program this way:
me@mypc /root #
jemalloc.sh your-program your-program-arguments &
You can read /usr/local/bin/jemalloc.sh
to verify that it uses a similar way with the one Iulius described.
me@mypc /root #
jemalloc-config --help
will help you see how your jemalloc was compiled, and
me@mypc /root #
jemalloc-config --version
will show you your jemalloc version.
This way you can verify that your programs work properly with jemalloc without needing to recompile them. You may then make your final decisions.
George.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With