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