1Building and installing a packaged release of jemalloc can be as simple as 2typing the following while in the root directory of the source tree: 3 4 ./configure 5 make 6 make install 7 8If building from unpackaged developer sources, the simplest command sequence 9that might work is: 10 11 ./autogen.sh 12 make dist 13 make 14 make install 15 16Note that documentation is not built by the default target because doing so 17would create a dependency on xsltproc in packaged releases, hence the 18requirement to either run 'make dist' or avoid installing docs via the various 19install_* targets documented below. 20 21=== Advanced configuration ===================================================== 22 23The 'configure' script supports numerous options that allow control of which 24functionality is enabled, where jemalloc is installed, etc. Optionally, pass 25any of the following arguments (not a definitive list) to 'configure': 26 27--help 28 Print a definitive list of options. 29 30--prefix=<install-root-dir> 31 Set the base directory in which to install. For example: 32 33 ./configure --prefix=/usr/local 34 35 will cause files to be installed into /usr/local/include, /usr/local/lib, 36 and /usr/local/man. 37 38--with-version=<major>.<minor>.<bugfix>-<nrev>-g<gid> 39 Use the specified version string rather than trying to generate one (if in 40 a git repository) or use existing the VERSION file (if present). 41 42--with-rpath=<colon-separated-rpath> 43 Embed one or more library paths, so that libjemalloc can find the libraries 44 it is linked to. This works only on ELF-based systems. 45 46--with-mangling=<map> 47 Mangle public symbols specified in <map> which is a comma-separated list of 48 name:mangled pairs. 49 50 For example, to use ld's --wrap option as an alternative method for 51 overriding libc's malloc implementation, specify something like: 52 53 --with-mangling=malloc:__wrap_malloc,free:__wrap_free[...] 54 55 Note that mangling happens prior to application of the prefix specified by 56 --with-jemalloc-prefix, and mangled symbols are then ignored when applying 57 the prefix. 58 59--with-jemalloc-prefix=<prefix> 60 Prefix all public APIs with <prefix>. For example, if <prefix> is 61 "prefix_", API changes like the following occur: 62 63 malloc() --> prefix_malloc() 64 malloc_conf --> prefix_malloc_conf 65 /etc/malloc.conf --> /etc/prefix_malloc.conf 66 MALLOC_CONF --> PREFIX_MALLOC_CONF 67 68 This makes it possible to use jemalloc at the same time as the system 69 allocator, or even to use multiple copies of jemalloc simultaneously. 70 71 By default, the prefix is "", except on OS X, where it is "je_". On OS X, 72 jemalloc overlays the default malloc zone, but makes no attempt to actually 73 replace the "malloc", "calloc", etc. symbols. 74 75--without-export 76 Don't export public APIs. This can be useful when building jemalloc as a 77 static library, or to avoid exporting public APIs when using the zone 78 allocator on OSX. 79 80--with-private-namespace=<prefix> 81 Prefix all library-private APIs with <prefix>je_. For shared libraries, 82 symbol visibility mechanisms prevent these symbols from being exported, but 83 for static libraries, naming collisions are a real possibility. By 84 default, <prefix> is empty, which results in a symbol prefix of je_ . 85 86--with-install-suffix=<suffix> 87 Append <suffix> to the base name of all installed files, such that multiple 88 versions of jemalloc can coexist in the same installation directory. For 89 example, libjemalloc.so.0 becomes libjemalloc<suffix>.so.0. 90 91--with-malloc-conf=<malloc_conf> 92 Embed <malloc_conf> as a run-time options string that is processed prior to 93 the malloc_conf global variable, the /etc/malloc.conf symlink, and the 94 MALLOC_CONF environment variable. For example, to change the default decay 95 time to 30 seconds: 96 97 --with-malloc-conf=decay_time:30 98 99--disable-cc-silence 100 Disable code that silences non-useful compiler warnings. This is mainly 101 useful during development when auditing the set of warnings that are being 102 silenced. 103 104--enable-debug 105 Enable assertions and validation code. This incurs a substantial 106 performance hit, but is very useful during application development. 107 Implies --enable-ivsalloc. 108 109--enable-code-coverage 110 Enable code coverage support, for use during jemalloc test development. 111 Additional testing targets are available if this option is enabled: 112 113 coverage 114 coverage_unit 115 coverage_integration 116 coverage_stress 117 118 These targets do not clear code coverage results from previous runs, and 119 there are interactions between the various coverage targets, so it is 120 usually advisable to run 'make clean' between repeated code coverage runs. 121 122--disable-stats 123 Disable statistics gathering functionality. See the "opt.stats_print" 124 option documentation for usage details. 125 126--enable-ivsalloc 127 Enable validation code for malloc_usable_size() and sallocx(), which 128 verifies that pointers reside within jemalloc-owned extents before 129 dereferencing metadata. This incurs a minor performance hit, and causes 130 the functions to return 0 for failed lookups. 131 132--enable-prof 133 Enable heap profiling and leak detection functionality. See the "opt.prof" 134 option documentation for usage details. When enabled, there are several 135 approaches to backtracing, and the configure script chooses the first one 136 in the following list that appears to function correctly: 137 138 + libunwind (requires --enable-prof-libunwind) 139 + libgcc (unless --disable-prof-libgcc) 140 + gcc intrinsics (unless --disable-prof-gcc) 141 142--enable-prof-libunwind 143 Use the libunwind library (http://www.nongnu.org/libunwind/) for stack 144 backtracing. 145 146--disable-prof-libgcc 147 Disable the use of libgcc's backtracing functionality. 148 149--disable-prof-gcc 150 Disable the use of gcc intrinsics for backtracing. 151 152--with-static-libunwind=<libunwind.a> 153 Statically link against the specified libunwind.a rather than dynamically 154 linking with -lunwind. 155 156--disable-tcache 157 Disable thread-specific caches for small objects. Objects are cached and 158 released in bulk, thus reducing the total number of mutex operations. See 159 the "opt.tcache" option for usage details. 160 161--disable-munmap 162 Disable virtual memory deallocation via munmap(2); instead keep track of 163 the virtual memory for later use. munmap() is disabled by default (i.e. 164 --disable-munmap is implied) on Linux, which has a quirk in its virtual 165 memory allocation algorithm that causes semi-permanent VM map holes under 166 normal jemalloc operation. 167 168--disable-fill 169 Disable support for junk/zero filling of memory. See the "opt.junk" and 170 "opt.zero" option documentation for usage details. 171 172--disable-zone-allocator 173 Disable zone allocator for Darwin. This means jemalloc won't be hooked as 174 the default allocator on OSX/iOS. 175 176--enable-utrace 177 Enable utrace(2)-based allocation tracing. This feature is not broadly 178 portable (FreeBSD has it, but Linux and OS X do not). 179 180--enable-xmalloc 181 Enable support for optional immediate termination due to out-of-memory 182 errors, as is commonly implemented by "xmalloc" wrapper function for malloc. 183 See the "opt.xmalloc" option documentation for usage details. 184 185--enable-lazy-lock 186 Enable code that wraps pthread_create() to detect when an application 187 switches from single-threaded to multi-threaded mode, so that it can avoid 188 mutex locking/unlocking operations while in single-threaded mode. In 189 practice, this feature usually has little impact on performance unless 190 thread-specific caching is disabled. 191 192--disable-tls 193 Disable thread-local storage (TLS), which allows for fast access to 194 thread-local variables via the __thread keyword. If TLS is available, 195 jemalloc uses it for several purposes. 196 197--disable-cache-oblivious 198 Disable cache-oblivious large allocation alignment for large allocation 199 requests with no alignment constraints. If this feature is disabled, all 200 large allocations are page-aligned as an implementation artifact, which can 201 severely harm CPU cache utilization. However, the cache-oblivious layout 202 comes at the cost of one extra page per large allocation, which in the 203 most extreme case increases physical memory usage for the 16 KiB size class 204 to 20 KiB. 205 206--disable-syscall 207 Disable use of syscall(2) rather than {open,read,write,close}(2). This is 208 intended as a workaround for systems that place security limitations on 209 syscall(2). 210 211--disable-cxx 212 Disable C++ integration. This will cause new and delete operator 213 implementations to be omitted. 214 215--with-xslroot=<path> 216 Specify where to find DocBook XSL stylesheets when building the 217 documentation. 218 219--with-lg-page=<lg-page> 220 Specify the base 2 log of the system page size. This option is only useful 221 when cross compiling, since the configure script automatically determines 222 the host's page size by default. 223 224--with-lg-page-sizes=<lg-page-sizes> 225 Specify the comma-separated base 2 logs of the page sizes to support. This 226 option may be useful when cross-compiling in combination with 227 --with-lg-page, but its primary use case is for integration with FreeBSD's 228 libc, wherein jemalloc is embedded. 229 230--with-lg-hugepage=<lg-hugepage> 231 Specify the base 2 log of the system huge page size. This option is useful 232 when cross compiling, or when overriding the default for systems that do 233 not explicitly support huge pages. 234 235--with-lg-size-class-group=<lg-size-class-group> 236 Specify the base 2 log of how many size classes to use for each doubling in 237 size. By default jemalloc uses <lg-size-class-group>=2, which results in 238 e.g. the following size classes: 239 240 [...], 64, 241 80, 96, 112, 128, 242 160, [...] 243 244 <lg-size-class-group>=3 results in e.g. the following size classes: 245 246 [...], 64, 247 72, 80, 88, 96, 104, 112, 120, 128, 248 144, [...] 249 250 The minimal <lg-size-class-group>=0 causes jemalloc to only provide size 251 classes that are powers of 2: 252 253 [...], 254 64, 255 128, 256 256, 257 [...] 258 259 An implementation detail currently limits the total number of small size 260 classes to 255, and a compilation error will result if the 261 <lg-size-class-group> you specify cannot be supported. The limit is 262 roughly <lg-size-class-group>=4, depending on page size. 263 264--with-lg-quantum=<lg-quantum> 265 Specify the base 2 log of the minimum allocation alignment. jemalloc needs 266 to know the minimum alignment that meets the following C standard 267 requirement (quoted from the April 12, 2011 draft of the C11 standard): 268 269 The pointer returned if the allocation succeeds is suitably aligned so 270 that it may be assigned to a pointer to any type of object with a 271 fundamental alignment requirement and then used to access such an object 272 or an array of such objects in the space allocated [...] 273 274 This setting is architecture-specific, and although jemalloc includes known 275 safe values for the most commonly used modern architectures, there is a 276 wrinkle related to GNU libc (glibc) that may impact your choice of 277 <lg-quantum>. On most modern architectures, this mandates 16-byte alignment 278 (<lg-quantum>=4), but the glibc developers chose not to meet this 279 requirement for performance reasons. An old discussion can be found at 280 https://sourceware.org/bugzilla/show_bug.cgi?id=206 . Unlike glibc, 281 jemalloc does follow the C standard by default (caveat: jemalloc 282 technically cheats if --with-lg-tiny-min is smaller than 283 --with-lg-quantum), but the fact that Linux systems already work around 284 this allocator noncompliance means that it is generally safe in practice to 285 let jemalloc's minimum alignment follow glibc's lead. If you specify 286 --with-lg-quantum=3 during configuration, jemalloc will provide additional 287 size classes that are not 16-byte-aligned (24, 40, and 56, assuming 288 --with-lg-size-class-group=2). 289 290--with-lg-tiny-min=<lg-tiny-min> 291 Specify the base 2 log of the minimum tiny size class to support. Tiny 292 size classes are powers of 2 less than the quantum, and are only 293 incorporated if <lg-tiny-min> is less than <lg-quantum> (see 294 --with-lg-quantum). Tiny size classes technically violate the C standard 295 requirement for minimum alignment, and crashes could conceivably result if 296 the compiler were to generate instructions that made alignment assumptions, 297 both because illegal instruction traps could result, and because accesses 298 could straddle page boundaries and cause segmentation faults due to 299 accessing unmapped addresses. 300 301 The default of <lg-tiny-min>=3 works well in practice even on architectures 302 that technically require 16-byte alignment, probably for the same reason 303 --with-lg-quantum=3 works. Smaller tiny size classes can, and will, cause 304 crashes (see https://bugzilla.mozilla.org/show_bug.cgi?id=691003 for an 305 example). 306 307 This option is rarely useful, and is mainly provided as documentation of a 308 subtle implementation detail. If you do use this option, specify a 309 value in [3, ..., <lg-quantum>]. 310 311The following environment variables (not a definitive list) impact configure's 312behavior: 313 314CFLAGS="?" 315CXXFLAGS="?" 316 Pass these flags to the C/C++ compiler. Any flags set by the configure 317 script are prepended, which means explicitly set flags generally take 318 precedence. Take care when specifying flags such as -Werror, because 319 configure tests may be affected in undesirable ways. 320 321EXTRA_CFLAGS="?" 322EXTRA_CXXFLAGS="?" 323 Append these flags to CFLAGS/CXXFLAGS, without passing them to the 324 compiler(s) during configuration. This makes it possible to add flags such 325 as -Werror, while allowing the configure script to determine what other 326 flags are appropriate for the specified configuration. 327 328CPPFLAGS="?" 329 Pass these flags to the C preprocessor. Note that CFLAGS is not passed to 330 'cpp' when 'configure' is looking for include files, so you must use 331 CPPFLAGS instead if you need to help 'configure' find header files. 332 333LD_LIBRARY_PATH="?" 334 'ld' uses this colon-separated list to find libraries. 335 336LDFLAGS="?" 337 Pass these flags when linking. 338 339PATH="?" 340 'configure' uses this to find programs. 341 342In some cases it may be necessary to work around configuration results that do 343not match reality. For example, Linux 4.5 added support for the MADV_FREE flag 344to madvise(2), which can cause problems if building on a host with MADV_FREE 345support and deploying to a target without. To work around this, use a cache 346file to override the relevant configuration variable defined in configure.ac, 347e.g.: 348 349 echo "je_cv_madv_free=no" > config.cache && ./configure -C 350 351=== Advanced compilation ======================================================= 352 353To build only parts of jemalloc, use the following targets: 354 355 build_lib_shared 356 build_lib_static 357 build_lib 358 build_doc_html 359 build_doc_man 360 build_doc 361 362To install only parts of jemalloc, use the following targets: 363 364 install_bin 365 install_include 366 install_lib_shared 367 install_lib_static 368 install_lib 369 install_doc_html 370 install_doc_man 371 install_doc 372 373To clean up build results to varying degrees, use the following make targets: 374 375 clean 376 distclean 377 relclean 378 379=== Advanced installation ====================================================== 380 381Optionally, define make variables when invoking make, including (not 382exclusively): 383 384INCLUDEDIR="?" 385 Use this as the installation prefix for header files. 386 387LIBDIR="?" 388 Use this as the installation prefix for libraries. 389 390MANDIR="?" 391 Use this as the installation prefix for man pages. 392 393DESTDIR="?" 394 Prepend DESTDIR to INCLUDEDIR, LIBDIR, DATADIR, and MANDIR. This is useful 395 when installing to a different path than was specified via --prefix. 396 397CC="?" 398 Use this to invoke the C compiler. 399 400CFLAGS="?" 401 Pass these flags to the compiler. 402 403CPPFLAGS="?" 404 Pass these flags to the C preprocessor. 405 406LDFLAGS="?" 407 Pass these flags when linking. 408 409PATH="?" 410 Use this to search for programs used during configuration and building. 411 412=== Development ================================================================ 413 414If you intend to make non-trivial changes to jemalloc, use the 'autogen.sh' 415script rather than 'configure'. This re-generates 'configure', enables 416configuration dependency rules, and enables re-generation of automatically 417generated source files. 418 419The build system supports using an object directory separate from the source 420tree. For example, you can create an 'obj' directory, and from within that 421directory, issue configuration and build commands: 422 423 autoconf 424 mkdir obj 425 cd obj 426 ../configure --enable-autogen 427 make 428 429=== Documentation ============================================================== 430 431The manual page is generated in both html and roff formats. Any web browser 432can be used to view the html manual. The roff manual page can be formatted 433prior to installation via the following command: 434 435 nroff -man -t doc/jemalloc.3 436