blob: 68787165352ead3c8209b97f6f6dd02a886d40a4 [file] [log] [blame]
Jason Evanseb5376a2014-09-23 09:21:49 -07001Building and installing a packaged release of jemalloc can be as simple as
2typing the following while in the root directory of the source tree:
Jason Evanscc00a152009-06-25 18:06:48 -07003
4 ./configure
5 make
6 make install
7
Jason Evanseb5376a2014-09-23 09:21:49 -07008If 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
Jason Evanscc00a152009-06-25 18:06:48 -070021=== 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
Jason Evans434ea642016-03-14 20:19:11 -070038--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
Jason Evanscc00a152009-06-25 18:06:48 -070042--with-rpath=<colon-separated-rpath>
Jason Evans6c8b13b2009-12-29 00:09:15 -080043 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.
Jason Evanscc00a152009-06-25 18:06:48 -070045
Jason Evans0a5489e2012-03-01 17:19:20 -080046--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
Jason Evans90895cf2009-12-29 00:09:15 -080059--with-jemalloc-prefix=<prefix>
Jason Evanse7339702010-10-23 18:37:06 -070060 Prefix all public APIs with <prefix>. For example, if <prefix> is
Jason Evans2b769792010-12-16 14:13:46 -080061 "prefix_", API changes like the following occur:
Jason Evanse7339702010-10-23 18:37:06 -070062
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
Jason Evans379f8472010-10-24 16:18:29 -070068 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.
Jason Evans90895cf2009-12-29 00:09:15 -080070
Jason Evans2dbecf12010-09-05 10:35:13 -070071 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
Mike Hommey99066602012-11-19 10:55:26 +010075--without-export
Jason Evansc21b05e2014-09-04 22:27:26 -070076 Don't export public APIs. This can be useful when building jemalloc as a
Mike Hommey99066602012-11-19 10:55:26 +010077 static library, or to avoid exporting public APIs when using the zone
78 allocator on OSX.
79
Jason Evans746e77a2011-07-30 16:40:52 -070080--with-private-namespace=<prefix>
Jason Evans86abd0d2013-11-30 15:25:42 -080081 Prefix all library-private APIs with <prefix>je_. For shared libraries,
Jason Evans746e77a2011-07-30 16:40:52 -070082 symbol visibility mechanisms prevent these symbols from being exported, but
83 for static libraries, naming collisions are a real possibility. By
Jason Evans86abd0d2013-11-30 15:25:42 -080084 default, <prefix> is empty, which results in a symbol prefix of je_ .
Jason Evans746e77a2011-07-30 16:40:52 -070085
Jason Evansb0fd5012010-01-17 01:49:20 -080086--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
Jason Evansf8290092016-02-07 14:23:22 -080091--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 chunk
95 size to 256 KiB:
96
97 --with-malloc-conf=lg_chunk:18
98
Jason Evans644d4142014-04-14 22:49:23 -070099--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.
Jason Evans355b4382010-09-20 19:20:48 -0700103
Jason Evanscc00a152009-06-25 18:06:48 -0700104--enable-debug
105 Enable assertions and validation code. This incurs a substantial
106 performance hit, but is very useful during application development.
Jason Evanse0a08a12015-03-18 21:06:58 -0700107 Implies --enable-ivsalloc.
Mike Hommey5135e342012-12-06 22:16:26 +0100108
Jason Evans748dfac2013-12-06 18:27:33 -0800109--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
Jason Evansd073a322012-02-28 20:41:16 -0800122--disable-stats
123 Disable statistics gathering functionality. See the "opt.stats_print"
Jason Evans379f8472010-10-24 16:18:29 -0700124 option documentation for usage details.
Jason Evanscc00a152009-06-25 18:06:48 -0700125
Jason Evanse0a08a12015-03-18 21:06:58 -0700126--enable-ivsalloc
127 Enable validation code, which verifies that pointers reside within
128 jemalloc-owned chunks before dereferencing them. This incurs a minor
129 performance hit.
130
Jason Evans6109fe02010-02-10 10:37:56 -0800131--enable-prof
Jason Evans379f8472010-10-24 16:18:29 -0700132 Enable heap profiling and leak detection functionality. See the "opt.prof"
Jason Evans77f350b2011-03-15 22:23:12 -0700133 option documentation for usage details. When enabled, there are several
134 approaches to backtracing, and the configure script chooses the first one
135 in the following list that appears to function correctly:
Jason Evans6109fe02010-02-10 10:37:56 -0800136
Jason Evans77f350b2011-03-15 22:23:12 -0700137 + libunwind (requires --enable-prof-libunwind)
138 + libgcc (unless --disable-prof-libgcc)
139 + gcc intrinsics (unless --disable-prof-gcc)
Jason Evansb27805b2010-02-10 18:15:53 -0800140
Jason Evans6109fe02010-02-10 10:37:56 -0800141--enable-prof-libunwind
142 Use the libunwind library (http://www.nongnu.org/libunwind/) for stack
Jason Evans77f350b2011-03-15 22:23:12 -0700143 backtracing.
144
145--disable-prof-libgcc
146 Disable the use of libgcc's backtracing functionality.
147
148--disable-prof-gcc
149 Disable the use of gcc intrinsics for backtracing.
Jason Evans6109fe02010-02-10 10:37:56 -0800150
Jason Evansca6bd4f2010-03-02 14:12:58 -0800151--with-static-libunwind=<libunwind.a>
152 Statically link against the specified libunwind.a rather than dynamically
153 linking with -lunwind.
154
Jason Evans84cbbcb2009-12-29 00:09:15 -0800155--disable-tcache
Jason Evansdafde142010-03-17 16:27:39 -0700156 Disable thread-specific caches for small objects. Objects are cached and
Jason Evans379f8472010-10-24 16:18:29 -0700157 released in bulk, thus reducing the total number of mutex operations. See
Jason Evans2b769792010-12-16 14:13:46 -0800158 the "opt.tcache" option for usage details.
Jason Evanscc00a152009-06-25 18:06:48 -0700159
Jason Evans59ae2762012-04-16 17:52:27 -0700160--disable-munmap
161 Disable virtual memory deallocation via munmap(2); instead keep track of
162 the virtual memory for later use. munmap() is disabled by default (i.e.
163 --disable-munmap is implied) on Linux, which has a quirk in its virtual
164 memory allocation algorithm that causes semi-permanent VM map holes under
Jason Evans2662ba52015-08-12 11:10:42 -0700165 normal jemalloc operation.
Jason Evans59ae2762012-04-16 17:52:27 -0700166
Jason Evans777c1912012-02-28 20:49:22 -0800167--disable-fill
Jason Evans122449b2012-04-06 00:35:09 -0700168 Disable support for junk/zero filling of memory, quarantine, and redzones.
169 See the "opt.junk", "opt.zero", "opt.quarantine", and "opt.redzone" option
170 documentation for usage details.
171
172--disable-valgrind
173 Disable support for Valgrind.
Jason Evanscc00a152009-06-25 18:06:48 -0700174
Mike Hommeyd0357f72012-11-26 18:52:41 +0100175--disable-zone-allocator
Jason Evansc21b05e2014-09-04 22:27:26 -0700176 Disable zone allocator for Darwin. This means jemalloc won't be hooked as
Mike Hommeyd0357f72012-11-26 18:52:41 +0100177 the default allocator on OSX/iOS.
178
Jason Evansb1476112012-04-05 13:36:17 -0700179--enable-utrace
180 Enable utrace(2)-based allocation tracing. This feature is not broadly
181 portable (FreeBSD has it, but Linux and OS X do not).
182
Jason Evanscc00a152009-06-25 18:06:48 -0700183--enable-xmalloc
184 Enable support for optional immediate termination due to out-of-memory
185 errors, as is commonly implemented by "xmalloc" wrapper function for malloc.
Jason Evans379f8472010-10-24 16:18:29 -0700186 See the "opt.xmalloc" option documentation for usage details.
Jason Evanscc00a152009-06-25 18:06:48 -0700187
Jason Evans0fee70d2012-02-13 12:36:11 -0800188--enable-lazy-lock
189 Enable code that wraps pthread_create() to detect when an application
Jason Evanscc00a152009-06-25 18:06:48 -0700190 switches from single-threaded to multi-threaded mode, so that it can avoid
191 mutex locking/unlocking operations while in single-threaded mode. In
192 practice, this feature usually has little impact on performance unless
Jason Evans84cbbcb2009-12-29 00:09:15 -0800193 thread-specific caching is disabled.
Jason Evanscc00a152009-06-25 18:06:48 -0700194
Jason Evans78d815c2010-01-17 14:06:20 -0800195--disable-tls
196 Disable thread-local storage (TLS), which allows for fast access to
197 thread-local variables via the __thread keyword. If TLS is available,
Jason Evansaee7fd22010-11-24 22:00:02 -0800198 jemalloc uses it for several purposes.
199
Jason Evans8a03cf02015-05-04 09:58:36 -0700200--disable-cache-oblivious
201 Disable cache-oblivious large allocation alignment for large allocation
202 requests with no alignment constraints. If this feature is disabled, all
203 large allocations are page-aligned as an implementation artifact, which can
204 severely harm CPU cache utilization. However, the cache-oblivious layout
205 comes at the cost of one extra page per large allocation, which in the
206 most extreme case increases physical memory usage for the 16 KiB size class
207 to 20 KiB.
208
Jason Evansaee7fd22010-11-24 22:00:02 -0800209--with-xslroot=<path>
210 Specify where to find DocBook XSL stylesheets when building the
211 documentation.
Jason Evans78d815c2010-01-17 14:06:20 -0800212
Jason Evansfc0b3b72014-10-09 17:54:06 -0700213--with-lg-page=<lg-page>
214 Specify the base 2 log of the system page size. This option is only useful
Jason Evansd1f3ab42014-10-14 22:31:49 -0700215 when cross compiling, since the configure script automatically determines
216 the host's page size by default.
Jason Evansfc0b3b72014-10-09 17:54:06 -0700217
218--with-lg-page-sizes=<lg-page-sizes>
219 Specify the comma-separated base 2 logs of the page sizes to support. This
220 option may be useful when cross-compiling in combination with
221 --with-lg-page, but its primary use case is for integration with FreeBSD's
222 libc, wherein jemalloc is embedded.
223
224--with-lg-size-class-group=<lg-size-class-group>
225 Specify the base 2 log of how many size classes to use for each doubling in
226 size. By default jemalloc uses <lg-size-class-group>=2, which results in
227 e.g. the following size classes:
228
229 [...], 64,
230 80, 96, 112, 128,
231 160, [...]
232
233 <lg-size-class-group>=3 results in e.g. the following size classes:
234
235 [...], 64,
236 72, 80, 88, 96, 104, 112, 120, 128,
237 144, [...]
238
239 The minimal <lg-size-class-group>=0 causes jemalloc to only provide size
240 classes that are powers of 2:
241
242 [...],
243 64,
244 128,
245 256,
246 [...]
247
248 An implementation detail currently limits the total number of small size
249 classes to 255, and a compilation error will result if the
250 <lg-size-class-group> you specify cannot be supported. The limit is
251 roughly <lg-size-class-group>=4, depending on page size.
252
253--with-lg-quantum=<lg-quantum>
Jason Evans81e54752014-10-10 22:34:25 -0700254 Specify the base 2 log of the minimum allocation alignment. jemalloc needs
255 to know the minimum alignment that meets the following C standard
256 requirement (quoted from the April 12, 2011 draft of the C11 standard):
Jason Evansfc0b3b72014-10-09 17:54:06 -0700257
258 The pointer returned if the allocation succeeds is suitably aligned so
259 that it may be assigned to a pointer to any type of object with a
260 fundamental alignment requirement and then used to access such an object
261 or an array of such objects in the space allocated [...]
262
263 This setting is architecture-specific, and although jemalloc includes known
264 safe values for the most commonly used modern architectures, there is a
265 wrinkle related to GNU libc (glibc) that may impact your choice of
266 <lg-quantum>. On most modern architectures, this mandates 16-byte alignment
Jason Evansd1f3ab42014-10-14 22:31:49 -0700267 (<lg-quantum>=4), but the glibc developers chose not to meet this
268 requirement for performance reasons. An old discussion can be found at
Jason Evansfc0b3b72014-10-09 17:54:06 -0700269 https://sourceware.org/bugzilla/show_bug.cgi?id=206 . Unlike glibc,
Jason Evans81e54752014-10-10 22:34:25 -0700270 jemalloc does follow the C standard by default (caveat: jemalloc
Jason Evansd1f3ab42014-10-14 22:31:49 -0700271 technically cheats if --with-lg-tiny-min is smaller than
272 --with-lg-quantum), but the fact that Linux systems already work around
273 this allocator noncompliance means that it is generally safe in practice to
274 let jemalloc's minimum alignment follow glibc's lead. If you specify
275 --with-lg-quantum=3 during configuration, jemalloc will provide additional
276 size classes that are not 16-byte-aligned (24, 40, and 56, assuming
Jason Evansfc0b3b72014-10-09 17:54:06 -0700277 --with-lg-size-class-group=2).
278
Jason Evans81e54752014-10-10 22:34:25 -0700279--with-lg-tiny-min=<lg-tiny-min>
280 Specify the base 2 log of the minimum tiny size class to support. Tiny
281 size classes are powers of 2 less than the quantum, and are only
282 incorporated if <lg-tiny-min> is less than <lg-quantum> (see
283 --with-lg-quantum). Tiny size classes technically violate the C standard
284 requirement for minimum alignment, and crashes could conceivably result if
285 the compiler were to generate instructions that made alignment assumptions,
286 both because illegal instruction traps could result, and because accesses
287 could straddle page boundaries and cause segmentation faults due to
288 accessing unmapped addresses.
289
290 The default of <lg-tiny-min>=3 works well in practice even on architectures
291 that technically require 16-byte alignment, probably for the same reason
292 --with-lg-quantum=3 works. Smaller tiny size classes can, and will, cause
293 crashes (see https://bugzilla.mozilla.org/show_bug.cgi?id=691003 for an
294 example).
295
296 This option is rarely useful, and is mainly provided as documentation of a
297 subtle implementation detail. If you do use this option, specify a
298 value in [3, ..., <lg-quantum>].
299
Jason Evanscc00a152009-06-25 18:06:48 -0700300The following environment variables (not a definitive list) impact configure's
301behavior:
302
303CFLAGS="?"
304 Pass these flags to the compiler. You probably shouldn't define this unless
305 you know what you are doing. (Use EXTRA_CFLAGS instead.)
306
307EXTRA_CFLAGS="?"
308 Append these flags to CFLAGS. This makes it possible to add flags such as
309 -Werror, while allowing the configure script to determine what other flags
310 are appropriate for the specified configuration.
311
312 The configure script specifically checks whether an optimization flag (-O*)
313 is specified in EXTRA_CFLAGS, and refrains from specifying an optimization
314 level if it finds that one has already been specified.
315
316CPPFLAGS="?"
317 Pass these flags to the C preprocessor. Note that CFLAGS is not passed to
318 'cpp' when 'configure' is looking for include files, so you must use
319 CPPFLAGS instead if you need to help 'configure' find header files.
320
321LD_LIBRARY_PATH="?"
322 'ld' uses this colon-separated list to find libraries.
323
324LDFLAGS="?"
325 Pass these flags when linking.
326
327PATH="?"
328 'configure' uses this to find programs.
329
330=== Advanced compilation =======================================================
331
Jason Evans7b398ac2012-03-02 16:38:37 -0800332To build only parts of jemalloc, use the following targets:
333
334 build_lib_shared
335 build_lib_static
336 build_lib
337 build_doc_html
338 build_doc_man
339 build_doc
340
Jason Evanscfeccd32010-03-03 15:48:20 -0800341To install only parts of jemalloc, use the following targets:
Jason Evanscc00a152009-06-25 18:06:48 -0700342
Jason Evans55233992010-04-11 19:02:43 -0700343 install_bin
Jason Evanscfeccd32010-03-03 15:48:20 -0800344 install_include
Jason Evans7b398ac2012-03-02 16:38:37 -0800345 install_lib_shared
346 install_lib_static
Jason Evanscfeccd32010-03-03 15:48:20 -0800347 install_lib
Jason Evans7b398ac2012-03-02 16:38:37 -0800348 install_doc_html
349 install_doc_man
Jason Evansaee7fd22010-11-24 22:00:02 -0800350 install_doc
Jason Evanscc00a152009-06-25 18:06:48 -0700351
352To clean up build results to varying degrees, use the following make targets:
353
354 clean
355 distclean
356 relclean
357
358=== Advanced installation ======================================================
359
360Optionally, define make variables when invoking make, including (not
361exclusively):
362
363INCLUDEDIR="?"
364 Use this as the installation prefix for header files.
365
366LIBDIR="?"
367 Use this as the installation prefix for libraries.
368
369MANDIR="?"
370 Use this as the installation prefix for man pages.
371
Jason Evanscfeccd32010-03-03 15:48:20 -0800372DESTDIR="?"
Jason Evans2b769792010-12-16 14:13:46 -0800373 Prepend DESTDIR to INCLUDEDIR, LIBDIR, DATADIR, and MANDIR. This is useful
374 when installing to a different path than was specified via --prefix.
Jason Evanscfeccd32010-03-03 15:48:20 -0800375
Jason Evanscc00a152009-06-25 18:06:48 -0700376CC="?"
377 Use this to invoke the C compiler.
378
379CFLAGS="?"
380 Pass these flags to the compiler.
381
382CPPFLAGS="?"
383 Pass these flags to the C preprocessor.
384
385LDFLAGS="?"
386 Pass these flags when linking.
387
388PATH="?"
389 Use this to search for programs used during configuration and building.
390
391=== Development ================================================================
392
393If you intend to make non-trivial changes to jemalloc, use the 'autogen.sh'
394script rather than 'configure'. This re-generates 'configure', enables
395configuration dependency rules, and enables re-generation of automatically
396generated source files.
397
398The build system supports using an object directory separate from the source
399tree. For example, you can create an 'obj' directory, and from within that
400directory, issue configuration and build commands:
401
402 autoconf
403 mkdir obj
404 cd obj
405 ../configure --enable-autogen
406 make
Jason Evans7e11b382010-09-11 22:47:39 -0700407
408=== Documentation ==============================================================
409
Jason Evansaee7fd22010-11-24 22:00:02 -0800410The manual page is generated in both html and roff formats. Any web browser
411can be used to view the html manual. The roff manual page can be formatted
Jason Evans079687b2012-04-23 12:49:23 -0700412prior to installation via the following command:
Jason Evans7e11b382010-09-11 22:47:39 -0700413
Jason Evansaee7fd22010-11-24 22:00:02 -0800414 nroff -man -t doc/jemalloc.3