Published Aug 27, 2008
I have received numerous requests for a version of jemalloc that is ported to various operating systems. My plan has long been to create a jemalloc distribution that supports *BSD, Linux, Solaris, OS X, and Windows, but there are a lot of portability headaches to deal with for OS X and Windows, so the project keeps being neglected.
Porting to Linux isn’t much trouble though, so I whipped up a minimal distribution this morning, and put it in this directory. Maybe someday I’ll get around to a proper widely portable distribution, but until then, I hope people find the Linux port useful.
Sweet! Glad to here you are making a stand-alone version. Jemalloc seems to be a nice allocator. Before this I ripped the code out of firefox and used it and that has worked well. Looking forward to seeing this picked up by distros so it easy to get and us.
Great work!
FWIW, a couple of remarks:
(1) under linux pthread_mutex_lock/unlock are available even if not linked against the libpthread. glibc has stubs to ensure that, that do nothing when libpthread isn’t loaded:
nm -D /lib/libc-2.7.so|grep pthread_mutex
00000000000db010 T pthread_mutex_destroy
00000000000db040 T pthread_mutex_init
00000000000db070 T pthread_mutex_lock
00000000000db0a0 T pthread_mutex_unlock
Sadly it’s not true for pthread_spin_*.
(2) your realloc case should really try to use mremap for the Huge allocations, because memcopy-ing the whole area is slow.
(3) Afaict, with recent glibc’s every linux architectures support TLS (at least every architectures you test for in your implementation).
Oh and as of pthread_atfork that is missing from the default libc stubs, you only need to write this:
#include <pthread.h>
int pthread_atfork() __attribute__((weak, alias("__zero_stub"));
static int __zero_stub() { return 0; }
If you wish to build jemalloc.so with -Bsymbolic or similar then you have to do that in a libjemalloc-pthread-stubs.so that jemalloc links against, so that when the libpthread is present, it takes precedence, if you don’t use -Bsymbolic, I believe it’ll just DWYM. In the worst case scenario the stubs library will be required, too bad.
This way you can get rid of your __threading define altogether.
(Note: I know the code is ugly, I took this from the libpthread-stubs xcb is using, it is obvious how to write it in a way that wont make gcc -Wall -Wextra complain about function prototypes, just it’s longer and doesn’t fit in a blog post ;p)
Does openoffice work with jemalloc? I have LD_PRELOADED the jemalloc lib, openoffice starts but it crashes while creating a new file. Any idea?