blob: 5413ae86d7cd23cd02953ba1cee853923c06b443 [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
38--with-rpath=<colon-separated-rpath>
Jason Evans6c8b13b2009-12-29 00:09:15 -080039 Embed one or more library paths, so that libjemalloc can find the libraries
40 it is linked to. This works only on ELF-based systems.
Jason Evanscc00a152009-06-25 18:06:48 -070041
Jason Evans0a5489e2012-03-01 17:19:20 -080042--with-mangling=<map>
43 Mangle public symbols specified in <map> which is a comma-separated list of
44 name:mangled pairs.
45
46 For example, to use ld's --wrap option as an alternative method for
47 overriding libc's malloc implementation, specify something like:
48
49 --with-mangling=malloc:__wrap_malloc,free:__wrap_free[...]
50
51 Note that mangling happens prior to application of the prefix specified by
52 --with-jemalloc-prefix, and mangled symbols are then ignored when applying
53 the prefix.
54
Jason Evans90895cf2009-12-29 00:09:15 -080055--with-jemalloc-prefix=<prefix>
Jason Evanse7339702010-10-23 18:37:06 -070056 Prefix all public APIs with <prefix>. For example, if <prefix> is
Jason Evans2b769792010-12-16 14:13:46 -080057 "prefix_", API changes like the following occur:
Jason Evanse7339702010-10-23 18:37:06 -070058
59 malloc() --> prefix_malloc()
60 malloc_conf --> prefix_malloc_conf
61 /etc/malloc.conf --> /etc/prefix_malloc.conf
62 MALLOC_CONF --> PREFIX_MALLOC_CONF
63
Jason Evans379f8472010-10-24 16:18:29 -070064 This makes it possible to use jemalloc at the same time as the system
65 allocator, or even to use multiple copies of jemalloc simultaneously.
Jason Evans90895cf2009-12-29 00:09:15 -080066
Jason Evans2dbecf12010-09-05 10:35:13 -070067 By default, the prefix is "", except on OS X, where it is "je_". On OS X,
68 jemalloc overlays the default malloc zone, but makes no attempt to actually
69 replace the "malloc", "calloc", etc. symbols.
70
Mike Hommey99066602012-11-19 10:55:26 +010071--without-export
Jason Evansc21b05e2014-09-04 22:27:26 -070072 Don't export public APIs. This can be useful when building jemalloc as a
Mike Hommey99066602012-11-19 10:55:26 +010073 static library, or to avoid exporting public APIs when using the zone
74 allocator on OSX.
75
Jason Evans746e77a2011-07-30 16:40:52 -070076--with-private-namespace=<prefix>
Jason Evans86abd0d2013-11-30 15:25:42 -080077 Prefix all library-private APIs with <prefix>je_. For shared libraries,
Jason Evans746e77a2011-07-30 16:40:52 -070078 symbol visibility mechanisms prevent these symbols from being exported, but
79 for static libraries, naming collisions are a real possibility. By
Jason Evans86abd0d2013-11-30 15:25:42 -080080 default, <prefix> is empty, which results in a symbol prefix of je_ .
Jason Evans746e77a2011-07-30 16:40:52 -070081
Jason Evansb0fd5012010-01-17 01:49:20 -080082--with-install-suffix=<suffix>
83 Append <suffix> to the base name of all installed files, such that multiple
84 versions of jemalloc can coexist in the same installation directory. For
85 example, libjemalloc.so.0 becomes libjemalloc<suffix>.so.0.
86
Jason Evans644d4142014-04-14 22:49:23 -070087--disable-cc-silence
88 Disable code that silences non-useful compiler warnings. This is mainly
89 useful during development when auditing the set of warnings that are being
90 silenced.
Jason Evans355b4382010-09-20 19:20:48 -070091
Jason Evanscc00a152009-06-25 18:06:48 -070092--enable-debug
93 Enable assertions and validation code. This incurs a substantial
94 performance hit, but is very useful during application development.
Jason Evanse0a08a12015-03-18 21:06:58 -070095 Implies --enable-ivsalloc.
Mike Hommey5135e342012-12-06 22:16:26 +010096
Jason Evans748dfac2013-12-06 18:27:33 -080097--enable-code-coverage
98 Enable code coverage support, for use during jemalloc test development.
99 Additional testing targets are available if this option is enabled:
100
101 coverage
102 coverage_unit
103 coverage_integration
104 coverage_stress
105
106 These targets do not clear code coverage results from previous runs, and
107 there are interactions between the various coverage targets, so it is
108 usually advisable to run 'make clean' between repeated code coverage runs.
109
Jason Evansd073a322012-02-28 20:41:16 -0800110--disable-stats
111 Disable statistics gathering functionality. See the "opt.stats_print"
Jason Evans379f8472010-10-24 16:18:29 -0700112 option documentation for usage details.
Jason Evanscc00a152009-06-25 18:06:48 -0700113
Jason Evanse0a08a12015-03-18 21:06:58 -0700114--enable-ivsalloc
115 Enable validation code, which verifies that pointers reside within
116 jemalloc-owned chunks before dereferencing them. This incurs a minor
117 performance hit.
118
Jason Evans6109fe02010-02-10 10:37:56 -0800119--enable-prof
Jason Evans379f8472010-10-24 16:18:29 -0700120 Enable heap profiling and leak detection functionality. See the "opt.prof"
Jason Evans77f350b2011-03-15 22:23:12 -0700121 option documentation for usage details. When enabled, there are several
122 approaches to backtracing, and the configure script chooses the first one
123 in the following list that appears to function correctly:
Jason Evans6109fe02010-02-10 10:37:56 -0800124
Jason Evans77f350b2011-03-15 22:23:12 -0700125 + libunwind (requires --enable-prof-libunwind)
126 + libgcc (unless --disable-prof-libgcc)
127 + gcc intrinsics (unless --disable-prof-gcc)
Jason Evansb27805b2010-02-10 18:15:53 -0800128
Jason Evans6109fe02010-02-10 10:37:56 -0800129--enable-prof-libunwind
130 Use the libunwind library (http://www.nongnu.org/libunwind/) for stack
Jason Evans77f350b2011-03-15 22:23:12 -0700131 backtracing.
132
133--disable-prof-libgcc
134 Disable the use of libgcc's backtracing functionality.
135
136--disable-prof-gcc
137 Disable the use of gcc intrinsics for backtracing.
Jason Evans6109fe02010-02-10 10:37:56 -0800138
Jason Evansca6bd4f2010-03-02 14:12:58 -0800139--with-static-libunwind=<libunwind.a>
140 Statically link against the specified libunwind.a rather than dynamically
141 linking with -lunwind.
142
Jason Evans84cbbcb2009-12-29 00:09:15 -0800143--disable-tcache
Jason Evansdafde142010-03-17 16:27:39 -0700144 Disable thread-specific caches for small objects. Objects are cached and
Jason Evans379f8472010-10-24 16:18:29 -0700145 released in bulk, thus reducing the total number of mutex operations. See
Jason Evans2b769792010-12-16 14:13:46 -0800146 the "opt.tcache" option for usage details.
Jason Evanscc00a152009-06-25 18:06:48 -0700147
Jason Evans59ae2762012-04-16 17:52:27 -0700148--disable-munmap
149 Disable virtual memory deallocation via munmap(2); instead keep track of
150 the virtual memory for later use. munmap() is disabled by default (i.e.
151 --disable-munmap is implied) on Linux, which has a quirk in its virtual
152 memory allocation algorithm that causes semi-permanent VM map holes under
Jason Evansd059b9d2015-07-24 18:21:42 -0700153 normal jemalloc operation. Conversely, munmap() (actually VirtualFree()) is
154 forcefully enabled on MinGW because virtual memory mappings do not
155 automatically coalesce (nor fragment on demand), and extra bookkeeping
156 would be required to track mapping boundaries.
Jason Evans59ae2762012-04-16 17:52:27 -0700157
Jason Evans777c1912012-02-28 20:49:22 -0800158--disable-fill
Jason Evans122449b2012-04-06 00:35:09 -0700159 Disable support for junk/zero filling of memory, quarantine, and redzones.
160 See the "opt.junk", "opt.zero", "opt.quarantine", and "opt.redzone" option
161 documentation for usage details.
162
163--disable-valgrind
164 Disable support for Valgrind.
Jason Evanscc00a152009-06-25 18:06:48 -0700165
Mike Hommeyd0357f72012-11-26 18:52:41 +0100166--disable-zone-allocator
Jason Evansc21b05e2014-09-04 22:27:26 -0700167 Disable zone allocator for Darwin. This means jemalloc won't be hooked as
Mike Hommeyd0357f72012-11-26 18:52:41 +0100168 the default allocator on OSX/iOS.
169
Jason Evansb1476112012-04-05 13:36:17 -0700170--enable-utrace
171 Enable utrace(2)-based allocation tracing. This feature is not broadly
172 portable (FreeBSD has it, but Linux and OS X do not).
173
Jason Evanscc00a152009-06-25 18:06:48 -0700174--enable-xmalloc
175 Enable support for optional immediate termination due to out-of-memory
176 errors, as is commonly implemented by "xmalloc" wrapper function for malloc.
Jason Evans379f8472010-10-24 16:18:29 -0700177 See the "opt.xmalloc" option documentation for usage details.
Jason Evanscc00a152009-06-25 18:06:48 -0700178
Jason Evans0fee70d2012-02-13 12:36:11 -0800179--enable-lazy-lock
180 Enable code that wraps pthread_create() to detect when an application
Jason Evanscc00a152009-06-25 18:06:48 -0700181 switches from single-threaded to multi-threaded mode, so that it can avoid
182 mutex locking/unlocking operations while in single-threaded mode. In
183 practice, this feature usually has little impact on performance unless
Jason Evans84cbbcb2009-12-29 00:09:15 -0800184 thread-specific caching is disabled.
Jason Evanscc00a152009-06-25 18:06:48 -0700185
Jason Evans78d815c2010-01-17 14:06:20 -0800186--disable-tls
187 Disable thread-local storage (TLS), which allows for fast access to
188 thread-local variables via the __thread keyword. If TLS is available,
Jason Evansaee7fd22010-11-24 22:00:02 -0800189 jemalloc uses it for several purposes.
190
Jason Evans8a03cf02015-05-04 09:58:36 -0700191--disable-cache-oblivious
192 Disable cache-oblivious large allocation alignment for large allocation
193 requests with no alignment constraints. If this feature is disabled, all
194 large allocations are page-aligned as an implementation artifact, which can
195 severely harm CPU cache utilization. However, the cache-oblivious layout
196 comes at the cost of one extra page per large allocation, which in the
197 most extreme case increases physical memory usage for the 16 KiB size class
198 to 20 KiB.
199
Jason Evansaee7fd22010-11-24 22:00:02 -0800200--with-xslroot=<path>
201 Specify where to find DocBook XSL stylesheets when building the
202 documentation.
Jason Evans78d815c2010-01-17 14:06:20 -0800203
Jason Evansfc0b3b72014-10-09 17:54:06 -0700204--with-lg-page=<lg-page>
205 Specify the base 2 log of the system page size. This option is only useful
Jason Evansd1f3ab42014-10-14 22:31:49 -0700206 when cross compiling, since the configure script automatically determines
207 the host's page size by default.
Jason Evansfc0b3b72014-10-09 17:54:06 -0700208
209--with-lg-page-sizes=<lg-page-sizes>
210 Specify the comma-separated base 2 logs of the page sizes to support. This
211 option may be useful when cross-compiling in combination with
212 --with-lg-page, but its primary use case is for integration with FreeBSD's
213 libc, wherein jemalloc is embedded.
214
215--with-lg-size-class-group=<lg-size-class-group>
216 Specify the base 2 log of how many size classes to use for each doubling in
217 size. By default jemalloc uses <lg-size-class-group>=2, which results in
218 e.g. the following size classes:
219
220 [...], 64,
221 80, 96, 112, 128,
222 160, [...]
223
224 <lg-size-class-group>=3 results in e.g. the following size classes:
225
226 [...], 64,
227 72, 80, 88, 96, 104, 112, 120, 128,
228 144, [...]
229
230 The minimal <lg-size-class-group>=0 causes jemalloc to only provide size
231 classes that are powers of 2:
232
233 [...],
234 64,
235 128,
236 256,
237 [...]
238
239 An implementation detail currently limits the total number of small size
240 classes to 255, and a compilation error will result if the
241 <lg-size-class-group> you specify cannot be supported. The limit is
242 roughly <lg-size-class-group>=4, depending on page size.
243
244--with-lg-quantum=<lg-quantum>
Jason Evans81e54752014-10-10 22:34:25 -0700245 Specify the base 2 log of the minimum allocation alignment. jemalloc needs
246 to know the minimum alignment that meets the following C standard
247 requirement (quoted from the April 12, 2011 draft of the C11 standard):
Jason Evansfc0b3b72014-10-09 17:54:06 -0700248
249 The pointer returned if the allocation succeeds is suitably aligned so
250 that it may be assigned to a pointer to any type of object with a
251 fundamental alignment requirement and then used to access such an object
252 or an array of such objects in the space allocated [...]
253
254 This setting is architecture-specific, and although jemalloc includes known
255 safe values for the most commonly used modern architectures, there is a
256 wrinkle related to GNU libc (glibc) that may impact your choice of
257 <lg-quantum>. On most modern architectures, this mandates 16-byte alignment
Jason Evansd1f3ab42014-10-14 22:31:49 -0700258 (<lg-quantum>=4), but the glibc developers chose not to meet this
259 requirement for performance reasons. An old discussion can be found at
Jason Evansfc0b3b72014-10-09 17:54:06 -0700260 https://sourceware.org/bugzilla/show_bug.cgi?id=206 . Unlike glibc,
Jason Evans81e54752014-10-10 22:34:25 -0700261 jemalloc does follow the C standard by default (caveat: jemalloc
Jason Evansd1f3ab42014-10-14 22:31:49 -0700262 technically cheats if --with-lg-tiny-min is smaller than
263 --with-lg-quantum), but the fact that Linux systems already work around
264 this allocator noncompliance means that it is generally safe in practice to
265 let jemalloc's minimum alignment follow glibc's lead. If you specify
266 --with-lg-quantum=3 during configuration, jemalloc will provide additional
267 size classes that are not 16-byte-aligned (24, 40, and 56, assuming
Jason Evansfc0b3b72014-10-09 17:54:06 -0700268 --with-lg-size-class-group=2).
269
Jason Evans81e54752014-10-10 22:34:25 -0700270--with-lg-tiny-min=<lg-tiny-min>
271 Specify the base 2 log of the minimum tiny size class to support. Tiny
272 size classes are powers of 2 less than the quantum, and are only
273 incorporated if <lg-tiny-min> is less than <lg-quantum> (see
274 --with-lg-quantum). Tiny size classes technically violate the C standard
275 requirement for minimum alignment, and crashes could conceivably result if
276 the compiler were to generate instructions that made alignment assumptions,
277 both because illegal instruction traps could result, and because accesses
278 could straddle page boundaries and cause segmentation faults due to
279 accessing unmapped addresses.
280
281 The default of <lg-tiny-min>=3 works well in practice even on architectures
282 that technically require 16-byte alignment, probably for the same reason
283 --with-lg-quantum=3 works. Smaller tiny size classes can, and will, cause
284 crashes (see https://bugzilla.mozilla.org/show_bug.cgi?id=691003 for an
285 example).
286
287 This option is rarely useful, and is mainly provided as documentation of a
288 subtle implementation detail. If you do use this option, specify a
289 value in [3, ..., <lg-quantum>].
290
Jason Evanscc00a152009-06-25 18:06:48 -0700291The following environment variables (not a definitive list) impact configure's
292behavior:
293
294CFLAGS="?"
295 Pass these flags to the compiler. You probably shouldn't define this unless
296 you know what you are doing. (Use EXTRA_CFLAGS instead.)
297
298EXTRA_CFLAGS="?"
299 Append these flags to CFLAGS. This makes it possible to add flags such as
300 -Werror, while allowing the configure script to determine what other flags
301 are appropriate for the specified configuration.
302
303 The configure script specifically checks whether an optimization flag (-O*)
304 is specified in EXTRA_CFLAGS, and refrains from specifying an optimization
305 level if it finds that one has already been specified.
306
307CPPFLAGS="?"
308 Pass these flags to the C preprocessor. Note that CFLAGS is not passed to
309 'cpp' when 'configure' is looking for include files, so you must use
310 CPPFLAGS instead if you need to help 'configure' find header files.
311
312LD_LIBRARY_PATH="?"
313 'ld' uses this colon-separated list to find libraries.
314
315LDFLAGS="?"
316 Pass these flags when linking.
317
318PATH="?"
319 'configure' uses this to find programs.
320
321=== Advanced compilation =======================================================
322
Jason Evans7b398ac2012-03-02 16:38:37 -0800323To build only parts of jemalloc, use the following targets:
324
325 build_lib_shared
326 build_lib_static
327 build_lib
328 build_doc_html
329 build_doc_man
330 build_doc
331
Jason Evanscfeccd32010-03-03 15:48:20 -0800332To install only parts of jemalloc, use the following targets:
Jason Evanscc00a152009-06-25 18:06:48 -0700333
Jason Evans55233992010-04-11 19:02:43 -0700334 install_bin
Jason Evanscfeccd32010-03-03 15:48:20 -0800335 install_include
Jason Evans7b398ac2012-03-02 16:38:37 -0800336 install_lib_shared
337 install_lib_static
Jason Evanscfeccd32010-03-03 15:48:20 -0800338 install_lib
Jason Evans7b398ac2012-03-02 16:38:37 -0800339 install_doc_html
340 install_doc_man
Jason Evansaee7fd22010-11-24 22:00:02 -0800341 install_doc
Jason Evanscc00a152009-06-25 18:06:48 -0700342
343To clean up build results to varying degrees, use the following make targets:
344
345 clean
346 distclean
347 relclean
348
349=== Advanced installation ======================================================
350
351Optionally, define make variables when invoking make, including (not
352exclusively):
353
354INCLUDEDIR="?"
355 Use this as the installation prefix for header files.
356
357LIBDIR="?"
358 Use this as the installation prefix for libraries.
359
360MANDIR="?"
361 Use this as the installation prefix for man pages.
362
Jason Evanscfeccd32010-03-03 15:48:20 -0800363DESTDIR="?"
Jason Evans2b769792010-12-16 14:13:46 -0800364 Prepend DESTDIR to INCLUDEDIR, LIBDIR, DATADIR, and MANDIR. This is useful
365 when installing to a different path than was specified via --prefix.
Jason Evanscfeccd32010-03-03 15:48:20 -0800366
Jason Evanscc00a152009-06-25 18:06:48 -0700367CC="?"
368 Use this to invoke the C compiler.
369
370CFLAGS="?"
371 Pass these flags to the compiler.
372
373CPPFLAGS="?"
374 Pass these flags to the C preprocessor.
375
376LDFLAGS="?"
377 Pass these flags when linking.
378
379PATH="?"
380 Use this to search for programs used during configuration and building.
381
382=== Development ================================================================
383
384If you intend to make non-trivial changes to jemalloc, use the 'autogen.sh'
385script rather than 'configure'. This re-generates 'configure', enables
386configuration dependency rules, and enables re-generation of automatically
387generated source files.
388
389The build system supports using an object directory separate from the source
390tree. For example, you can create an 'obj' directory, and from within that
391directory, issue configuration and build commands:
392
393 autoconf
394 mkdir obj
395 cd obj
396 ../configure --enable-autogen
397 make
Jason Evans7e11b382010-09-11 22:47:39 -0700398
399=== Documentation ==============================================================
400
Jason Evansaee7fd22010-11-24 22:00:02 -0800401The manual page is generated in both html and roff formats. Any web browser
402can be used to view the html manual. The roff manual page can be formatted
Jason Evans079687b2012-04-23 12:49:23 -0700403prior to installation via the following command:
Jason Evans7e11b382010-09-11 22:47:39 -0700404
Jason Evansaee7fd22010-11-24 22:00:02 -0800405 nroff -man -t doc/jemalloc.3