Changing memory allocator to Jemalloc Centos 6

9,587

Solution 1

It's trivial answer (actually I still don't get it how your research could have missed it):

/etc/ld.so.preload

It's documented in ld.so(8) — man 8 ld.so: «…

/etc/ld.so.preload — File containing a whitespace separated list of ELF shared libraries to be loaded before the program.

…»

Solution 2

I found the same solution during my research. More detailed with stepwise instructions. There it is also stated that many companies switch to jemalloc (ex. Facebook) or tcmalloc (ex. Github). So you can as well try using tcmalloc (installing is quite similar) or follow the instructions and use jemalloc.

Share:
9,587

Related videos on Youtube

Brian Lovett
Author by

Brian Lovett

Updated on September 18, 2022

Comments

  • Brian Lovett
    Brian Lovett almost 2 years

    After reading this blog post about the impact of memory allocators like jemalloc on highly threaded applications, I wanted to test things on a larger scale on some of our cluster of servers. We run sphinx, and apache using threads, and on 24 core machines.

    Installing jemalloc was simple enough. We are running Centos 6, so yum install jemalloc jemalloc-devel did the trick. My question is, how do we change everything on the system over to using jemalloc instead of the default malloc built into Centos. Research pointed me at this as a potential option:

    LD_PRELOAD=$LD_PRELOAD:/usr/lib64/libjemalloc.so.1
    

    Would this be sufficient to get everything using jemalloc?

    • Brian Lovett
      Brian Lovett over 11 years
      I enabled the above and restarted the services that I wanted to rest. In observing, I have seen a decrease in the Reserved memory column as well as quite a bit of movement in that column. Prior to the change the value there was typically static in size. In our case 5.4gb. Now, it fluctuates quite often, and quite quickly, but averages about 4.7gb. Since jemalloc is a faster memory allocator I "think" I can attribute my observation to the fact that it is working. If so, my next question becomes. How can I tell which memory allocator a process is using in linux?
    • David Schwartz
      David Schwartz almost 10 years
      You can look at /proc/<pid>/maps to see if libjemalloc.so is mapped.