Using jemalloc in existing huge code

I have a huge code distributed by the number of files. This code currently uses regular malloc.

I want to implement Jemalloc in it to improve performance, and also want to use the Jemalloc memory profiler to find out how and where exactly each distribution occurs inside this code.

I have been trying this for more than 3 weeks. Please help me.

Thanks in advance.

+4
source share
2 answers

After you build jemalloc without any prefix, you will have a shared library with the entire redefined family of malloc functions.

Assumption: Linux environment

You can use the LD_PRELOAD jemalloc.so variable to preload jemalloc.so before launching the application if it runs in the same terminal. Sort of:

 export LD_PRELOAD=$LD_PRELOAD:/path/to/jemalloc-build/lib/jemalloc.so.1 

For all applications that may be affected by the change, you can add a new line in the /etc/ld.so.preload file with the path to your library. (This certainly works on Debian based systems, but possibly others too)

+10
source

I installed my jemalloc in / usr / local, so it exited the "normal" library paths.

The installation kindly created a wrapper for me to run programs using the jemalloc library.

To some extent, it automates the above procedure described above, but uses only jemalloc for the program that I want to execute. If this is the intended use, you can do the following:

First check if there is something small script somewhere in your path:

me@mypc /root # which jemalloc.sh

/usr/local/bin/jemalloc.sh

If it exists, you can simply execute your program as follows:

me@mypc /root # jemalloc.sh your-program your-program-arguments &

You can read /usr/local/bin/jemalloc.sh to make sure it uses a similar method with Iulius described.

me@mypc /root # jemalloc-config --help will help you understand how your jemalloc was compiled, and me@mypc /root # jemalloc-config --version will show you your version of jemalloc.

This way you can check if your programs are working properly with jemalloc without repackaging them. You can make the final decisions.

George.

0
source

All Articles