]> git.saurik.com Git - redis.git/blame - deps/jemalloc/doc/jemalloc.xml.in
Jemalloc updated to 3.0.0.
[redis.git] / deps / jemalloc / doc / jemalloc.xml.in
CommitLineData
a78e148b 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>
4934f93d 33 <refname>aligned_alloc</refname>
a78e148b 34 <refname>realloc</refname>
35 <refname>free</refname>
36 <refname>malloc_usable_size</refname>
37 <refname>malloc_stats_print</refname>
38 <refname>mallctl</refname>
39 <refname>mallctlnametomib</refname>
40 <refname>mallctlbymib</refname>
41 <refname>allocm</refname>
42 <refname>rallocm</refname>
43 <refname>sallocm</refname>
44 <refname>dallocm</refname>
4934f93d 45 <refname>nallocm</refname>
a78e148b 46 -->
47 <refpurpose>general purpose memory allocation functions</refpurpose>
48 </refnamediv>
49 <refsect1 id="library">
50 <title>LIBRARY</title>
51 <para>This manual describes jemalloc @jemalloc_version@. More information
52 can be found at the <ulink
53 url="http://www.canonware.com/jemalloc/">jemalloc website</ulink>.</para>
54 </refsect1>
55 <refsynopsisdiv>
56 <title>SYNOPSIS</title>
57 <funcsynopsis>
58 <funcsynopsisinfo>#include &lt;<filename class="headerfile">stdlib.h</filename>&gt;
59#include &lt;<filename class="headerfile">jemalloc/jemalloc.h</filename>&gt;</funcsynopsisinfo>
60 <refsect2>
61 <title>Standard API</title>
62 <funcprototype>
63 <funcdef>void *<function>malloc</function></funcdef>
64 <paramdef>size_t <parameter>size</parameter></paramdef>
65 </funcprototype>
66 <funcprototype>
67 <funcdef>void *<function>calloc</function></funcdef>
68 <paramdef>size_t <parameter>number</parameter></paramdef>
69 <paramdef>size_t <parameter>size</parameter></paramdef>
70 </funcprototype>
71 <funcprototype>
72 <funcdef>int <function>posix_memalign</function></funcdef>
73 <paramdef>void **<parameter>ptr</parameter></paramdef>
74 <paramdef>size_t <parameter>alignment</parameter></paramdef>
75 <paramdef>size_t <parameter>size</parameter></paramdef>
76 </funcprototype>
4934f93d 77 <funcprototype>
78 <funcdef>void *<function>aligned_alloc</function></funcdef>
79 <paramdef>size_t <parameter>alignment</parameter></paramdef>
80 <paramdef>size_t <parameter>size</parameter></paramdef>
81 </funcprototype>
a78e148b 82 <funcprototype>
83 <funcdef>void *<function>realloc</function></funcdef>
84 <paramdef>void *<parameter>ptr</parameter></paramdef>
85 <paramdef>size_t <parameter>size</parameter></paramdef>
86 </funcprototype>
87 <funcprototype>
88 <funcdef>void <function>free</function></funcdef>
89 <paramdef>void *<parameter>ptr</parameter></paramdef>
90 </funcprototype>
91 </refsect2>
92 <refsect2>
93 <title>Non-standard API</title>
94 <funcprototype>
95 <funcdef>size_t <function>malloc_usable_size</function></funcdef>
96 <paramdef>const void *<parameter>ptr</parameter></paramdef>
97 </funcprototype>
98 <funcprototype>
99 <funcdef>void <function>malloc_stats_print</function></funcdef>
100 <paramdef>void <parameter>(*write_cb)</parameter>
101 <funcparams>void *, const char *</funcparams>
102 </paramdef>
103 <paramdef>void *<parameter>cbopaque</parameter></paramdef>
104 <paramdef>const char *<parameter>opts</parameter></paramdef>
105 </funcprototype>
106 <funcprototype>
107 <funcdef>int <function>mallctl</function></funcdef>
108 <paramdef>const char *<parameter>name</parameter></paramdef>
109 <paramdef>void *<parameter>oldp</parameter></paramdef>
110 <paramdef>size_t *<parameter>oldlenp</parameter></paramdef>
111 <paramdef>void *<parameter>newp</parameter></paramdef>
112 <paramdef>size_t <parameter>newlen</parameter></paramdef>
113 </funcprototype>
114 <funcprototype>
115 <funcdef>int <function>mallctlnametomib</function></funcdef>
116 <paramdef>const char *<parameter>name</parameter></paramdef>
117 <paramdef>size_t *<parameter>mibp</parameter></paramdef>
118 <paramdef>size_t *<parameter>miblenp</parameter></paramdef>
119 </funcprototype>
120 <funcprototype>
121 <funcdef>int <function>mallctlbymib</function></funcdef>
122 <paramdef>const size_t *<parameter>mib</parameter></paramdef>
123 <paramdef>size_t <parameter>miblen</parameter></paramdef>
124 <paramdef>void *<parameter>oldp</parameter></paramdef>
125 <paramdef>size_t *<parameter>oldlenp</parameter></paramdef>
126 <paramdef>void *<parameter>newp</parameter></paramdef>
127 <paramdef>size_t <parameter>newlen</parameter></paramdef>
128 </funcprototype>
129 <funcprototype>
130 <funcdef>void <function>(*malloc_message)</function></funcdef>
131 <paramdef>void *<parameter>cbopaque</parameter></paramdef>
132 <paramdef>const char *<parameter>s</parameter></paramdef>
133 </funcprototype>
134 <para><type>const char *</type><varname>malloc_conf</varname>;</para>
135 </refsect2>
136 <refsect2>
137 <title>Experimental API</title>
138 <funcprototype>
139 <funcdef>int <function>allocm</function></funcdef>
140 <paramdef>void **<parameter>ptr</parameter></paramdef>
141 <paramdef>size_t *<parameter>rsize</parameter></paramdef>
142 <paramdef>size_t <parameter>size</parameter></paramdef>
143 <paramdef>int <parameter>flags</parameter></paramdef>
144 </funcprototype>
145 <funcprototype>
146 <funcdef>int <function>rallocm</function></funcdef>
147 <paramdef>void **<parameter>ptr</parameter></paramdef>
148 <paramdef>size_t *<parameter>rsize</parameter></paramdef>
149 <paramdef>size_t <parameter>size</parameter></paramdef>
150 <paramdef>size_t <parameter>extra</parameter></paramdef>
151 <paramdef>int <parameter>flags</parameter></paramdef>
152 </funcprototype>
153 <funcprototype>
154 <funcdef>int <function>sallocm</function></funcdef>
155 <paramdef>const void *<parameter>ptr</parameter></paramdef>
156 <paramdef>size_t *<parameter>rsize</parameter></paramdef>
157 <paramdef>int <parameter>flags</parameter></paramdef>
158 </funcprototype>
159 <funcprototype>
160 <funcdef>int <function>dallocm</function></funcdef>
161 <paramdef>void *<parameter>ptr</parameter></paramdef>
162 <paramdef>int <parameter>flags</parameter></paramdef>
163 </funcprototype>
4934f93d 164 <funcprototype>
165 <funcdef>int <function>nallocm</function></funcdef>
166 <paramdef>size_t *<parameter>rsize</parameter></paramdef>
167 <paramdef>size_t <parameter>size</parameter></paramdef>
168 <paramdef>int <parameter>flags</parameter></paramdef>
169 </funcprototype>
a78e148b 170 </refsect2>
171 </funcsynopsis>
172 </refsynopsisdiv>
173 <refsect1 id="description">
174 <title>DESCRIPTION</title>
175 <refsect2>
176 <title>Standard API</title>
177
178 <para>The <function>malloc<parameter/></function> function allocates
179 <parameter>size</parameter> bytes of uninitialized memory. The allocated
180 space is suitably aligned (after possible pointer coercion) for storage
181 of any type of object.</para>
182
183 <para>The <function>calloc<parameter/></function> function allocates
184 space for <parameter>number</parameter> objects, each
185 <parameter>size</parameter> bytes in length. The result is identical to
186 calling <function>malloc<parameter/></function> with an argument of
187 <parameter>number</parameter> * <parameter>size</parameter>, with the
188 exception that the allocated memory is explicitly initialized to zero
189 bytes.</para>
190
191 <para>The <function>posix_memalign<parameter/></function> function
192 allocates <parameter>size</parameter> bytes of memory such that the
193 allocation's base address is an even multiple of
194 <parameter>alignment</parameter>, and returns the allocation in the value
195 pointed to by <parameter>ptr</parameter>. The requested
196 <parameter>alignment</parameter> must be a power of 2 at least as large
197 as <code language="C">sizeof(<type>void *</type>)</code>.</para>
198
4934f93d 199 <para>The <function>aligned_alloc<parameter/></function> function
200 allocates <parameter>size</parameter> bytes of memory such that the
201 allocation's base address is an even multiple of
202 <parameter>alignment</parameter>. The requested
203 <parameter>alignment</parameter> must be a power of 2. Behavior is
204 undefined if <parameter>size</parameter> is not an integral multiple of
205 <parameter>alignment</parameter>.</para>
206
a78e148b 207 <para>The <function>realloc<parameter/></function> function changes the
208 size of the previously allocated memory referenced by
209 <parameter>ptr</parameter> to <parameter>size</parameter> bytes. The
210 contents of the memory are unchanged up to the lesser of the new and old
211 sizes. If the new size is larger, the contents of the newly allocated
212 portion of the memory are undefined. Upon success, the memory referenced
213 by <parameter>ptr</parameter> is freed and a pointer to the newly
214 allocated memory is returned. Note that
215 <function>realloc<parameter/></function> may move the memory allocation,
216 resulting in a different return value than <parameter>ptr</parameter>.
217 If <parameter>ptr</parameter> is <constant>NULL</constant>, the
218 <function>realloc<parameter/></function> function behaves identically to
219 <function>malloc<parameter/></function> for the specified size.</para>
220
221 <para>The <function>free<parameter/></function> function causes the
222 allocated memory referenced by <parameter>ptr</parameter> to be made
223 available for future allocations. If <parameter>ptr</parameter> is
224 <constant>NULL</constant>, no action occurs.</para>
225 </refsect2>
226 <refsect2>
227 <title>Non-standard API</title>
228
229 <para>The <function>malloc_usable_size<parameter/></function> function
230 returns the usable size of the allocation pointed to by
231 <parameter>ptr</parameter>. The return value may be larger than the size
232 that was requested during allocation. The
233 <function>malloc_usable_size<parameter/></function> function is not a
234 mechanism for in-place <function>realloc<parameter/></function>; rather
235 it is provided solely as a tool for introspection purposes. Any
236 discrepancy between the requested allocation size and the size reported
237 by <function>malloc_usable_size<parameter/></function> should not be
238 depended on, since such behavior is entirely implementation-dependent.
239 </para>
240
241 <para>The <function>malloc_stats_print<parameter/></function> function
242 writes human-readable summary statistics via the
243 <parameter>write_cb</parameter> callback function pointer and
244 <parameter>cbopaque</parameter> data passed to
245 <parameter>write_cb</parameter>, or
246 <function>malloc_message<parameter/></function> if
247 <parameter>write_cb</parameter> is <constant>NULL</constant>. This
248 function can be called repeatedly. General information that never
249 changes during execution can be omitted by specifying "g" as a character
250 within the <parameter>opts</parameter> string. Note that
251 <function>malloc_message<parameter/></function> uses the
252 <function>mallctl*<parameter/></function> functions internally, so
253 inconsistent statistics can be reported if multiple threads use these
254 functions simultaneously. If <option>--enable-stats</option> is
255 specified during configuration, &ldquo;m&rdquo; and &ldquo;a&rdquo; can
256 be specified to omit merged arena and per arena statistics, respectively;
257 &ldquo;b&rdquo; and &ldquo;l&rdquo; can be specified to omit per size
258 class statistics for bins and large objects, respectively. Unrecognized
259 characters are silently ignored. Note that thread caching may prevent
260 some statistics from being completely up to date, since extra locking
261 would be required to merge counters that track thread cache operations.
262 </para>
263
264 <para>The <function>mallctl<parameter/></function> function provides a
265 general interface for introspecting the memory allocator, as well as
266 setting modifiable parameters and triggering actions. The
267 period-separated <parameter>name</parameter> argument specifies a
268 location in a tree-structured namespace; see the <xref
269 linkend="mallctl_namespace" xrefstyle="template:%t"/> section for
270 documentation on the tree contents. To read a value, pass a pointer via
271 <parameter>oldp</parameter> to adequate space to contain the value, and a
272 pointer to its length via <parameter>oldlenp</parameter>; otherwise pass
273 <constant>NULL</constant> and <constant>NULL</constant>. Similarly, to
274 write a value, pass a pointer to the value via
275 <parameter>newp</parameter>, and its length via
276 <parameter>newlen</parameter>; otherwise pass <constant>NULL</constant>
277 and <constant>0</constant>.</para>
278
279 <para>The <function>mallctlnametomib<parameter/></function> function
280 provides a way to avoid repeated name lookups for applications that
281 repeatedly query the same portion of the namespace, by translating a name
282 to a &ldquo;Management Information Base&rdquo; (MIB) that can be passed
283 repeatedly to <function>mallctlbymib<parameter/></function>. Upon
284 successful return from <function>mallctlnametomib<parameter/></function>,
285 <parameter>mibp</parameter> contains an array of
286 <parameter>*miblenp</parameter> integers, where
287 <parameter>*miblenp</parameter> is the lesser of the number of components
288 in <parameter>name</parameter> and the input value of
289 <parameter>*miblenp</parameter>. Thus it is possible to pass a
290 <parameter>*miblenp</parameter> that is smaller than the number of
291 period-separated name components, which results in a partial MIB that can
292 be used as the basis for constructing a complete MIB. For name
293 components that are integers (e.g. the 2 in
294 <link
295 linkend="arenas.bin.i.size"><mallctl>arenas.bin.2.size</mallctl></link>),
296 the corresponding MIB component will always be that integer. Therefore,
297 it is legitimate to construct code like the following: <programlisting
298 language="C"><![CDATA[
299unsigned nbins, i;
300
301int mib[4];
302size_t len, miblen;
303
304len = sizeof(nbins);
305mallctl("arenas.nbins", &nbins, &len, NULL, 0);
306
307miblen = 4;
308mallnametomib("arenas.bin.0.size", mib, &miblen);
309for (i = 0; i < nbins; i++) {
310 size_t bin_size;
311
312 mib[2] = i;
313 len = sizeof(bin_size);
314 mallctlbymib(mib, miblen, &bin_size, &len, NULL, 0);
315 /* Do something with bin_size... */
316}]]></programlisting></para>
317 </refsect2>
318 <refsect2>
319 <title>Experimental API</title>
320 <para>The experimental API is subject to change or removal without regard
4934f93d 321 for backward compatibility. If <option>--disable-experimental</option>
322 is specified during configuration, the experimental API is
323 omitted.</para>
a78e148b 324
325 <para>The <function>allocm<parameter/></function>,
326 <function>rallocm<parameter/></function>,
4934f93d 327 <function>sallocm<parameter/></function>,
328 <function>dallocm<parameter/></function>, and
329 <function>nallocm<parameter/></function> functions all have a
a78e148b 330 <parameter>flags</parameter> argument that can be used to specify
331 options. The functions only check the options that are contextually
332 relevant. Use bitwise or (<code language="C">|</code>) operations to
333 specify one or more of the following:
334 <variablelist>
335 <varlistentry>
336 <term><constant>ALLOCM_LG_ALIGN(<parameter>la</parameter>)
337 </constant></term>
338
339 <listitem><para>Align the memory allocation to start at an address
340 that is a multiple of <code language="C">(1 &lt;&lt;
341 <parameter>la</parameter>)</code>. This macro does not validate
342 that <parameter>la</parameter> is within the valid
343 range.</para></listitem>
344 </varlistentry>
345 <varlistentry>
346 <term><constant>ALLOCM_ALIGN(<parameter>a</parameter>)
347 </constant></term>
348
349 <listitem><para>Align the memory allocation to start at an address
350 that is a multiple of <parameter>a</parameter>, where
351 <parameter>a</parameter> is a power of two. This macro does not
352 validate that <parameter>a</parameter> is a power of 2.
353 </para></listitem>
354 </varlistentry>
355 <varlistentry>
356 <term><constant>ALLOCM_ZERO</constant></term>
357
358 <listitem><para>Initialize newly allocated memory to contain zero
359 bytes. In the growing reallocation case, the real size prior to
360 reallocation defines the boundary between untouched bytes and those
361 that are initialized to contain zero bytes. If this option is
362 absent, newly allocated memory is uninitialized.</para></listitem>
363 </varlistentry>
364 <varlistentry>
365 <term><constant>ALLOCM_NO_MOVE</constant></term>
366
367 <listitem><para>For reallocation, fail rather than moving the
368 object. This constraint can apply to both growth and
369 shrinkage.</para></listitem>
370 </varlistentry>
371 </variablelist>
372 </para>
373
374 <para>The <function>allocm<parameter/></function> function allocates at
375 least <parameter>size</parameter> bytes of memory, sets
376 <parameter>*ptr</parameter> to the base address of the allocation, and
377 sets <parameter>*rsize</parameter> to the real size of the allocation if
4934f93d 378 <parameter>rsize</parameter> is not <constant>NULL</constant>. Behavior
379 is undefined if <parameter>size</parameter> is
380 <constant>0</constant>.</para>
a78e148b 381
382 <para>The <function>rallocm<parameter/></function> function resizes the
383 allocation at <parameter>*ptr</parameter> to be at least
384 <parameter>size</parameter> bytes, sets <parameter>*ptr</parameter> to
385 the base address of the allocation if it moved, and sets
386 <parameter>*rsize</parameter> to the real size of the allocation if
387 <parameter>rsize</parameter> is not <constant>NULL</constant>. If
388 <parameter>extra</parameter> is non-zero, an attempt is made to resize
389 the allocation to be at least <code
390 language="C"><parameter>size</parameter> +
391 <parameter>extra</parameter>)</code> bytes, though inability to allocate
392 the extra byte(s) will not by itself result in failure. Behavior is
4934f93d 393 undefined if <parameter>size</parameter> is <constant>0</constant>, or if
394 <code language="C">(<parameter>size</parameter> +
a78e148b 395 <parameter>extra</parameter> &gt;
396 <constant>SIZE_T_MAX</constant>)</code>.</para>
397
398 <para>The <function>sallocm<parameter/></function> function sets
399 <parameter>*rsize</parameter> to the real size of the allocation.</para>
400
401 <para>The <function>dallocm<parameter/></function> function causes the
402 memory referenced by <parameter>ptr</parameter> to be made available for
403 future allocations.</para>
4934f93d 404
405 <para>The <function>nallocm<parameter/></function> function allocates no
406 memory, but it performs the same size computation as the
407 <function>allocm<parameter/></function> function, and if
408 <parameter>rsize</parameter> is not <constant>NULL</constant> it sets
409 <parameter>*rsize</parameter> to the real size of the allocation that
410 would result from the equivalent <function>allocm<parameter/></function>
411 function call. Behavior is undefined if
412 <parameter>size</parameter> is <constant>0</constant>.</para>
a78e148b 413 </refsect2>
414 </refsect1>
415 <refsect1 id="tuning">
416 <title>TUNING</title>
417 <para>Once, when the first call is made to one of the memory allocation
418 routines, the allocator initializes its internals based in part on various
419 options that can be specified at compile- or run-time.</para>
420
421 <para>The string pointed to by the global variable
422 <varname>malloc_conf</varname>, the &ldquo;name&rdquo; of the file
423 referenced by the symbolic link named <filename
424 class="symlink">/etc/malloc.conf</filename>, and the value of the
425 environment variable <envar>MALLOC_CONF</envar>, will be interpreted, in
426 that order, from left to right as options.</para>
427
428 <para>An options string is a comma-separated list of option:value pairs.
429 There is one key corresponding to each <link
430 linkend="opt.abort"><mallctl>opt.*</mallctl></link> mallctl (see the <xref
431 linkend="mallctl_namespace" xrefstyle="template:%t"/> section for options
432 documentation). For example, <literal>abort:true,narenas:1</literal> sets
433 the <link linkend="opt.abort"><mallctl>opt.abort</mallctl></link> and <link
434 linkend="opt.narenas"><mallctl>opt.narenas</mallctl></link> options. Some
435 options have boolean values (true/false), others have integer values (base
436 8, 10, or 16, depending on prefix), and yet others have raw string
437 values.</para>
438 </refsect1>
439 <refsect1 id="implementation_notes">
440 <title>IMPLEMENTATION NOTES</title>
441 <para>Traditionally, allocators have used
442 <citerefentry><refentrytitle>sbrk</refentrytitle>
443 <manvolnum>2</manvolnum></citerefentry> to obtain memory, which is
444 suboptimal for several reasons, including race conditions, increased
445 fragmentation, and artificial limitations on maximum usable memory. If
446 <option>--enable-dss</option> is specified during configuration, this
4934f93d 447 allocator uses both <citerefentry><refentrytitle>mmap</refentrytitle>
a78e148b 448 <manvolnum>2</manvolnum></citerefentry> and
4934f93d 449 <citerefentry><refentrytitle>sbrk</refentrytitle>
a78e148b 450 <manvolnum>2</manvolnum></citerefentry>, in that order of preference;
451 otherwise only <citerefentry><refentrytitle>mmap</refentrytitle>
452 <manvolnum>2</manvolnum></citerefentry> is used.</para>
453
454 <para>This allocator uses multiple arenas in order to reduce lock
455 contention for threaded programs on multi-processor systems. This works
456 well with regard to threading scalability, but incurs some costs. There is
457 a small fixed per-arena overhead, and additionally, arenas manage memory
458 completely independently of each other, which means a small fixed increase
459 in overall memory fragmentation. These overheads are not generally an
460 issue, given the number of arenas normally used. Note that using
461 substantially more arenas than the default is not likely to improve
462 performance, mainly due to reduced cache performance. However, it may make
463 sense to reduce the number of arenas if an application does not make much
464 use of the allocation functions.</para>
465
466 <para>In addition to multiple arenas, unless
467 <option>--disable-tcache</option> is specified during configuration, this
468 allocator supports thread-specific caching for small and large objects, in
469 order to make it possible to completely avoid synchronization for most
470 allocation requests. Such caching allows very fast allocation in the
471 common case, but it increases memory usage and fragmentation, since a
472 bounded number of objects can remain allocated in each thread cache.</para>
473
474 <para>Memory is conceptually broken into equal-sized chunks, where the
475 chunk size is a power of two that is greater than the page size. Chunks
476 are always aligned to multiples of the chunk size. This alignment makes it
477 possible to find metadata for user objects very quickly.</para>
478
479 <para>User objects are broken into three categories according to size:
480 small, large, and huge. Small objects are smaller than one page. Large
481 objects are smaller than the chunk size. Huge objects are a multiple of
482 the chunk size. Small and large objects are managed by arenas; huge
483 objects are managed separately in a single data structure that is shared by
484 all threads. Huge objects are used by applications infrequently enough
485 that this single data structure is not a scalability issue.</para>
486
487 <para>Each chunk that is managed by an arena tracks its contents as runs of
488 contiguous pages (unused, backing a set of small objects, or backing one
489 large object). The combination of chunk alignment and chunk page maps
490 makes it possible to determine all metadata regarding small and large
491 allocations in constant time.</para>
492
493 <para>Small objects are managed in groups by page runs. Each run maintains
4934f93d 494 a frontier and free list to track which regions are in use. Allocation
495 requests that are no more than half the quantum (8 or 16, depending on
496 architecture) are rounded up to the nearest power of two that is at least
497 <code language="C">sizeof(<type>double</type>)</code>. All other small
498 object size classes are multiples of the quantum, spaced such that internal
499 fragmentation is limited to approximately 25% for all but the smallest size
500 classes. Allocation requests that are larger than the maximum small size
501 class, but small enough to fit in an arena-managed chunk (see the <link
a78e148b 502 linkend="opt.lg_chunk"><mallctl>opt.lg_chunk</mallctl></link> option), are
503 rounded up to the nearest run size. Allocation requests that are too large
504 to fit in an arena-managed chunk are rounded up to the nearest multiple of
505 the chunk size.</para>
506
507 <para>Allocations are packed tightly together, which can be an issue for
508 multi-threaded applications. If you need to assure that allocations do not
509 suffer from cacheline sharing, round your allocation requests up to the
510 nearest multiple of the cacheline size, or specify cacheline alignment when
511 allocating.</para>
512
513 <para>Assuming 4 MiB chunks, 4 KiB pages, and a 16-byte quantum on a 64-bit
514 system, the size classes in each category are as shown in <xref
515 linkend="size_classes" xrefstyle="template:Table %n"/>.</para>
516
517 <table xml:id="size_classes" frame="all">
518 <title>Size classes</title>
4934f93d 519 <tgroup cols="3" colsep="1" rowsep="1">
520 <colspec colname="c1" align="left"/>
521 <colspec colname="c2" align="right"/>
522 <colspec colname="c3" align="left"/>
a78e148b 523 <thead>
524 <row>
525 <entry>Category</entry>
4934f93d 526 <entry>Spacing</entry>
a78e148b 527 <entry>Size</entry>
528 </row>
529 </thead>
530 <tbody>
531 <row>
4934f93d 532 <entry morerows="6">Small</entry>
533 <entry>lg</entry>
a78e148b 534 <entry>[8]</entry>
535 </row>
536 <row>
4934f93d 537 <entry>16</entry>
a78e148b 538 <entry>[16, 32, 48, ..., 128]</entry>
539 </row>
540 <row>
4934f93d 541 <entry>32</entry>
542 <entry>[160, 192, 224, 256]</entry>
a78e148b 543 </row>
544 <row>
4934f93d 545 <entry>64</entry>
546 <entry>[320, 384, 448, 512]</entry>
a78e148b 547 </row>
548 <row>
4934f93d 549 <entry>128</entry>
550 <entry>[640, 768, 896, 1024]</entry>
551 </row>
552 <row>
553 <entry>256</entry>
554 <entry>[1280, 1536, 1792, 2048]</entry>
555 </row>
556 <row>
557 <entry>512</entry>
558 <entry>[2560, 3072, 3584]</entry>
559 </row>
560 <row>
561 <entry>Large</entry>
562 <entry>4 KiB</entry>
a78e148b 563 <entry>[4 KiB, 8 KiB, 12 KiB, ..., 4072 KiB]</entry>
564 </row>
565 <row>
4934f93d 566 <entry>Huge</entry>
567 <entry>4 MiB</entry>
a78e148b 568 <entry>[4 MiB, 8 MiB, 12 MiB, ...]</entry>
569 </row>
570 </tbody>
571 </tgroup>
572 </table>
573 </refsect1>
574 <refsect1 id="mallctl_namespace">
575 <title>MALLCTL NAMESPACE</title>
576 <para>The following names are defined in the namespace accessible via the
577 <function>mallctl*<parameter/></function> functions. Value types are
578 specified in parentheses, their readable/writable statuses are encoded as
579 <literal>rw</literal>, <literal>r-</literal>, <literal>-w</literal>, or
580 <literal>--</literal>, and required build configuration flags follow, if
581 any. A name element encoded as <literal>&lt;i&gt;</literal> or
582 <literal>&lt;j&gt;</literal> indicates an integer component, where the
583 integer varies from 0 to some upper value that must be determined via
584 introspection. In the case of <mallctl>stats.arenas.&lt;i&gt;.*</mallctl>,
585 <literal>&lt;i&gt;</literal> equal to <link
586 linkend="arenas.narenas"><mallctl>arenas.narenas</mallctl></link> can be
587 used to access the summation of statistics from all arenas. Take special
588 note of the <link linkend="epoch"><mallctl>epoch</mallctl></link> mallctl,
589 which controls refreshing of cached dynamic statistics.</para>
590
591 <variablelist>
592 <varlistentry>
593 <term>
594 <mallctl>version</mallctl>
595 (<type>const char *</type>)
596 <literal>r-</literal>
597 </term>
598 <listitem><para>Return the jemalloc version string.</para></listitem>
599 </varlistentry>
600
601 <varlistentry id="epoch">
602 <term>
603 <mallctl>epoch</mallctl>
604 (<type>uint64_t</type>)
605 <literal>rw</literal>
606 </term>
607 <listitem><para>If a value is passed in, refresh the data from which
608 the <function>mallctl*<parameter/></function> functions report values,
609 and increment the epoch. Return the current epoch. This is useful for
610 detecting whether another thread caused a refresh.</para></listitem>
611 </varlistentry>
612
613 <varlistentry>
614 <term>
615 <mallctl>config.debug</mallctl>
616 (<type>bool</type>)
617 <literal>r-</literal>
618 </term>
619 <listitem><para><option>--enable-debug</option> was specified during
620 build configuration.</para></listitem>
621 </varlistentry>
622
623 <varlistentry>
624 <term>
625 <mallctl>config.dss</mallctl>
626 (<type>bool</type>)
627 <literal>r-</literal>
628 </term>
629 <listitem><para><option>--enable-dss</option> was specified during
630 build configuration.</para></listitem>
631 </varlistentry>
632
633 <varlistentry>
634 <term>
4934f93d 635 <mallctl>config.fill</mallctl>
a78e148b 636 (<type>bool</type>)
637 <literal>r-</literal>
638 </term>
4934f93d 639 <listitem><para><option>--enable-fill</option> was specified during
640 build configuration.</para></listitem>
a78e148b 641 </varlistentry>
642
643 <varlistentry>
644 <term>
4934f93d 645 <mallctl>config.lazy_lock</mallctl>
a78e148b 646 (<type>bool</type>)
647 <literal>r-</literal>
648 </term>
4934f93d 649 <listitem><para><option>--enable-lazy-lock</option> was specified
650 during build configuration.</para></listitem>
651 </varlistentry>
652
653 <varlistentry>
654 <term>
655 <mallctl>config.mremap</mallctl>
656 (<type>bool</type>)
657 <literal>r-</literal>
658 </term>
659 <listitem><para><option>--enable-mremap</option> was specified during
a78e148b 660 build configuration.</para></listitem>
661 </varlistentry>
662
663 <varlistentry>
664 <term>
4934f93d 665 <mallctl>config.munmap</mallctl>
a78e148b 666 (<type>bool</type>)
667 <literal>r-</literal>
668 </term>
4934f93d 669 <listitem><para><option>--enable-munmap</option> was specified during
670 build configuration.</para></listitem>
a78e148b 671 </varlistentry>
672
673 <varlistentry>
674 <term>
675 <mallctl>config.prof</mallctl>
676 (<type>bool</type>)
677 <literal>r-</literal>
678 </term>
679 <listitem><para><option>--enable-prof</option> was specified during
680 build configuration.</para></listitem>
681 </varlistentry>
682
683 <varlistentry>
684 <term>
685 <mallctl>config.prof_libgcc</mallctl>
686 (<type>bool</type>)
687 <literal>r-</literal>
688 </term>
689 <listitem><para><option>--disable-prof-libgcc</option> was not
690 specified during build configuration.</para></listitem>
691 </varlistentry>
692
693 <varlistentry>
694 <term>
695 <mallctl>config.prof_libunwind</mallctl>
696 (<type>bool</type>)
697 <literal>r-</literal>
698 </term>
699 <listitem><para><option>--enable-prof-libunwind</option> was specified
700 during build configuration.</para></listitem>
701 </varlistentry>
702
703 <varlistentry>
704 <term>
705 <mallctl>config.stats</mallctl>
706 (<type>bool</type>)
707 <literal>r-</literal>
708 </term>
709 <listitem><para><option>--enable-stats</option> was specified during
710 build configuration.</para></listitem>
711 </varlistentry>
712
713 <varlistentry>
714 <term>
4934f93d 715 <mallctl>config.tcache</mallctl>
a78e148b 716 (<type>bool</type>)
717 <literal>r-</literal>
718 </term>
4934f93d 719 <listitem><para><option>--disable-tcache</option> was not specified
720 during build configuration.</para></listitem>
a78e148b 721 </varlistentry>
722
723 <varlistentry>
724 <term>
4934f93d 725 <mallctl>config.tls</mallctl>
a78e148b 726 (<type>bool</type>)
727 <literal>r-</literal>
728 </term>
4934f93d 729 <listitem><para><option>--disable-tls</option> was not specified during
a78e148b 730 build configuration.</para></listitem>
731 </varlistentry>
732
733 <varlistentry>
734 <term>
4934f93d 735 <mallctl>config.utrace</mallctl>
a78e148b 736 (<type>bool</type>)
737 <literal>r-</literal>
738 </term>
4934f93d 739 <listitem><para><option>--enable-utrace</option> was specified during
740 build configuration.</para></listitem>
a78e148b 741 </varlistentry>
742
743 <varlistentry>
744 <term>
4934f93d 745 <mallctl>config.valgrind</mallctl>
a78e148b 746 (<type>bool</type>)
747 <literal>r-</literal>
748 </term>
4934f93d 749 <listitem><para><option>--enable-valgrind</option> was specified during
a78e148b 750 build configuration.</para></listitem>
751 </varlistentry>
752
753 <varlistentry>
754 <term>
755 <mallctl>config.xmalloc</mallctl>
756 (<type>bool</type>)
757 <literal>r-</literal>
758 </term>
759 <listitem><para><option>--enable-xmalloc</option> was specified during
760 build configuration.</para></listitem>
761 </varlistentry>
762
763 <varlistentry id="opt.abort">
764 <term>
765 <mallctl>opt.abort</mallctl>
766 (<type>bool</type>)
767 <literal>r-</literal>
768 </term>
769 <listitem><para>Abort-on-warning enabled/disabled. If true, most
770 warnings are fatal. The process will call
771 <citerefentry><refentrytitle>abort</refentrytitle>
772 <manvolnum>3</manvolnum></citerefentry> in these cases. This option is
773 disabled by default unless <option>--enable-debug</option> is
774 specified during configuration, in which case it is enabled by default.
775 </para></listitem>
776 </varlistentry>
777
a78e148b 778 <varlistentry id="opt.lg_chunk">
779 <term>
780 <mallctl>opt.lg_chunk</mallctl>
781 (<type>size_t</type>)
782 <literal>r-</literal>
783 </term>
784 <listitem><para>Virtual memory chunk size (log base 2). The default
785 chunk size is 4 MiB (2^22).</para></listitem>
786 </varlistentry>
787
788 <varlistentry id="opt.narenas">
789 <term>
790 <mallctl>opt.narenas</mallctl>
791 (<type>size_t</type>)
792 <literal>r-</literal>
793 </term>
794 <listitem><para>Maximum number of arenas to use. The default maximum
795 number of arenas is four times the number of CPUs, or one if there is a
796 single CPU.</para></listitem>
797 </varlistentry>
798
799 <varlistentry id="opt.lg_dirty_mult">
800 <term>
801 <mallctl>opt.lg_dirty_mult</mallctl>
802 (<type>ssize_t</type>)
803 <literal>r-</literal>
804 </term>
805 <listitem><para>Per-arena minimum ratio (log base 2) of active to dirty
806 pages. Some dirty unused pages may be allowed to accumulate, within
807 the limit set by the ratio (or one chunk worth of dirty pages,
808 whichever is greater), before informing the kernel about some of those
809 pages via <citerefentry><refentrytitle>madvise</refentrytitle>
810 <manvolnum>2</manvolnum></citerefentry> or a similar system call. This
811 provides the kernel with sufficient information to recycle dirty pages
812 if physical memory becomes scarce and the pages remain unused. The
813 default minimum ratio is 32:1 (2^5:1); an option value of -1 will
814 disable dirty page purging.</para></listitem>
815 </varlistentry>
816
817 <varlistentry id="opt.stats_print">
818 <term>
819 <mallctl>opt.stats_print</mallctl>
820 (<type>bool</type>)
821 <literal>r-</literal>
822 </term>
823 <listitem><para>Enable/disable statistics printing at exit. If
824 enabled, the <function>malloc_stats_print<parameter/></function>
825 function is called at program exit via an
826 <citerefentry><refentrytitle>atexit</refentrytitle>
827 <manvolnum>3</manvolnum></citerefentry> function. If
828 <option>--enable-stats</option> is specified during configuration, this
829 has the potential to cause deadlock for a multi-threaded process that
830 exits while one or more threads are executing in the memory allocation
831 functions. Therefore, this option should only be used with care; it is
832 primarily intended as a performance tuning aid during application
833 development. This option is disabled by default.</para></listitem>
834 </varlistentry>
835
836 <varlistentry id="opt.junk">
837 <term>
838 <mallctl>opt.junk</mallctl>
839 (<type>bool</type>)
840 <literal>r-</literal>
841 [<option>--enable-fill</option>]
842 </term>
843 <listitem><para>Junk filling enabled/disabled. If enabled, each byte
844 of uninitialized allocated memory will be initialized to
845 <literal>0xa5</literal>. All deallocated memory will be initialized to
846 <literal>0x5a</literal>. This is intended for debugging and will
847 impact performance negatively. This option is disabled by default
848 unless <option>--enable-debug</option> is specified during
849 configuration, in which case it is enabled by default.</para></listitem>
850 </varlistentry>
851
4934f93d 852 <varlistentry id="opt.quarantine">
853 <term>
854 <mallctl>opt.quarantine</mallctl>
855 (<type>size_t</type>)
856 <literal>r-</literal>
857 [<option>--enable-fill</option>]
858 </term>
859 <listitem><para>Per thread quarantine size in bytes. If non-zero, each
860 thread maintains a FIFO object quarantine that stores up to the
861 specified number of bytes of memory. The quarantined memory is not
862 freed until it is released from quarantine, though it is immediately
863 junk-filled if the <link
864 linkend="opt.junk"><mallctl>opt.junk</mallctl></link> option is
865 enabled. This feature is of particular use in combination with <ulink
866 url="http://valgrind.org/">Valgrind</ulink>, which can detect attempts
867 to access quarantined objects. This is intended for debugging and will
868 impact performance negatively. The default quarantine size is
869 0.</para></listitem>
870 </varlistentry>
871
872 <varlistentry id="opt.redzone">
873 <term>
874 <mallctl>opt.redzone</mallctl>
875 (<type>bool</type>)
876 <literal>r-</literal>
877 [<option>--enable-fill</option>]
878 </term>
879 <listitem><para>Redzones enabled/disabled. If enabled, small
880 allocations have redzones before and after them. Furthermore, if the
881 <link linkend="opt.junk"><mallctl>opt.junk</mallctl></link> option is
882 enabled, the redzones are checked for corruption during deallocation.
883 However, the primary intended purpose of this feature is to be used in
884 combination with <ulink url="http://valgrind.org/">Valgrind</ulink>,
885 which needs redzones in order to do effective buffer overflow/underflow
886 detection. This option is intended for debugging and will impact
887 performance negatively. This option is disabled by
888 default.</para></listitem>
889 </varlistentry>
890
a78e148b 891 <varlistentry id="opt.zero">
892 <term>
893 <mallctl>opt.zero</mallctl>
894 (<type>bool</type>)
895 <literal>r-</literal>
896 [<option>--enable-fill</option>]
897 </term>
898 <listitem><para>Zero filling enabled/disabled. If enabled, each byte
899 of uninitialized allocated memory will be initialized to 0. Note that
900 this initialization only happens once for each byte, so
901 <function>realloc<parameter/></function> and
902 <function>rallocm<parameter/></function> calls do not zero memory that
903 was previously allocated. This is intended for debugging and will
904 impact performance negatively. This option is disabled by default.
905 </para></listitem>
906 </varlistentry>
907
4934f93d 908 <varlistentry id="opt.utrace">
a78e148b 909 <term>
4934f93d 910 <mallctl>opt.utrace</mallctl>
a78e148b 911 (<type>bool</type>)
912 <literal>r-</literal>
4934f93d 913 [<option>--enable-utrace</option>]
a78e148b 914 </term>
4934f93d 915 <listitem><para>Allocation tracing based on
916 <citerefentry><refentrytitle>utrace</refentrytitle>
917 <manvolnum>2</manvolnum></citerefentry> enabled/disabled. This option
918 is disabled by default.</para></listitem>
919 </varlistentry>
920
921 <varlistentry id="opt.valgrind">
922 <term>
923 <mallctl>opt.valgrind</mallctl>
924 (<type>bool</type>)
925 <literal>r-</literal>
926 [<option>--enable-valgrind</option>]
927 </term>
928 <listitem><para><ulink url="http://valgrind.org/">Valgrind</ulink>
929 support enabled/disabled. If enabled, several other options are
930 automatically modified during options processing to work well with
931 Valgrind: <link linkend="opt.junk"><mallctl>opt.junk</mallctl></link>
932 and <link linkend="opt.zero"><mallctl>opt.zero</mallctl></link> are set
933 to false, <link
934 linkend="opt.quarantine"><mallctl>opt.quarantine</mallctl></link> is
935 set to 16 MiB, and <link
936 linkend="opt.redzone"><mallctl>opt.redzone</mallctl></link> is set to
937 true. This option is disabled by default.</para></listitem>
a78e148b 938 </varlistentry>
939
940 <varlistentry id="opt.xmalloc">
941 <term>
942 <mallctl>opt.xmalloc</mallctl>
943 (<type>bool</type>)
944 <literal>r-</literal>
945 [<option>--enable-xmalloc</option>]
946 </term>
947 <listitem><para>Abort-on-out-of-memory enabled/disabled. If enabled,
948 rather than returning failure for any allocation function, display a
949 diagnostic message on <constant>STDERR_FILENO</constant> and cause the
950 program to drop core (using
951 <citerefentry><refentrytitle>abort</refentrytitle>
952 <manvolnum>3</manvolnum></citerefentry>). If an application is
953 designed to depend on this behavior, set the option at compile time by
954 including the following in the source code:
955 <programlisting language="C"><![CDATA[
956malloc_conf = "xmalloc:true";]]></programlisting>
957 This option is disabled by default.</para></listitem>
958 </varlistentry>
959
960 <varlistentry id="opt.tcache">
961 <term>
962 <mallctl>opt.tcache</mallctl>
963 (<type>bool</type>)
964 <literal>r-</literal>
965 [<option>--enable-tcache</option>]
966 </term>
967 <listitem><para>Thread-specific caching enabled/disabled. When there
968 are multiple threads, each thread uses a thread-specific cache for
969 objects up to a certain size. Thread-specific caching allows many
970 allocations to be satisfied without performing any thread
971 synchronization, at the cost of increased memory use. See the
972 <link
a78e148b 973 linkend="opt.lg_tcache_max"><mallctl>opt.lg_tcache_max</mallctl></link>
4934f93d 974 option for related tuning information. This option is enabled by
a78e148b 975 default.</para></listitem>
976 </varlistentry>
977
a78e148b 978 <varlistentry id="opt.lg_tcache_max">
979 <term>
980 <mallctl>opt.lg_tcache_max</mallctl>
981 (<type>size_t</type>)
982 <literal>r-</literal>
983 [<option>--enable-tcache</option>]
984 </term>
985 <listitem><para>Maximum size class (log base 2) to cache in the
986 thread-specific cache. At a minimum, all small size classes are
987 cached, and at a maximum all large size classes are cached. The
988 default maximum is 32 KiB (2^15).</para></listitem>
989 </varlistentry>
990
991 <varlistentry id="opt.prof">
992 <term>
993 <mallctl>opt.prof</mallctl>
994 (<type>bool</type>)
995 <literal>r-</literal>
996 [<option>--enable-prof</option>]
997 </term>
998 <listitem><para>Memory profiling enabled/disabled. If enabled, profile
4934f93d 999 memory allocation activity. See the <link
a78e148b 1000 linkend="opt.prof_active"><mallctl>opt.prof_active</mallctl></link>
1001 option for on-the-fly activation/deactivation. See the <link
1002 linkend="opt.lg_prof_sample"><mallctl>opt.lg_prof_sample</mallctl></link>
1003 option for probabilistic sampling control. See the <link
1004 linkend="opt.prof_accum"><mallctl>opt.prof_accum</mallctl></link>
1005 option for control of cumulative sample reporting. See the <link
a78e148b 1006 linkend="opt.lg_prof_interval"><mallctl>opt.lg_prof_interval</mallctl></link>
4934f93d 1007 option for information on interval-triggered profile dumping, the <link
1008 linkend="opt.prof_gdump"><mallctl>opt.prof_gdump</mallctl></link>
1009 option for information on high-water-triggered profile dumping, and the
1010 <link linkend="opt.prof_final"><mallctl>opt.prof_final</mallctl></link>
1011 option for final profile dumping. Profile output is compatible with
1012 the included <command>pprof</command> Perl script, which originates
1013 from the <ulink url="http://code.google.com/p/gperftools/">gperftools
a78e148b 1014 package</ulink>.</para></listitem>
1015 </varlistentry>
1016
1017 <varlistentry id="opt.prof_prefix">
1018 <term>
1019 <mallctl>opt.prof_prefix</mallctl>
1020 (<type>const char *</type>)
1021 <literal>r-</literal>
1022 [<option>--enable-prof</option>]
1023 </term>
1024 <listitem><para>Filename prefix for profile dumps. If the prefix is
1025 set to the empty string, no automatic dumps will occur; this is
1026 primarily useful for disabling the automatic final heap dump (which
1027 also disables leak reporting, if enabled). The default prefix is
1028 <filename>jeprof</filename>.</para></listitem>
1029 </varlistentry>
1030
a78e148b 1031 <varlistentry id="opt.prof_active">
1032 <term>
1033 <mallctl>opt.prof_active</mallctl>
1034 (<type>bool</type>)
1035 <literal>r-</literal>
1036 [<option>--enable-prof</option>]
1037 </term>
1038 <listitem><para>Profiling activated/deactivated. This is a secondary
1039 control mechanism that makes it possible to start the application with
1040 profiling enabled (see the <link
1041 linkend="opt.prof"><mallctl>opt.prof</mallctl></link> option) but
1042 inactive, then toggle profiling at any time during program execution
1043 with the <link
1044 linkend="prof.active"><mallctl>prof.active</mallctl></link> mallctl.
1045 This option is enabled by default.</para></listitem>
1046 </varlistentry>
1047
1048 <varlistentry id="opt.lg_prof_sample">
1049 <term>
1050 <mallctl>opt.lg_prof_sample</mallctl>
1051 (<type>ssize_t</type>)
1052 <literal>r-</literal>
1053 [<option>--enable-prof</option>]
1054 </term>
1055 <listitem><para>Average interval (log base 2) between allocation
1056 samples, as measured in bytes of allocation activity. Increasing the
1057 sampling interval decreases profile fidelity, but also decreases the
4934f93d 1058 computational overhead. The default sample interval is 512 KiB (2^19
1059 B).</para></listitem>
a78e148b 1060 </varlistentry>
1061
1062 <varlistentry id="opt.prof_accum">
1063 <term>
1064 <mallctl>opt.prof_accum</mallctl>
1065 (<type>bool</type>)
1066 <literal>r-</literal>
1067 [<option>--enable-prof</option>]
1068 </term>
1069 <listitem><para>Reporting of cumulative object/byte counts in profile
1070 dumps enabled/disabled. If this option is enabled, every unique
1071 backtrace must be stored for the duration of execution. Depending on
1072 the application, this can impose a large memory overhead, and the
4934f93d 1073 cumulative counts are not always of interest. This option is disabled
1074 by default.</para></listitem>
a78e148b 1075 </varlistentry>
1076
1077 <varlistentry id="opt.lg_prof_interval">
1078 <term>
1079 <mallctl>opt.lg_prof_interval</mallctl>
1080 (<type>ssize_t</type>)
1081 <literal>r-</literal>
1082 [<option>--enable-prof</option>]
1083 </term>
1084 <listitem><para>Average interval (log base 2) between memory profile
1085 dumps, as measured in bytes of allocation activity. The actual
1086 interval between dumps may be sporadic because decentralized allocation
1087 counters are used to avoid synchronization bottlenecks. Profiles are
1088 dumped to files named according to the pattern
1089 <filename>&lt;prefix&gt;.&lt;pid&gt;.&lt;seq&gt;.i&lt;iseq&gt;.heap</filename>,
1090 where <literal>&lt;prefix&gt;</literal> is controlled by the
1091 <link
1092 linkend="opt.prof_prefix"><mallctl>opt.prof_prefix</mallctl></link>
1093 option. By default, interval-triggered profile dumping is disabled
1094 (encoded as -1).
1095 </para></listitem>
1096 </varlistentry>
1097
1098 <varlistentry id="opt.prof_gdump">
1099 <term>
1100 <mallctl>opt.prof_gdump</mallctl>
1101 (<type>bool</type>)
1102 <literal>r-</literal>
1103 [<option>--enable-prof</option>]
1104 </term>
1105 <listitem><para>Trigger a memory profile dump every time the total
1106 virtual memory exceeds the previous maximum. Profiles are dumped to
1107 files named according to the pattern
1108 <filename>&lt;prefix&gt;.&lt;pid&gt;.&lt;seq&gt;.u&lt;useq&gt;.heap</filename>,
1109 where <literal>&lt;prefix&gt;</literal> is controlled by the <link
1110 linkend="opt.prof_prefix"><mallctl>opt.prof_prefix</mallctl></link>
1111 option. This option is disabled by default.</para></listitem>
1112 </varlistentry>
1113
4934f93d 1114 <varlistentry id="opt.prof_final">
1115 <term>
1116 <mallctl>opt.prof_final</mallctl>
1117 (<type>bool</type>)
1118 <literal>r-</literal>
1119 [<option>--enable-prof</option>]
1120 </term>
1121 <listitem><para>Use an
1122 <citerefentry><refentrytitle>atexit</refentrytitle>
1123 <manvolnum>3</manvolnum></citerefentry> function to dump final memory
1124 usage to a file named according to the pattern
1125 <filename>&lt;prefix&gt;.&lt;pid&gt;.&lt;seq&gt;.f.heap</filename>,
1126 where <literal>&lt;prefix&gt;</literal> is controlled by the <link
1127 linkend="opt.prof_prefix"><mallctl>opt.prof_prefix</mallctl></link>
1128 option. This option is enabled by default.</para></listitem>
1129 </varlistentry>
1130
a78e148b 1131 <varlistentry id="opt.prof_leak">
1132 <term>
1133 <mallctl>opt.prof_leak</mallctl>
1134 (<type>bool</type>)
1135 <literal>r-</literal>
1136 [<option>--enable-prof</option>]
1137 </term>
1138 <listitem><para>Leak reporting enabled/disabled. If enabled, use an
1139 <citerefentry><refentrytitle>atexit</refentrytitle>
1140 <manvolnum>3</manvolnum></citerefentry> function to report memory leaks
1141 detected by allocation sampling. See the
a78e148b 1142 <link linkend="opt.prof"><mallctl>opt.prof</mallctl></link> option for
1143 information on analyzing heap profile output. This option is disabled
1144 by default.</para></listitem>
1145 </varlistentry>
1146
a78e148b 1147 <varlistentry>
1148 <term>
1149 <mallctl>thread.arena</mallctl>
1150 (<type>unsigned</type>)
1151 <literal>rw</literal>
1152 </term>
1153 <listitem><para>Get or set the arena associated with the calling
1154 thread. The arena index must be less than the maximum number of arenas
1155 (see the <link
1156 linkend="arenas.narenas"><mallctl>arenas.narenas</mallctl></link>
1157 mallctl). If the specified arena was not initialized beforehand (see
1158 the <link
1159 linkend="arenas.initialized"><mallctl>arenas.initialized</mallctl></link>
1160 mallctl), it will be automatically initialized as a side effect of
1161 calling this interface.</para></listitem>
1162 </varlistentry>
1163
1164 <varlistentry id="thread.allocated">
1165 <term>
1166 <mallctl>thread.allocated</mallctl>
1167 (<type>uint64_t</type>)
1168 <literal>r-</literal>
1169 [<option>--enable-stats</option>]
1170 </term>
1171 <listitem><para>Get the total number of bytes ever allocated by the
1172 calling thread. This counter has the potential to wrap around; it is
1173 up to the application to appropriately interpret the counter in such
1174 cases.</para></listitem>
1175 </varlistentry>
1176
1177 <varlistentry>
1178 <term>
1179 <mallctl>thread.allocatedp</mallctl>
1180 (<type>uint64_t *</type>)
1181 <literal>r-</literal>
1182 [<option>--enable-stats</option>]
1183 </term>
1184 <listitem><para>Get a pointer to the the value that is returned by the
1185 <link
1186 linkend="thread.allocated"><mallctl>thread.allocated</mallctl></link>
1187 mallctl. This is useful for avoiding the overhead of repeated
1188 <function>mallctl*<parameter/></function> calls.</para></listitem>
1189 </varlistentry>
1190
1191 <varlistentry id="thread.deallocated">
1192 <term>
1193 <mallctl>thread.deallocated</mallctl>
1194 (<type>uint64_t</type>)
1195 <literal>r-</literal>
1196 [<option>--enable-stats</option>]
1197 </term>
1198 <listitem><para>Get the total number of bytes ever deallocated by the
1199 calling thread. This counter has the potential to wrap around; it is
1200 up to the application to appropriately interpret the counter in such
1201 cases.</para></listitem>
1202 </varlistentry>
1203
1204 <varlistentry>
1205 <term>
1206 <mallctl>thread.deallocatedp</mallctl>
1207 (<type>uint64_t *</type>)
1208 <literal>r-</literal>
1209 [<option>--enable-stats</option>]
1210 </term>
1211 <listitem><para>Get a pointer to the the value that is returned by the
1212 <link
1213 linkend="thread.deallocated"><mallctl>thread.deallocated</mallctl></link>
1214 mallctl. This is useful for avoiding the overhead of repeated
1215 <function>mallctl*<parameter/></function> calls.</para></listitem>
1216 </varlistentry>
1217
4934f93d 1218 <varlistentry>
1219 <term>
1220 <mallctl>thread.tcache.enabled</mallctl>
1221 (<type>bool</type>)
1222 <literal>rw</literal>
1223 [<option>--enable-tcache</option>]
1224 </term>
1225 <listitem><para>Enable/disable calling thread's tcache. The tcache is
1226 implicitly flushed as a side effect of becoming
1227 disabled (see <link
1228 lenkend="thread.tcache.flush"><mallctl>thread.tcache.flush</mallctl></link>).
1229 </para></listitem>
1230 </varlistentry>
1231
1232 <varlistentry>
1233 <term>
1234 <mallctl>thread.tcache.flush</mallctl>
1235 (<type>void</type>)
1236 <literal>--</literal>
1237 [<option>--enable-tcache</option>]
1238 </term>
1239 <listitem><para>Flush calling thread's tcache. This interface releases
1240 all cached objects and internal data structures associated with the
1241 calling thread's thread-specific cache. Ordinarily, this interface
1242 need not be called, since automatic periodic incremental garbage
1243 collection occurs, and the thread cache is automatically discarded when
1244 a thread exits. However, garbage collection is triggered by allocation
1245 activity, so it is possible for a thread that stops
1246 allocating/deallocating to retain its cache indefinitely, in which case
1247 the developer may find manual flushing useful.</para></listitem>
1248 </varlistentry>
1249
a78e148b 1250 <varlistentry id="arenas.narenas">
1251 <term>
1252 <mallctl>arenas.narenas</mallctl>
1253 (<type>unsigned</type>)
1254 <literal>r-</literal>
1255 </term>
1256 <listitem><para>Maximum number of arenas.</para></listitem>
1257 </varlistentry>
1258
1259 <varlistentry id="arenas.initialized">
1260 <term>
1261 <mallctl>arenas.initialized</mallctl>
1262 (<type>bool *</type>)
1263 <literal>r-</literal>
1264 </term>
1265 <listitem><para>An array of <link
1266 linkend="arenas.narenas"><mallctl>arenas.narenas</mallctl></link>
1267 booleans. Each boolean indicates whether the corresponding arena is
1268 initialized.</para></listitem>
1269 </varlistentry>
1270
1271 <varlistentry>
1272 <term>
1273 <mallctl>arenas.quantum</mallctl>
1274 (<type>size_t</type>)
1275 <literal>r-</literal>
1276 </term>
1277 <listitem><para>Quantum size.</para></listitem>
1278 </varlistentry>
1279
1280 <varlistentry>
1281 <term>
4934f93d 1282 <mallctl>arenas.page</mallctl>
a78e148b 1283 (<type>size_t</type>)
1284 <literal>r-</literal>
1285 </term>
1286 <listitem><para>Page size.</para></listitem>
1287 </varlistentry>
1288
a78e148b 1289 <varlistentry>
1290 <term>
1291 <mallctl>arenas.tcache_max</mallctl>
1292 (<type>size_t</type>)
1293 <literal>r-</literal>
1294 [<option>--enable-tcache</option>]
1295 </term>
1296 <listitem><para>Maximum thread-cached size class.</para></listitem>
1297 </varlistentry>
1298
a78e148b 1299 <varlistentry>
1300 <term>
1301 <mallctl>arenas.nbins</mallctl>
1302 (<type>unsigned</type>)
1303 <literal>r-</literal>
1304 </term>
4934f93d 1305 <listitem><para>Number of bin size classes.</para></listitem>
a78e148b 1306 </varlistentry>
1307
1308 <varlistentry>
1309 <term>
1310 <mallctl>arenas.nhbins</mallctl>
1311 (<type>unsigned</type>)
1312 <literal>r-</literal>
1313 [<option>--enable-tcache</option>]
1314 </term>
1315 <listitem><para>Total number of thread cache bin size
1316 classes.</para></listitem>
1317 </varlistentry>
1318
1319 <varlistentry id="arenas.bin.i.size">
1320 <term>
1321 <mallctl>arenas.bin.&lt;i&gt;.size</mallctl>
1322 (<type>size_t</type>)
1323 <literal>r-</literal>
1324 </term>
1325 <listitem><para>Maximum size supported by size class.</para></listitem>
1326 </varlistentry>
1327
1328 <varlistentry>
1329 <term>
1330 <mallctl>arenas.bin.&lt;i&gt;.nregs</mallctl>
1331 (<type>uint32_t</type>)
1332 <literal>r-</literal>
1333 </term>
1334 <listitem><para>Number of regions per page run.</para></listitem>
1335 </varlistentry>
1336
1337 <varlistentry>
1338 <term>
1339 <mallctl>arenas.bin.&lt;i&gt;.run_size</mallctl>
1340 (<type>size_t</type>)
1341 <literal>r-</literal>
1342 </term>
1343 <listitem><para>Number of bytes per page run.</para></listitem>
1344 </varlistentry>
1345
1346 <varlistentry>
1347 <term>
1348 <mallctl>arenas.nlruns</mallctl>
1349 (<type>size_t</type>)
1350 <literal>r-</literal>
1351 </term>
1352 <listitem><para>Total number of large size classes.</para></listitem>
1353 </varlistentry>
1354
1355 <varlistentry>
1356 <term>
1357 <mallctl>arenas.lrun.&lt;i&gt;.size</mallctl>
1358 (<type>size_t</type>)
1359 <literal>r-</literal>
1360 </term>
1361 <listitem><para>Maximum size supported by this large size
1362 class.</para></listitem>
1363 </varlistentry>
1364
1365 <varlistentry>
1366 <term>
1367 <mallctl>arenas.purge</mallctl>
1368 (<type>unsigned</type>)
1369 <literal>-w</literal>
1370 </term>
1371 <listitem><para>Purge unused dirty pages for the specified arena, or
1372 for all arenas if none is specified.</para></listitem>
1373 </varlistentry>
1374
1375 <varlistentry id="prof.active">
1376 <term>
1377 <mallctl>prof.active</mallctl>
1378 (<type>bool</type>)
1379 <literal>rw</literal>
1380 [<option>--enable-prof</option>]
1381 </term>
1382 <listitem><para>Control whether sampling is currently active. See the
1383 <link
1384 linkend="opt.prof_active"><mallctl>opt.prof_active</mallctl></link>
1385 option for additional information.
1386 </para></listitem>
1387 </varlistentry>
1388
1389 <varlistentry>
1390 <term>
1391 <mallctl>prof.dump</mallctl>
1392 (<type>const char *</type>)
1393 <literal>-w</literal>
1394 [<option>--enable-prof</option>]
1395 </term>
1396 <listitem><para>Dump a memory profile to the specified file, or if NULL
1397 is specified, to a file according to the pattern
1398 <filename>&lt;prefix&gt;.&lt;pid&gt;.&lt;seq&gt;.m&lt;mseq&gt;.heap</filename>,
1399 where <literal>&lt;prefix&gt;</literal> is controlled by the
1400 <link
1401 linkend="opt.prof_prefix"><mallctl>opt.prof_prefix</mallctl></link>
1402 option.</para></listitem>
1403 </varlistentry>
1404
1405 <varlistentry>
1406 <term>
1407 <mallctl>prof.interval</mallctl>
1408 (<type>uint64_t</type>)
1409 <literal>r-</literal>
1410 [<option>--enable-prof</option>]
1411 </term>
1412 <listitem><para>Average number of bytes allocated between
1413 inverval-based profile dumps. See the
1414 <link
1415 linkend="opt.lg_prof_interval"><mallctl>opt.lg_prof_interval</mallctl></link>
1416 option for additional information.</para></listitem>
1417 </varlistentry>
1418
1419 <varlistentry id="stats.cactive">
1420 <term>
1421 <mallctl>stats.cactive</mallctl>
1422 (<type>size_t *</type>)
1423 <literal>r-</literal>
1424 [<option>--enable-stats</option>]
1425 </term>
1426 <listitem><para>Pointer to a counter that contains an approximate count
1427 of the current number of bytes in active pages. The estimate may be
1428 high, but never low, because each arena rounds up to the nearest
1429 multiple of the chunk size when computing its contribution to the
1430 counter. Note that the <link
1431 linkend="epoch"><mallctl>epoch</mallctl></link> mallctl has no bearing
1432 on this counter. Furthermore, counter consistency is maintained via
1433 atomic operations, so it is necessary to use an atomic operation in
1434 order to guarantee a consistent read when dereferencing the pointer.
1435 </para></listitem>
1436 </varlistentry>
1437
1438 <varlistentry id="stats.allocated">
1439 <term>
1440 <mallctl>stats.allocated</mallctl>
1441 (<type>size_t</type>)
1442 <literal>r-</literal>
1443 [<option>--enable-stats</option>]
1444 </term>
1445 <listitem><para>Total number of bytes allocated by the
1446 application.</para></listitem>
1447 </varlistentry>
1448
1449 <varlistentry id="stats.active">
1450 <term>
1451 <mallctl>stats.active</mallctl>
1452 (<type>size_t</type>)
1453 <literal>r-</literal>
1454 [<option>--enable-stats</option>]
1455 </term>
1456 <listitem><para>Total number of bytes in active pages allocated by the
1457 application. This is a multiple of the page size, and greater than or
1458 equal to <link
1459 linkend="stats.allocated"><mallctl>stats.allocated</mallctl></link>.
1460 </para></listitem>
1461 </varlistentry>
1462
1463 <varlistentry>
1464 <term>
1465 <mallctl>stats.mapped</mallctl>
1466 (<type>size_t</type>)
1467 <literal>r-</literal>
1468 [<option>--enable-stats</option>]
1469 </term>
1470 <listitem><para>Total number of bytes in chunks mapped on behalf of the
1471 application. This is a multiple of the chunk size, and is at least as
1472 large as <link
1473 linkend="stats.active"><mallctl>stats.active</mallctl></link>. This
4934f93d 1474 does not include inactive chunks.</para></listitem>
a78e148b 1475 </varlistentry>
1476
1477 <varlistentry>
1478 <term>
1479 <mallctl>stats.chunks.current</mallctl>
1480 (<type>size_t</type>)
1481 <literal>r-</literal>
1482 [<option>--enable-stats</option>]
1483 </term>
1484 <listitem><para>Total number of chunks actively mapped on behalf of the
4934f93d 1485 application. This does not include inactive chunks.
a78e148b 1486 </para></listitem>
1487 </varlistentry>
1488
1489 <varlistentry>
1490 <term>
1491 <mallctl>stats.chunks.total</mallctl>
1492 (<type>uint64_t</type>)
1493 <literal>r-</literal>
1494 [<option>--enable-stats</option>]
1495 </term>
1496 <listitem><para>Cumulative number of chunks allocated.</para></listitem>
1497 </varlistentry>
1498
1499 <varlistentry>
1500 <term>
1501 <mallctl>stats.chunks.high</mallctl>
1502 (<type>size_t</type>)
1503 <literal>r-</literal>
1504 [<option>--enable-stats</option>]
1505 </term>
1506 <listitem><para>Maximum number of active chunks at any time thus far.
1507 </para></listitem>
1508 </varlistentry>
1509
1510 <varlistentry>
1511 <term>
1512 <mallctl>stats.huge.allocated</mallctl>
1513 (<type>size_t</type>)
1514 <literal>r-</literal>
1515 [<option>--enable-stats</option>]
1516 </term>
1517 <listitem><para>Number of bytes currently allocated by huge objects.
1518 </para></listitem>
1519 </varlistentry>
1520
1521 <varlistentry>
1522 <term>
1523 <mallctl>stats.huge.nmalloc</mallctl>
1524 (<type>uint64_t</type>)
1525 <literal>r-</literal>
1526 [<option>--enable-stats</option>]
1527 </term>
1528 <listitem><para>Cumulative number of huge allocation requests.
1529 </para></listitem>
1530 </varlistentry>
1531
1532 <varlistentry>
1533 <term>
1534 <mallctl>stats.huge.ndalloc</mallctl>
1535 (<type>uint64_t</type>)
1536 <literal>r-</literal>
1537 [<option>--enable-stats</option>]
1538 </term>
1539 <listitem><para>Cumulative number of huge deallocation requests.
1540 </para></listitem>
1541 </varlistentry>
1542
1543 <varlistentry>
1544 <term>
1545 <mallctl>stats.arenas.&lt;i&gt;.nthreads</mallctl>
1546 (<type>unsigned</type>)
1547 <literal>r-</literal>
1548 </term>
1549 <listitem><para>Number of threads currently assigned to
1550 arena.</para></listitem>
1551 </varlistentry>
1552
1553 <varlistentry>
1554 <term>
1555 <mallctl>stats.arenas.&lt;i&gt;.pactive</mallctl>
1556 (<type>size_t</type>)
1557 <literal>r-</literal>
1558 </term>
1559 <listitem><para>Number of pages in active runs.</para></listitem>
1560 </varlistentry>
1561
1562 <varlistentry>
1563 <term>
1564 <mallctl>stats.arenas.&lt;i&gt;.pdirty</mallctl>
1565 (<type>size_t</type>)
1566 <literal>r-</literal>
1567 </term>
1568 <listitem><para>Number of pages within unused runs that are potentially
1569 dirty, and for which <function>madvise<parameter>...</parameter>
1570 <parameter><constant>MADV_DONTNEED</constant></parameter></function> or
1571 similar has not been called.</para></listitem>
1572 </varlistentry>
1573
1574 <varlistentry>
1575 <term>
1576 <mallctl>stats.arenas.&lt;i&gt;.mapped</mallctl>
1577 (<type>size_t</type>)
1578 <literal>r-</literal>
1579 [<option>--enable-stats</option>]
1580 </term>
1581 <listitem><para>Number of mapped bytes.</para></listitem>
1582 </varlistentry>
1583
1584 <varlistentry>
1585 <term>
1586 <mallctl>stats.arenas.&lt;i&gt;.npurge</mallctl>
1587 (<type>uint64_t</type>)
1588 <literal>r-</literal>
1589 [<option>--enable-stats</option>]
1590 </term>
1591 <listitem><para>Number of dirty page purge sweeps performed.
1592 </para></listitem>
1593 </varlistentry>
1594
1595 <varlistentry>
1596 <term>
1597 <mallctl>stats.arenas.&lt;i&gt;.nmadvise</mallctl>
1598 (<type>uint64_t</type>)
1599 <literal>r-</literal>
1600 [<option>--enable-stats</option>]
1601 </term>
1602 <listitem><para>Number of <function>madvise<parameter>...</parameter>
1603 <parameter><constant>MADV_DONTNEED</constant></parameter></function> or
1604 similar calls made to purge dirty pages.</para></listitem>
1605 </varlistentry>
1606
1607 <varlistentry>
1608 <term>
1609 <mallctl>stats.arenas.&lt;i&gt;.npurged</mallctl>
1610 (<type>uint64_t</type>)
1611 <literal>r-</literal>
1612 [<option>--enable-stats</option>]
1613 </term>
1614 <listitem><para>Number of pages purged.</para></listitem>
1615 </varlistentry>
1616
1617 <varlistentry>
1618 <term>
1619 <mallctl>stats.arenas.&lt;i&gt;.small.allocated</mallctl>
1620 (<type>size_t</type>)
1621 <literal>r-</literal>
1622 [<option>--enable-stats</option>]
1623 </term>
1624 <listitem><para>Number of bytes currently allocated by small objects.
1625 </para></listitem>
1626 </varlistentry>
1627
1628 <varlistentry>
1629 <term>
1630 <mallctl>stats.arenas.&lt;i&gt;.small.nmalloc</mallctl>
1631 (<type>uint64_t</type>)
1632 <literal>r-</literal>
1633 [<option>--enable-stats</option>]
1634 </term>
1635 <listitem><para>Cumulative number of allocation requests served by
1636 small bins.</para></listitem>
1637 </varlistentry>
1638
1639 <varlistentry>
1640 <term>
1641 <mallctl>stats.arenas.&lt;i&gt;.small.ndalloc</mallctl>
1642 (<type>uint64_t</type>)
1643 <literal>r-</literal>
1644 [<option>--enable-stats</option>]
1645 </term>
1646 <listitem><para>Cumulative number of small objects returned to bins.
1647 </para></listitem>
1648 </varlistentry>
1649
1650 <varlistentry>
1651 <term>
1652 <mallctl>stats.arenas.&lt;i&gt;.small.nrequests</mallctl>
1653 (<type>uint64_t</type>)
1654 <literal>r-</literal>
1655 [<option>--enable-stats</option>]
1656 </term>
1657 <listitem><para>Cumulative number of small allocation requests.
1658 </para></listitem>
1659 </varlistentry>
1660
1661 <varlistentry>
1662 <term>
1663 <mallctl>stats.arenas.&lt;i&gt;.large.allocated</mallctl>
1664 (<type>size_t</type>)
1665 <literal>r-</literal>
1666 [<option>--enable-stats</option>]
1667 </term>
1668 <listitem><para>Number of bytes currently allocated by large objects.
1669 </para></listitem>
1670 </varlistentry>
1671
1672 <varlistentry>
1673 <term>
1674 <mallctl>stats.arenas.&lt;i&gt;.large.nmalloc</mallctl>
1675 (<type>uint64_t</type>)
1676 <literal>r-</literal>
1677 [<option>--enable-stats</option>]
1678 </term>
1679 <listitem><para>Cumulative number of large allocation requests served
1680 directly by the arena.</para></listitem>
1681 </varlistentry>
1682
1683 <varlistentry>
1684 <term>
1685 <mallctl>stats.arenas.&lt;i&gt;.large.ndalloc</mallctl>
1686 (<type>uint64_t</type>)
1687 <literal>r-</literal>
1688 [<option>--enable-stats</option>]
1689 </term>
1690 <listitem><para>Cumulative number of large deallocation requests served
1691 directly by the arena.</para></listitem>
1692 </varlistentry>
1693
1694 <varlistentry>
1695 <term>
1696 <mallctl>stats.arenas.&lt;i&gt;.large.nrequests</mallctl>
1697 (<type>uint64_t</type>)
1698 <literal>r-</literal>
1699 [<option>--enable-stats</option>]
1700 </term>
1701 <listitem><para>Cumulative number of large allocation requests.
1702 </para></listitem>
1703 </varlistentry>
1704
1705 <varlistentry>
1706 <term>
1707 <mallctl>stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.allocated</mallctl>
1708 (<type>size_t</type>)
1709 <literal>r-</literal>
1710 [<option>--enable-stats</option>]
1711 </term>
1712 <listitem><para>Current number of bytes allocated by
1713 bin.</para></listitem>
1714 </varlistentry>
1715
1716 <varlistentry>
1717 <term>
1718 <mallctl>stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.nmalloc</mallctl>
1719 (<type>uint64_t</type>)
1720 <literal>r-</literal>
1721 [<option>--enable-stats</option>]
1722 </term>
1723 <listitem><para>Cumulative number of allocations served by bin.
1724 </para></listitem>
1725 </varlistentry>
1726
1727 <varlistentry>
1728 <term>
1729 <mallctl>stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.ndalloc</mallctl>
1730 (<type>uint64_t</type>)
1731 <literal>r-</literal>
1732 [<option>--enable-stats</option>]
1733 </term>
1734 <listitem><para>Cumulative number of allocations returned to bin.
1735 </para></listitem>
1736 </varlistentry>
1737
1738 <varlistentry>
1739 <term>
1740 <mallctl>stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.nrequests</mallctl>
1741 (<type>uint64_t</type>)
1742 <literal>r-</literal>
1743 [<option>--enable-stats</option>]
1744 </term>
1745 <listitem><para>Cumulative number of allocation
1746 requests.</para></listitem>
1747 </varlistentry>
1748
1749 <varlistentry>
1750 <term>
1751 <mallctl>stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.nfills</mallctl>
1752 (<type>uint64_t</type>)
1753 <literal>r-</literal>
1754 [<option>--enable-stats</option> <option>--enable-tcache</option>]
1755 </term>
1756 <listitem><para>Cumulative number of tcache fills.</para></listitem>
1757 </varlistentry>
1758
1759 <varlistentry>
1760 <term>
1761 <mallctl>stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.nflushes</mallctl>
1762 (<type>uint64_t</type>)
1763 <literal>r-</literal>
1764 [<option>--enable-stats</option> <option>--enable-tcache</option>]
1765 </term>
1766 <listitem><para>Cumulative number of tcache flushes.</para></listitem>
1767 </varlistentry>
1768
1769 <varlistentry>
1770 <term>
1771 <mallctl>stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.nruns</mallctl>
1772 (<type>uint64_t</type>)
1773 <literal>r-</literal>
1774 [<option>--enable-stats</option>]
1775 </term>
1776 <listitem><para>Cumulative number of runs created.</para></listitem>
1777 </varlistentry>
1778
1779 <varlistentry>
1780 <term>
1781 <mallctl>stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.nreruns</mallctl>
1782 (<type>uint64_t</type>)
1783 <literal>r-</literal>
1784 [<option>--enable-stats</option>]
1785 </term>
1786 <listitem><para>Cumulative number of times the current run from which
1787 to allocate changed.</para></listitem>
1788 </varlistentry>
1789
a78e148b 1790 <varlistentry>
1791 <term>
1792 <mallctl>stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.curruns</mallctl>
1793 (<type>size_t</type>)
1794 <literal>r-</literal>
1795 [<option>--enable-stats</option>]
1796 </term>
1797 <listitem><para>Current number of runs.</para></listitem>
1798 </varlistentry>
1799
1800 <varlistentry>
1801 <term>
1802 <mallctl>stats.arenas.&lt;i&gt;.lruns.&lt;j&gt;.nmalloc</mallctl>
1803 (<type>uint64_t</type>)
1804 <literal>r-</literal>
1805 [<option>--enable-stats</option>]
1806 </term>
1807 <listitem><para>Cumulative number of allocation requests for this size
1808 class served directly by the arena.</para></listitem>
1809 </varlistentry>
1810
1811 <varlistentry>
1812 <term>
1813 <mallctl>stats.arenas.&lt;i&gt;.lruns.&lt;j&gt;.ndalloc</mallctl>
1814 (<type>uint64_t</type>)
1815 <literal>r-</literal>
1816 [<option>--enable-stats</option>]
1817 </term>
1818 <listitem><para>Cumulative number of deallocation requests for this
1819 size class served directly by the arena.</para></listitem>
1820 </varlistentry>
1821
1822 <varlistentry>
1823 <term>
1824 <mallctl>stats.arenas.&lt;i&gt;.lruns.&lt;j&gt;.nrequests</mallctl>
1825 (<type>uint64_t</type>)
1826 <literal>r-</literal>
1827 [<option>--enable-stats</option>]
1828 </term>
1829 <listitem><para>Cumulative number of allocation requests for this size
1830 class.</para></listitem>
1831 </varlistentry>
1832
a78e148b 1833 <varlistentry>
1834 <term>
1835 <mallctl>stats.arenas.&lt;i&gt;.lruns.&lt;j&gt;.curruns</mallctl>
1836 (<type>size_t</type>)
1837 <literal>r-</literal>
1838 [<option>--enable-stats</option>]
1839 </term>
1840 <listitem><para>Current number of runs for this size class.
1841 </para></listitem>
1842 </varlistentry>
a78e148b 1843 </variablelist>
1844 </refsect1>
1845 <refsect1 id="debugging_malloc_problems">
1846 <title>DEBUGGING MALLOC PROBLEMS</title>
1847 <para>When debugging, it is a good idea to configure/build jemalloc with
1848 the <option>--enable-debug</option> and <option>--enable-fill</option>
1849 options, and recompile the program with suitable options and symbols for
1850 debugger support. When so configured, jemalloc incorporates a wide variety
1851 of run-time assertions that catch application errors such as double-free,
1852 write-after-free, etc.</para>
1853
1854 <para>Programs often accidentally depend on &ldquo;uninitialized&rdquo;
1855 memory actually being filled with zero bytes. Junk filling
1856 (see the <link linkend="opt.junk"><mallctl>opt.junk</mallctl></link>
1857 option) tends to expose such bugs in the form of obviously incorrect
1858 results and/or coredumps. Conversely, zero
1859 filling (see the <link
1860 linkend="opt.zero"><mallctl>opt.zero</mallctl></link> option) eliminates
1861 the symptoms of such bugs. Between these two options, it is usually
1862 possible to quickly detect, diagnose, and eliminate such bugs.</para>
1863
1864 <para>This implementation does not provide much detail about the problems
1865 it detects, because the performance impact for storing such information
4934f93d 1866 would be prohibitive. However, jemalloc does integrate with the most
1867 excellent <ulink url="http://valgrind.org/">Valgrind</ulink> tool if the
1868 <option>--enable-valgrind</option> configuration option is enabled and the
1869 <link linkend="opt.valgrind"><mallctl>opt.valgrind</mallctl></link> option
1870 is enabled.</para>
a78e148b 1871 </refsect1>
1872 <refsect1 id="diagnostic_messages">
1873 <title>DIAGNOSTIC MESSAGES</title>
1874 <para>If any of the memory allocation/deallocation functions detect an
1875 error or warning condition, a message will be printed to file descriptor
1876 <constant>STDERR_FILENO</constant>. Errors will result in the process
1877 dumping core. If the <link
1878 linkend="opt.abort"><mallctl>opt.abort</mallctl></link> option is set, most
1879 warnings are treated as errors.</para>
1880
1881 <para>The <varname>malloc_message</varname> variable allows the programmer
1882 to override the function which emits the text strings forming the errors
1883 and warnings if for some reason the <constant>STDERR_FILENO</constant> file
1884 descriptor is not suitable for this.
1885 <function>malloc_message<parameter/></function> takes the
1886 <parameter>cbopaque</parameter> pointer argument that is
1887 <constant>NULL</constant> unless overridden by the arguments in a call to
1888 <function>malloc_stats_print<parameter/></function>, followed by a string
1889 pointer. Please note that doing anything which tries to allocate memory in
1890 this function is likely to result in a crash or deadlock.</para>
1891
1892 <para>All messages are prefixed by
1893 &ldquo;<computeroutput>&lt;jemalloc&gt;: </computeroutput>&rdquo;.</para>
1894 </refsect1>
1895 <refsect1 id="return_values">
1896 <title>RETURN VALUES</title>
1897 <refsect2>
1898 <title>Standard API</title>
1899 <para>The <function>malloc<parameter/></function> and
1900 <function>calloc<parameter/></function> functions return a pointer to the
1901 allocated memory if successful; otherwise a <constant>NULL</constant>
1902 pointer is returned and <varname>errno</varname> is set to
1903 <errorname>ENOMEM</errorname>.</para>
1904
1905 <para>The <function>posix_memalign<parameter/></function> function
1906 returns the value 0 if successful; otherwise it returns an error value.
1907 The <function>posix_memalign<parameter/></function> function will fail
1908 if:
1909 <variablelist>
1910 <varlistentry>
1911 <term><errorname>EINVAL</errorname></term>
1912
1913 <listitem><para>The <parameter>alignment</parameter> parameter is
1914 not a power of 2 at least as large as
1915 <code language="C">sizeof(<type>void *</type>)</code>.
1916 </para></listitem>
1917 </varlistentry>
1918 <varlistentry>
1919 <term><errorname>ENOMEM</errorname></term>
1920
1921 <listitem><para>Memory allocation error.</para></listitem>
1922 </varlistentry>
1923 </variablelist>
1924 </para>
1925
4934f93d 1926 <para>The <function>aligned_alloc<parameter/></function> function returns
1927 a pointer to the allocated memory if successful; otherwise a
1928 <constant>NULL</constant> pointer is returned and
1929 <varname>errno</varname> is set. The
1930 <function>aligned_alloc<parameter/></function> function will fail if:
1931 <variablelist>
1932 <varlistentry>
1933 <term><errorname>EINVAL</errorname></term>
1934
1935 <listitem><para>The <parameter>alignment</parameter> parameter is
1936 not a power of 2.
1937 </para></listitem>
1938 </varlistentry>
1939 <varlistentry>
1940 <term><errorname>ENOMEM</errorname></term>
1941
1942 <listitem><para>Memory allocation error.</para></listitem>
1943 </varlistentry>
1944 </variablelist>
1945 </para>
1946
a78e148b 1947 <para>The <function>realloc<parameter/></function> function returns a
1948 pointer, possibly identical to <parameter>ptr</parameter>, to the
1949 allocated memory if successful; otherwise a <constant>NULL</constant>
1950 pointer is returned, and <varname>errno</varname> is set to
1951 <errorname>ENOMEM</errorname> if the error was the result of an
1952 allocation failure. The <function>realloc<parameter/></function>
1953 function always leaves the original buffer intact when an error occurs.
1954 </para>
1955
1956 <para>The <function>free<parameter/></function> function returns no
1957 value.</para>
1958 </refsect2>
1959 <refsect2>
1960 <title>Non-standard API</title>
1961 <para>The <function>malloc_usable_size<parameter/></function> function
1962 returns the usable size of the allocation pointed to by
1963 <parameter>ptr</parameter>. </para>
1964
1965 <para>The <function>mallctl<parameter/></function>,
1966 <function>mallctlnametomib<parameter/></function>, and
1967 <function>mallctlbymib<parameter/></function> functions return 0 on
1968 success; otherwise they return an error value. The functions will fail
1969 if:
1970 <variablelist>
1971 <varlistentry>
1972 <term><errorname>EINVAL</errorname></term>
1973
1974 <listitem><para><parameter>newp</parameter> is not
1975 <constant>NULL</constant>, and <parameter>newlen</parameter> is too
1976 large or too small. Alternatively, <parameter>*oldlenp</parameter>
1977 is too large or too small; in this case as much data as possible
1978 are read despite the error.</para></listitem>
1979 </varlistentry>
1980 <varlistentry>
1981 <term><errorname>ENOMEM</errorname></term>
1982
1983 <listitem><para><parameter>*oldlenp</parameter> is too short to
1984 hold the requested value.</para></listitem>
1985 </varlistentry>
1986 <varlistentry>
1987 <term><errorname>ENOENT</errorname></term>
1988
1989 <listitem><para><parameter>name</parameter> or
1990 <parameter>mib</parameter> specifies an unknown/invalid
1991 value.</para></listitem>
1992 </varlistentry>
1993 <varlistentry>
1994 <term><errorname>EPERM</errorname></term>
1995
1996 <listitem><para>Attempt to read or write void value, or attempt to
1997 write read-only value.</para></listitem>
1998 </varlistentry>
1999 <varlistentry>
2000 <term><errorname>EAGAIN</errorname></term>
2001
2002 <listitem><para>A memory allocation failure
2003 occurred.</para></listitem>
2004 </varlistentry>
2005 <varlistentry>
2006 <term><errorname>EFAULT</errorname></term>
2007
2008 <listitem><para>An interface with side effects failed in some way
2009 not directly related to <function>mallctl*<parameter/></function>
2010 read/write processing.</para></listitem>
2011 </varlistentry>
2012 </variablelist>
2013 </para>
2014 </refsect2>
2015 <refsect2>
2016 <title>Experimental API</title>
2017 <para>The <function>allocm<parameter/></function>,
2018 <function>rallocm<parameter/></function>,
4934f93d 2019 <function>sallocm<parameter/></function>,
2020 <function>dallocm<parameter/></function>, and
2021 <function>nallocm<parameter/></function> functions return
a78e148b 2022 <constant>ALLOCM_SUCCESS</constant> on success; otherwise they return an
4934f93d 2023 error value. The <function>allocm<parameter/></function>,
2024 <function>rallocm<parameter/></function>, and
2025 <function>nallocm<parameter/></function> functions will fail if:
a78e148b 2026 <variablelist>
2027 <varlistentry>
2028 <term><errorname>ALLOCM_ERR_OOM</errorname></term>
2029
2030 <listitem><para>Out of memory. Insufficient contiguous memory was
2031 available to service the allocation request. The
2032 <function>allocm<parameter/></function> function additionally sets
2033 <parameter>*ptr</parameter> to <constant>NULL</constant>, whereas
2034 the <function>rallocm<parameter/></function> function leaves
2035 <constant>*ptr</constant> unmodified.</para></listitem>
2036 </varlistentry>
2037 </variablelist>
2038 The <function>rallocm<parameter/></function> function will also
2039 fail if:
2040 <variablelist>
2041 <varlistentry>
2042 <term><errorname>ALLOCM_ERR_NOT_MOVED</errorname></term>
2043
2044 <listitem><para><constant>ALLOCM_NO_MOVE</constant> was specified,
2045 but the reallocation request could not be serviced without moving
2046 the object.</para></listitem>
2047 </varlistentry>
2048 </variablelist>
2049 </para>
2050 </refsect2>
2051 </refsect1>
2052 <refsect1 id="environment">
2053 <title>ENVIRONMENT</title>
2054 <para>The following environment variable affects the execution of the
2055 allocation functions:
2056 <variablelist>
2057 <varlistentry>
2058 <term><envar>MALLOC_CONF</envar></term>
2059
2060 <listitem><para>If the environment variable
2061 <envar>MALLOC_CONF</envar> is set, the characters it contains
2062 will be interpreted as options.</para></listitem>
2063 </varlistentry>
2064 </variablelist>
2065 </para>
2066 </refsect1>
2067 <refsect1 id="examples">
2068 <title>EXAMPLES</title>
2069 <para>To dump core whenever a problem occurs:
2070 <screen>ln -s 'abort:true' /etc/malloc.conf</screen>
2071 </para>
2072 <para>To specify in the source a chunk size that is 16 MiB:
2073 <programlisting language="C"><![CDATA[
2074malloc_conf = "lg_chunk:24";]]></programlisting></para>
2075 </refsect1>
2076 <refsect1 id="see_also">
2077 <title>SEE ALSO</title>
2078 <para><citerefentry><refentrytitle>madvise</refentrytitle>
2079 <manvolnum>2</manvolnum></citerefentry>,
2080 <citerefentry><refentrytitle>mmap</refentrytitle>
2081 <manvolnum>2</manvolnum></citerefentry>,
2082 <citerefentry><refentrytitle>sbrk</refentrytitle>
2083 <manvolnum>2</manvolnum></citerefentry>,
4934f93d 2084 <citerefentry><refentrytitle>utrace</refentrytitle>
2085 <manvolnum>2</manvolnum></citerefentry>,
a78e148b 2086 <citerefentry><refentrytitle>alloca</refentrytitle>
2087 <manvolnum>3</manvolnum></citerefentry>,
2088 <citerefentry><refentrytitle>atexit</refentrytitle>
2089 <manvolnum>3</manvolnum></citerefentry>,
2090 <citerefentry><refentrytitle>getpagesize</refentrytitle>
2091 <manvolnum>3</manvolnum></citerefentry></para>
2092 </refsect1>
2093 <refsect1 id="standards">
2094 <title>STANDARDS</title>
2095 <para>The <function>malloc<parameter/></function>,
2096 <function>calloc<parameter/></function>,
2097 <function>realloc<parameter/></function>, and
2098 <function>free<parameter/></function> functions conform to ISO/IEC
2099 9899:1990 (&ldquo;ISO C90&rdquo;).</para>
2100
2101 <para>The <function>posix_memalign<parameter/></function> function conforms
2102 to IEEE Std 1003.1-2001 (&ldquo;POSIX.1&rdquo;).</para>
2103 </refsect1>
2104</refentry>