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