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