1{ stdenv, fetchurl, fetchpatch }:
2
3stdenv.mkDerivation rec {
4 name = "jemalloc-${version}";
5 version = "5.0.1";
6
7 src = fetchurl {
8 url = "https://github.com/jemalloc/jemalloc/releases/download/${version}/${name}.tar.bz2";
9 sha256 = "4814781d395b0ef093b21a08e8e6e0bd3dab8762f9935bbfb71679b0dea7c3e9";
10 };
11
12 # By default, jemalloc puts a je_ prefix onto all its symbols on OSX, which
13 # then stops downstream builds (mariadb in particular) from detecting it. This
14 # option should remove the prefix and give us a working jemalloc.
15 configureFlags = stdenv.lib.optional stdenv.isDarwin "--with-jemalloc-prefix="
16 # jemalloc is unable to correctly detect transparent hugepage support on
17 # ARM (https://github.com/jemalloc/jemalloc/issues/526), and the default
18 # kernel ARMv6/7 kernel does not enable it, so we explicitly disable support
19 ++ stdenv.lib.optional stdenv.isAarch32 "--disable-thp";
20 doCheck = true;
21
22 patches = stdenv.lib.optional stdenv.isAarch64 (fetchpatch {
23 url = "https://patch-diff.githubusercontent.com/raw/jemalloc/jemalloc/pull/1035.patch";
24 sha256 = "02y0q3dp253bipxv4r954nqipbjbj92p6ww9bx5bk3d8pa81wkqq";
25 });
26
27 enableParallelBuilding = true;
28
29 meta = with stdenv.lib; {
30 homepage = http://jemalloc.net;
31 description = "General purpose malloc(3) implementation";
32 longDescription = ''
33 malloc(3)-compatible memory allocator that emphasizes fragmentation
34 avoidance and scalable concurrency support.
35 '';
36 license = licenses.bsd2;
37 platforms = platforms.all;
38 maintainers = with maintainers; [ wkennington ];
39 };
40}