]> git.proxmox.com Git - rustc.git/blame - src/jemalloc/doc/jemalloc.xml.in
New upstream version 1.22.1+dfsg1
[rustc.git] / src / jemalloc / doc / jemalloc.xml.in
CommitLineData
970d7e83
LB
1<?xml version='1.0' encoding='UTF-8'?>
2<?xml-stylesheet type="text/xsl"
3 href="http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl"?>
4<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
5 "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
6]>
7
8<refentry>
9 <refentryinfo>
10 <title>User Manual</title>
11 <productname>jemalloc</productname>
12 <releaseinfo role="version">@jemalloc_version@</releaseinfo>
13 <authorgroup>
14 <author>
15 <firstname>Jason</firstname>
16 <surname>Evans</surname>
17 <personblurb>Author</personblurb>
18 </author>
19 </authorgroup>
20 </refentryinfo>
21 <refmeta>
22 <refentrytitle>JEMALLOC</refentrytitle>
23 <manvolnum>3</manvolnum>
24 </refmeta>
25 <refnamediv>
26 <refdescriptor>jemalloc</refdescriptor>
27 <refname>jemalloc</refname>
28 <!-- Each refname causes a man page file to be created. Only if this were
29 the system malloc(3) implementation would these files be appropriate.
30 <refname>malloc</refname>
31 <refname>calloc</refname>
32 <refname>posix_memalign</refname>
33 <refname>aligned_alloc</refname>
34 <refname>realloc</refname>
35 <refname>free</refname>
1a4d82fc
JJ
36 <refname>mallocx</refname>
37 <refname>rallocx</refname>
38 <refname>xallocx</refname>
39 <refname>sallocx</refname>
40 <refname>dallocx</refname>
41 <refname>sdallocx</refname>
42 <refname>nallocx</refname>
970d7e83
LB
43 <refname>mallctl</refname>
44 <refname>mallctlnametomib</refname>
45 <refname>mallctlbymib</refname>
1a4d82fc
JJ
46 <refname>malloc_stats_print</refname>
47 <refname>malloc_usable_size</refname>
970d7e83
LB
48 -->
49 <refpurpose>general purpose memory allocation functions</refpurpose>
50 </refnamediv>
51 <refsect1 id="library">
52 <title>LIBRARY</title>
53 <para>This manual describes jemalloc @jemalloc_version@. More information
54 can be found at the <ulink
3b2f2976 55 url="http://jemalloc.net/">jemalloc website</ulink>.</para>
970d7e83
LB
56 </refsect1>
57 <refsynopsisdiv>
58 <title>SYNOPSIS</title>
59 <funcsynopsis>
1a4d82fc 60 <funcsynopsisinfo>#include &lt;<filename class="headerfile">jemalloc/jemalloc.h</filename>&gt;</funcsynopsisinfo>
970d7e83
LB
61 <refsect2>
62 <title>Standard API</title>
63 <funcprototype>
64 <funcdef>void *<function>malloc</function></funcdef>
65 <paramdef>size_t <parameter>size</parameter></paramdef>
66 </funcprototype>
67 <funcprototype>
68 <funcdef>void *<function>calloc</function></funcdef>
69 <paramdef>size_t <parameter>number</parameter></paramdef>
70 <paramdef>size_t <parameter>size</parameter></paramdef>
71 </funcprototype>
72 <funcprototype>
73 <funcdef>int <function>posix_memalign</function></funcdef>
74 <paramdef>void **<parameter>ptr</parameter></paramdef>
75 <paramdef>size_t <parameter>alignment</parameter></paramdef>
76 <paramdef>size_t <parameter>size</parameter></paramdef>
77 </funcprototype>
78 <funcprototype>
79 <funcdef>void *<function>aligned_alloc</function></funcdef>
80 <paramdef>size_t <parameter>alignment</parameter></paramdef>
81 <paramdef>size_t <parameter>size</parameter></paramdef>
82 </funcprototype>
83 <funcprototype>
84 <funcdef>void *<function>realloc</function></funcdef>
85 <paramdef>void *<parameter>ptr</parameter></paramdef>
86 <paramdef>size_t <parameter>size</parameter></paramdef>
87 </funcprototype>
88 <funcprototype>
89 <funcdef>void <function>free</function></funcdef>
90 <paramdef>void *<parameter>ptr</parameter></paramdef>
91 </funcprototype>
92 </refsect2>
93 <refsect2>
94 <title>Non-standard API</title>
95 <funcprototype>
1a4d82fc
JJ
96 <funcdef>void *<function>mallocx</function></funcdef>
97 <paramdef>size_t <parameter>size</parameter></paramdef>
98 <paramdef>int <parameter>flags</parameter></paramdef>
970d7e83
LB
99 </funcprototype>
100 <funcprototype>
1a4d82fc
JJ
101 <funcdef>void *<function>rallocx</function></funcdef>
102 <paramdef>void *<parameter>ptr</parameter></paramdef>
103 <paramdef>size_t <parameter>size</parameter></paramdef>
104 <paramdef>int <parameter>flags</parameter></paramdef>
105 </funcprototype>
106 <funcprototype>
107 <funcdef>size_t <function>xallocx</function></funcdef>
108 <paramdef>void *<parameter>ptr</parameter></paramdef>
109 <paramdef>size_t <parameter>size</parameter></paramdef>
110 <paramdef>size_t <parameter>extra</parameter></paramdef>
111 <paramdef>int <parameter>flags</parameter></paramdef>
112 </funcprototype>
113 <funcprototype>
114 <funcdef>size_t <function>sallocx</function></funcdef>
115 <paramdef>void *<parameter>ptr</parameter></paramdef>
116 <paramdef>int <parameter>flags</parameter></paramdef>
117 </funcprototype>
118 <funcprototype>
119 <funcdef>void <function>dallocx</function></funcdef>
120 <paramdef>void *<parameter>ptr</parameter></paramdef>
121 <paramdef>int <parameter>flags</parameter></paramdef>
122 </funcprototype>
123 <funcprototype>
124 <funcdef>void <function>sdallocx</function></funcdef>
125 <paramdef>void *<parameter>ptr</parameter></paramdef>
126 <paramdef>size_t <parameter>size</parameter></paramdef>
127 <paramdef>int <parameter>flags</parameter></paramdef>
128 </funcprototype>
129 <funcprototype>
130 <funcdef>size_t <function>nallocx</function></funcdef>
131 <paramdef>size_t <parameter>size</parameter></paramdef>
132 <paramdef>int <parameter>flags</parameter></paramdef>
970d7e83
LB
133 </funcprototype>
134 <funcprototype>
135 <funcdef>int <function>mallctl</function></funcdef>
136 <paramdef>const char *<parameter>name</parameter></paramdef>
137 <paramdef>void *<parameter>oldp</parameter></paramdef>
138 <paramdef>size_t *<parameter>oldlenp</parameter></paramdef>
139 <paramdef>void *<parameter>newp</parameter></paramdef>
140 <paramdef>size_t <parameter>newlen</parameter></paramdef>
141 </funcprototype>
142 <funcprototype>
143 <funcdef>int <function>mallctlnametomib</function></funcdef>
144 <paramdef>const char *<parameter>name</parameter></paramdef>
145 <paramdef>size_t *<parameter>mibp</parameter></paramdef>
146 <paramdef>size_t *<parameter>miblenp</parameter></paramdef>
147 </funcprototype>
148 <funcprototype>
149 <funcdef>int <function>mallctlbymib</function></funcdef>
150 <paramdef>const size_t *<parameter>mib</parameter></paramdef>
151 <paramdef>size_t <parameter>miblen</parameter></paramdef>
152 <paramdef>void *<parameter>oldp</parameter></paramdef>
153 <paramdef>size_t *<parameter>oldlenp</parameter></paramdef>
154 <paramdef>void *<parameter>newp</parameter></paramdef>
155 <paramdef>size_t <parameter>newlen</parameter></paramdef>
156 </funcprototype>
157 <funcprototype>
1a4d82fc
JJ
158 <funcdef>void <function>malloc_stats_print</function></funcdef>
159 <paramdef>void <parameter>(*write_cb)</parameter>
160 <funcparams>void *, const char *</funcparams>
161 </paramdef>
970d7e83 162 <paramdef>void *<parameter>cbopaque</parameter></paramdef>
1a4d82fc 163 <paramdef>const char *<parameter>opts</parameter></paramdef>
970d7e83
LB
164 </funcprototype>
165 <funcprototype>
1a4d82fc 166 <funcdef>size_t <function>malloc_usable_size</function></funcdef>
970d7e83 167 <paramdef>const void *<parameter>ptr</parameter></paramdef>
970d7e83
LB
168 </funcprototype>
169 <funcprototype>
1a4d82fc
JJ
170 <funcdef>void <function>(*malloc_message)</function></funcdef>
171 <paramdef>void *<parameter>cbopaque</parameter></paramdef>
172 <paramdef>const char *<parameter>s</parameter></paramdef>
970d7e83 173 </funcprototype>
1a4d82fc 174 <para><type>const char *</type><varname>malloc_conf</varname>;</para>
970d7e83
LB
175 </refsect2>
176 </funcsynopsis>
177 </refsynopsisdiv>
178 <refsect1 id="description">
179 <title>DESCRIPTION</title>
180 <refsect2>
181 <title>Standard API</title>
182
3b2f2976 183 <para>The <function>malloc()</function> function allocates
970d7e83
LB
184 <parameter>size</parameter> bytes of uninitialized memory. The allocated
185 space is suitably aligned (after possible pointer coercion) for storage
186 of any type of object.</para>
187
3b2f2976 188 <para>The <function>calloc()</function> function allocates
970d7e83
LB
189 space for <parameter>number</parameter> objects, each
190 <parameter>size</parameter> bytes in length. The result is identical to
3b2f2976 191 calling <function>malloc()</function> with an argument of
970d7e83
LB
192 <parameter>number</parameter> * <parameter>size</parameter>, with the
193 exception that the allocated memory is explicitly initialized to zero
194 bytes.</para>
195
3b2f2976 196 <para>The <function>posix_memalign()</function> function
970d7e83 197 allocates <parameter>size</parameter> bytes of memory such that the
1a4d82fc 198 allocation's base address is a multiple of
970d7e83
LB
199 <parameter>alignment</parameter>, and returns the allocation in the value
200 pointed to by <parameter>ptr</parameter>. The requested
1a4d82fc
JJ
201 <parameter>alignment</parameter> must be a power of 2 at least as large as
202 <code language="C">sizeof(<type>void *</type>)</code>.</para>
970d7e83 203
3b2f2976 204 <para>The <function>aligned_alloc()</function> function
970d7e83 205 allocates <parameter>size</parameter> bytes of memory such that the
1a4d82fc 206 allocation's base address is a multiple of
970d7e83
LB
207 <parameter>alignment</parameter>. The requested
208 <parameter>alignment</parameter> must be a power of 2. Behavior is
209 undefined if <parameter>size</parameter> is not an integral multiple of
210 <parameter>alignment</parameter>.</para>
211
3b2f2976 212 <para>The <function>realloc()</function> function changes the
970d7e83
LB
213 size of the previously allocated memory referenced by
214 <parameter>ptr</parameter> to <parameter>size</parameter> bytes. The
215 contents of the memory are unchanged up to the lesser of the new and old
216 sizes. If the new size is larger, the contents of the newly allocated
217 portion of the memory are undefined. Upon success, the memory referenced
218 by <parameter>ptr</parameter> is freed and a pointer to the newly
219 allocated memory is returned. Note that
3b2f2976 220 <function>realloc()</function> may move the memory allocation,
970d7e83
LB
221 resulting in a different return value than <parameter>ptr</parameter>.
222 If <parameter>ptr</parameter> is <constant>NULL</constant>, the
3b2f2976
XL
223 <function>realloc()</function> function behaves identically to
224 <function>malloc()</function> for the specified size.</para>
970d7e83 225
3b2f2976 226 <para>The <function>free()</function> function causes the
970d7e83
LB
227 allocated memory referenced by <parameter>ptr</parameter> to be made
228 available for future allocations. If <parameter>ptr</parameter> is
229 <constant>NULL</constant>, no action occurs.</para>
230 </refsect2>
231 <refsect2>
232 <title>Non-standard API</title>
3b2f2976
XL
233 <para>The <function>mallocx()</function>,
234 <function>rallocx()</function>,
235 <function>xallocx()</function>,
236 <function>sallocx()</function>,
237 <function>dallocx()</function>,
238 <function>sdallocx()</function>, and
239 <function>nallocx()</function> functions all have a
1a4d82fc
JJ
240 <parameter>flags</parameter> argument that can be used to specify
241 options. The functions only check the options that are contextually
242 relevant. Use bitwise or (<code language="C">|</code>) operations to
243 specify one or more of the following:
244 <variablelist>
54a0048b 245 <varlistentry id="MALLOCX_LG_ALIGN">
1a4d82fc
JJ
246 <term><constant>MALLOCX_LG_ALIGN(<parameter>la</parameter>)
247 </constant></term>
970d7e83 248
1a4d82fc
JJ
249 <listitem><para>Align the memory allocation to start at an address
250 that is a multiple of <code language="C">(1 &lt;&lt;
251 <parameter>la</parameter>)</code>. This macro does not validate
252 that <parameter>la</parameter> is within the valid
253 range.</para></listitem>
254 </varlistentry>
54a0048b 255 <varlistentry id="MALLOCX_ALIGN">
1a4d82fc
JJ
256 <term><constant>MALLOCX_ALIGN(<parameter>a</parameter>)
257 </constant></term>
970d7e83 258
1a4d82fc
JJ
259 <listitem><para>Align the memory allocation to start at an address
260 that is a multiple of <parameter>a</parameter>, where
261 <parameter>a</parameter> is a power of two. This macro does not
262 validate that <parameter>a</parameter> is a power of 2.
263 </para></listitem>
264 </varlistentry>
54a0048b 265 <varlistentry id="MALLOCX_ZERO">
1a4d82fc
JJ
266 <term><constant>MALLOCX_ZERO</constant></term>
267
268 <listitem><para>Initialize newly allocated memory to contain zero
269 bytes. In the growing reallocation case, the real size prior to
270 reallocation defines the boundary between untouched bytes and those
271 that are initialized to contain zero bytes. If this macro is
272 absent, newly allocated memory is uninitialized.</para></listitem>
273 </varlistentry>
54a0048b
SL
274 <varlistentry id="MALLOCX_TCACHE">
275 <term><constant>MALLOCX_TCACHE(<parameter>tc</parameter>)
276 </constant></term>
277
278 <listitem><para>Use the thread-specific cache (tcache) specified by
279 the identifier <parameter>tc</parameter>, which must have been
280 acquired via the <link
281 linkend="tcache.create"><mallctl>tcache.create</mallctl></link>
282 mallctl. This macro does not validate that
283 <parameter>tc</parameter> specifies a valid
284 identifier.</para></listitem>
285 </varlistentry>
286 <varlistentry id="MALLOC_TCACHE_NONE">
287 <term><constant>MALLOCX_TCACHE_NONE</constant></term>
288
289 <listitem><para>Do not use a thread-specific cache (tcache). Unless
290 <constant>MALLOCX_TCACHE(<parameter>tc</parameter>)</constant> or
291 <constant>MALLOCX_TCACHE_NONE</constant> is specified, an
292 automatically managed tcache will be used under many circumstances.
293 This macro cannot be used in the same <parameter>flags</parameter>
294 argument as
295 <constant>MALLOCX_TCACHE(<parameter>tc</parameter>)</constant>.</para></listitem>
296 </varlistentry>
297 <varlistentry id="MALLOCX_ARENA">
1a4d82fc
JJ
298 <term><constant>MALLOCX_ARENA(<parameter>a</parameter>)
299 </constant></term>
300
301 <listitem><para>Use the arena specified by the index
54a0048b
SL
302 <parameter>a</parameter>. This macro has no effect for regions that
303 were allocated via an arena other than the one specified. This
304 macro does not validate that <parameter>a</parameter> specifies an
305 arena index in the valid range.</para></listitem>
1a4d82fc
JJ
306 </varlistentry>
307 </variablelist>
970d7e83
LB
308 </para>
309
3b2f2976 310 <para>The <function>mallocx()</function> function allocates at
1a4d82fc
JJ
311 least <parameter>size</parameter> bytes of memory, and returns a pointer
312 to the base address of the allocation. Behavior is undefined if
54a0048b 313 <parameter>size</parameter> is <constant>0</constant>.</para>
1a4d82fc 314
3b2f2976 315 <para>The <function>rallocx()</function> function resizes the
1a4d82fc
JJ
316 allocation at <parameter>ptr</parameter> to be at least
317 <parameter>size</parameter> bytes, and returns a pointer to the base
318 address of the resulting allocation, which may or may not have moved from
319 its original location. Behavior is undefined if
54a0048b 320 <parameter>size</parameter> is <constant>0</constant>.</para>
1a4d82fc 321
3b2f2976 322 <para>The <function>xallocx()</function> function resizes the
1a4d82fc
JJ
323 allocation at <parameter>ptr</parameter> in place to be at least
324 <parameter>size</parameter> bytes, and returns the real size of the
325 allocation. If <parameter>extra</parameter> is non-zero, an attempt is
326 made to resize the allocation to be at least <code
327 language="C">(<parameter>size</parameter> +
328 <parameter>extra</parameter>)</code> bytes, though inability to allocate
329 the extra byte(s) will not by itself result in failure to resize.
330 Behavior is undefined if <parameter>size</parameter> is
331 <constant>0</constant>, or if <code
332 language="C">(<parameter>size</parameter> + <parameter>extra</parameter>
333 &gt; <constant>SIZE_T_MAX</constant>)</code>.</para>
334
3b2f2976 335 <para>The <function>sallocx()</function> function returns the
1a4d82fc
JJ
336 real size of the allocation at <parameter>ptr</parameter>.</para>
337
3b2f2976 338 <para>The <function>dallocx()</function> function causes the
1a4d82fc
JJ
339 memory referenced by <parameter>ptr</parameter> to be made available for
340 future allocations.</para>
341
3b2f2976
XL
342 <para>The <function>sdallocx()</function> function is an
343 extension of <function>dallocx()</function> with a
1a4d82fc
JJ
344 <parameter>size</parameter> parameter to allow the caller to pass in the
345 allocation size as an optimization. The minimum valid input size is the
346 original requested size of the allocation, and the maximum valid input
347 size is the corresponding value returned by
3b2f2976
XL
348 <function>nallocx()</function> or
349 <function>sallocx()</function>.</para>
1a4d82fc 350
3b2f2976 351 <para>The <function>nallocx()</function> function allocates no
1a4d82fc 352 memory, but it performs the same size computation as the
3b2f2976 353 <function>mallocx()</function> function, and returns the real
1a4d82fc 354 size of the allocation that would result from the equivalent
3b2f2976 355 <function>mallocx()</function> function call, or
54a0048b
SL
356 <constant>0</constant> if the inputs exceed the maximum supported size
357 class and/or alignment. Behavior is undefined if
358 <parameter>size</parameter> is <constant>0</constant>.</para>
1a4d82fc 359
3b2f2976 360 <para>The <function>mallctl()</function> function provides a
970d7e83
LB
361 general interface for introspecting the memory allocator, as well as
362 setting modifiable parameters and triggering actions. The
363 period-separated <parameter>name</parameter> argument specifies a
364 location in a tree-structured namespace; see the <xref
365 linkend="mallctl_namespace" xrefstyle="template:%t"/> section for
366 documentation on the tree contents. To read a value, pass a pointer via
367 <parameter>oldp</parameter> to adequate space to contain the value, and a
368 pointer to its length via <parameter>oldlenp</parameter>; otherwise pass
369 <constant>NULL</constant> and <constant>NULL</constant>. Similarly, to
370 write a value, pass a pointer to the value via
371 <parameter>newp</parameter>, and its length via
372 <parameter>newlen</parameter>; otherwise pass <constant>NULL</constant>
373 and <constant>0</constant>.</para>
374
3b2f2976 375 <para>The <function>mallctlnametomib()</function> function
970d7e83
LB
376 provides a way to avoid repeated name lookups for applications that
377 repeatedly query the same portion of the namespace, by translating a name
3b2f2976
XL
378 to a <quote>Management Information Base</quote> (MIB) that can be passed
379 repeatedly to <function>mallctlbymib()</function>. Upon
380 successful return from <function>mallctlnametomib()</function>,
970d7e83
LB
381 <parameter>mibp</parameter> contains an array of
382 <parameter>*miblenp</parameter> integers, where
383 <parameter>*miblenp</parameter> is the lesser of the number of components
384 in <parameter>name</parameter> and the input value of
385 <parameter>*miblenp</parameter>. Thus it is possible to pass a
386 <parameter>*miblenp</parameter> that is smaller than the number of
387 period-separated name components, which results in a partial MIB that can
388 be used as the basis for constructing a complete MIB. For name
389 components that are integers (e.g. the 2 in
390 <link
391 linkend="arenas.bin.i.size"><mallctl>arenas.bin.2.size</mallctl></link>),
392 the corresponding MIB component will always be that integer. Therefore,
393 it is legitimate to construct code like the following: <programlisting
394 language="C"><![CDATA[
395unsigned nbins, i;
1a4d82fc 396size_t mib[4];
970d7e83
LB
397size_t len, miblen;
398
399len = sizeof(nbins);
400mallctl("arenas.nbins", &nbins, &len, NULL, 0);
401
402miblen = 4;
1a4d82fc 403mallctlnametomib("arenas.bin.0.size", mib, &miblen);
970d7e83
LB
404for (i = 0; i < nbins; i++) {
405 size_t bin_size;
406
407 mib[2] = i;
408 len = sizeof(bin_size);
3b2f2976 409 mallctlbymib(mib, miblen, (void *)&bin_size, &len, NULL, 0);
970d7e83
LB
410 /* Do something with bin_size... */
411}]]></programlisting></para>
970d7e83 412
3b2f2976
XL
413 <para>The <function>malloc_stats_print()</function> function writes
414 summary statistics via the <parameter>write_cb</parameter> callback
415 function pointer and <parameter>cbopaque</parameter> data passed to
416 <parameter>write_cb</parameter>, or <function>malloc_message()</function>
417 if <parameter>write_cb</parameter> is <constant>NULL</constant>. The
418 statistics are presented in human-readable form unless <quote>J</quote> is
419 specified as a character within the <parameter>opts</parameter> string, in
420 which case the statistics are presented in <ulink
421 url="http://www.json.org/">JSON format</ulink>. This function can be
422 called repeatedly. General information that never changes during
423 execution can be omitted by specifying <quote>g</quote> as a character
1a4d82fc 424 within the <parameter>opts</parameter> string. Note that
3b2f2976
XL
425 <function>malloc_message()</function> uses the
426 <function>mallctl*()</function> functions internally, so inconsistent
427 statistics can be reported if multiple threads use these functions
428 simultaneously. If <option>--enable-stats</option> is specified during
429 configuration, <quote>m</quote> and <quote>a</quote> can be specified to
430 omit merged arena and per arena statistics, respectively;
431 <quote>b</quote>, <quote>l</quote>, and <quote>h</quote> can be specified
432 to omit per size class statistics for bins, large objects, and huge
433 objects, respectively. Unrecognized characters are silently ignored.
434 Note that thread caching may prevent some statistics from being completely
435 up to date, since extra locking would be required to merge counters that
436 track thread cache operations.</para>
437
438 <para>The <function>malloc_usable_size()</function> function
1a4d82fc
JJ
439 returns the usable size of the allocation pointed to by
440 <parameter>ptr</parameter>. The return value may be larger than the size
441 that was requested during allocation. The
3b2f2976
XL
442 <function>malloc_usable_size()</function> function is not a
443 mechanism for in-place <function>realloc()</function>; rather
1a4d82fc
JJ
444 it is provided solely as a tool for introspection purposes. Any
445 discrepancy between the requested allocation size and the size reported
3b2f2976 446 by <function>malloc_usable_size()</function> should not be
1a4d82fc
JJ
447 depended on, since such behavior is entirely implementation-dependent.
448 </para>
970d7e83
LB
449 </refsect2>
450 </refsect1>
451 <refsect1 id="tuning">
452 <title>TUNING</title>
453 <para>Once, when the first call is made to one of the memory allocation
454 routines, the allocator initializes its internals based in part on various
455 options that can be specified at compile- or run-time.</para>
456
54a0048b
SL
457 <para>The string specified via <option>--with-malloc-conf</option>, the
458 string pointed to by the global variable <varname>malloc_conf</varname>, the
3b2f2976 459 <quote>name</quote> of the file referenced by the symbolic link named
54a0048b 460 <filename class="symlink">/etc/malloc.conf</filename>, and the value of the
970d7e83
LB
461 environment variable <envar>MALLOC_CONF</envar>, will be interpreted, in
462 that order, from left to right as options. Note that
463 <varname>malloc_conf</varname> may be read before
3b2f2976 464 <function>main()</function> is entered, so the declaration of
970d7e83 465 <varname>malloc_conf</varname> should specify an initializer that contains
54a0048b
SL
466 the final value to be read by jemalloc. <option>--with-malloc-conf</option>
467 and <varname>malloc_conf</varname> are compile-time mechanisms, whereas
468 <filename class="symlink">/etc/malloc.conf</filename> and
469 <envar>MALLOC_CONF</envar> can be safely set any time prior to program
470 invocation.</para>
970d7e83
LB
471
472 <para>An options string is a comma-separated list of option:value pairs.
473 There is one key corresponding to each <link
474 linkend="opt.abort"><mallctl>opt.*</mallctl></link> mallctl (see the <xref
475 linkend="mallctl_namespace" xrefstyle="template:%t"/> section for options
476 documentation). For example, <literal>abort:true,narenas:1</literal> sets
477 the <link linkend="opt.abort"><mallctl>opt.abort</mallctl></link> and <link
478 linkend="opt.narenas"><mallctl>opt.narenas</mallctl></link> options. Some
479 options have boolean values (true/false), others have integer values (base
480 8, 10, or 16, depending on prefix), and yet others have raw string
481 values.</para>
482 </refsect1>
483 <refsect1 id="implementation_notes">
484 <title>IMPLEMENTATION NOTES</title>
485 <para>Traditionally, allocators have used
486 <citerefentry><refentrytitle>sbrk</refentrytitle>
487 <manvolnum>2</manvolnum></citerefentry> to obtain memory, which is
488 suboptimal for several reasons, including race conditions, increased
489 fragmentation, and artificial limitations on maximum usable memory. If
1a4d82fc
JJ
490 <citerefentry><refentrytitle>sbrk</refentrytitle>
491 <manvolnum>2</manvolnum></citerefentry> is supported by the operating
492 system, this allocator uses both
493 <citerefentry><refentrytitle>mmap</refentrytitle>
970d7e83
LB
494 <manvolnum>2</manvolnum></citerefentry> and
495 <citerefentry><refentrytitle>sbrk</refentrytitle>
496 <manvolnum>2</manvolnum></citerefentry>, in that order of preference;
497 otherwise only <citerefentry><refentrytitle>mmap</refentrytitle>
498 <manvolnum>2</manvolnum></citerefentry> is used.</para>
499
500 <para>This allocator uses multiple arenas in order to reduce lock
501 contention for threaded programs on multi-processor systems. This works
502 well with regard to threading scalability, but incurs some costs. There is
503 a small fixed per-arena overhead, and additionally, arenas manage memory
504 completely independently of each other, which means a small fixed increase
505 in overall memory fragmentation. These overheads are not generally an
506 issue, given the number of arenas normally used. Note that using
507 substantially more arenas than the default is not likely to improve
508 performance, mainly due to reduced cache performance. However, it may make
509 sense to reduce the number of arenas if an application does not make much
510 use of the allocation functions.</para>
511
512 <para>In addition to multiple arenas, unless
513 <option>--disable-tcache</option> is specified during configuration, this
514 allocator supports thread-specific caching for small and large objects, in
515 order to make it possible to completely avoid synchronization for most
516 allocation requests. Such caching allows very fast allocation in the
517 common case, but it increases memory usage and fragmentation, since a
518 bounded number of objects can remain allocated in each thread cache.</para>
519
54a0048b
SL
520 <para>Memory is conceptually broken into equal-sized chunks, where the chunk
521 size is a power of two that is greater than the page size. Chunks are
522 always aligned to multiples of the chunk size. This alignment makes it
523 possible to find metadata for user objects very quickly. User objects are
524 broken into three categories according to size: small, large, and huge.
525 Multiple small and large objects can reside within a single chunk, whereas
526 huge objects each have one or more chunks backing them. Each chunk that
527 contains small and/or large objects tracks its contents as runs of
970d7e83 528 contiguous pages (unused, backing a set of small objects, or backing one
54a0048b
SL
529 large object). The combination of chunk alignment and chunk page maps makes
530 it possible to determine all metadata regarding small and large allocations
531 in constant time.</para>
970d7e83
LB
532
533 <para>Small objects are managed in groups by page runs. Each run maintains
54a0048b
SL
534 a bitmap to track which regions are in use. Allocation requests that are no
535 more than half the quantum (8 or 16, depending on architecture) are rounded
536 up to the nearest power of two that is at least <code
537 language="C">sizeof(<type>double</type>)</code>. All other object size
538 classes are multiples of the quantum, spaced such that there are four size
539 classes for each doubling in size, which limits internal fragmentation to
540 approximately 20% for all but the smallest size classes. Small size classes
541 are smaller than four times the page size, large size classes are smaller
542 than the chunk size (see the <link
543 linkend="opt.lg_chunk"><mallctl>opt.lg_chunk</mallctl></link> option), and
3b2f2976
XL
544 huge size classes extend from the chunk size up to the largest size class
545 that does not exceed <constant>PTRDIFF_MAX</constant>.</para>
970d7e83
LB
546
547 <para>Allocations are packed tightly together, which can be an issue for
548 multi-threaded applications. If you need to assure that allocations do not
549 suffer from cacheline sharing, round your allocation requests up to the
550 nearest multiple of the cacheline size, or specify cacheline alignment when
551 allocating.</para>
552
3b2f2976
XL
553 <para>The <function>realloc()</function>,
554 <function>rallocx()</function>, and
555 <function>xallocx()</function> functions may resize allocations
54a0048b 556 without moving them under limited circumstances. Unlike the
3b2f2976 557 <function>*allocx()</function> API, the standard API does not
54a0048b
SL
558 officially round up the usable size of an allocation to the nearest size
559 class, so technically it is necessary to call
3b2f2976 560 <function>realloc()</function> to grow e.g. a 9-byte allocation to
54a0048b
SL
561 16 bytes, or shrink a 16-byte allocation to 9 bytes. Growth and shrinkage
562 trivially succeeds in place as long as the pre-size and post-size both round
563 up to the same size class. No other API guarantees are made regarding
564 in-place resizing, but the current implementation also tries to resize large
565 and huge allocations in place, as long as the pre-size and post-size are
566 both large or both huge. In such cases shrinkage always succeeds for large
567 size classes, but for huge size classes the chunk allocator must support
568 splitting (see <link
569 linkend="arena.i.chunk_hooks"><mallctl>arena.&lt;i&gt;.chunk_hooks</mallctl></link>).
570 Growth only succeeds if the trailing memory is currently available, and
571 additionally for huge size classes the chunk allocator must support
572 merging.</para>
573
574 <para>Assuming 2 MiB chunks, 4 KiB pages, and a 16-byte quantum on a
575 64-bit system, the size classes in each category are as shown in <xref
970d7e83
LB
576 linkend="size_classes" xrefstyle="template:Table %n"/>.</para>
577
578 <table xml:id="size_classes" frame="all">
579 <title>Size classes</title>
580 <tgroup cols="3" colsep="1" rowsep="1">
581 <colspec colname="c1" align="left"/>
582 <colspec colname="c2" align="right"/>
583 <colspec colname="c3" align="left"/>
584 <thead>
585 <row>
586 <entry>Category</entry>
587 <entry>Spacing</entry>
588 <entry>Size</entry>
589 </row>
590 </thead>
591 <tbody>
592 <row>
54a0048b 593 <entry morerows="8">Small</entry>
970d7e83
LB
594 <entry>lg</entry>
595 <entry>[8]</entry>
596 </row>
597 <row>
598 <entry>16</entry>
54a0048b 599 <entry>[16, 32, 48, 64, 80, 96, 112, 128]</entry>
970d7e83
LB
600 </row>
601 <row>
602 <entry>32</entry>
603 <entry>[160, 192, 224, 256]</entry>
604 </row>
605 <row>
606 <entry>64</entry>
607 <entry>[320, 384, 448, 512]</entry>
608 </row>
609 <row>
610 <entry>128</entry>
611 <entry>[640, 768, 896, 1024]</entry>
612 </row>
613 <row>
614 <entry>256</entry>
615 <entry>[1280, 1536, 1792, 2048]</entry>
616 </row>
617 <row>
618 <entry>512</entry>
54a0048b
SL
619 <entry>[2560, 3072, 3584, 4096]</entry>
620 </row>
621 <row>
622 <entry>1 KiB</entry>
623 <entry>[5 KiB, 6 KiB, 7 KiB, 8 KiB]</entry>
624 </row>
625 <row>
626 <entry>2 KiB</entry>
627 <entry>[10 KiB, 12 KiB, 14 KiB]</entry>
628 </row>
629 <row>
630 <entry morerows="7">Large</entry>
631 <entry>2 KiB</entry>
632 <entry>[16 KiB]</entry>
970d7e83
LB
633 </row>
634 <row>
970d7e83 635 <entry>4 KiB</entry>
54a0048b
SL
636 <entry>[20 KiB, 24 KiB, 28 KiB, 32 KiB]</entry>
637 </row>
638 <row>
639 <entry>8 KiB</entry>
640 <entry>[40 KiB, 48 KiB, 54 KiB, 64 KiB]</entry>
641 </row>
642 <row>
643 <entry>16 KiB</entry>
644 <entry>[80 KiB, 96 KiB, 112 KiB, 128 KiB]</entry>
645 </row>
646 <row>
647 <entry>32 KiB</entry>
648 <entry>[160 KiB, 192 KiB, 224 KiB, 256 KiB]</entry>
649 </row>
650 <row>
651 <entry>64 KiB</entry>
652 <entry>[320 KiB, 384 KiB, 448 KiB, 512 KiB]</entry>
653 </row>
654 <row>
655 <entry>128 KiB</entry>
656 <entry>[640 KiB, 768 KiB, 896 KiB, 1 MiB]</entry>
657 </row>
658 <row>
659 <entry>256 KiB</entry>
660 <entry>[1280 KiB, 1536 KiB, 1792 KiB]</entry>
661 </row>
662 <row>
3b2f2976 663 <entry morerows="8">Huge</entry>
54a0048b
SL
664 <entry>256 KiB</entry>
665 <entry>[2 MiB]</entry>
666 </row>
667 <row>
668 <entry>512 KiB</entry>
669 <entry>[2560 KiB, 3 MiB, 3584 KiB, 4 MiB]</entry>
670 </row>
671 <row>
672 <entry>1 MiB</entry>
673 <entry>[5 MiB, 6 MiB, 7 MiB, 8 MiB]</entry>
674 </row>
675 <row>
676 <entry>2 MiB</entry>
677 <entry>[10 MiB, 12 MiB, 14 MiB, 16 MiB]</entry>
970d7e83
LB
678 </row>
679 <row>
970d7e83 680 <entry>4 MiB</entry>
54a0048b
SL
681 <entry>[20 MiB, 24 MiB, 28 MiB, 32 MiB]</entry>
682 </row>
683 <row>
684 <entry>8 MiB</entry>
685 <entry>[40 MiB, 48 MiB, 56 MiB, 64 MiB]</entry>
686 </row>
687 <row>
688 <entry>...</entry>
689 <entry>...</entry>
970d7e83 690 </row>
3b2f2976
XL
691 <row>
692 <entry>512 PiB</entry>
693 <entry>[2560 PiB, 3 EiB, 3584 PiB, 4 EiB]</entry>
694 </row>
695 <row>
696 <entry>1 EiB</entry>
697 <entry>[5 EiB, 6 EiB, 7 EiB]</entry>
698 </row>
970d7e83
LB
699 </tbody>
700 </tgroup>
701 </table>
702 </refsect1>
703 <refsect1 id="mallctl_namespace">
704 <title>MALLCTL NAMESPACE</title>
705 <para>The following names are defined in the namespace accessible via the
3b2f2976 706 <function>mallctl*()</function> functions. Value types are
970d7e83
LB
707 specified in parentheses, their readable/writable statuses are encoded as
708 <literal>rw</literal>, <literal>r-</literal>, <literal>-w</literal>, or
709 <literal>--</literal>, and required build configuration flags follow, if
710 any. A name element encoded as <literal>&lt;i&gt;</literal> or
711 <literal>&lt;j&gt;</literal> indicates an integer component, where the
712 integer varies from 0 to some upper value that must be determined via
713 introspection. In the case of <mallctl>stats.arenas.&lt;i&gt;.*</mallctl>,
714 <literal>&lt;i&gt;</literal> equal to <link
715 linkend="arenas.narenas"><mallctl>arenas.narenas</mallctl></link> can be
716 used to access the summation of statistics from all arenas. Take special
717 note of the <link linkend="epoch"><mallctl>epoch</mallctl></link> mallctl,
718 which controls refreshing of cached dynamic statistics.</para>
719
720 <variablelist>
1a4d82fc 721 <varlistentry id="version">
970d7e83
LB
722 <term>
723 <mallctl>version</mallctl>
724 (<type>const char *</type>)
725 <literal>r-</literal>
726 </term>
727 <listitem><para>Return the jemalloc version string.</para></listitem>
728 </varlistentry>
729
730 <varlistentry id="epoch">
731 <term>
732 <mallctl>epoch</mallctl>
733 (<type>uint64_t</type>)
734 <literal>rw</literal>
735 </term>
736 <listitem><para>If a value is passed in, refresh the data from which
3b2f2976 737 the <function>mallctl*()</function> functions report values,
970d7e83
LB
738 and increment the epoch. Return the current epoch. This is useful for
739 detecting whether another thread caused a refresh.</para></listitem>
740 </varlistentry>
741
54a0048b
SL
742 <varlistentry id="config.cache_oblivious">
743 <term>
744 <mallctl>config.cache_oblivious</mallctl>
745 (<type>bool</type>)
746 <literal>r-</literal>
747 </term>
748 <listitem><para><option>--enable-cache-oblivious</option> was specified
749 during build configuration.</para></listitem>
750 </varlistentry>
751
1a4d82fc 752 <varlistentry id="config.debug">
970d7e83
LB
753 <term>
754 <mallctl>config.debug</mallctl>
755 (<type>bool</type>)
756 <literal>r-</literal>
757 </term>
758 <listitem><para><option>--enable-debug</option> was specified during
759 build configuration.</para></listitem>
760 </varlistentry>
761
1a4d82fc 762 <varlistentry id="config.fill">
970d7e83
LB
763 <term>
764 <mallctl>config.fill</mallctl>
765 (<type>bool</type>)
766 <literal>r-</literal>
767 </term>
768 <listitem><para><option>--enable-fill</option> was specified during
769 build configuration.</para></listitem>
770 </varlistentry>
771
1a4d82fc 772 <varlistentry id="config.lazy_lock">
970d7e83
LB
773 <term>
774 <mallctl>config.lazy_lock</mallctl>
775 (<type>bool</type>)
776 <literal>r-</literal>
777 </term>
778 <listitem><para><option>--enable-lazy-lock</option> was specified
779 during build configuration.</para></listitem>
780 </varlistentry>
781
54a0048b
SL
782 <varlistentry id="config.malloc_conf">
783 <term>
784 <mallctl>config.malloc_conf</mallctl>
785 (<type>const char *</type>)
786 <literal>r-</literal>
787 </term>
788 <listitem><para>Embedded configure-time-specified run-time options
789 string, empty unless <option>--with-malloc-conf</option> was specified
790 during build configuration.</para></listitem>
791 </varlistentry>
792
1a4d82fc 793 <varlistentry id="config.munmap">
970d7e83
LB
794 <term>
795 <mallctl>config.munmap</mallctl>
796 (<type>bool</type>)
797 <literal>r-</literal>
798 </term>
799 <listitem><para><option>--enable-munmap</option> was specified during
800 build configuration.</para></listitem>
801 </varlistentry>
802
1a4d82fc 803 <varlistentry id="config.prof">
970d7e83
LB
804 <term>
805 <mallctl>config.prof</mallctl>
806 (<type>bool</type>)
807 <literal>r-</literal>
808 </term>
809 <listitem><para><option>--enable-prof</option> was specified during
810 build configuration.</para></listitem>
811 </varlistentry>
812
1a4d82fc 813 <varlistentry id="config.prof_libgcc">
970d7e83
LB
814 <term>
815 <mallctl>config.prof_libgcc</mallctl>
816 (<type>bool</type>)
817 <literal>r-</literal>
818 </term>
819 <listitem><para><option>--disable-prof-libgcc</option> was not
820 specified during build configuration.</para></listitem>
821 </varlistentry>
822
1a4d82fc 823 <varlistentry id="config.prof_libunwind">
970d7e83
LB
824 <term>
825 <mallctl>config.prof_libunwind</mallctl>
826 (<type>bool</type>)
827 <literal>r-</literal>
828 </term>
829 <listitem><para><option>--enable-prof-libunwind</option> was specified
830 during build configuration.</para></listitem>
831 </varlistentry>
832
1a4d82fc 833 <varlistentry id="config.stats">
970d7e83
LB
834 <term>
835 <mallctl>config.stats</mallctl>
836 (<type>bool</type>)
837 <literal>r-</literal>
838 </term>
839 <listitem><para><option>--enable-stats</option> was specified during
840 build configuration.</para></listitem>
841 </varlistentry>
842
1a4d82fc 843 <varlistentry id="config.tcache">
970d7e83
LB
844 <term>
845 <mallctl>config.tcache</mallctl>
846 (<type>bool</type>)
847 <literal>r-</literal>
848 </term>
849 <listitem><para><option>--disable-tcache</option> was not specified
850 during build configuration.</para></listitem>
851 </varlistentry>
852
3b2f2976
XL
853 <varlistentry id="config.thp">
854 <term>
855 <mallctl>config.thp</mallctl>
856 (<type>bool</type>)
857 <literal>r-</literal>
858 </term>
859 <listitem><para><option>--disable-thp</option> was not specified
860 during build configuration, and the system supports transparent huge
861 page manipulation.</para></listitem>
862 </varlistentry>
863
1a4d82fc 864 <varlistentry id="config.tls">
970d7e83
LB
865 <term>
866 <mallctl>config.tls</mallctl>
867 (<type>bool</type>)
868 <literal>r-</literal>
869 </term>
870 <listitem><para><option>--disable-tls</option> was not specified during
871 build configuration.</para></listitem>
872 </varlistentry>
873
1a4d82fc 874 <varlistentry id="config.utrace">
970d7e83
LB
875 <term>
876 <mallctl>config.utrace</mallctl>
877 (<type>bool</type>)
878 <literal>r-</literal>
879 </term>
880 <listitem><para><option>--enable-utrace</option> was specified during
881 build configuration.</para></listitem>
882 </varlistentry>
883
1a4d82fc 884 <varlistentry id="config.valgrind">
970d7e83
LB
885 <term>
886 <mallctl>config.valgrind</mallctl>
887 (<type>bool</type>)
888 <literal>r-</literal>
889 </term>
890 <listitem><para><option>--enable-valgrind</option> was specified during
891 build configuration.</para></listitem>
892 </varlistentry>
893
1a4d82fc 894 <varlistentry id="config.xmalloc">
970d7e83
LB
895 <term>
896 <mallctl>config.xmalloc</mallctl>
897 (<type>bool</type>)
898 <literal>r-</literal>
899 </term>
900 <listitem><para><option>--enable-xmalloc</option> was specified during
901 build configuration.</para></listitem>
902 </varlistentry>
903
904 <varlistentry id="opt.abort">
905 <term>
906 <mallctl>opt.abort</mallctl>
907 (<type>bool</type>)
908 <literal>r-</literal>
909 </term>
910 <listitem><para>Abort-on-warning enabled/disabled. If true, most
911 warnings are fatal. The process will call
912 <citerefentry><refentrytitle>abort</refentrytitle>
913 <manvolnum>3</manvolnum></citerefentry> in these cases. This option is
914 disabled by default unless <option>--enable-debug</option> is
915 specified during configuration, in which case it is enabled by default.
916 </para></listitem>
917 </varlistentry>
918
1a4d82fc
JJ
919 <varlistentry id="opt.dss">
920 <term>
921 <mallctl>opt.dss</mallctl>
922 (<type>const char *</type>)
923 <literal>r-</literal>
924 </term>
925 <listitem><para>dss (<citerefentry><refentrytitle>sbrk</refentrytitle>
926 <manvolnum>2</manvolnum></citerefentry>) allocation precedence as
927 related to <citerefentry><refentrytitle>mmap</refentrytitle>
928 <manvolnum>2</manvolnum></citerefentry> allocation. The following
929 settings are supported if
930 <citerefentry><refentrytitle>sbrk</refentrytitle>
931 <manvolnum>2</manvolnum></citerefentry> is supported by the operating
3b2f2976
XL
932 system: <quote>disabled</quote>, <quote>primary</quote>, and
933 <quote>secondary</quote>; otherwise only <quote>disabled</quote> is
934 supported. The default is <quote>secondary</quote> if
1a4d82fc
JJ
935 <citerefentry><refentrytitle>sbrk</refentrytitle>
936 <manvolnum>2</manvolnum></citerefentry> is supported by the operating
3b2f2976 937 system; <quote>disabled</quote> otherwise.
1a4d82fc
JJ
938 </para></listitem>
939 </varlistentry>
940
970d7e83
LB
941 <varlistentry id="opt.lg_chunk">
942 <term>
943 <mallctl>opt.lg_chunk</mallctl>
944 (<type>size_t</type>)
945 <literal>r-</literal>
946 </term>
947 <listitem><para>Virtual memory chunk size (log base 2). If a chunk
948 size outside the supported size range is specified, the size is
949 silently clipped to the minimum/maximum supported size. The default
54a0048b 950 chunk size is 2 MiB (2^21).
970d7e83
LB
951 </para></listitem>
952 </varlistentry>
953
970d7e83
LB
954 <varlistentry id="opt.narenas">
955 <term>
956 <mallctl>opt.narenas</mallctl>
54a0048b 957 (<type>unsigned</type>)
970d7e83
LB
958 <literal>r-</literal>
959 </term>
960 <listitem><para>Maximum number of arenas to use for automatic
961 multiplexing of threads and arenas. The default is four times the
962 number of CPUs, or one if there is a single CPU.</para></listitem>
963 </varlistentry>
964
54a0048b
SL
965 <varlistentry id="opt.purge">
966 <term>
967 <mallctl>opt.purge</mallctl>
968 (<type>const char *</type>)
969 <literal>r-</literal>
970 </term>
971 <listitem><para>Purge mode is &ldquo;ratio&rdquo; (default) or
972 &ldquo;decay&rdquo;. See <link
973 linkend="opt.lg_dirty_mult"><mallctl>opt.lg_dirty_mult</mallctl></link>
974 for details of the ratio mode. See <link
975 linkend="opt.decay_time"><mallctl>opt.decay_time</mallctl></link> for
976 details of the decay mode.</para></listitem>
977 </varlistentry>
978
970d7e83
LB
979 <varlistentry id="opt.lg_dirty_mult">
980 <term>
981 <mallctl>opt.lg_dirty_mult</mallctl>
982 (<type>ssize_t</type>)
983 <literal>r-</literal>
984 </term>
985 <listitem><para>Per-arena minimum ratio (log base 2) of active to dirty
986 pages. Some dirty unused pages may be allowed to accumulate, within
987 the limit set by the ratio (or one chunk worth of dirty pages,
988 whichever is greater), before informing the kernel about some of those
989 pages via <citerefentry><refentrytitle>madvise</refentrytitle>
990 <manvolnum>2</manvolnum></citerefentry> or a similar system call. This
991 provides the kernel with sufficient information to recycle dirty pages
992 if physical memory becomes scarce and the pages remain unused. The
993 default minimum ratio is 8:1 (2^3:1); an option value of -1 will
54a0048b
SL
994 disable dirty page purging. See <link
995 linkend="arenas.lg_dirty_mult"><mallctl>arenas.lg_dirty_mult</mallctl></link>
996 and <link
997 linkend="arena.i.lg_dirty_mult"><mallctl>arena.&lt;i&gt;.lg_dirty_mult</mallctl></link>
998 for related dynamic control options.</para></listitem>
999 </varlistentry>
1000
1001 <varlistentry id="opt.decay_time">
1002 <term>
1003 <mallctl>opt.decay_time</mallctl>
1004 (<type>ssize_t</type>)
1005 <literal>r-</literal>
1006 </term>
1007 <listitem><para>Approximate time in seconds from the creation of a set
1008 of unused dirty pages until an equivalent set of unused dirty pages is
1009 purged and/or reused. The pages are incrementally purged according to a
1010 sigmoidal decay curve that starts and ends with zero purge rate. A
1011 decay time of 0 causes all unused dirty pages to be purged immediately
1012 upon creation. A decay time of -1 disables purging. The default decay
1013 time is 10 seconds. See <link
1014 linkend="arenas.decay_time"><mallctl>arenas.decay_time</mallctl></link>
1015 and <link
1016 linkend="arena.i.decay_time"><mallctl>arena.&lt;i&gt;.decay_time</mallctl></link>
1017 for related dynamic control options.
1018 </para></listitem>
970d7e83
LB
1019 </varlistentry>
1020
1021 <varlistentry id="opt.stats_print">
1022 <term>
1023 <mallctl>opt.stats_print</mallctl>
1024 (<type>bool</type>)
1025 <literal>r-</literal>
1026 </term>
1027 <listitem><para>Enable/disable statistics printing at exit. If
3b2f2976 1028 enabled, the <function>malloc_stats_print()</function>
970d7e83
LB
1029 function is called at program exit via an
1030 <citerefentry><refentrytitle>atexit</refentrytitle>
1031 <manvolnum>3</manvolnum></citerefentry> function. If
1032 <option>--enable-stats</option> is specified during configuration, this
1033 has the potential to cause deadlock for a multi-threaded process that
1034 exits while one or more threads are executing in the memory allocation
3b2f2976 1035 functions. Furthermore, <function>atexit()</function> may
54a0048b
SL
1036 allocate memory during application initialization and then deadlock
1037 internally when jemalloc in turn calls
3b2f2976
XL
1038 <function>atexit()</function>, so this option is not
1039 universally usable (though the application can register its own
1040 <function>atexit()</function> function with equivalent
54a0048b
SL
1041 functionality). Therefore, this option should only be used with care;
1042 it is primarily intended as a performance tuning aid during application
970d7e83
LB
1043 development. This option is disabled by default.</para></listitem>
1044 </varlistentry>
1045
1046 <varlistentry id="opt.junk">
1047 <term>
1048 <mallctl>opt.junk</mallctl>
54a0048b 1049 (<type>const char *</type>)
970d7e83
LB
1050 <literal>r-</literal>
1051 [<option>--enable-fill</option>]
1052 </term>
3b2f2976
XL
1053 <listitem><para>Junk filling. If set to <quote>alloc</quote>, each byte
1054 of uninitialized allocated memory will be initialized to
1055 <literal>0xa5</literal>. If set to <quote>free</quote>, all deallocated
1056 memory will be initialized to <literal>0x5a</literal>. If set to
1057 <quote>true</quote>, both allocated and deallocated memory will be
1058 initialized, and if set to <quote>false</quote>, junk filling be
1059 disabled entirely. This is intended for debugging and will impact
1060 performance negatively. This option is <quote>false</quote> by default
1061 unless <option>--enable-debug</option> is specified during
1062 configuration, in which case it is <quote>true</quote> by default unless
54a0048b 1063 running inside <ulink
970d7e83
LB
1064 url="http://valgrind.org/">Valgrind</ulink>.</para></listitem>
1065 </varlistentry>
1066
1067 <varlistentry id="opt.quarantine">
1068 <term>
1069 <mallctl>opt.quarantine</mallctl>
1070 (<type>size_t</type>)
1071 <literal>r-</literal>
1072 [<option>--enable-fill</option>]
1073 </term>
1074 <listitem><para>Per thread quarantine size in bytes. If non-zero, each
1075 thread maintains a FIFO object quarantine that stores up to the
1076 specified number of bytes of memory. The quarantined memory is not
1077 freed until it is released from quarantine, though it is immediately
1078 junk-filled if the <link
1079 linkend="opt.junk"><mallctl>opt.junk</mallctl></link> option is
1080 enabled. This feature is of particular use in combination with <ulink
1081 url="http://valgrind.org/">Valgrind</ulink>, which can detect attempts
1082 to access quarantined objects. This is intended for debugging and will
1083 impact performance negatively. The default quarantine size is 0 unless
1084 running inside Valgrind, in which case the default is 16
1085 MiB.</para></listitem>
1086 </varlistentry>
1087
1088 <varlistentry id="opt.redzone">
1089 <term>
1090 <mallctl>opt.redzone</mallctl>
1091 (<type>bool</type>)
1092 <literal>r-</literal>
1093 [<option>--enable-fill</option>]
1094 </term>
1095 <listitem><para>Redzones enabled/disabled. If enabled, small
1096 allocations have redzones before and after them. Furthermore, if the
1097 <link linkend="opt.junk"><mallctl>opt.junk</mallctl></link> option is
1098 enabled, the redzones are checked for corruption during deallocation.
1099 However, the primary intended purpose of this feature is to be used in
1100 combination with <ulink url="http://valgrind.org/">Valgrind</ulink>,
1101 which needs redzones in order to do effective buffer overflow/underflow
1102 detection. This option is intended for debugging and will impact
1103 performance negatively. This option is disabled by
1104 default unless running inside Valgrind.</para></listitem>
1105 </varlistentry>
1106
1107 <varlistentry id="opt.zero">
1108 <term>
1109 <mallctl>opt.zero</mallctl>
1110 (<type>bool</type>)
1111 <literal>r-</literal>
1112 [<option>--enable-fill</option>]
1113 </term>
1114 <listitem><para>Zero filling enabled/disabled. If enabled, each byte
1115 of uninitialized allocated memory will be initialized to 0. Note that
1116 this initialization only happens once for each byte, so
3b2f2976
XL
1117 <function>realloc()</function> and
1118 <function>rallocx()</function> calls do not zero memory that
970d7e83
LB
1119 was previously allocated. This is intended for debugging and will
1120 impact performance negatively. This option is disabled by default.
1121 </para></listitem>
1122 </varlistentry>
1123
1124 <varlistentry id="opt.utrace">
1125 <term>
1126 <mallctl>opt.utrace</mallctl>
1127 (<type>bool</type>)
1128 <literal>r-</literal>
1129 [<option>--enable-utrace</option>]
1130 </term>
1131 <listitem><para>Allocation tracing based on
1132 <citerefentry><refentrytitle>utrace</refentrytitle>
1133 <manvolnum>2</manvolnum></citerefentry> enabled/disabled. This option
1134 is disabled by default.</para></listitem>
1135 </varlistentry>
1136
970d7e83
LB
1137 <varlistentry id="opt.xmalloc">
1138 <term>
1139 <mallctl>opt.xmalloc</mallctl>
1140 (<type>bool</type>)
1141 <literal>r-</literal>
1142 [<option>--enable-xmalloc</option>]
1143 </term>
1144 <listitem><para>Abort-on-out-of-memory enabled/disabled. If enabled,
1145 rather than returning failure for any allocation function, display a
1146 diagnostic message on <constant>STDERR_FILENO</constant> and cause the
1147 program to drop core (using
1148 <citerefentry><refentrytitle>abort</refentrytitle>
1149 <manvolnum>3</manvolnum></citerefentry>). If an application is
1150 designed to depend on this behavior, set the option at compile time by
1151 including the following in the source code:
1152 <programlisting language="C"><![CDATA[
1153malloc_conf = "xmalloc:true";]]></programlisting>
1154 This option is disabled by default.</para></listitem>
1155 </varlistentry>
1156
1157 <varlistentry id="opt.tcache">
1158 <term>
1159 <mallctl>opt.tcache</mallctl>
1160 (<type>bool</type>)
1161 <literal>r-</literal>
1162 [<option>--enable-tcache</option>]
1163 </term>
54a0048b
SL
1164 <listitem><para>Thread-specific caching (tcache) enabled/disabled. When
1165 there are multiple threads, each thread uses a tcache for objects up to
1166 a certain size. Thread-specific caching allows many allocations to be
1167 satisfied without performing any thread synchronization, at the cost of
1168 increased memory use. See the <link
970d7e83
LB
1169 linkend="opt.lg_tcache_max"><mallctl>opt.lg_tcache_max</mallctl></link>
1170 option for related tuning information. This option is enabled by
1171 default unless running inside <ulink
1a4d82fc
JJ
1172 url="http://valgrind.org/">Valgrind</ulink>, in which case it is
1173 forcefully disabled.</para></listitem>
970d7e83
LB
1174 </varlistentry>
1175
3b2f2976
XL
1176 <varlistentry id="opt.thp">
1177 <term>
1178 <mallctl>opt.thp</mallctl>
1179 (<type>bool</type>)
1180 <literal>r-</literal>
1181 [<option>--enable-thp</option>]
1182 </term>
1183 <listitem><para>Transparent huge page (THP) integration
1184 enabled/disabled. When enabled, THPs are explicitly disabled as a side
1185 effect of unused dirty page purging for chunks that back small and/or
1186 large allocations, because such chunks typically comprise active,
1187 unused dirty, and untouched clean pages. This option is enabled by
1188 default.</para></listitem>
1189 </varlistentry>
1190
970d7e83
LB
1191 <varlistentry id="opt.lg_tcache_max">
1192 <term>
1193 <mallctl>opt.lg_tcache_max</mallctl>
1194 (<type>size_t</type>)
1195 <literal>r-</literal>
1196 [<option>--enable-tcache</option>]
1197 </term>
1198 <listitem><para>Maximum size class (log base 2) to cache in the
54a0048b
SL
1199 thread-specific cache (tcache). At a minimum, all small size classes
1200 are cached, and at a maximum all large size classes are cached. The
970d7e83
LB
1201 default maximum is 32 KiB (2^15).</para></listitem>
1202 </varlistentry>
1203
1204 <varlistentry id="opt.prof">
1205 <term>
1206 <mallctl>opt.prof</mallctl>
1207 (<type>bool</type>)
1208 <literal>r-</literal>
1209 [<option>--enable-prof</option>]
1210 </term>
1211 <listitem><para>Memory profiling enabled/disabled. If enabled, profile
1212 memory allocation activity. See the <link
1213 linkend="opt.prof_active"><mallctl>opt.prof_active</mallctl></link>
1214 option for on-the-fly activation/deactivation. See the <link
1215 linkend="opt.lg_prof_sample"><mallctl>opt.lg_prof_sample</mallctl></link>
1216 option for probabilistic sampling control. See the <link
1217 linkend="opt.prof_accum"><mallctl>opt.prof_accum</mallctl></link>
1218 option for control of cumulative sample reporting. See the <link
1219 linkend="opt.lg_prof_interval"><mallctl>opt.lg_prof_interval</mallctl></link>
1220 option for information on interval-triggered profile dumping, the <link
1221 linkend="opt.prof_gdump"><mallctl>opt.prof_gdump</mallctl></link>
1222 option for information on high-water-triggered profile dumping, and the
1223 <link linkend="opt.prof_final"><mallctl>opt.prof_final</mallctl></link>
1224 option for final profile dumping. Profile output is compatible with
54a0048b
SL
1225 the <command>jeprof</command> command, which is based on the
1226 <command>pprof</command> that is developed as part of the <ulink
1227 url="http://code.google.com/p/gperftools/">gperftools
1228 package</ulink>. See <link linkend="heap_profile_format">HEAP PROFILE
1229 FORMAT</link> for heap profile format documentation.</para></listitem>
970d7e83
LB
1230 </varlistentry>
1231
1232 <varlistentry id="opt.prof_prefix">
1233 <term>
1234 <mallctl>opt.prof_prefix</mallctl>
1235 (<type>const char *</type>)
1236 <literal>r-</literal>
1237 [<option>--enable-prof</option>]
1238 </term>
1239 <listitem><para>Filename prefix for profile dumps. If the prefix is
1240 set to the empty string, no automatic dumps will occur; this is
1241 primarily useful for disabling the automatic final heap dump (which
1242 also disables leak reporting, if enabled). The default prefix is
1243 <filename>jeprof</filename>.</para></listitem>
1244 </varlistentry>
1245
1246 <varlistentry id="opt.prof_active">
1247 <term>
1248 <mallctl>opt.prof_active</mallctl>
1249 (<type>bool</type>)
54a0048b 1250 <literal>r-</literal>
970d7e83
LB
1251 [<option>--enable-prof</option>]
1252 </term>
1253 <listitem><para>Profiling activated/deactivated. This is a secondary
1254 control mechanism that makes it possible to start the application with
1255 profiling enabled (see the <link
1256 linkend="opt.prof"><mallctl>opt.prof</mallctl></link> option) but
1257 inactive, then toggle profiling at any time during program execution
1258 with the <link
1259 linkend="prof.active"><mallctl>prof.active</mallctl></link> mallctl.
1260 This option is enabled by default.</para></listitem>
1261 </varlistentry>
1262
1a4d82fc
JJ
1263 <varlistentry id="opt.prof_thread_active_init">
1264 <term>
1265 <mallctl>opt.prof_thread_active_init</mallctl>
1266 (<type>bool</type>)
1267 <literal>r-</literal>
1268 [<option>--enable-prof</option>]
1269 </term>
1270 <listitem><para>Initial setting for <link
1271 linkend="thread.prof.active"><mallctl>thread.prof.active</mallctl></link>
1272 in newly created threads. The initial setting for newly created threads
1273 can also be changed during execution via the <link
1274 linkend="prof.thread_active_init"><mallctl>prof.thread_active_init</mallctl></link>
1275 mallctl. This option is enabled by default.</para></listitem>
1276 </varlistentry>
1277
970d7e83
LB
1278 <varlistentry id="opt.lg_prof_sample">
1279 <term>
1280 <mallctl>opt.lg_prof_sample</mallctl>
1a4d82fc 1281 (<type>size_t</type>)
970d7e83
LB
1282 <literal>r-</literal>
1283 [<option>--enable-prof</option>]
1284 </term>
1285 <listitem><para>Average interval (log base 2) between allocation
1286 samples, as measured in bytes of allocation activity. Increasing the
1287 sampling interval decreases profile fidelity, but also decreases the
1288 computational overhead. The default sample interval is 512 KiB (2^19
1289 B).</para></listitem>
1290 </varlistentry>
1291
1292 <varlistentry id="opt.prof_accum">
1293 <term>
1294 <mallctl>opt.prof_accum</mallctl>
1295 (<type>bool</type>)
1296 <literal>r-</literal>
1297 [<option>--enable-prof</option>]
1298 </term>
1299 <listitem><para>Reporting of cumulative object/byte counts in profile
1300 dumps enabled/disabled. If this option is enabled, every unique
1301 backtrace must be stored for the duration of execution. Depending on
1302 the application, this can impose a large memory overhead, and the
1303 cumulative counts are not always of interest. This option is disabled
1304 by default.</para></listitem>
1305 </varlistentry>
1306
1307 <varlistentry id="opt.lg_prof_interval">
1308 <term>
1309 <mallctl>opt.lg_prof_interval</mallctl>
1310 (<type>ssize_t</type>)
1311 <literal>r-</literal>
1312 [<option>--enable-prof</option>]
1313 </term>
1314 <listitem><para>Average interval (log base 2) between memory profile
1315 dumps, as measured in bytes of allocation activity. The actual
1316 interval between dumps may be sporadic because decentralized allocation
1317 counters are used to avoid synchronization bottlenecks. Profiles are
1318 dumped to files named according to the pattern
1319 <filename>&lt;prefix&gt;.&lt;pid&gt;.&lt;seq&gt;.i&lt;iseq&gt;.heap</filename>,
1320 where <literal>&lt;prefix&gt;</literal> is controlled by the
1321 <link
1322 linkend="opt.prof_prefix"><mallctl>opt.prof_prefix</mallctl></link>
1323 option. By default, interval-triggered profile dumping is disabled
1324 (encoded as -1).
1325 </para></listitem>
1326 </varlistentry>
1327
1328 <varlistentry id="opt.prof_gdump">
1329 <term>
1330 <mallctl>opt.prof_gdump</mallctl>
1331 (<type>bool</type>)
1332 <literal>r-</literal>
1333 [<option>--enable-prof</option>]
1334 </term>
54a0048b
SL
1335 <listitem><para>Set the initial state of <link
1336 linkend="prof.gdump"><mallctl>prof.gdump</mallctl></link>, which when
1337 enabled triggers a memory profile dump every time the total virtual
1338 memory exceeds the previous maximum. This option is disabled by
1339 default.</para></listitem>
970d7e83
LB
1340 </varlistentry>
1341
1342 <varlistentry id="opt.prof_final">
1343 <term>
1344 <mallctl>opt.prof_final</mallctl>
1345 (<type>bool</type>)
1346 <literal>r-</literal>
1347 [<option>--enable-prof</option>]
1348 </term>
1349 <listitem><para>Use an
1350 <citerefentry><refentrytitle>atexit</refentrytitle>
1351 <manvolnum>3</manvolnum></citerefentry> function to dump final memory
1352 usage to a file named according to the pattern
1353 <filename>&lt;prefix&gt;.&lt;pid&gt;.&lt;seq&gt;.f.heap</filename>,
1354 where <literal>&lt;prefix&gt;</literal> is controlled by the <link
1355 linkend="opt.prof_prefix"><mallctl>opt.prof_prefix</mallctl></link>
3b2f2976 1356 option. Note that <function>atexit()</function> may allocate
54a0048b 1357 memory during application initialization and then deadlock internally
3b2f2976
XL
1358 when jemalloc in turn calls <function>atexit()</function>, so
1359 this option is not universally usable (though the application can
1360 register its own <function>atexit()</function> function with
54a0048b
SL
1361 equivalent functionality). This option is disabled by
1362 default.</para></listitem>
970d7e83
LB
1363 </varlistentry>
1364
1365 <varlistentry id="opt.prof_leak">
1366 <term>
1367 <mallctl>opt.prof_leak</mallctl>
1368 (<type>bool</type>)
1369 <literal>r-</literal>
1370 [<option>--enable-prof</option>]
1371 </term>
1372 <listitem><para>Leak reporting enabled/disabled. If enabled, use an
1373 <citerefentry><refentrytitle>atexit</refentrytitle>
1374 <manvolnum>3</manvolnum></citerefentry> function to report memory leaks
1375 detected by allocation sampling. See the
1376 <link linkend="opt.prof"><mallctl>opt.prof</mallctl></link> option for
1377 information on analyzing heap profile output. This option is disabled
1378 by default.</para></listitem>
1379 </varlistentry>
1380
1a4d82fc 1381 <varlistentry id="thread.arena">
970d7e83
LB
1382 <term>
1383 <mallctl>thread.arena</mallctl>
1384 (<type>unsigned</type>)
1385 <literal>rw</literal>
1386 </term>
1387 <listitem><para>Get or set the arena associated with the calling
1388 thread. If the specified arena was not initialized beforehand (see the
1389 <link
1390 linkend="arenas.initialized"><mallctl>arenas.initialized</mallctl></link>
1391 mallctl), it will be automatically initialized as a side effect of
1392 calling this interface.</para></listitem>
1393 </varlistentry>
1394
1395 <varlistentry id="thread.allocated">
1396 <term>
1397 <mallctl>thread.allocated</mallctl>
1398 (<type>uint64_t</type>)
1399 <literal>r-</literal>
1400 [<option>--enable-stats</option>]
1401 </term>
1402 <listitem><para>Get the total number of bytes ever allocated by the
1403 calling thread. This counter has the potential to wrap around; it is
1404 up to the application to appropriately interpret the counter in such
1405 cases.</para></listitem>
1406 </varlistentry>
1407
1a4d82fc 1408 <varlistentry id="thread.allocatedp">
970d7e83
LB
1409 <term>
1410 <mallctl>thread.allocatedp</mallctl>
1411 (<type>uint64_t *</type>)
1412 <literal>r-</literal>
1413 [<option>--enable-stats</option>]
1414 </term>
1415 <listitem><para>Get a pointer to the the value that is returned by the
1416 <link
1417 linkend="thread.allocated"><mallctl>thread.allocated</mallctl></link>
1418 mallctl. This is useful for avoiding the overhead of repeated
3b2f2976 1419 <function>mallctl*()</function> calls.</para></listitem>
970d7e83
LB
1420 </varlistentry>
1421
1422 <varlistentry id="thread.deallocated">
1423 <term>
1424 <mallctl>thread.deallocated</mallctl>
1425 (<type>uint64_t</type>)
1426 <literal>r-</literal>
1427 [<option>--enable-stats</option>]
1428 </term>
1429 <listitem><para>Get the total number of bytes ever deallocated by the
1430 calling thread. This counter has the potential to wrap around; it is
1431 up to the application to appropriately interpret the counter in such
1432 cases.</para></listitem>
1433 </varlistentry>
1434
1a4d82fc 1435 <varlistentry id="thread.deallocatedp">
970d7e83
LB
1436 <term>
1437 <mallctl>thread.deallocatedp</mallctl>
1438 (<type>uint64_t *</type>)
1439 <literal>r-</literal>
1440 [<option>--enable-stats</option>]
1441 </term>
1442 <listitem><para>Get a pointer to the the value that is returned by the
1443 <link
1444 linkend="thread.deallocated"><mallctl>thread.deallocated</mallctl></link>
1445 mallctl. This is useful for avoiding the overhead of repeated
3b2f2976 1446 <function>mallctl*()</function> calls.</para></listitem>
970d7e83
LB
1447 </varlistentry>
1448
1a4d82fc 1449 <varlistentry id="thread.tcache.enabled">
970d7e83
LB
1450 <term>
1451 <mallctl>thread.tcache.enabled</mallctl>
1452 (<type>bool</type>)
1453 <literal>rw</literal>
1454 [<option>--enable-tcache</option>]
1455 </term>
1456 <listitem><para>Enable/disable calling thread's tcache. The tcache is
1457 implicitly flushed as a side effect of becoming
1458 disabled (see <link
54a0048b 1459 linkend="thread.tcache.flush"><mallctl>thread.tcache.flush</mallctl></link>).
970d7e83
LB
1460 </para></listitem>
1461 </varlistentry>
1462
1a4d82fc 1463 <varlistentry id="thread.tcache.flush">
970d7e83
LB
1464 <term>
1465 <mallctl>thread.tcache.flush</mallctl>
1466 (<type>void</type>)
1467 <literal>--</literal>
1468 [<option>--enable-tcache</option>]
1469 </term>
54a0048b
SL
1470 <listitem><para>Flush calling thread's thread-specific cache (tcache).
1471 This interface releases all cached objects and internal data structures
1472 associated with the calling thread's tcache. Ordinarily, this interface
970d7e83
LB
1473 need not be called, since automatic periodic incremental garbage
1474 collection occurs, and the thread cache is automatically discarded when
1475 a thread exits. However, garbage collection is triggered by allocation
1476 activity, so it is possible for a thread that stops
1477 allocating/deallocating to retain its cache indefinitely, in which case
1478 the developer may find manual flushing useful.</para></listitem>
1479 </varlistentry>
1480
1a4d82fc
JJ
1481 <varlistentry id="thread.prof.name">
1482 <term>
1483 <mallctl>thread.prof.name</mallctl>
1484 (<type>const char *</type>)
1485 <literal>r-</literal> or
1486 <literal>-w</literal>
1487 [<option>--enable-prof</option>]
1488 </term>
1489 <listitem><para>Get/set the descriptive name associated with the calling
1490 thread in memory profile dumps. An internal copy of the name string is
1491 created, so the input string need not be maintained after this interface
1492 completes execution. The output string of this interface should be
1493 copied for non-ephemeral uses, because multiple implementation details
1494 can cause asynchronous string deallocation. Furthermore, each
1495 invocation of this interface can only read or write; simultaneous
1496 read/write is not supported due to string lifetime limitations. The
54a0048b
SL
1497 name string must be nil-terminated and comprised only of characters in
1498 the sets recognized
1a4d82fc
JJ
1499 by <citerefentry><refentrytitle>isgraph</refentrytitle>
1500 <manvolnum>3</manvolnum></citerefentry> and
1501 <citerefentry><refentrytitle>isblank</refentrytitle>
1502 <manvolnum>3</manvolnum></citerefentry>.</para></listitem>
1503 </varlistentry>
1504
1505 <varlistentry id="thread.prof.active">
1506 <term>
1507 <mallctl>thread.prof.active</mallctl>
1508 (<type>bool</type>)
1509 <literal>rw</literal>
1510 [<option>--enable-prof</option>]
1511 </term>
1512 <listitem><para>Control whether sampling is currently active for the
1513 calling thread. This is an activation mechanism in addition to <link
1514 linkend="prof.active"><mallctl>prof.active</mallctl></link>; both must
1515 be active for the calling thread to sample. This flag is enabled by
1516 default.</para></listitem>
1517 </varlistentry>
1518
54a0048b
SL
1519 <varlistentry id="tcache.create">
1520 <term>
1521 <mallctl>tcache.create</mallctl>
1522 (<type>unsigned</type>)
1523 <literal>r-</literal>
1524 [<option>--enable-tcache</option>]
1525 </term>
1526 <listitem><para>Create an explicit thread-specific cache (tcache) and
1527 return an identifier that can be passed to the <link
1528 linkend="MALLOCX_TCACHE"><constant>MALLOCX_TCACHE(<parameter>tc</parameter>)</constant></link>
1529 macro to explicitly use the specified cache rather than the
1530 automatically managed one that is used by default. Each explicit cache
1531 can be used by only one thread at a time; the application must assure
1532 that this constraint holds.
1533 </para></listitem>
1534 </varlistentry>
1535
1536 <varlistentry id="tcache.flush">
1537 <term>
1538 <mallctl>tcache.flush</mallctl>
1539 (<type>unsigned</type>)
1540 <literal>-w</literal>
1541 [<option>--enable-tcache</option>]
1542 </term>
1543 <listitem><para>Flush the specified thread-specific cache (tcache). The
1544 same considerations apply to this interface as to <link
1545 linkend="thread.tcache.flush"><mallctl>thread.tcache.flush</mallctl></link>,
1546 except that the tcache will never be automatically discarded.
1547 </para></listitem>
1548 </varlistentry>
1549
1550 <varlistentry id="tcache.destroy">
1551 <term>
1552 <mallctl>tcache.destroy</mallctl>
1553 (<type>unsigned</type>)
1554 <literal>-w</literal>
1555 [<option>--enable-tcache</option>]
1556 </term>
1557 <listitem><para>Flush the specified thread-specific cache (tcache) and
1558 make the identifier available for use during a future tcache creation.
1559 </para></listitem>
1560 </varlistentry>
1561
970d7e83
LB
1562 <varlistentry id="arena.i.purge">
1563 <term>
1564 <mallctl>arena.&lt;i&gt;.purge</mallctl>
1a4d82fc 1565 (<type>void</type>)
970d7e83
LB
1566 <literal>--</literal>
1567 </term>
54a0048b 1568 <listitem><para>Purge all unused dirty pages for arena &lt;i&gt;, or for
970d7e83
LB
1569 all arenas if &lt;i&gt; equals <link
1570 linkend="arenas.narenas"><mallctl>arenas.narenas</mallctl></link>.
1571 </para></listitem>
1572 </varlistentry>
1573
54a0048b
SL
1574 <varlistentry id="arena.i.decay">
1575 <term>
1576 <mallctl>arena.&lt;i&gt;.decay</mallctl>
1577 (<type>void</type>)
1578 <literal>--</literal>
1579 </term>
1580 <listitem><para>Trigger decay-based purging of unused dirty pages for
1581 arena &lt;i&gt;, or for all arenas if &lt;i&gt; equals <link
1582 linkend="arenas.narenas"><mallctl>arenas.narenas</mallctl></link>.
1583 The proportion of unused dirty pages to be purged depends on the current
1584 time; see <link
1585 linkend="opt.decay_time"><mallctl>opt.decay_time</mallctl></link> for
1586 details.</para></listitem>
1587 </varlistentry>
1588
3b2f2976
XL
1589 <varlistentry id="arena.i.reset">
1590 <term>
1591 <mallctl>arena.&lt;i&gt;.reset</mallctl>
1592 (<type>void</type>)
1593 <literal>--</literal>
1594 </term>
1595 <listitem><para>Discard all of the arena's extant allocations. This
1596 interface can only be used with arenas created via <link
1597 linkend="arenas.extend"><mallctl>arenas.extend</mallctl></link>. None
1598 of the arena's discarded/cached allocations may accessed afterward. As
1599 part of this requirement, all thread caches which were used to
1600 allocate/deallocate in conjunction with the arena must be flushed
1601 beforehand. This interface cannot be used if running inside Valgrind,
1602 nor if the <link linkend="opt.quarantine">quarantine</link> size is
1603 non-zero.</para></listitem>
1604 </varlistentry>
1605
970d7e83
LB
1606 <varlistentry id="arena.i.dss">
1607 <term>
1608 <mallctl>arena.&lt;i&gt;.dss</mallctl>
1609 (<type>const char *</type>)
1610 <literal>rw</literal>
1611 </term>
1612 <listitem><para>Set the precedence of dss allocation as related to mmap
1613 allocation for arena &lt;i&gt;, or for all arenas if &lt;i&gt; equals
1614 <link
1615 linkend="arenas.narenas"><mallctl>arenas.narenas</mallctl></link>. See
1616 <link linkend="opt.dss"><mallctl>opt.dss</mallctl></link> for supported
1a4d82fc
JJ
1617 settings.</para></listitem>
1618 </varlistentry>
1619
54a0048b
SL
1620 <varlistentry id="arena.i.lg_dirty_mult">
1621 <term>
1622 <mallctl>arena.&lt;i&gt;.lg_dirty_mult</mallctl>
1623 (<type>ssize_t</type>)
1624 <literal>rw</literal>
1625 </term>
1626 <listitem><para>Current per-arena minimum ratio (log base 2) of active
1627 to dirty pages for arena &lt;i&gt;. Each time this interface is set and
1628 the ratio is increased, pages are synchronously purged as necessary to
1629 impose the new ratio. See <link
1630 linkend="opt.lg_dirty_mult"><mallctl>opt.lg_dirty_mult</mallctl></link>
1631 for additional information.</para></listitem>
1632 </varlistentry>
1633
1634 <varlistentry id="arena.i.decay_time">
1635 <term>
1636 <mallctl>arena.&lt;i&gt;.decay_time</mallctl>
1637 (<type>ssize_t</type>)
1638 <literal>rw</literal>
1639 </term>
1640 <listitem><para>Current per-arena approximate time in seconds from the
1641 creation of a set of unused dirty pages until an equivalent set of
1642 unused dirty pages is purged and/or reused. Each time this interface is
1643 set, all currently unused dirty pages are considered to have fully
1644 decayed, which causes immediate purging of all unused dirty pages unless
1645 the decay time is set to -1 (i.e. purging disabled). See <link
1646 linkend="opt.decay_time"><mallctl>opt.decay_time</mallctl></link> for
1647 additional information.</para></listitem>
1648 </varlistentry>
1649
1650 <varlistentry id="arena.i.chunk_hooks">
1a4d82fc 1651 <term>
54a0048b
SL
1652 <mallctl>arena.&lt;i&gt;.chunk_hooks</mallctl>
1653 (<type>chunk_hooks_t</type>)
1a4d82fc
JJ
1654 <literal>rw</literal>
1655 </term>
54a0048b
SL
1656 <listitem><para>Get or set the chunk management hook functions for arena
1657 &lt;i&gt;. The functions must be capable of operating on all extant
1658 chunks associated with arena &lt;i&gt;, usually by passing unknown
1659 chunks to the replaced functions. In practice, it is feasible to
1660 control allocation for arenas created via <link
1661 linkend="arenas.extend"><mallctl>arenas.extend</mallctl></link> such
1662 that all chunks originate from an application-supplied chunk allocator
1663 (by setting custom chunk hook functions just after arena creation), but
1664 the automatically created arenas may have already created chunks prior
1665 to the application having an opportunity to take over chunk
1666 allocation.</para>
1667
1668 <programlisting language="C"><![CDATA[
1669typedef struct {
1670 chunk_alloc_t *alloc;
1671 chunk_dalloc_t *dalloc;
1672 chunk_commit_t *commit;
1673 chunk_decommit_t *decommit;
1674 chunk_purge_t *purge;
1675 chunk_split_t *split;
1676 chunk_merge_t *merge;
1677} chunk_hooks_t;]]></programlisting>
1678 <para>The <type>chunk_hooks_t</type> structure comprises function
1679 pointers which are described individually below. jemalloc uses these
1680 functions to manage chunk lifetime, which starts off with allocation of
1681 mapped committed memory, in the simplest case followed by deallocation.
1682 However, there are performance and platform reasons to retain chunks for
1683 later reuse. Cleanup attempts cascade from deallocation to decommit to
1684 purging, which gives the chunk management functions opportunities to
1685 reject the most permanent cleanup operations in favor of less permanent
1686 (and often less costly) operations. The chunk splitting and merging
1687 operations can also be opted out of, but this is mainly intended to
1688 support platforms on which virtual memory mappings provided by the
1689 operating system kernel do not automatically coalesce and split, e.g.
1690 Windows.</para>
1691
1a4d82fc
JJ
1692 <funcsynopsis><funcprototype>
1693 <funcdef>typedef void *<function>(chunk_alloc_t)</function></funcdef>
1694 <paramdef>void *<parameter>chunk</parameter></paramdef>
1695 <paramdef>size_t <parameter>size</parameter></paramdef>
1696 <paramdef>size_t <parameter>alignment</parameter></paramdef>
1697 <paramdef>bool *<parameter>zero</parameter></paramdef>
54a0048b 1698 <paramdef>bool *<parameter>commit</parameter></paramdef>
1a4d82fc
JJ
1699 <paramdef>unsigned <parameter>arena_ind</parameter></paramdef>
1700 </funcprototype></funcsynopsis>
54a0048b
SL
1701 <literallayout></literallayout>
1702 <para>A chunk allocation function conforms to the
1703 <type>chunk_alloc_t</type> type and upon success returns a pointer to
1704 <parameter>size</parameter> bytes of mapped memory on behalf of arena
1705 <parameter>arena_ind</parameter> such that the chunk's base address is a
1706 multiple of <parameter>alignment</parameter>, as well as setting
1707 <parameter>*zero</parameter> to indicate whether the chunk is zeroed and
1708 <parameter>*commit</parameter> to indicate whether the chunk is
1709 committed. Upon error the function returns <constant>NULL</constant>
1710 and leaves <parameter>*zero</parameter> and
1711 <parameter>*commit</parameter> unmodified. The
1a4d82fc
JJ
1712 <parameter>size</parameter> parameter is always a multiple of the chunk
1713 size. The <parameter>alignment</parameter> parameter is always a power
1714 of two at least as large as the chunk size. Zeroing is mandatory if
54a0048b
SL
1715 <parameter>*zero</parameter> is true upon function entry. Committing is
1716 mandatory if <parameter>*commit</parameter> is true upon function entry.
1717 If <parameter>chunk</parameter> is not <constant>NULL</constant>, the
1718 returned pointer must be <parameter>chunk</parameter> on success or
1719 <constant>NULL</constant> on error. Committed memory may be committed
1720 in absolute terms as on a system that does not overcommit, or in
1721 implicit terms as on a system that overcommits and satisfies physical
1722 memory needs on demand via soft page faults. Note that replacing the
1723 default chunk allocation function makes the arena's <link
1a4d82fc 1724 linkend="arena.i.dss"><mallctl>arena.&lt;i&gt;.dss</mallctl></link>
54a0048b 1725 setting irrelevant.</para>
1a4d82fc 1726
1a4d82fc 1727 <funcsynopsis><funcprototype>
54a0048b 1728 <funcdef>typedef bool <function>(chunk_dalloc_t)</function></funcdef>
1a4d82fc
JJ
1729 <paramdef>void *<parameter>chunk</parameter></paramdef>
1730 <paramdef>size_t <parameter>size</parameter></paramdef>
54a0048b 1731 <paramdef>bool <parameter>committed</parameter></paramdef>
1a4d82fc
JJ
1732 <paramdef>unsigned <parameter>arena_ind</parameter></paramdef>
1733 </funcprototype></funcsynopsis>
54a0048b
SL
1734 <literallayout></literallayout>
1735 <para>
1a4d82fc
JJ
1736 A chunk deallocation function conforms to the
1737 <type>chunk_dalloc_t</type> type and deallocates a
54a0048b
SL
1738 <parameter>chunk</parameter> of given <parameter>size</parameter> with
1739 <parameter>committed</parameter>/decommited memory as indicated, on
1740 behalf of arena <parameter>arena_ind</parameter>, returning false upon
1741 success. If the function returns true, this indicates opt-out from
1742 deallocation; the virtual memory mapping associated with the chunk
1743 remains mapped, in the same commit state, and available for future use,
1744 in which case it will be automatically retained for later reuse.</para>
1745
1746 <funcsynopsis><funcprototype>
1747 <funcdef>typedef bool <function>(chunk_commit_t)</function></funcdef>
1748 <paramdef>void *<parameter>chunk</parameter></paramdef>
1749 <paramdef>size_t <parameter>size</parameter></paramdef>
1750 <paramdef>size_t <parameter>offset</parameter></paramdef>
1751 <paramdef>size_t <parameter>length</parameter></paramdef>
1752 <paramdef>unsigned <parameter>arena_ind</parameter></paramdef>
1753 </funcprototype></funcsynopsis>
1754 <literallayout></literallayout>
1755 <para>A chunk commit function conforms to the
1756 <type>chunk_commit_t</type> type and commits zeroed physical memory to
1757 back pages within a <parameter>chunk</parameter> of given
1758 <parameter>size</parameter> at <parameter>offset</parameter> bytes,
1759 extending for <parameter>length</parameter> on behalf of arena
1760 <parameter>arena_ind</parameter>, returning false upon success.
1761 Committed memory may be committed in absolute terms as on a system that
1762 does not overcommit, or in implicit terms as on a system that
1763 overcommits and satisfies physical memory needs on demand via soft page
1764 faults. If the function returns true, this indicates insufficient
1765 physical memory to satisfy the request.</para>
1766
1767 <funcsynopsis><funcprototype>
1768 <funcdef>typedef bool <function>(chunk_decommit_t)</function></funcdef>
1769 <paramdef>void *<parameter>chunk</parameter></paramdef>
1770 <paramdef>size_t <parameter>size</parameter></paramdef>
1771 <paramdef>size_t <parameter>offset</parameter></paramdef>
1772 <paramdef>size_t <parameter>length</parameter></paramdef>
1773 <paramdef>unsigned <parameter>arena_ind</parameter></paramdef>
1774 </funcprototype></funcsynopsis>
1775 <literallayout></literallayout>
1776 <para>A chunk decommit function conforms to the
1777 <type>chunk_decommit_t</type> type and decommits any physical memory
1778 that is backing pages within a <parameter>chunk</parameter> of given
1779 <parameter>size</parameter> at <parameter>offset</parameter> bytes,
1780 extending for <parameter>length</parameter> on behalf of arena
1781 <parameter>arena_ind</parameter>, returning false upon success, in which
1782 case the pages will be committed via the chunk commit function before
1783 being reused. If the function returns true, this indicates opt-out from
1784 decommit; the memory remains committed and available for future use, in
1785 which case it will be automatically retained for later reuse.</para>
1786
1787 <funcsynopsis><funcprototype>
1788 <funcdef>typedef bool <function>(chunk_purge_t)</function></funcdef>
1789 <paramdef>void *<parameter>chunk</parameter></paramdef>
1790 <paramdef>size_t<parameter>size</parameter></paramdef>
1791 <paramdef>size_t <parameter>offset</parameter></paramdef>
1792 <paramdef>size_t <parameter>length</parameter></paramdef>
1793 <paramdef>unsigned <parameter>arena_ind</parameter></paramdef>
1794 </funcprototype></funcsynopsis>
1795 <literallayout></literallayout>
1796 <para>A chunk purge function conforms to the <type>chunk_purge_t</type>
1797 type and optionally discards physical pages within the virtual memory
1798 mapping associated with <parameter>chunk</parameter> of given
1799 <parameter>size</parameter> at <parameter>offset</parameter> bytes,
1800 extending for <parameter>length</parameter> on behalf of arena
1801 <parameter>arena_ind</parameter>, returning false if pages within the
1802 purged virtual memory range will be zero-filled the next time they are
1803 accessed.</para>
1804
1805 <funcsynopsis><funcprototype>
1806 <funcdef>typedef bool <function>(chunk_split_t)</function></funcdef>
1807 <paramdef>void *<parameter>chunk</parameter></paramdef>
1808 <paramdef>size_t <parameter>size</parameter></paramdef>
1809 <paramdef>size_t <parameter>size_a</parameter></paramdef>
1810 <paramdef>size_t <parameter>size_b</parameter></paramdef>
1811 <paramdef>bool <parameter>committed</parameter></paramdef>
1812 <paramdef>unsigned <parameter>arena_ind</parameter></paramdef>
1813 </funcprototype></funcsynopsis>
1814 <literallayout></literallayout>
1815 <para>A chunk split function conforms to the <type>chunk_split_t</type>
1816 type and optionally splits <parameter>chunk</parameter> of given
1817 <parameter>size</parameter> into two adjacent chunks, the first of
1818 <parameter>size_a</parameter> bytes, and the second of
1819 <parameter>size_b</parameter> bytes, operating on
1820 <parameter>committed</parameter>/decommitted memory as indicated, on
1821 behalf of arena <parameter>arena_ind</parameter>, returning false upon
1822 success. If the function returns true, this indicates that the chunk
1823 remains unsplit and therefore should continue to be operated on as a
1824 whole.</para>
1825
1826 <funcsynopsis><funcprototype>
1827 <funcdef>typedef bool <function>(chunk_merge_t)</function></funcdef>
1828 <paramdef>void *<parameter>chunk_a</parameter></paramdef>
1829 <paramdef>size_t <parameter>size_a</parameter></paramdef>
1830 <paramdef>void *<parameter>chunk_b</parameter></paramdef>
1831 <paramdef>size_t <parameter>size_b</parameter></paramdef>
1832 <paramdef>bool <parameter>committed</parameter></paramdef>
1833 <paramdef>unsigned <parameter>arena_ind</parameter></paramdef>
1834 </funcprototype></funcsynopsis>
1835 <literallayout></literallayout>
1836 <para>A chunk merge function conforms to the <type>chunk_merge_t</type>
1837 type and optionally merges adjacent chunks,
1838 <parameter>chunk_a</parameter> of given <parameter>size_a</parameter>
1839 and <parameter>chunk_b</parameter> of given
1840 <parameter>size_b</parameter> into one contiguous chunk, operating on
1841 <parameter>committed</parameter>/decommitted memory as indicated, on
1842 behalf of arena <parameter>arena_ind</parameter>, returning false upon
1843 success. If the function returns true, this indicates that the chunks
1844 remain distinct mappings and therefore should continue to be operated on
1845 independently.</para>
1846 </listitem>
970d7e83
LB
1847 </varlistentry>
1848
1849 <varlistentry id="arenas.narenas">
1850 <term>
1851 <mallctl>arenas.narenas</mallctl>
1852 (<type>unsigned</type>)
1853 <literal>r-</literal>
1854 </term>
1855 <listitem><para>Current limit on number of arenas.</para></listitem>
1856 </varlistentry>
1857
1858 <varlistentry id="arenas.initialized">
1859 <term>
1860 <mallctl>arenas.initialized</mallctl>
1861 (<type>bool *</type>)
1862 <literal>r-</literal>
1863 </term>
1864 <listitem><para>An array of <link
1865 linkend="arenas.narenas"><mallctl>arenas.narenas</mallctl></link>
1866 booleans. Each boolean indicates whether the corresponding arena is
1867 initialized.</para></listitem>
1868 </varlistentry>
1869
54a0048b
SL
1870 <varlistentry id="arenas.lg_dirty_mult">
1871 <term>
1872 <mallctl>arenas.lg_dirty_mult</mallctl>
1873 (<type>ssize_t</type>)
1874 <literal>rw</literal>
1875 </term>
1876 <listitem><para>Current default per-arena minimum ratio (log base 2) of
1877 active to dirty pages, used to initialize <link
1878 linkend="arena.i.lg_dirty_mult"><mallctl>arena.&lt;i&gt;.lg_dirty_mult</mallctl></link>
1879 during arena creation. See <link
1880 linkend="opt.lg_dirty_mult"><mallctl>opt.lg_dirty_mult</mallctl></link>
1881 for additional information.</para></listitem>
1882 </varlistentry>
1883
1884 <varlistentry id="arenas.decay_time">
1885 <term>
1886 <mallctl>arenas.decay_time</mallctl>
1887 (<type>ssize_t</type>)
1888 <literal>rw</literal>
1889 </term>
1890 <listitem><para>Current default per-arena approximate time in seconds
1891 from the creation of a set of unused dirty pages until an equivalent set
1892 of unused dirty pages is purged and/or reused, used to initialize <link
1893 linkend="arena.i.decay_time"><mallctl>arena.&lt;i&gt;.decay_time</mallctl></link>
1894 during arena creation. See <link
1895 linkend="opt.decay_time"><mallctl>opt.decay_time</mallctl></link> for
1896 additional information.</para></listitem>
1897 </varlistentry>
1898
1a4d82fc 1899 <varlistentry id="arenas.quantum">
970d7e83
LB
1900 <term>
1901 <mallctl>arenas.quantum</mallctl>
1902 (<type>size_t</type>)
1903 <literal>r-</literal>
1904 </term>
1905 <listitem><para>Quantum size.</para></listitem>
1906 </varlistentry>
1907
1a4d82fc 1908 <varlistentry id="arenas.page">
970d7e83
LB
1909 <term>
1910 <mallctl>arenas.page</mallctl>
1911 (<type>size_t</type>)
1912 <literal>r-</literal>
1913 </term>
1914 <listitem><para>Page size.</para></listitem>
1915 </varlistentry>
1916
1a4d82fc 1917 <varlistentry id="arenas.tcache_max">
970d7e83
LB
1918 <term>
1919 <mallctl>arenas.tcache_max</mallctl>
1920 (<type>size_t</type>)
1921 <literal>r-</literal>
1922 [<option>--enable-tcache</option>]
1923 </term>
1924 <listitem><para>Maximum thread-cached size class.</para></listitem>
1925 </varlistentry>
1926
1a4d82fc 1927 <varlistentry id="arenas.nbins">
970d7e83
LB
1928 <term>
1929 <mallctl>arenas.nbins</mallctl>
1930 (<type>unsigned</type>)
1931 <literal>r-</literal>
1932 </term>
1933 <listitem><para>Number of bin size classes.</para></listitem>
1934 </varlistentry>
1935
1a4d82fc 1936 <varlistentry id="arenas.nhbins">
970d7e83
LB
1937 <term>
1938 <mallctl>arenas.nhbins</mallctl>
1939 (<type>unsigned</type>)
1940 <literal>r-</literal>
1941 [<option>--enable-tcache</option>]
1942 </term>
1943 <listitem><para>Total number of thread cache bin size
1944 classes.</para></listitem>
1945 </varlistentry>
1946
1947 <varlistentry id="arenas.bin.i.size">
1948 <term>
1949 <mallctl>arenas.bin.&lt;i&gt;.size</mallctl>
1950 (<type>size_t</type>)
1951 <literal>r-</literal>
1952 </term>
1953 <listitem><para>Maximum size supported by size class.</para></listitem>
1954 </varlistentry>
1955
1a4d82fc 1956 <varlistentry id="arenas.bin.i.nregs">
970d7e83
LB
1957 <term>
1958 <mallctl>arenas.bin.&lt;i&gt;.nregs</mallctl>
1959 (<type>uint32_t</type>)
1960 <literal>r-</literal>
1961 </term>
1962 <listitem><para>Number of regions per page run.</para></listitem>
1963 </varlistentry>
1964
1a4d82fc 1965 <varlistentry id="arenas.bin.i.run_size">
970d7e83
LB
1966 <term>
1967 <mallctl>arenas.bin.&lt;i&gt;.run_size</mallctl>
1968 (<type>size_t</type>)
1969 <literal>r-</literal>
1970 </term>
1971 <listitem><para>Number of bytes per page run.</para></listitem>
1972 </varlistentry>
1973
1a4d82fc 1974 <varlistentry id="arenas.nlruns">
970d7e83
LB
1975 <term>
1976 <mallctl>arenas.nlruns</mallctl>
54a0048b 1977 (<type>unsigned</type>)
970d7e83
LB
1978 <literal>r-</literal>
1979 </term>
1980 <listitem><para>Total number of large size classes.</para></listitem>
1981 </varlistentry>
1982
1a4d82fc 1983 <varlistentry id="arenas.lrun.i.size">
970d7e83
LB
1984 <term>
1985 <mallctl>arenas.lrun.&lt;i&gt;.size</mallctl>
1986 (<type>size_t</type>)
1987 <literal>r-</literal>
1988 </term>
1989 <listitem><para>Maximum size supported by this large size
1990 class.</para></listitem>
1991 </varlistentry>
1992
54a0048b
SL
1993 <varlistentry id="arenas.nhchunks">
1994 <term>
1995 <mallctl>arenas.nhchunks</mallctl>
1996 (<type>unsigned</type>)
1997 <literal>r-</literal>
1998 </term>
1999 <listitem><para>Total number of huge size classes.</para></listitem>
2000 </varlistentry>
2001
2002 <varlistentry id="arenas.hchunk.i.size">
2003 <term>
2004 <mallctl>arenas.hchunk.&lt;i&gt;.size</mallctl>
2005 (<type>size_t</type>)
2006 <literal>r-</literal>
2007 </term>
2008 <listitem><para>Maximum size supported by this huge size
2009 class.</para></listitem>
2010 </varlistentry>
2011
1a4d82fc 2012 <varlistentry id="arenas.extend">
970d7e83
LB
2013 <term>
2014 <mallctl>arenas.extend</mallctl>
2015 (<type>unsigned</type>)
2016 <literal>r-</literal>
2017 </term>
2018 <listitem><para>Extend the array of arenas by appending a new arena,
2019 and returning the new arena index.</para></listitem>
2020 </varlistentry>
2021
1a4d82fc
JJ
2022 <varlistentry id="prof.thread_active_init">
2023 <term>
2024 <mallctl>prof.thread_active_init</mallctl>
2025 (<type>bool</type>)
2026 <literal>rw</literal>
2027 [<option>--enable-prof</option>]
2028 </term>
2029 <listitem><para>Control the initial setting for <link
2030 linkend="thread.prof.active"><mallctl>thread.prof.active</mallctl></link>
2031 in newly created threads. See the <link
2032 linkend="opt.prof_thread_active_init"><mallctl>opt.prof_thread_active_init</mallctl></link>
2033 option for additional information.</para></listitem>
2034 </varlistentry>
2035
970d7e83
LB
2036 <varlistentry id="prof.active">
2037 <term>
2038 <mallctl>prof.active</mallctl>
2039 (<type>bool</type>)
2040 <literal>rw</literal>
2041 [<option>--enable-prof</option>]
2042 </term>
2043 <listitem><para>Control whether sampling is currently active. See the
2044 <link
2045 linkend="opt.prof_active"><mallctl>opt.prof_active</mallctl></link>
1a4d82fc
JJ
2046 option for additional information, as well as the interrelated <link
2047 linkend="thread.prof.active"><mallctl>thread.prof.active</mallctl></link>
2048 mallctl.</para></listitem>
970d7e83
LB
2049 </varlistentry>
2050
1a4d82fc 2051 <varlistentry id="prof.dump">
970d7e83
LB
2052 <term>
2053 <mallctl>prof.dump</mallctl>
2054 (<type>const char *</type>)
2055 <literal>-w</literal>
2056 [<option>--enable-prof</option>]
2057 </term>
2058 <listitem><para>Dump a memory profile to the specified file, or if NULL
2059 is specified, to a file according to the pattern
2060 <filename>&lt;prefix&gt;.&lt;pid&gt;.&lt;seq&gt;.m&lt;mseq&gt;.heap</filename>,
2061 where <literal>&lt;prefix&gt;</literal> is controlled by the
2062 <link
2063 linkend="opt.prof_prefix"><mallctl>opt.prof_prefix</mallctl></link>
2064 option.</para></listitem>
2065 </varlistentry>
2066
54a0048b
SL
2067 <varlistentry id="prof.gdump">
2068 <term>
2069 <mallctl>prof.gdump</mallctl>
2070 (<type>bool</type>)
2071 <literal>rw</literal>
2072 [<option>--enable-prof</option>]
2073 </term>
2074 <listitem><para>When enabled, trigger a memory profile dump every time
2075 the total virtual memory exceeds the previous maximum. Profiles are
2076 dumped to files named according to the pattern
2077 <filename>&lt;prefix&gt;.&lt;pid&gt;.&lt;seq&gt;.u&lt;useq&gt;.heap</filename>,
2078 where <literal>&lt;prefix&gt;</literal> is controlled by the <link
2079 linkend="opt.prof_prefix"><mallctl>opt.prof_prefix</mallctl></link>
2080 option.</para></listitem>
2081 </varlistentry>
2082
1a4d82fc
JJ
2083 <varlistentry id="prof.reset">
2084 <term>
2085 <mallctl>prof.reset</mallctl>
2086 (<type>size_t</type>)
2087 <literal>-w</literal>
2088 [<option>--enable-prof</option>]
2089 </term>
2090 <listitem><para>Reset all memory profile statistics, and optionally
2091 update the sample rate (see <link
2092 linkend="opt.lg_prof_sample"><mallctl>opt.lg_prof_sample</mallctl></link>
2093 and <link
2094 linkend="prof.lg_sample"><mallctl>prof.lg_sample</mallctl></link>).
2095 </para></listitem>
2096 </varlistentry>
2097
2098 <varlistentry id="prof.lg_sample">
2099 <term>
2100 <mallctl>prof.lg_sample</mallctl>
2101 (<type>size_t</type>)
2102 <literal>r-</literal>
2103 [<option>--enable-prof</option>]
2104 </term>
2105 <listitem><para>Get the current sample rate (see <link
2106 linkend="opt.lg_prof_sample"><mallctl>opt.lg_prof_sample</mallctl></link>).
2107 </para></listitem>
2108 </varlistentry>
2109
2110 <varlistentry id="prof.interval">
970d7e83
LB
2111 <term>
2112 <mallctl>prof.interval</mallctl>
2113 (<type>uint64_t</type>)
2114 <literal>r-</literal>
2115 [<option>--enable-prof</option>]
2116 </term>
2117 <listitem><para>Average number of bytes allocated between
3b2f2976 2118 interval-based profile dumps. See the
970d7e83
LB
2119 <link
2120 linkend="opt.lg_prof_interval"><mallctl>opt.lg_prof_interval</mallctl></link>
2121 option for additional information.</para></listitem>
2122 </varlistentry>
2123
2124 <varlistentry id="stats.cactive">
2125 <term>
2126 <mallctl>stats.cactive</mallctl>
2127 (<type>size_t *</type>)
2128 <literal>r-</literal>
2129 [<option>--enable-stats</option>]
2130 </term>
2131 <listitem><para>Pointer to a counter that contains an approximate count
2132 of the current number of bytes in active pages. The estimate may be
54a0048b
SL
2133 high, but never low, because each arena rounds up when computing its
2134 contribution to the counter. Note that the <link
970d7e83
LB
2135 linkend="epoch"><mallctl>epoch</mallctl></link> mallctl has no bearing
2136 on this counter. Furthermore, counter consistency is maintained via
2137 atomic operations, so it is necessary to use an atomic operation in
2138 order to guarantee a consistent read when dereferencing the pointer.
2139 </para></listitem>
2140 </varlistentry>
2141
2142 <varlistentry id="stats.allocated">
2143 <term>
2144 <mallctl>stats.allocated</mallctl>
2145 (<type>size_t</type>)
2146 <literal>r-</literal>
2147 [<option>--enable-stats</option>]
2148 </term>
2149 <listitem><para>Total number of bytes allocated by the
2150 application.</para></listitem>
2151 </varlistentry>
2152
2153 <varlistentry id="stats.active">
2154 <term>
2155 <mallctl>stats.active</mallctl>
2156 (<type>size_t</type>)
2157 <literal>r-</literal>
2158 [<option>--enable-stats</option>]
2159 </term>
2160 <listitem><para>Total number of bytes in active pages allocated by the
2161 application. This is a multiple of the page size, and greater than or
2162 equal to <link
2163 linkend="stats.allocated"><mallctl>stats.allocated</mallctl></link>.
2164 This does not include <link linkend="stats.arenas.i.pdirty">
54a0048b 2165 <mallctl>stats.arenas.&lt;i&gt;.pdirty</mallctl></link>, nor pages
970d7e83
LB
2166 entirely devoted to allocator metadata.</para></listitem>
2167 </varlistentry>
2168
54a0048b 2169 <varlistentry id="stats.metadata">
970d7e83 2170 <term>
54a0048b 2171 <mallctl>stats.metadata</mallctl>
970d7e83
LB
2172 (<type>size_t</type>)
2173 <literal>r-</literal>
2174 [<option>--enable-stats</option>]
2175 </term>
54a0048b
SL
2176 <listitem><para>Total number of bytes dedicated to metadata, which
2177 comprise base allocations used for bootstrap-sensitive internal
2178 allocator data structures, arena chunk headers (see <link
2179 linkend="stats.arenas.i.metadata.mapped"><mallctl>stats.arenas.&lt;i&gt;.metadata.mapped</mallctl></link>),
2180 and internal allocations (see <link
2181 linkend="stats.arenas.i.metadata.allocated"><mallctl>stats.arenas.&lt;i&gt;.metadata.allocated</mallctl></link>).</para></listitem>
970d7e83
LB
2182 </varlistentry>
2183
54a0048b 2184 <varlistentry id="stats.resident">
970d7e83 2185 <term>
54a0048b 2186 <mallctl>stats.resident</mallctl>
970d7e83
LB
2187 (<type>size_t</type>)
2188 <literal>r-</literal>
2189 [<option>--enable-stats</option>]
2190 </term>
54a0048b
SL
2191 <listitem><para>Maximum number of bytes in physically resident data
2192 pages mapped by the allocator, comprising all pages dedicated to
2193 allocator metadata, pages backing active allocations, and unused dirty
2194 pages. This is a maximum rather than precise because pages may not
2195 actually be physically resident if they correspond to demand-zeroed
2196 virtual memory that has not yet been touched. This is a multiple of the
2197 page size, and is larger than <link
2198 linkend="stats.active"><mallctl>stats.active</mallctl></link>.</para></listitem>
7453a54e
SL
2199 </varlistentry>
2200
54a0048b 2201 <varlistentry id="stats.mapped">
7453a54e 2202 <term>
54a0048b 2203 <mallctl>stats.mapped</mallctl>
970d7e83
LB
2204 (<type>size_t</type>)
2205 <literal>r-</literal>
2206 [<option>--enable-stats</option>]
2207 </term>
54a0048b
SL
2208 <listitem><para>Total number of bytes in active chunks mapped by the
2209 allocator. This is a multiple of the chunk size, and is larger than
2210 <link linkend="stats.active"><mallctl>stats.active</mallctl></link>.
2211 This does not include inactive chunks, even those that contain unused
2212 dirty pages, which means that there is no strict ordering between this
2213 and <link
2214 linkend="stats.resident"><mallctl>stats.resident</mallctl></link>.</para></listitem>
970d7e83
LB
2215 </varlistentry>
2216
3b2f2976
XL
2217 <varlistentry id="stats.retained">
2218 <term>
2219 <mallctl>stats.retained</mallctl>
2220 (<type>size_t</type>)
2221 <literal>r-</literal>
2222 [<option>--enable-stats</option>]
2223 </term>
2224 <listitem><para>Total number of bytes in virtual memory mappings that
2225 were retained rather than being returned to the operating system via
2226 e.g. <citerefentry><refentrytitle>munmap</refentrytitle>
2227 <manvolnum>2</manvolnum></citerefentry>. Retained virtual memory is
2228 typically untouched, decommitted, or purged, so it has no strongly
2229 associated physical memory (see <link
2230 linkend="arena.i.chunk_hooks">chunk hooks</link> for details). Retained
2231 memory is excluded from mapped memory statistics, e.g. <link
2232 linkend="stats.mapped"><mallctl>stats.mapped</mallctl></link>.
2233 </para></listitem>
2234 </varlistentry>
2235
1a4d82fc 2236 <varlistentry id="stats.arenas.i.dss">
970d7e83
LB
2237 <term>
2238 <mallctl>stats.arenas.&lt;i&gt;.dss</mallctl>
2239 (<type>const char *</type>)
2240 <literal>r-</literal>
2241 </term>
2242 <listitem><para>dss (<citerefentry><refentrytitle>sbrk</refentrytitle>
2243 <manvolnum>2</manvolnum></citerefentry>) allocation precedence as
2244 related to <citerefentry><refentrytitle>mmap</refentrytitle>
2245 <manvolnum>2</manvolnum></citerefentry> allocation. See <link
2246 linkend="opt.dss"><mallctl>opt.dss</mallctl></link> for details.
2247 </para></listitem>
2248 </varlistentry>
2249
54a0048b
SL
2250 <varlistentry id="stats.arenas.i.lg_dirty_mult">
2251 <term>
2252 <mallctl>stats.arenas.&lt;i&gt;.lg_dirty_mult</mallctl>
2253 (<type>ssize_t</type>)
2254 <literal>r-</literal>
2255 </term>
2256 <listitem><para>Minimum ratio (log base 2) of active to dirty pages.
2257 See <link
2258 linkend="opt.lg_dirty_mult"><mallctl>opt.lg_dirty_mult</mallctl></link>
2259 for details.</para></listitem>
2260 </varlistentry>
2261
2262 <varlistentry id="stats.arenas.i.decay_time">
2263 <term>
2264 <mallctl>stats.arenas.&lt;i&gt;.decay_time</mallctl>
2265 (<type>ssize_t</type>)
2266 <literal>r-</literal>
2267 </term>
2268 <listitem><para>Approximate time in seconds from the creation of a set
2269 of unused dirty pages until an equivalent set of unused dirty pages is
2270 purged and/or reused. See <link
2271 linkend="opt.decay_time"><mallctl>opt.decay_time</mallctl></link>
2272 for details.</para></listitem>
2273 </varlistentry>
2274
1a4d82fc 2275 <varlistentry id="stats.arenas.i.nthreads">
970d7e83
LB
2276 <term>
2277 <mallctl>stats.arenas.&lt;i&gt;.nthreads</mallctl>
2278 (<type>unsigned</type>)
2279 <literal>r-</literal>
2280 </term>
2281 <listitem><para>Number of threads currently assigned to
2282 arena.</para></listitem>
2283 </varlistentry>
2284
1a4d82fc 2285 <varlistentry id="stats.arenas.i.pactive">
970d7e83
LB
2286 <term>
2287 <mallctl>stats.arenas.&lt;i&gt;.pactive</mallctl>
2288 (<type>size_t</type>)
2289 <literal>r-</literal>
2290 </term>
2291 <listitem><para>Number of pages in active runs.</para></listitem>
2292 </varlistentry>
2293
2294 <varlistentry id="stats.arenas.i.pdirty">
2295 <term>
2296 <mallctl>stats.arenas.&lt;i&gt;.pdirty</mallctl>
2297 (<type>size_t</type>)
2298 <literal>r-</literal>
2299 </term>
2300 <listitem><para>Number of pages within unused runs that are potentially
2301 dirty, and for which <function>madvise<parameter>...</parameter>
2302 <parameter><constant>MADV_DONTNEED</constant></parameter></function> or
2303 similar has not been called.</para></listitem>
2304 </varlistentry>
2305
1a4d82fc 2306 <varlistentry id="stats.arenas.i.mapped">
970d7e83
LB
2307 <term>
2308 <mallctl>stats.arenas.&lt;i&gt;.mapped</mallctl>
2309 (<type>size_t</type>)
2310 <literal>r-</literal>
2311 [<option>--enable-stats</option>]
2312 </term>
2313 <listitem><para>Number of mapped bytes.</para></listitem>
2314 </varlistentry>
2315
3b2f2976
XL
2316 <varlistentry id="stats.arenas.i.retained">
2317 <term>
2318 <mallctl>stats.arenas.&lt;i&gt;.retained</mallctl>
2319 (<type>size_t</type>)
2320 <literal>r-</literal>
2321 [<option>--enable-stats</option>]
2322 </term>
2323 <listitem><para>Number of retained bytes. See <link
2324 linkend="stats.retained"><mallctl>stats.retained</mallctl></link> for
2325 details.</para></listitem>
2326 </varlistentry>
2327
54a0048b
SL
2328 <varlistentry id="stats.arenas.i.metadata.mapped">
2329 <term>
2330 <mallctl>stats.arenas.&lt;i&gt;.metadata.mapped</mallctl>
2331 (<type>size_t</type>)
2332 <literal>r-</literal>
2333 [<option>--enable-stats</option>]
2334 </term>
2335 <listitem><para>Number of mapped bytes in arena chunk headers, which
2336 track the states of the non-metadata pages.</para></listitem>
2337 </varlistentry>
2338
2339 <varlistentry id="stats.arenas.i.metadata.allocated">
2340 <term>
2341 <mallctl>stats.arenas.&lt;i&gt;.metadata.allocated</mallctl>
2342 (<type>size_t</type>)
2343 <literal>r-</literal>
2344 [<option>--enable-stats</option>]
2345 </term>
2346 <listitem><para>Number of bytes dedicated to internal allocations.
2347 Internal allocations differ from application-originated allocations in
2348 that they are for internal use, and that they are omitted from heap
2349 profiles. This statistic is reported separately from <link
2350 linkend="stats.metadata"><mallctl>stats.metadata</mallctl></link> and
2351 <link
2352 linkend="stats.arenas.i.metadata.mapped"><mallctl>stats.arenas.&lt;i&gt;.metadata.mapped</mallctl></link>
2353 because it overlaps with e.g. the <link
2354 linkend="stats.allocated"><mallctl>stats.allocated</mallctl></link> and
2355 <link linkend="stats.active"><mallctl>stats.active</mallctl></link>
2356 statistics, whereas the other metadata statistics do
2357 not.</para></listitem>
2358 </varlistentry>
2359
1a4d82fc 2360 <varlistentry id="stats.arenas.i.npurge">
970d7e83
LB
2361 <term>
2362 <mallctl>stats.arenas.&lt;i&gt;.npurge</mallctl>
2363 (<type>uint64_t</type>)
2364 <literal>r-</literal>
2365 [<option>--enable-stats</option>]
2366 </term>
2367 <listitem><para>Number of dirty page purge sweeps performed.
2368 </para></listitem>
2369 </varlistentry>
2370
1a4d82fc 2371 <varlistentry id="stats.arenas.i.nmadvise">
970d7e83
LB
2372 <term>
2373 <mallctl>stats.arenas.&lt;i&gt;.nmadvise</mallctl>
2374 (<type>uint64_t</type>)
2375 <literal>r-</literal>
2376 [<option>--enable-stats</option>]
2377 </term>
2378 <listitem><para>Number of <function>madvise<parameter>...</parameter>
2379 <parameter><constant>MADV_DONTNEED</constant></parameter></function> or
2380 similar calls made to purge dirty pages.</para></listitem>
2381 </varlistentry>
2382
1a4d82fc 2383 <varlistentry id="stats.arenas.i.purged">
970d7e83 2384 <term>
1a4d82fc 2385 <mallctl>stats.arenas.&lt;i&gt;.purged</mallctl>
970d7e83
LB
2386 (<type>uint64_t</type>)
2387 <literal>r-</literal>
2388 [<option>--enable-stats</option>]
2389 </term>
2390 <listitem><para>Number of pages purged.</para></listitem>
2391 </varlistentry>
2392
1a4d82fc 2393 <varlistentry id="stats.arenas.i.small.allocated">
970d7e83
LB
2394 <term>
2395 <mallctl>stats.arenas.&lt;i&gt;.small.allocated</mallctl>
2396 (<type>size_t</type>)
2397 <literal>r-</literal>
2398 [<option>--enable-stats</option>]
2399 </term>
2400 <listitem><para>Number of bytes currently allocated by small objects.
2401 </para></listitem>
2402 </varlistentry>
2403
1a4d82fc 2404 <varlistentry id="stats.arenas.i.small.nmalloc">
970d7e83
LB
2405 <term>
2406 <mallctl>stats.arenas.&lt;i&gt;.small.nmalloc</mallctl>
2407 (<type>uint64_t</type>)
2408 <literal>r-</literal>
2409 [<option>--enable-stats</option>]
2410 </term>
2411 <listitem><para>Cumulative number of allocation requests served by
2412 small bins.</para></listitem>
2413 </varlistentry>
2414
1a4d82fc 2415 <varlistentry id="stats.arenas.i.small.ndalloc">
970d7e83
LB
2416 <term>
2417 <mallctl>stats.arenas.&lt;i&gt;.small.ndalloc</mallctl>
2418 (<type>uint64_t</type>)
2419 <literal>r-</literal>
2420 [<option>--enable-stats</option>]
2421 </term>
2422 <listitem><para>Cumulative number of small objects returned to bins.
2423 </para></listitem>
2424 </varlistentry>
2425
1a4d82fc 2426 <varlistentry id="stats.arenas.i.small.nrequests">
970d7e83
LB
2427 <term>
2428 <mallctl>stats.arenas.&lt;i&gt;.small.nrequests</mallctl>
2429 (<type>uint64_t</type>)
2430 <literal>r-</literal>
2431 [<option>--enable-stats</option>]
2432 </term>
2433 <listitem><para>Cumulative number of small allocation requests.
2434 </para></listitem>
2435 </varlistentry>
2436
1a4d82fc 2437 <varlistentry id="stats.arenas.i.large.allocated">
970d7e83
LB
2438 <term>
2439 <mallctl>stats.arenas.&lt;i&gt;.large.allocated</mallctl>
2440 (<type>size_t</type>)
2441 <literal>r-</literal>
2442 [<option>--enable-stats</option>]
2443 </term>
2444 <listitem><para>Number of bytes currently allocated by large objects.
2445 </para></listitem>
2446 </varlistentry>
2447
1a4d82fc 2448 <varlistentry id="stats.arenas.i.large.nmalloc">
970d7e83
LB
2449 <term>
2450 <mallctl>stats.arenas.&lt;i&gt;.large.nmalloc</mallctl>
2451 (<type>uint64_t</type>)
2452 <literal>r-</literal>
2453 [<option>--enable-stats</option>]
2454 </term>
2455 <listitem><para>Cumulative number of large allocation requests served
2456 directly by the arena.</para></listitem>
2457 </varlistentry>
2458
1a4d82fc 2459 <varlistentry id="stats.arenas.i.large.ndalloc">
970d7e83
LB
2460 <term>
2461 <mallctl>stats.arenas.&lt;i&gt;.large.ndalloc</mallctl>
2462 (<type>uint64_t</type>)
2463 <literal>r-</literal>
2464 [<option>--enable-stats</option>]
2465 </term>
2466 <listitem><para>Cumulative number of large deallocation requests served
2467 directly by the arena.</para></listitem>
2468 </varlistentry>
2469
1a4d82fc 2470 <varlistentry id="stats.arenas.i.large.nrequests">
970d7e83
LB
2471 <term>
2472 <mallctl>stats.arenas.&lt;i&gt;.large.nrequests</mallctl>
2473 (<type>uint64_t</type>)
2474 <literal>r-</literal>
2475 [<option>--enable-stats</option>]
2476 </term>
2477 <listitem><para>Cumulative number of large allocation requests.
2478 </para></listitem>
2479 </varlistentry>
2480
1a4d82fc
JJ
2481 <varlistentry id="stats.arenas.i.huge.allocated">
2482 <term>
2483 <mallctl>stats.arenas.&lt;i&gt;.huge.allocated</mallctl>
2484 (<type>size_t</type>)
2485 <literal>r-</literal>
2486 [<option>--enable-stats</option>]
2487 </term>
2488 <listitem><para>Number of bytes currently allocated by huge objects.
2489 </para></listitem>
2490 </varlistentry>
2491
2492 <varlistentry id="stats.arenas.i.huge.nmalloc">
2493 <term>
2494 <mallctl>stats.arenas.&lt;i&gt;.huge.nmalloc</mallctl>
2495 (<type>uint64_t</type>)
2496 <literal>r-</literal>
2497 [<option>--enable-stats</option>]
2498 </term>
2499 <listitem><para>Cumulative number of huge allocation requests served
2500 directly by the arena.</para></listitem>
2501 </varlistentry>
2502
2503 <varlistentry id="stats.arenas.i.huge.ndalloc">
2504 <term>
2505 <mallctl>stats.arenas.&lt;i&gt;.huge.ndalloc</mallctl>
2506 (<type>uint64_t</type>)
2507 <literal>r-</literal>
2508 [<option>--enable-stats</option>]
2509 </term>
2510 <listitem><para>Cumulative number of huge deallocation requests served
2511 directly by the arena.</para></listitem>
2512 </varlistentry>
2513
2514 <varlistentry id="stats.arenas.i.huge.nrequests">
2515 <term>
2516 <mallctl>stats.arenas.&lt;i&gt;.huge.nrequests</mallctl>
2517 (<type>uint64_t</type>)
2518 <literal>r-</literal>
2519 [<option>--enable-stats</option>]
2520 </term>
2521 <listitem><para>Cumulative number of huge allocation requests.
2522 </para></listitem>
2523 </varlistentry>
2524
1a4d82fc 2525 <varlistentry id="stats.arenas.i.bins.j.nmalloc">
970d7e83
LB
2526 <term>
2527 <mallctl>stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.nmalloc</mallctl>
2528 (<type>uint64_t</type>)
2529 <literal>r-</literal>
2530 [<option>--enable-stats</option>]
2531 </term>
2532 <listitem><para>Cumulative number of allocations served by bin.
2533 </para></listitem>
2534 </varlistentry>
2535
1a4d82fc 2536 <varlistentry id="stats.arenas.i.bins.j.ndalloc">
970d7e83
LB
2537 <term>
2538 <mallctl>stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.ndalloc</mallctl>
2539 (<type>uint64_t</type>)
2540 <literal>r-</literal>
2541 [<option>--enable-stats</option>]
2542 </term>
2543 <listitem><para>Cumulative number of allocations returned to bin.
2544 </para></listitem>
2545 </varlistentry>
2546
1a4d82fc 2547 <varlistentry id="stats.arenas.i.bins.j.nrequests">
970d7e83
LB
2548 <term>
2549 <mallctl>stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.nrequests</mallctl>
2550 (<type>uint64_t</type>)
2551 <literal>r-</literal>
2552 [<option>--enable-stats</option>]
2553 </term>
2554 <listitem><para>Cumulative number of allocation
2555 requests.</para></listitem>
2556 </varlistentry>
2557
54a0048b
SL
2558 <varlistentry id="stats.arenas.i.bins.j.curregs">
2559 <term>
2560 <mallctl>stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.curregs</mallctl>
2561 (<type>size_t</type>)
2562 <literal>r-</literal>
2563 [<option>--enable-stats</option>]
2564 </term>
2565 <listitem><para>Current number of regions for this size
2566 class.</para></listitem>
2567 </varlistentry>
2568
1a4d82fc 2569 <varlistentry id="stats.arenas.i.bins.j.nfills">
970d7e83
LB
2570 <term>
2571 <mallctl>stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.nfills</mallctl>
2572 (<type>uint64_t</type>)
2573 <literal>r-</literal>
2574 [<option>--enable-stats</option> <option>--enable-tcache</option>]
2575 </term>
2576 <listitem><para>Cumulative number of tcache fills.</para></listitem>
2577 </varlistentry>
2578
1a4d82fc 2579 <varlistentry id="stats.arenas.i.bins.j.nflushes">
970d7e83
LB
2580 <term>
2581 <mallctl>stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.nflushes</mallctl>
2582 (<type>uint64_t</type>)
2583 <literal>r-</literal>
2584 [<option>--enable-stats</option> <option>--enable-tcache</option>]
2585 </term>
2586 <listitem><para>Cumulative number of tcache flushes.</para></listitem>
2587 </varlistentry>
2588
1a4d82fc 2589 <varlistentry id="stats.arenas.i.bins.j.nruns">
970d7e83
LB
2590 <term>
2591 <mallctl>stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.nruns</mallctl>
2592 (<type>uint64_t</type>)
2593 <literal>r-</literal>
2594 [<option>--enable-stats</option>]
2595 </term>
2596 <listitem><para>Cumulative number of runs created.</para></listitem>
2597 </varlistentry>
2598
1a4d82fc 2599 <varlistentry id="stats.arenas.i.bins.j.nreruns">
970d7e83
LB
2600 <term>
2601 <mallctl>stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.nreruns</mallctl>
2602 (<type>uint64_t</type>)
2603 <literal>r-</literal>
2604 [<option>--enable-stats</option>]
2605 </term>
2606 <listitem><para>Cumulative number of times the current run from which
2607 to allocate changed.</para></listitem>
2608 </varlistentry>
2609
1a4d82fc 2610 <varlistentry id="stats.arenas.i.bins.j.curruns">
970d7e83
LB
2611 <term>
2612 <mallctl>stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.curruns</mallctl>
2613 (<type>size_t</type>)
2614 <literal>r-</literal>
2615 [<option>--enable-stats</option>]
2616 </term>
2617 <listitem><para>Current number of runs.</para></listitem>
2618 </varlistentry>
2619
1a4d82fc 2620 <varlistentry id="stats.arenas.i.lruns.j.nmalloc">
970d7e83
LB
2621 <term>
2622 <mallctl>stats.arenas.&lt;i&gt;.lruns.&lt;j&gt;.nmalloc</mallctl>
2623 (<type>uint64_t</type>)
2624 <literal>r-</literal>
2625 [<option>--enable-stats</option>]
2626 </term>
2627 <listitem><para>Cumulative number of allocation requests for this size
2628 class served directly by the arena.</para></listitem>
2629 </varlistentry>
2630
1a4d82fc 2631 <varlistentry id="stats.arenas.i.lruns.j.ndalloc">
970d7e83
LB
2632 <term>
2633 <mallctl>stats.arenas.&lt;i&gt;.lruns.&lt;j&gt;.ndalloc</mallctl>
2634 (<type>uint64_t</type>)
2635 <literal>r-</literal>
2636 [<option>--enable-stats</option>]
2637 </term>
2638 <listitem><para>Cumulative number of deallocation requests for this
2639 size class served directly by the arena.</para></listitem>
2640 </varlistentry>
2641
1a4d82fc 2642 <varlistentry id="stats.arenas.i.lruns.j.nrequests">
970d7e83
LB
2643 <term>
2644 <mallctl>stats.arenas.&lt;i&gt;.lruns.&lt;j&gt;.nrequests</mallctl>
2645 (<type>uint64_t</type>)
2646 <literal>r-</literal>
2647 [<option>--enable-stats</option>]
2648 </term>
2649 <listitem><para>Cumulative number of allocation requests for this size
2650 class.</para></listitem>
2651 </varlistentry>
2652
1a4d82fc 2653 <varlistentry id="stats.arenas.i.lruns.j.curruns">
970d7e83
LB
2654 <term>
2655 <mallctl>stats.arenas.&lt;i&gt;.lruns.&lt;j&gt;.curruns</mallctl>
2656 (<type>size_t</type>)
2657 <literal>r-</literal>
2658 [<option>--enable-stats</option>]
2659 </term>
2660 <listitem><para>Current number of runs for this size class.
2661 </para></listitem>
2662 </varlistentry>
54a0048b
SL
2663
2664 <varlistentry id="stats.arenas.i.hchunks.j.nmalloc">
2665 <term>
2666 <mallctl>stats.arenas.&lt;i&gt;.hchunks.&lt;j&gt;.nmalloc</mallctl>
2667 (<type>uint64_t</type>)
2668 <literal>r-</literal>
2669 [<option>--enable-stats</option>]
2670 </term>
2671 <listitem><para>Cumulative number of allocation requests for this size
2672 class served directly by the arena.</para></listitem>
2673 </varlistentry>
2674
2675 <varlistentry id="stats.arenas.i.hchunks.j.ndalloc">
2676 <term>
2677 <mallctl>stats.arenas.&lt;i&gt;.hchunks.&lt;j&gt;.ndalloc</mallctl>
2678 (<type>uint64_t</type>)
2679 <literal>r-</literal>
2680 [<option>--enable-stats</option>]
2681 </term>
2682 <listitem><para>Cumulative number of deallocation requests for this
2683 size class served directly by the arena.</para></listitem>
2684 </varlistentry>
2685
2686 <varlistentry id="stats.arenas.i.hchunks.j.nrequests">
2687 <term>
2688 <mallctl>stats.arenas.&lt;i&gt;.hchunks.&lt;j&gt;.nrequests</mallctl>
2689 (<type>uint64_t</type>)
2690 <literal>r-</literal>
2691 [<option>--enable-stats</option>]
2692 </term>
2693 <listitem><para>Cumulative number of allocation requests for this size
2694 class.</para></listitem>
2695 </varlistentry>
2696
2697 <varlistentry id="stats.arenas.i.hchunks.j.curhchunks">
2698 <term>
2699 <mallctl>stats.arenas.&lt;i&gt;.hchunks.&lt;j&gt;.curhchunks</mallctl>
2700 (<type>size_t</type>)
2701 <literal>r-</literal>
2702 [<option>--enable-stats</option>]
2703 </term>
2704 <listitem><para>Current number of huge allocations for this size class.
2705 </para></listitem>
2706 </varlistentry>
970d7e83
LB
2707 </variablelist>
2708 </refsect1>
54a0048b
SL
2709 <refsect1 id="heap_profile_format">
2710 <title>HEAP PROFILE FORMAT</title>
2711 <para>Although the heap profiling functionality was originally designed to
2712 be compatible with the
2713 <command>pprof</command> command that is developed as part of the <ulink
2714 url="http://code.google.com/p/gperftools/">gperftools
2715 package</ulink>, the addition of per thread heap profiling functionality
2716 required a different heap profile format. The <command>jeprof</command>
2717 command is derived from <command>pprof</command>, with enhancements to
2718 support the heap profile format described here.</para>
2719
2720 <para>In the following hypothetical heap profile, <constant>[...]</constant>
2721 indicates elision for the sake of compactness. <programlisting><![CDATA[
2722heap_v2/524288
2723 t*: 28106: 56637512 [0: 0]
2724 [...]
2725 t3: 352: 16777344 [0: 0]
2726 [...]
2727 t99: 17754: 29341640 [0: 0]
2728 [...]
2729@ 0x5f86da8 0x5f5a1dc [...] 0x29e4d4e 0xa200316 0xabb2988 [...]
2730 t*: 13: 6688 [0: 0]
2731 t3: 12: 6496 [0: ]
2732 t99: 1: 192 [0: 0]
2733[...]
2734
2735MAPPED_LIBRARIES:
2736[...]]]></programlisting> The following matches the above heap profile, but most
2737tokens are replaced with <constant>&lt;description&gt;</constant> to indicate
2738descriptions of the corresponding fields. <programlisting><![CDATA[
2739<heap_profile_format_version>/<mean_sample_interval>
2740 <aggregate>: <curobjs>: <curbytes> [<cumobjs>: <cumbytes>]
2741 [...]
2742 <thread_3_aggregate>: <curobjs>: <curbytes>[<cumobjs>: <cumbytes>]
2743 [...]
2744 <thread_99_aggregate>: <curobjs>: <curbytes>[<cumobjs>: <cumbytes>]
2745 [...]
2746@ <top_frame> <frame> [...] <frame> <frame> <frame> [...]
2747 <backtrace_aggregate>: <curobjs>: <curbytes> [<cumobjs>: <cumbytes>]
2748 <backtrace_thread_3>: <curobjs>: <curbytes> [<cumobjs>: <cumbytes>]
2749 <backtrace_thread_99>: <curobjs>: <curbytes> [<cumobjs>: <cumbytes>]
2750[...]
2751
2752MAPPED_LIBRARIES:
2753</proc/<pid>/maps>]]></programlisting></para>
2754 </refsect1>
2755
970d7e83
LB
2756 <refsect1 id="debugging_malloc_problems">
2757 <title>DEBUGGING MALLOC PROBLEMS</title>
2758 <para>When debugging, it is a good idea to configure/build jemalloc with
2759 the <option>--enable-debug</option> and <option>--enable-fill</option>
2760 options, and recompile the program with suitable options and symbols for
2761 debugger support. When so configured, jemalloc incorporates a wide variety
2762 of run-time assertions that catch application errors such as double-free,
2763 write-after-free, etc.</para>
2764
3b2f2976 2765 <para>Programs often accidentally depend on <quote>uninitialized</quote>
970d7e83
LB
2766 memory actually being filled with zero bytes. Junk filling
2767 (see the <link linkend="opt.junk"><mallctl>opt.junk</mallctl></link>
2768 option) tends to expose such bugs in the form of obviously incorrect
2769 results and/or coredumps. Conversely, zero
2770 filling (see the <link
2771 linkend="opt.zero"><mallctl>opt.zero</mallctl></link> option) eliminates
2772 the symptoms of such bugs. Between these two options, it is usually
2773 possible to quickly detect, diagnose, and eliminate such bugs.</para>
2774
2775 <para>This implementation does not provide much detail about the problems
2776 it detects, because the performance impact for storing such information
2777 would be prohibitive. However, jemalloc does integrate with the most
2778 excellent <ulink url="http://valgrind.org/">Valgrind</ulink> tool if the
2779 <option>--enable-valgrind</option> configuration option is enabled.</para>
2780 </refsect1>
2781 <refsect1 id="diagnostic_messages">
2782 <title>DIAGNOSTIC MESSAGES</title>
2783 <para>If any of the memory allocation/deallocation functions detect an
2784 error or warning condition, a message will be printed to file descriptor
2785 <constant>STDERR_FILENO</constant>. Errors will result in the process
2786 dumping core. If the <link
2787 linkend="opt.abort"><mallctl>opt.abort</mallctl></link> option is set, most
2788 warnings are treated as errors.</para>
2789
2790 <para>The <varname>malloc_message</varname> variable allows the programmer
2791 to override the function which emits the text strings forming the errors
2792 and warnings if for some reason the <constant>STDERR_FILENO</constant> file
2793 descriptor is not suitable for this.
3b2f2976 2794 <function>malloc_message()</function> takes the
970d7e83
LB
2795 <parameter>cbopaque</parameter> pointer argument that is
2796 <constant>NULL</constant> unless overridden by the arguments in a call to
3b2f2976 2797 <function>malloc_stats_print()</function>, followed by a string
970d7e83
LB
2798 pointer. Please note that doing anything which tries to allocate memory in
2799 this function is likely to result in a crash or deadlock.</para>
2800
2801 <para>All messages are prefixed by
3b2f2976 2802 <quote><computeroutput>&lt;jemalloc&gt;: </computeroutput></quote>.</para>
970d7e83
LB
2803 </refsect1>
2804 <refsect1 id="return_values">
2805 <title>RETURN VALUES</title>
2806 <refsect2>
2807 <title>Standard API</title>
3b2f2976
XL
2808 <para>The <function>malloc()</function> and
2809 <function>calloc()</function> functions return a pointer to the
970d7e83
LB
2810 allocated memory if successful; otherwise a <constant>NULL</constant>
2811 pointer is returned and <varname>errno</varname> is set to
2812 <errorname>ENOMEM</errorname>.</para>
2813
3b2f2976 2814 <para>The <function>posix_memalign()</function> function
970d7e83 2815 returns the value 0 if successful; otherwise it returns an error value.
3b2f2976 2816 The <function>posix_memalign()</function> function will fail
970d7e83
LB
2817 if:
2818 <variablelist>
2819 <varlistentry>
2820 <term><errorname>EINVAL</errorname></term>
2821
2822 <listitem><para>The <parameter>alignment</parameter> parameter is
2823 not a power of 2 at least as large as
2824 <code language="C">sizeof(<type>void *</type>)</code>.
2825 </para></listitem>
2826 </varlistentry>
2827 <varlistentry>
2828 <term><errorname>ENOMEM</errorname></term>
2829
2830 <listitem><para>Memory allocation error.</para></listitem>
2831 </varlistentry>
2832 </variablelist>
2833 </para>
2834
3b2f2976 2835 <para>The <function>aligned_alloc()</function> function returns
970d7e83
LB
2836 a pointer to the allocated memory if successful; otherwise a
2837 <constant>NULL</constant> pointer is returned and
2838 <varname>errno</varname> is set. The
3b2f2976 2839 <function>aligned_alloc()</function> function will fail if:
970d7e83
LB
2840 <variablelist>
2841 <varlistentry>
2842 <term><errorname>EINVAL</errorname></term>
2843
2844 <listitem><para>The <parameter>alignment</parameter> parameter is
2845 not a power of 2.
2846 </para></listitem>
2847 </varlistentry>
2848 <varlistentry>
2849 <term><errorname>ENOMEM</errorname></term>
2850
2851 <listitem><para>Memory allocation error.</para></listitem>
2852 </varlistentry>
2853 </variablelist>
2854 </para>
2855
3b2f2976 2856 <para>The <function>realloc()</function> function returns a
970d7e83
LB
2857 pointer, possibly identical to <parameter>ptr</parameter>, to the
2858 allocated memory if successful; otherwise a <constant>NULL</constant>
2859 pointer is returned, and <varname>errno</varname> is set to
2860 <errorname>ENOMEM</errorname> if the error was the result of an
3b2f2976 2861 allocation failure. The <function>realloc()</function>
970d7e83
LB
2862 function always leaves the original buffer intact when an error occurs.
2863 </para>
2864
3b2f2976 2865 <para>The <function>free()</function> function returns no
970d7e83
LB
2866 value.</para>
2867 </refsect2>
2868 <refsect2>
2869 <title>Non-standard API</title>
3b2f2976
XL
2870 <para>The <function>mallocx()</function> and
2871 <function>rallocx()</function> functions return a pointer to
1a4d82fc
JJ
2872 the allocated memory if successful; otherwise a <constant>NULL</constant>
2873 pointer is returned to indicate insufficient contiguous memory was
2874 available to service the allocation request. </para>
2875
3b2f2976 2876 <para>The <function>xallocx()</function> function returns the
1a4d82fc
JJ
2877 real size of the resulting resized allocation pointed to by
2878 <parameter>ptr</parameter>, which is a value less than
2879 <parameter>size</parameter> if the allocation could not be adequately
2880 grown in place. </para>
2881
3b2f2976 2882 <para>The <function>sallocx()</function> function returns the
1a4d82fc
JJ
2883 real size of the allocation pointed to by <parameter>ptr</parameter>.
2884 </para>
2885
3b2f2976 2886 <para>The <function>nallocx()</function> returns the real size
1a4d82fc 2887 that would result from a successful equivalent
3b2f2976 2888 <function>mallocx()</function> function call, or zero if
1a4d82fc 2889 insufficient memory is available to perform the size computation. </para>
970d7e83 2890
3b2f2976
XL
2891 <para>The <function>mallctl()</function>,
2892 <function>mallctlnametomib()</function>, and
2893 <function>mallctlbymib()</function> functions return 0 on
970d7e83
LB
2894 success; otherwise they return an error value. The functions will fail
2895 if:
2896 <variablelist>
2897 <varlistentry>
2898 <term><errorname>EINVAL</errorname></term>
2899
2900 <listitem><para><parameter>newp</parameter> is not
2901 <constant>NULL</constant>, and <parameter>newlen</parameter> is too
2902 large or too small. Alternatively, <parameter>*oldlenp</parameter>
2903 is too large or too small; in this case as much data as possible
2904 are read despite the error.</para></listitem>
2905 </varlistentry>
970d7e83
LB
2906 <varlistentry>
2907 <term><errorname>ENOENT</errorname></term>
2908
2909 <listitem><para><parameter>name</parameter> or
2910 <parameter>mib</parameter> specifies an unknown/invalid
2911 value.</para></listitem>
2912 </varlistentry>
2913 <varlistentry>
2914 <term><errorname>EPERM</errorname></term>
2915
2916 <listitem><para>Attempt to read or write void value, or attempt to
2917 write read-only value.</para></listitem>
2918 </varlistentry>
2919 <varlistentry>
2920 <term><errorname>EAGAIN</errorname></term>
2921
2922 <listitem><para>A memory allocation failure
2923 occurred.</para></listitem>
2924 </varlistentry>
2925 <varlistentry>
2926 <term><errorname>EFAULT</errorname></term>
2927
2928 <listitem><para>An interface with side effects failed in some way
3b2f2976 2929 not directly related to <function>mallctl*()</function>
970d7e83
LB
2930 read/write processing.</para></listitem>
2931 </varlistentry>
2932 </variablelist>
2933 </para>
970d7e83 2934
3b2f2976 2935 <para>The <function>malloc_usable_size()</function> function
1a4d82fc
JJ
2936 returns the usable size of the allocation pointed to by
2937 <parameter>ptr</parameter>. </para>
970d7e83
LB
2938 </refsect2>
2939 </refsect1>
2940 <refsect1 id="environment">
2941 <title>ENVIRONMENT</title>
2942 <para>The following environment variable affects the execution of the
2943 allocation functions:
2944 <variablelist>
2945 <varlistentry>
2946 <term><envar>MALLOC_CONF</envar></term>
2947
2948 <listitem><para>If the environment variable
2949 <envar>MALLOC_CONF</envar> is set, the characters it contains
2950 will be interpreted as options.</para></listitem>
2951 </varlistentry>
2952 </variablelist>
2953 </para>
2954 </refsect1>
2955 <refsect1 id="examples">
2956 <title>EXAMPLES</title>
2957 <para>To dump core whenever a problem occurs:
2958 <screen>ln -s 'abort:true' /etc/malloc.conf</screen>
2959 </para>
2960 <para>To specify in the source a chunk size that is 16 MiB:
2961 <programlisting language="C"><![CDATA[
2962malloc_conf = "lg_chunk:24";]]></programlisting></para>
2963 </refsect1>
2964 <refsect1 id="see_also">
2965 <title>SEE ALSO</title>
2966 <para><citerefentry><refentrytitle>madvise</refentrytitle>
2967 <manvolnum>2</manvolnum></citerefentry>,
2968 <citerefentry><refentrytitle>mmap</refentrytitle>
2969 <manvolnum>2</manvolnum></citerefentry>,
2970 <citerefentry><refentrytitle>sbrk</refentrytitle>
2971 <manvolnum>2</manvolnum></citerefentry>,
2972 <citerefentry><refentrytitle>utrace</refentrytitle>
2973 <manvolnum>2</manvolnum></citerefentry>,
2974 <citerefentry><refentrytitle>alloca</refentrytitle>
2975 <manvolnum>3</manvolnum></citerefentry>,
2976 <citerefentry><refentrytitle>atexit</refentrytitle>
2977 <manvolnum>3</manvolnum></citerefentry>,
2978 <citerefentry><refentrytitle>getpagesize</refentrytitle>
2979 <manvolnum>3</manvolnum></citerefentry></para>
2980 </refsect1>
2981 <refsect1 id="standards">
2982 <title>STANDARDS</title>
3b2f2976
XL
2983 <para>The <function>malloc()</function>,
2984 <function>calloc()</function>,
2985 <function>realloc()</function>, and
2986 <function>free()</function> functions conform to ISO/IEC
2987 9899:1990 (<quote>ISO C90</quote>).</para>
2988
2989 <para>The <function>posix_memalign()</function> function conforms
2990 to IEEE Std 1003.1-2001 (<quote>POSIX.1</quote>).</para>
970d7e83
LB
2991 </refsect1>
2992</refentry>