xref: /redis-3.2.3/deps/jemalloc/doc/jemalloc.html (revision 79d2f70f)
1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>JEMALLOC</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="refentry"><a name="idm316394519664"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>jemalloc &#8212; general purpose memory allocation functions</p></div><div class="refsect1"><a name="library"></a><h2>LIBRARY</h2><p>This manual describes jemalloc 3.6.0-0-g46c0af68bd248b04df75e4f92d5fb804c3d75340.  More information
2    can be found at the <a class="ulink" href="http://www.canonware.com/jemalloc/" target="_top">jemalloc website</a>.</p></div><div class="refsynopsisdiv"><h2>SYNOPSIS</h2><div class="funcsynopsis"><pre class="funcsynopsisinfo">#include &lt;<code class="filename">stdlib.h</code>&gt;
3#include &lt;<code class="filename">jemalloc/jemalloc.h</code>&gt;</pre><div class="refsect2"><a name="idm316394002288"></a><h3>Standard API</h3><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">void *<b class="fsfunc">malloc</b>(</code></td><td>size_t <var class="pdparam">size</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer">�</div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">void *<b class="fsfunc">calloc</b>(</code></td><td>size_t <var class="pdparam">number</var>, </td></tr><tr><td>�</td><td>size_t <var class="pdparam">size</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer">�</div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">posix_memalign</b>(</code></td><td>void **<var class="pdparam">ptr</var>, </td></tr><tr><td>�</td><td>size_t <var class="pdparam">alignment</var>, </td></tr><tr><td>�</td><td>size_t <var class="pdparam">size</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer">�</div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">void *<b class="fsfunc">aligned_alloc</b>(</code></td><td>size_t <var class="pdparam">alignment</var>, </td></tr><tr><td>�</td><td>size_t <var class="pdparam">size</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer">�</div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">void *<b class="fsfunc">realloc</b>(</code></td><td>void *<var class="pdparam">ptr</var>, </td></tr><tr><td>�</td><td>size_t <var class="pdparam">size</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer">�</div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">void <b class="fsfunc">free</b>(</code></td><td>void *<var class="pdparam">ptr</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer">�</div></div><div class="refsect2"><a name="idm316393986160"></a><h3>Non-standard API</h3><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">void *<b class="fsfunc">mallocx</b>(</code></td><td>size_t <var class="pdparam">size</var>, </td></tr><tr><td>�</td><td>int <var class="pdparam">flags</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer">�</div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">void *<b class="fsfunc">rallocx</b>(</code></td><td>void *<var class="pdparam">ptr</var>, </td></tr><tr><td>�</td><td>size_t <var class="pdparam">size</var>, </td></tr><tr><td>�</td><td>int <var class="pdparam">flags</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer">�</div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">size_t <b class="fsfunc">xallocx</b>(</code></td><td>void *<var class="pdparam">ptr</var>, </td></tr><tr><td>�</td><td>size_t <var class="pdparam">size</var>, </td></tr><tr><td>�</td><td>size_t <var class="pdparam">extra</var>, </td></tr><tr><td>�</td><td>int <var class="pdparam">flags</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer">�</div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">size_t <b class="fsfunc">sallocx</b>(</code></td><td>void *<var class="pdparam">ptr</var>, </td></tr><tr><td>�</td><td>int <var class="pdparam">flags</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer">�</div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">void <b class="fsfunc">dallocx</b>(</code></td><td>void *<var class="pdparam">ptr</var>, </td></tr><tr><td>�</td><td>int <var class="pdparam">flags</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer">�</div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">size_t <b class="fsfunc">nallocx</b>(</code></td><td>size_t <var class="pdparam">size</var>, </td></tr><tr><td>�</td><td>int <var class="pdparam">flags</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer">�</div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">mallctl</b>(</code></td><td>const char *<var class="pdparam">name</var>, </td></tr><tr><td>�</td><td>void *<var class="pdparam">oldp</var>, </td></tr><tr><td>�</td><td>size_t *<var class="pdparam">oldlenp</var>, </td></tr><tr><td>�</td><td>void *<var class="pdparam">newp</var>, </td></tr><tr><td>�</td><td>size_t <var class="pdparam">newlen</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer">�</div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">mallctlnametomib</b>(</code></td><td>const char *<var class="pdparam">name</var>, </td></tr><tr><td>�</td><td>size_t *<var class="pdparam">mibp</var>, </td></tr><tr><td>�</td><td>size_t *<var class="pdparam">miblenp</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer">�</div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">mallctlbymib</b>(</code></td><td>const size_t *<var class="pdparam">mib</var>, </td></tr><tr><td>�</td><td>size_t <var class="pdparam">miblen</var>, </td></tr><tr><td>�</td><td>void *<var class="pdparam">oldp</var>, </td></tr><tr><td>�</td><td>size_t *<var class="pdparam">oldlenp</var>, </td></tr><tr><td>�</td><td>void *<var class="pdparam">newp</var>, </td></tr><tr><td>�</td><td>size_t <var class="pdparam">newlen</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer">�</div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">void <b class="fsfunc">malloc_stats_print</b>(</code></td><td>void <var class="pdparam">(*write_cb)</var>
4            <code>(</code>void *, const char *<code>)</code>
5          , </td></tr><tr><td>�</td><td>void *<var class="pdparam">cbopaque</var>, </td></tr><tr><td>�</td><td>const char *<var class="pdparam">opts</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer">�</div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">size_t <b class="fsfunc">malloc_usable_size</b>(</code></td><td>const void *<var class="pdparam">ptr</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer">�</div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">void <b class="fsfunc">(*malloc_message)</b>(</code></td><td>void *<var class="pdparam">cbopaque</var>, </td></tr><tr><td>�</td><td>const char *<var class="pdparam">s</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer">�</div><p><span class="type">const char *</span><code class="varname">malloc_conf</code>;</p></div><div class="refsect2"><a name="idm316388684112"></a><h3>Experimental API</h3><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">allocm</b>(</code></td><td>void **<var class="pdparam">ptr</var>, </td></tr><tr><td>�</td><td>size_t *<var class="pdparam">rsize</var>, </td></tr><tr><td>�</td><td>size_t <var class="pdparam">size</var>, </td></tr><tr><td>�</td><td>int <var class="pdparam">flags</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer">�</div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">rallocm</b>(</code></td><td>void **<var class="pdparam">ptr</var>, </td></tr><tr><td>�</td><td>size_t *<var class="pdparam">rsize</var>, </td></tr><tr><td>�</td><td>size_t <var class="pdparam">size</var>, </td></tr><tr><td>�</td><td>size_t <var class="pdparam">extra</var>, </td></tr><tr><td>�</td><td>int <var class="pdparam">flags</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer">�</div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sallocm</b>(</code></td><td>const void *<var class="pdparam">ptr</var>, </td></tr><tr><td>�</td><td>size_t *<var class="pdparam">rsize</var>, </td></tr><tr><td>�</td><td>int <var class="pdparam">flags</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer">�</div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">dallocm</b>(</code></td><td>void *<var class="pdparam">ptr</var>, </td></tr><tr><td>�</td><td>int <var class="pdparam">flags</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer">�</div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">nallocm</b>(</code></td><td>size_t *<var class="pdparam">rsize</var>, </td></tr><tr><td>�</td><td>size_t <var class="pdparam">size</var>, </td></tr><tr><td>�</td><td>int <var class="pdparam">flags</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer">�</div></div></div></div><div class="refsect1"><a name="description"></a><h2>DESCRIPTION</h2><div class="refsect2"><a name="idm316388663504"></a><h3>Standard API</h3><p>The <code class="function">malloc</code>(<em class="parameter"><code></code></em>) function allocates
6      <em class="parameter"><code>size</code></em> bytes of uninitialized memory.  The allocated
7      space is suitably aligned (after possible pointer coercion) for storage
8      of any type of object.</p><p>The <code class="function">calloc</code>(<em class="parameter"><code></code></em>) function allocates
9      space for <em class="parameter"><code>number</code></em> objects, each
10      <em class="parameter"><code>size</code></em> bytes in length.  The result is identical to
11      calling <code class="function">malloc</code>(<em class="parameter"><code></code></em>) with an argument of
12      <em class="parameter"><code>number</code></em> * <em class="parameter"><code>size</code></em>, with the
13      exception that the allocated memory is explicitly initialized to zero
14      bytes.</p><p>The <code class="function">posix_memalign</code>(<em class="parameter"><code></code></em>) function
15      allocates <em class="parameter"><code>size</code></em> bytes of memory such that the
16      allocation's base address is an even multiple of
17      <em class="parameter"><code>alignment</code></em>, and returns the allocation in the value
18      pointed to by <em class="parameter"><code>ptr</code></em>.  The requested
19      <em class="parameter"><code>alignment</code></em> must be a power of 2 at least as large
20      as <code class="code">sizeof(<span class="type">void *</span>)</code>.</p><p>The <code class="function">aligned_alloc</code>(<em class="parameter"><code></code></em>) function
21      allocates <em class="parameter"><code>size</code></em> bytes of memory such that the
22      allocation's base address is an even multiple of
23      <em class="parameter"><code>alignment</code></em>.  The requested
24      <em class="parameter"><code>alignment</code></em> must be a power of 2.  Behavior is
25      undefined if <em class="parameter"><code>size</code></em> is not an integral multiple of
26      <em class="parameter"><code>alignment</code></em>.</p><p>The <code class="function">realloc</code>(<em class="parameter"><code></code></em>) function changes the
27      size of the previously allocated memory referenced by
28      <em class="parameter"><code>ptr</code></em> to <em class="parameter"><code>size</code></em> bytes.  The
29      contents of the memory are unchanged up to the lesser of the new and old
30      sizes.  If the new size is larger, the contents of the newly allocated
31      portion of the memory are undefined.  Upon success, the memory referenced
32      by <em class="parameter"><code>ptr</code></em> is freed and a pointer to the newly
33      allocated memory is returned.  Note that
34      <code class="function">realloc</code>(<em class="parameter"><code></code></em>) may move the memory allocation,
35      resulting in a different return value than <em class="parameter"><code>ptr</code></em>.
36      If <em class="parameter"><code>ptr</code></em> is <code class="constant">NULL</code>, the
37      <code class="function">realloc</code>(<em class="parameter"><code></code></em>) function behaves identically to
38      <code class="function">malloc</code>(<em class="parameter"><code></code></em>) for the specified size.</p><p>The <code class="function">free</code>(<em class="parameter"><code></code></em>) function causes the
39      allocated memory referenced by <em class="parameter"><code>ptr</code></em> to be made
40      available for future allocations.  If <em class="parameter"><code>ptr</code></em> is
41      <code class="constant">NULL</code>, no action occurs.</p></div><div class="refsect2"><a name="idm316388639904"></a><h3>Non-standard API</h3><p>The <code class="function">mallocx</code>(<em class="parameter"><code></code></em>),
42      <code class="function">rallocx</code>(<em class="parameter"><code></code></em>),
43      <code class="function">xallocx</code>(<em class="parameter"><code></code></em>),
44      <code class="function">sallocx</code>(<em class="parameter"><code></code></em>),
45      <code class="function">dallocx</code>(<em class="parameter"><code></code></em>), and
46      <code class="function">nallocx</code>(<em class="parameter"><code></code></em>) functions all have a
47      <em class="parameter"><code>flags</code></em> argument that can be used to specify
48      options.  The functions only check the options that are contextually
49      relevant.  Use bitwise or (<code class="code">|</code>) operations to
50      specify one or more of the following:
51        </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="constant">MALLOCX_LG_ALIGN(<em class="parameter"><code>la</code></em>)
52            </code></span></dt><dd><p>Align the memory allocation to start at an address
53            that is a multiple of <code class="code">(1 &lt;&lt;
54            <em class="parameter"><code>la</code></em>)</code>.  This macro does not validate
55            that <em class="parameter"><code>la</code></em> is within the valid
56            range.</p></dd><dt><span class="term"><code class="constant">MALLOCX_ALIGN(<em class="parameter"><code>a</code></em>)
57            </code></span></dt><dd><p>Align the memory allocation to start at an address
58            that is a multiple of <em class="parameter"><code>a</code></em>, where
59            <em class="parameter"><code>a</code></em> is a power of two.  This macro does not
60            validate that <em class="parameter"><code>a</code></em> is a power of 2.
61            </p></dd><dt><span class="term"><code class="constant">MALLOCX_ZERO</code></span></dt><dd><p>Initialize newly allocated memory to contain zero
62            bytes.  In the growing reallocation case, the real size prior to
63            reallocation defines the boundary between untouched bytes and those
64            that are initialized to contain zero bytes.  If this macro is
65            absent, newly allocated memory is uninitialized.</p></dd><dt><span class="term"><code class="constant">MALLOCX_ARENA(<em class="parameter"><code>a</code></em>)
66            </code></span></dt><dd><p>Use the arena specified by the index
67            <em class="parameter"><code>a</code></em> (and by necessity bypass the thread
68            cache).  This macro has no effect for huge regions, nor for regions
69            that were allocated via an arena other than the one specified.
70            This macro does not validate that <em class="parameter"><code>a</code></em>
71            specifies an arena index in the valid range.</p></dd></dl></div><p>
72      </p><p>The <code class="function">mallocx</code>(<em class="parameter"><code></code></em>) function allocates at
73      least <em class="parameter"><code>size</code></em> bytes of memory, and returns a pointer
74      to the base address of the allocation.  Behavior is undefined if
75      <em class="parameter"><code>size</code></em> is <code class="constant">0</code>, or if request size
76      overflows due to size class and/or alignment constraints.</p><p>The <code class="function">rallocx</code>(<em class="parameter"><code></code></em>) function resizes the
77      allocation at <em class="parameter"><code>ptr</code></em> to be at least
78      <em class="parameter"><code>size</code></em> bytes, and returns a pointer to the base
79      address of the resulting allocation, which may or may not have moved from
80      its original location.  Behavior is undefined if
81      <em class="parameter"><code>size</code></em> is <code class="constant">0</code>, or if request size
82      overflows due to size class and/or alignment constraints.</p><p>The <code class="function">xallocx</code>(<em class="parameter"><code></code></em>) function resizes the
83      allocation at <em class="parameter"><code>ptr</code></em> in place to be at least
84      <em class="parameter"><code>size</code></em> bytes, and returns the real size of the
85      allocation.  If <em class="parameter"><code>extra</code></em> is non-zero, an attempt is
86      made to resize the allocation to be at least <code class="code">(<em class="parameter"><code>size</code></em> +
87      <em class="parameter"><code>extra</code></em>)</code> bytes, though inability to allocate
88      the extra byte(s) will not by itself result in failure to resize.
89      Behavior is undefined if <em class="parameter"><code>size</code></em> is
90      <code class="constant">0</code>, or if <code class="code">(<em class="parameter"><code>size</code></em> + <em class="parameter"><code>extra</code></em>
91      &gt; <code class="constant">SIZE_T_MAX</code>)</code>.</p><p>The <code class="function">sallocx</code>(<em class="parameter"><code></code></em>) function returns the
92      real size of the allocation at <em class="parameter"><code>ptr</code></em>.</p><p>The <code class="function">dallocx</code>(<em class="parameter"><code></code></em>) function causes the
93      memory referenced by <em class="parameter"><code>ptr</code></em> to be made available for
94      future allocations.</p><p>The <code class="function">nallocx</code>(<em class="parameter"><code></code></em>) function allocates no
95      memory, but it performs the same size computation as the
96      <code class="function">mallocx</code>(<em class="parameter"><code></code></em>) function, and returns the real
97      size of the allocation that would result from the equivalent
98      <code class="function">mallocx</code>(<em class="parameter"><code></code></em>) function call.  Behavior is
99      undefined if <em class="parameter"><code>size</code></em> is <code class="constant">0</code>, or if
100      request size overflows due to size class and/or alignment
101      constraints.</p><p>The <code class="function">mallctl</code>(<em class="parameter"><code></code></em>) function provides a
102      general interface for introspecting the memory allocator, as well as
103      setting modifiable parameters and triggering actions.  The
104      period-separated <em class="parameter"><code>name</code></em> argument specifies a
105      location in a tree-structured namespace; see the <a class="xref" href="#mallctl_namespace" title="MALLCTL NAMESPACE">MALLCTL NAMESPACE</a> section for
106      documentation on the tree contents.  To read a value, pass a pointer via
107      <em class="parameter"><code>oldp</code></em> to adequate space to contain the value, and a
108      pointer to its length via <em class="parameter"><code>oldlenp</code></em>; otherwise pass
109      <code class="constant">NULL</code> and <code class="constant">NULL</code>.  Similarly, to
110      write a value, pass a pointer to the value via
111      <em class="parameter"><code>newp</code></em>, and its length via
112      <em class="parameter"><code>newlen</code></em>; otherwise pass <code class="constant">NULL</code>
113      and <code class="constant">0</code>.</p><p>The <code class="function">mallctlnametomib</code>(<em class="parameter"><code></code></em>) function
114      provides a way to avoid repeated name lookups for applications that
115      repeatedly query the same portion of the namespace, by translating a name
116      to a &#8220;Management Information Base&#8221; (MIB) that can be passed
117      repeatedly to <code class="function">mallctlbymib</code>(<em class="parameter"><code></code></em>).  Upon
118      successful return from <code class="function">mallctlnametomib</code>(<em class="parameter"><code></code></em>),
119      <em class="parameter"><code>mibp</code></em> contains an array of
120      <em class="parameter"><code>*miblenp</code></em> integers, where
121      <em class="parameter"><code>*miblenp</code></em> is the lesser of the number of components
122      in <em class="parameter"><code>name</code></em> and the input value of
123      <em class="parameter"><code>*miblenp</code></em>.  Thus it is possible to pass a
124      <em class="parameter"><code>*miblenp</code></em> that is smaller than the number of
125      period-separated name components, which results in a partial MIB that can
126      be used as the basis for constructing a complete MIB.  For name
127      components that are integers (e.g. the 2 in
128      <a class="link" href="#arenas.bin.i.size">
129    "<code class="mallctl">arenas.bin.2.size</code>"
130  </a>),
131      the corresponding MIB component will always be that integer.  Therefore,
132      it is legitimate to construct code like the following: </p><pre class="programlisting">
133unsigned nbins, i;
134size_t mib[4];
135size_t len, miblen;
136
137len = sizeof(nbins);
138mallctl("arenas.nbins", &amp;nbins, &amp;len, NULL, 0);
139
140miblen = 4;
141mallctlnametomib("arenas.bin.0.size", mib, &amp;miblen);
142for (i = 0; i &lt; nbins; i++) {
143	size_t bin_size;
144
145	mib[2] = i;
146	len = sizeof(bin_size);
147	mallctlbymib(mib, miblen, &amp;bin_size, &amp;len, NULL, 0);
148	/* Do something with bin_size... */
149}</pre><p>The <code class="function">malloc_stats_print</code>(<em class="parameter"><code></code></em>) function
150      writes human-readable summary statistics via the
151      <em class="parameter"><code>write_cb</code></em> callback function pointer and
152      <em class="parameter"><code>cbopaque</code></em> data passed to
153      <em class="parameter"><code>write_cb</code></em>, or
154      <code class="function">malloc_message</code>(<em class="parameter"><code></code></em>) if
155      <em class="parameter"><code>write_cb</code></em> is <code class="constant">NULL</code>.  This
156      function can be called repeatedly.  General information that never
157      changes during execution can be omitted by specifying "g" as a character
158      within the <em class="parameter"><code>opts</code></em> string.  Note that
159      <code class="function">malloc_message</code>(<em class="parameter"><code></code></em>) uses the
160      <code class="function">mallctl*</code>(<em class="parameter"><code></code></em>) functions internally, so
161      inconsistent statistics can be reported if multiple threads use these
162      functions simultaneously.  If <code class="option">--enable-stats</code> is
163      specified during configuration, &#8220;m&#8221; and &#8220;a&#8221; can
164      be specified to omit merged arena and per arena statistics, respectively;
165      &#8220;b&#8221; and &#8220;l&#8221; can be specified to omit per size
166      class statistics for bins and large objects, respectively.  Unrecognized
167      characters are silently ignored.  Note that thread caching may prevent
168      some statistics from being completely up to date, since extra locking
169      would be required to merge counters that track thread cache operations.
170      </p><p>The <code class="function">malloc_usable_size</code>(<em class="parameter"><code></code></em>) function
171      returns the usable size of the allocation pointed to by
172      <em class="parameter"><code>ptr</code></em>.  The return value may be larger than the size
173      that was requested during allocation.  The
174      <code class="function">malloc_usable_size</code>(<em class="parameter"><code></code></em>) function is not a
175      mechanism for in-place <code class="function">realloc</code>(<em class="parameter"><code></code></em>); rather
176      it is provided solely as a tool for introspection purposes.  Any
177      discrepancy between the requested allocation size and the size reported
178      by <code class="function">malloc_usable_size</code>(<em class="parameter"><code></code></em>) should not be
179      depended on, since such behavior is entirely implementation-dependent.
180      </p></div><div class="refsect2"><a name="idm316388574208"></a><h3>Experimental API</h3><p>The experimental API is subject to change or removal without regard
181      for backward compatibility.  If <code class="option">--disable-experimental</code>
182      is specified during configuration, the experimental API is
183      omitted.</p><p>The <code class="function">allocm</code>(<em class="parameter"><code></code></em>),
184      <code class="function">rallocm</code>(<em class="parameter"><code></code></em>),
185      <code class="function">sallocm</code>(<em class="parameter"><code></code></em>),
186      <code class="function">dallocm</code>(<em class="parameter"><code></code></em>), and
187      <code class="function">nallocm</code>(<em class="parameter"><code></code></em>) functions all have a
188      <em class="parameter"><code>flags</code></em> argument that can be used to specify
189      options.  The functions only check the options that are contextually
190      relevant.  Use bitwise or (<code class="code">|</code>) operations to
191      specify one or more of the following:
192        </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="constant">ALLOCM_LG_ALIGN(<em class="parameter"><code>la</code></em>)
193            </code></span></dt><dd><p>Align the memory allocation to start at an address
194            that is a multiple of <code class="code">(1 &lt;&lt;
195            <em class="parameter"><code>la</code></em>)</code>.  This macro does not validate
196            that <em class="parameter"><code>la</code></em> is within the valid
197            range.</p></dd><dt><span class="term"><code class="constant">ALLOCM_ALIGN(<em class="parameter"><code>a</code></em>)
198            </code></span></dt><dd><p>Align the memory allocation to start at an address
199            that is a multiple of <em class="parameter"><code>a</code></em>, where
200            <em class="parameter"><code>a</code></em> is a power of two.  This macro does not
201            validate that <em class="parameter"><code>a</code></em> is a power of 2.
202            </p></dd><dt><span class="term"><code class="constant">ALLOCM_ZERO</code></span></dt><dd><p>Initialize newly allocated memory to contain zero
203            bytes.  In the growing reallocation case, the real size prior to
204            reallocation defines the boundary between untouched bytes and those
205            that are initialized to contain zero bytes.  If this macro is
206            absent, newly allocated memory is uninitialized.</p></dd><dt><span class="term"><code class="constant">ALLOCM_NO_MOVE</code></span></dt><dd><p>For reallocation, fail rather than moving the
207            object.  This constraint can apply to both growth and
208            shrinkage.</p></dd><dt><span class="term"><code class="constant">ALLOCM_ARENA(<em class="parameter"><code>a</code></em>)
209            </code></span></dt><dd><p>Use the arena specified by the index
210            <em class="parameter"><code>a</code></em> (and by necessity bypass the thread
211            cache).  This macro has no effect for huge regions, nor for regions
212            that were allocated via an arena other than the one specified.
213            This macro does not validate that <em class="parameter"><code>a</code></em>
214            specifies an arena index in the valid range.</p></dd></dl></div><p>
215      </p><p>The <code class="function">allocm</code>(<em class="parameter"><code></code></em>) function allocates at
216      least <em class="parameter"><code>size</code></em> bytes of memory, sets
217      <em class="parameter"><code>*ptr</code></em> to the base address of the allocation, and
218      sets <em class="parameter"><code>*rsize</code></em> to the real size of the allocation if
219      <em class="parameter"><code>rsize</code></em> is not <code class="constant">NULL</code>.  Behavior
220      is undefined if <em class="parameter"><code>size</code></em> is <code class="constant">0</code>, or
221      if request size overflows due to size class and/or alignment
222      constraints.</p><p>The <code class="function">rallocm</code>(<em class="parameter"><code></code></em>) function resizes the
223      allocation at <em class="parameter"><code>*ptr</code></em> to be at least
224      <em class="parameter"><code>size</code></em> bytes, sets <em class="parameter"><code>*ptr</code></em> to
225      the base address of the allocation if it moved, and sets
226      <em class="parameter"><code>*rsize</code></em> to the real size of the allocation if
227      <em class="parameter"><code>rsize</code></em> is not <code class="constant">NULL</code>.  If
228      <em class="parameter"><code>extra</code></em> is non-zero, an attempt is made to resize
229      the allocation to be at least <code class="code">(<em class="parameter"><code>size</code></em> +
230      <em class="parameter"><code>extra</code></em>)</code> bytes, though inability to allocate
231      the extra byte(s) will not by itself result in failure.  Behavior is
232      undefined if <em class="parameter"><code>size</code></em> is <code class="constant">0</code>, if
233      request size overflows due to size class and/or alignment constraints, or
234      if <code class="code">(<em class="parameter"><code>size</code></em> +
235      <em class="parameter"><code>extra</code></em> &gt;
236      <code class="constant">SIZE_T_MAX</code>)</code>.</p><p>The <code class="function">sallocm</code>(<em class="parameter"><code></code></em>) function sets
237      <em class="parameter"><code>*rsize</code></em> to the real size of the allocation.</p><p>The <code class="function">dallocm</code>(<em class="parameter"><code></code></em>) function causes the
238      memory referenced by <em class="parameter"><code>ptr</code></em> to be made available for
239      future allocations.</p><p>The <code class="function">nallocm</code>(<em class="parameter"><code></code></em>) function allocates no
240      memory, but it performs the same size computation as the
241      <code class="function">allocm</code>(<em class="parameter"><code></code></em>) function, and if
242      <em class="parameter"><code>rsize</code></em> is not <code class="constant">NULL</code> it sets
243      <em class="parameter"><code>*rsize</code></em> to the real size of the allocation that
244      would result from the equivalent <code class="function">allocm</code>(<em class="parameter"><code></code></em>)
245      function call.  Behavior is undefined if <em class="parameter"><code>size</code></em> is
246      <code class="constant">0</code>, or if request size overflows due to size class
247      and/or alignment constraints.</p></div></div><div class="refsect1"><a name="tuning"></a><h2>TUNING</h2><p>Once, when the first call is made to one of the memory allocation
248    routines, the allocator initializes its internals based in part on various
249    options that can be specified at compile- or run-time.</p><p>The string pointed to by the global variable
250    <code class="varname">malloc_conf</code>, the &#8220;name&#8221; of the file
251    referenced by the symbolic link named <code class="filename">/etc/malloc.conf</code>, and the value of the
252    environment variable <code class="envar">MALLOC_CONF</code>, will be interpreted, in
253    that order, from left to right as options.  Note that
254    <code class="varname">malloc_conf</code> may be read before
255    <code class="function">main</code>(<em class="parameter"><code></code></em>) is entered, so the declaration of
256    <code class="varname">malloc_conf</code> should specify an initializer that contains
257    the final value to be read by jemalloc.  <code class="varname">malloc_conf</code> is
258    a compile-time setting, whereas <code class="filename">/etc/malloc.conf</code> and <code class="envar">MALLOC_CONF</code>
259    can be safely set any time prior to program invocation.</p><p>An options string is a comma-separated list of option:value pairs.
260    There is one key corresponding to each <a class="link" href="#opt.abort">
261    "<code class="mallctl">opt.*</code>"
262  </a> mallctl (see the <a class="xref" href="#mallctl_namespace" title="MALLCTL NAMESPACE">MALLCTL NAMESPACE</a> section for options
263    documentation).  For example, <code class="literal">abort:true,narenas:1</code> sets
264    the <a class="link" href="#opt.abort">
265    "<code class="mallctl">opt.abort</code>"
266  </a> and <a class="link" href="#opt.narenas">
267    "<code class="mallctl">opt.narenas</code>"
268  </a> options.  Some
269    options have boolean values (true/false), others have integer values (base
270    8, 10, or 16, depending on prefix), and yet others have raw string
271    values.</p></div><div class="refsect1"><a name="implementation_notes"></a><h2>IMPLEMENTATION NOTES</h2><p>Traditionally, allocators have used
272    <span class="citerefentry"><span class="refentrytitle">sbrk</span>(2)</span> to obtain memory, which is
273    suboptimal for several reasons, including race conditions, increased
274    fragmentation, and artificial limitations on maximum usable memory.  If
275    <code class="option">--enable-dss</code> is specified during configuration, this
276    allocator uses both <span class="citerefentry"><span class="refentrytitle">mmap</span>(2)</span> and
277    <span class="citerefentry"><span class="refentrytitle">sbrk</span>(2)</span>, in that order of preference;
278    otherwise only <span class="citerefentry"><span class="refentrytitle">mmap</span>(2)</span> is used.</p><p>This allocator uses multiple arenas in order to reduce lock
279    contention for threaded programs on multi-processor systems.  This works
280    well with regard to threading scalability, but incurs some costs.  There is
281    a small fixed per-arena overhead, and additionally, arenas manage memory
282    completely independently of each other, which means a small fixed increase
283    in overall memory fragmentation.  These overheads are not generally an
284    issue, given the number of arenas normally used.  Note that using
285    substantially more arenas than the default is not likely to improve
286    performance, mainly due to reduced cache performance.  However, it may make
287    sense to reduce the number of arenas if an application does not make much
288    use of the allocation functions.</p><p>In addition to multiple arenas, unless
289    <code class="option">--disable-tcache</code> is specified during configuration, this
290    allocator supports thread-specific caching for small and large objects, in
291    order to make it possible to completely avoid synchronization for most
292    allocation requests.  Such caching allows very fast allocation in the
293    common case, but it increases memory usage and fragmentation, since a
294    bounded number of objects can remain allocated in each thread cache.</p><p>Memory is conceptually broken into equal-sized chunks, where the
295    chunk size is a power of two that is greater than the page size.  Chunks
296    are always aligned to multiples of the chunk size.  This alignment makes it
297    possible to find metadata for user objects very quickly.</p><p>User objects are broken into three categories according to size:
298    small, large, and huge.  Small objects are smaller than one page.  Large
299    objects are smaller than the chunk size.  Huge objects are a multiple of
300    the chunk size.  Small and large objects are managed by arenas; huge
301    objects are managed separately in a single data structure that is shared by
302    all threads.  Huge objects are used by applications infrequently enough
303    that this single data structure is not a scalability issue.</p><p>Each chunk that is managed by an arena tracks its contents as runs of
304    contiguous pages (unused, backing a set of small objects, or backing one
305    large object).  The combination of chunk alignment and chunk page maps
306    makes it possible to determine all metadata regarding small and large
307    allocations in constant time.</p><p>Small objects are managed in groups by page runs.  Each run maintains
308    a frontier and free list to track which regions are in use.  Allocation
309    requests that are no more than half the quantum (8 or 16, depending on
310    architecture) are rounded up to the nearest power of two that is at least
311    <code class="code">sizeof(<span class="type">double</span>)</code>.  All other small
312    object size classes are multiples of the quantum, spaced such that internal
313    fragmentation is limited to approximately 25% for all but the smallest size
314    classes.  Allocation requests that are larger than the maximum small size
315    class, but small enough to fit in an arena-managed chunk (see the <a class="link" href="#opt.lg_chunk">
316    "<code class="mallctl">opt.lg_chunk</code>"
317  </a> option), are
318    rounded up to the nearest run size.  Allocation requests that are too large
319    to fit in an arena-managed chunk are rounded up to the nearest multiple of
320    the chunk size.</p><p>Allocations are packed tightly together, which can be an issue for
321    multi-threaded applications.  If you need to assure that allocations do not
322    suffer from cacheline sharing, round your allocation requests up to the
323    nearest multiple of the cacheline size, or specify cacheline alignment when
324    allocating.</p><p>Assuming 4 MiB chunks, 4 KiB pages, and a 16-byte quantum on a 64-bit
325    system, the size classes in each category are as shown in <a class="xref" href="#size_classes" title="Table�1.�Size classes">Table 1</a>.</p><div class="table"><a name="size_classes"></a><p class="title"><b>Table�1.�Size classes</b></p><div class="table-contents"><table summary="Size classes" border="1"><colgroup><col align="left" class="c1"><col align="right" class="c2"><col align="left" class="c3"></colgroup><thead><tr><th align="left">Category</th><th align="right">Spacing</th><th align="left">Size</th></tr></thead><tbody><tr><td rowspan="7" align="left">Small</td><td align="right">lg</td><td align="left">[8]</td></tr><tr><td align="right">16</td><td align="left">[16, 32, 48, ..., 128]</td></tr><tr><td align="right">32</td><td align="left">[160, 192, 224, 256]</td></tr><tr><td align="right">64</td><td align="left">[320, 384, 448, 512]</td></tr><tr><td align="right">128</td><td align="left">[640, 768, 896, 1024]</td></tr><tr><td align="right">256</td><td align="left">[1280, 1536, 1792, 2048]</td></tr><tr><td align="right">512</td><td align="left">[2560, 3072, 3584]</td></tr><tr><td align="left">Large</td><td align="right">4 KiB</td><td align="left">[4 KiB, 8 KiB, 12 KiB, ..., 4072 KiB]</td></tr><tr><td align="left">Huge</td><td align="right">4 MiB</td><td align="left">[4 MiB, 8 MiB, 12 MiB, ...]</td></tr></tbody></table></div></div><br class="table-break"></div><div class="refsect1"><a name="mallctl_namespace"></a><h2>MALLCTL NAMESPACE</h2><p>The following names are defined in the namespace accessible via the
326    <code class="function">mallctl*</code>(<em class="parameter"><code></code></em>) functions.  Value types are
327    specified in parentheses, their readable/writable statuses are encoded as
328    <code class="literal">rw</code>, <code class="literal">r-</code>, <code class="literal">-w</code>, or
329    <code class="literal">--</code>, and required build configuration flags follow, if
330    any.  A name element encoded as <code class="literal">&lt;i&gt;</code> or
331    <code class="literal">&lt;j&gt;</code> indicates an integer component, where the
332    integer varies from 0 to some upper value that must be determined via
333    introspection.  In the case of
334    "<code class="mallctl">stats.arenas.&lt;i&gt;.*</code>"
335  ,
336    <code class="literal">&lt;i&gt;</code> equal to <a class="link" href="#arenas.narenas">
337    "<code class="mallctl">arenas.narenas</code>"
338  </a> can be
339    used to access the summation of statistics from all arenas.  Take special
340    note of the <a class="link" href="#epoch">
341    "<code class="mallctl">epoch</code>"
342  </a> mallctl,
343    which controls refreshing of cached dynamic statistics.</p><div class="variablelist"><dl class="variablelist"><dt><a name="version"></a><span class="term">
344
345    "<code class="mallctl">version</code>"
346
347          (<span class="type">const char *</span>)
348          <code class="literal">r-</code>
349        </span></dt><dd><p>Return the jemalloc version string.</p></dd><dt><a name="epoch"></a><span class="term">
350
351    "<code class="mallctl">epoch</code>"
352
353          (<span class="type">uint64_t</span>)
354          <code class="literal">rw</code>
355        </span></dt><dd><p>If a value is passed in, refresh the data from which
356        the <code class="function">mallctl*</code>(<em class="parameter"><code></code></em>) functions report values,
357        and increment the epoch.  Return the current epoch.  This is useful for
358        detecting whether another thread caused a refresh.</p></dd><dt><a name="config.debug"></a><span class="term">
359
360    "<code class="mallctl">config.debug</code>"
361
362          (<span class="type">bool</span>)
363          <code class="literal">r-</code>
364        </span></dt><dd><p><code class="option">--enable-debug</code> was specified during
365        build configuration.</p></dd><dt><a name="config.dss"></a><span class="term">
366
367    "<code class="mallctl">config.dss</code>"
368
369          (<span class="type">bool</span>)
370          <code class="literal">r-</code>
371        </span></dt><dd><p><code class="option">--enable-dss</code> was specified during
372        build configuration.</p></dd><dt><a name="config.fill"></a><span class="term">
373
374    "<code class="mallctl">config.fill</code>"
375
376          (<span class="type">bool</span>)
377          <code class="literal">r-</code>
378        </span></dt><dd><p><code class="option">--enable-fill</code> was specified during
379        build configuration.</p></dd><dt><a name="config.lazy_lock"></a><span class="term">
380
381    "<code class="mallctl">config.lazy_lock</code>"
382
383          (<span class="type">bool</span>)
384          <code class="literal">r-</code>
385        </span></dt><dd><p><code class="option">--enable-lazy-lock</code> was specified
386        during build configuration.</p></dd><dt><a name="config.mremap"></a><span class="term">
387
388    "<code class="mallctl">config.mremap</code>"
389
390          (<span class="type">bool</span>)
391          <code class="literal">r-</code>
392        </span></dt><dd><p><code class="option">--enable-mremap</code> was specified during
393        build configuration.</p></dd><dt><a name="config.munmap"></a><span class="term">
394
395    "<code class="mallctl">config.munmap</code>"
396
397          (<span class="type">bool</span>)
398          <code class="literal">r-</code>
399        </span></dt><dd><p><code class="option">--enable-munmap</code> was specified during
400        build configuration.</p></dd><dt><a name="config.prof"></a><span class="term">
401
402    "<code class="mallctl">config.prof</code>"
403
404          (<span class="type">bool</span>)
405          <code class="literal">r-</code>
406        </span></dt><dd><p><code class="option">--enable-prof</code> was specified during
407        build configuration.</p></dd><dt><a name="config.prof_libgcc"></a><span class="term">
408
409    "<code class="mallctl">config.prof_libgcc</code>"
410
411          (<span class="type">bool</span>)
412          <code class="literal">r-</code>
413        </span></dt><dd><p><code class="option">--disable-prof-libgcc</code> was not
414        specified during build configuration.</p></dd><dt><a name="config.prof_libunwind"></a><span class="term">
415
416    "<code class="mallctl">config.prof_libunwind</code>"
417
418          (<span class="type">bool</span>)
419          <code class="literal">r-</code>
420        </span></dt><dd><p><code class="option">--enable-prof-libunwind</code> was specified
421        during build configuration.</p></dd><dt><a name="config.stats"></a><span class="term">
422
423    "<code class="mallctl">config.stats</code>"
424
425          (<span class="type">bool</span>)
426          <code class="literal">r-</code>
427        </span></dt><dd><p><code class="option">--enable-stats</code> was specified during
428        build configuration.</p></dd><dt><a name="config.tcache"></a><span class="term">
429
430    "<code class="mallctl">config.tcache</code>"
431
432          (<span class="type">bool</span>)
433          <code class="literal">r-</code>
434        </span></dt><dd><p><code class="option">--disable-tcache</code> was not specified
435        during build configuration.</p></dd><dt><a name="config.tls"></a><span class="term">
436
437    "<code class="mallctl">config.tls</code>"
438
439          (<span class="type">bool</span>)
440          <code class="literal">r-</code>
441        </span></dt><dd><p><code class="option">--disable-tls</code> was not specified during
442        build configuration.</p></dd><dt><a name="config.utrace"></a><span class="term">
443
444    "<code class="mallctl">config.utrace</code>"
445
446          (<span class="type">bool</span>)
447          <code class="literal">r-</code>
448        </span></dt><dd><p><code class="option">--enable-utrace</code> was specified during
449        build configuration.</p></dd><dt><a name="config.valgrind"></a><span class="term">
450
451    "<code class="mallctl">config.valgrind</code>"
452
453          (<span class="type">bool</span>)
454          <code class="literal">r-</code>
455        </span></dt><dd><p><code class="option">--enable-valgrind</code> was specified during
456        build configuration.</p></dd><dt><a name="config.xmalloc"></a><span class="term">
457
458    "<code class="mallctl">config.xmalloc</code>"
459
460          (<span class="type">bool</span>)
461          <code class="literal">r-</code>
462        </span></dt><dd><p><code class="option">--enable-xmalloc</code> was specified during
463        build configuration.</p></dd><dt><a name="opt.abort"></a><span class="term">
464
465    "<code class="mallctl">opt.abort</code>"
466
467          (<span class="type">bool</span>)
468          <code class="literal">r-</code>
469        </span></dt><dd><p>Abort-on-warning enabled/disabled.  If true, most
470        warnings are fatal.  The process will call
471        <span class="citerefentry"><span class="refentrytitle">abort</span>(3)</span> in these cases.  This option is
472        disabled by default unless <code class="option">--enable-debug</code> is
473        specified during configuration, in which case it is enabled by default.
474        </p></dd><dt><a name="opt.dss"></a><span class="term">
475
476    "<code class="mallctl">opt.dss</code>"
477
478          (<span class="type">const char *</span>)
479          <code class="literal">r-</code>
480        </span></dt><dd><p>dss (<span class="citerefentry"><span class="refentrytitle">sbrk</span>(2)</span>) allocation precedence as
481        related to <span class="citerefentry"><span class="refentrytitle">mmap</span>(2)</span> allocation.  The following
482        settings are supported: &#8220;disabled&#8221;, &#8220;primary&#8221;,
483        and &#8220;secondary&#8221;.  The default is &#8220;secondary&#8221; if
484        <a class="link" href="#config.dss">
485    "<code class="mallctl">config.dss</code>"
486  </a> is
487        true, &#8220;disabled&#8221; otherwise.
488        </p></dd><dt><a name="opt.lg_chunk"></a><span class="term">
489
490    "<code class="mallctl">opt.lg_chunk</code>"
491
492          (<span class="type">size_t</span>)
493          <code class="literal">r-</code>
494        </span></dt><dd><p>Virtual memory chunk size (log base 2).  If a chunk
495        size outside the supported size range is specified, the size is
496        silently clipped to the minimum/maximum supported size.  The default
497        chunk size is 4 MiB (2^22).
498        </p></dd><dt><a name="opt.narenas"></a><span class="term">
499
500    "<code class="mallctl">opt.narenas</code>"
501
502          (<span class="type">size_t</span>)
503          <code class="literal">r-</code>
504        </span></dt><dd><p>Maximum number of arenas to use for automatic
505        multiplexing of threads and arenas.  The default is four times the
506        number of CPUs, or one if there is a single CPU.</p></dd><dt><a name="opt.lg_dirty_mult"></a><span class="term">
507
508    "<code class="mallctl">opt.lg_dirty_mult</code>"
509
510          (<span class="type">ssize_t</span>)
511          <code class="literal">r-</code>
512        </span></dt><dd><p>Per-arena minimum ratio (log base 2) of active to dirty
513        pages.  Some dirty unused pages may be allowed to accumulate, within
514        the limit set by the ratio (or one chunk worth of dirty pages,
515        whichever is greater), before informing the kernel about some of those
516        pages via <span class="citerefentry"><span class="refentrytitle">madvise</span>(2)</span> or a similar system call.  This
517        provides the kernel with sufficient information to recycle dirty pages
518        if physical memory becomes scarce and the pages remain unused.  The
519        default minimum ratio is 8:1 (2^3:1); an option value of -1 will
520        disable dirty page purging.</p></dd><dt><a name="opt.stats_print"></a><span class="term">
521
522    "<code class="mallctl">opt.stats_print</code>"
523
524          (<span class="type">bool</span>)
525          <code class="literal">r-</code>
526        </span></dt><dd><p>Enable/disable statistics printing at exit.  If
527        enabled, the <code class="function">malloc_stats_print</code>(<em class="parameter"><code></code></em>)
528        function is called at program exit via an
529        <span class="citerefentry"><span class="refentrytitle">atexit</span>(3)</span> function.  If
530        <code class="option">--enable-stats</code> is specified during configuration, this
531        has the potential to cause deadlock for a multi-threaded process that
532        exits while one or more threads are executing in the memory allocation
533        functions.  Therefore, this option should only be used with care; it is
534        primarily intended as a performance tuning aid during application
535        development.  This option is disabled by default.</p></dd><dt><a name="opt.junk"></a><span class="term">
536
537    "<code class="mallctl">opt.junk</code>"
538
539          (<span class="type">bool</span>)
540          <code class="literal">r-</code>
541          [<code class="option">--enable-fill</code>]
542        </span></dt><dd><p>Junk filling enabled/disabled.  If enabled, each byte
543        of uninitialized allocated memory will be initialized to
544        <code class="literal">0xa5</code>.  All deallocated memory will be initialized to
545        <code class="literal">0x5a</code>.  This is intended for debugging and will
546        impact performance negatively.  This option is disabled by default
547        unless <code class="option">--enable-debug</code> is specified during
548        configuration, in which case it is enabled by default unless running
549        inside <a class="ulink" href="http://valgrind.org/" target="_top">Valgrind</a>.</p></dd><dt><a name="opt.quarantine"></a><span class="term">
550
551    "<code class="mallctl">opt.quarantine</code>"
552
553          (<span class="type">size_t</span>)
554          <code class="literal">r-</code>
555          [<code class="option">--enable-fill</code>]
556        </span></dt><dd><p>Per thread quarantine size in bytes.  If non-zero, each
557        thread maintains a FIFO object quarantine that stores up to the
558        specified number of bytes of memory.  The quarantined memory is not
559        freed until it is released from quarantine, though it is immediately
560        junk-filled if the <a class="link" href="#opt.junk">
561    "<code class="mallctl">opt.junk</code>"
562  </a> option is
563        enabled.  This feature is of particular use in combination with <a class="ulink" href="http://valgrind.org/" target="_top">Valgrind</a>, which can detect attempts
564        to access quarantined objects.  This is intended for debugging and will
565        impact performance negatively.  The default quarantine size is 0 unless
566        running inside Valgrind, in which case the default is 16
567        MiB.</p></dd><dt><a name="opt.redzone"></a><span class="term">
568
569    "<code class="mallctl">opt.redzone</code>"
570
571          (<span class="type">bool</span>)
572          <code class="literal">r-</code>
573          [<code class="option">--enable-fill</code>]
574        </span></dt><dd><p>Redzones enabled/disabled.  If enabled, small
575        allocations have redzones before and after them.  Furthermore, if the
576        <a class="link" href="#opt.junk">
577    "<code class="mallctl">opt.junk</code>"
578  </a> option is
579        enabled, the redzones are checked for corruption during deallocation.
580        However, the primary intended purpose of this feature is to be used in
581        combination with <a class="ulink" href="http://valgrind.org/" target="_top">Valgrind</a>,
582        which needs redzones in order to do effective buffer overflow/underflow
583        detection.  This option is intended for debugging and will impact
584        performance negatively.  This option is disabled by
585        default unless running inside Valgrind.</p></dd><dt><a name="opt.zero"></a><span class="term">
586
587    "<code class="mallctl">opt.zero</code>"
588
589          (<span class="type">bool</span>)
590          <code class="literal">r-</code>
591          [<code class="option">--enable-fill</code>]
592        </span></dt><dd><p>Zero filling enabled/disabled.  If enabled, each byte
593        of uninitialized allocated memory will be initialized to 0.  Note that
594        this initialization only happens once for each byte, so
595        <code class="function">realloc</code>(<em class="parameter"><code></code></em>),
596        <code class="function">rallocx</code>(<em class="parameter"><code></code></em>) and
597        <code class="function">rallocm</code>(<em class="parameter"><code></code></em>) calls do not zero memory that
598        was previously allocated.  This is intended for debugging and will
599        impact performance negatively.  This option is disabled by default.
600        </p></dd><dt><a name="opt.utrace"></a><span class="term">
601
602    "<code class="mallctl">opt.utrace</code>"
603
604          (<span class="type">bool</span>)
605          <code class="literal">r-</code>
606          [<code class="option">--enable-utrace</code>]
607        </span></dt><dd><p>Allocation tracing based on
608        <span class="citerefentry"><span class="refentrytitle">utrace</span>(2)</span> enabled/disabled.  This option
609        is disabled by default.</p></dd><dt><a name="opt.valgrind"></a><span class="term">
610
611    "<code class="mallctl">opt.valgrind</code>"
612
613          (<span class="type">bool</span>)
614          <code class="literal">r-</code>
615          [<code class="option">--enable-valgrind</code>]
616        </span></dt><dd><p><a class="ulink" href="http://valgrind.org/" target="_top">Valgrind</a>
617        support enabled/disabled.  This option is vestigal because jemalloc
618        auto-detects whether it is running inside Valgrind.  This option is
619        disabled by default, unless running inside Valgrind.</p></dd><dt><a name="opt.xmalloc"></a><span class="term">
620
621    "<code class="mallctl">opt.xmalloc</code>"
622
623          (<span class="type">bool</span>)
624          <code class="literal">r-</code>
625          [<code class="option">--enable-xmalloc</code>]
626        </span></dt><dd><p>Abort-on-out-of-memory enabled/disabled.  If enabled,
627        rather than returning failure for any allocation function, display a
628        diagnostic message on <code class="constant">STDERR_FILENO</code> and cause the
629        program to drop core (using
630        <span class="citerefentry"><span class="refentrytitle">abort</span>(3)</span>).  If an application is
631        designed to depend on this behavior, set the option at compile time by
632        including the following in the source code:
633        </p><pre class="programlisting">
634malloc_conf = "xmalloc:true";</pre><p>
635        This option is disabled by default.</p></dd><dt><a name="opt.tcache"></a><span class="term">
636
637    "<code class="mallctl">opt.tcache</code>"
638
639          (<span class="type">bool</span>)
640          <code class="literal">r-</code>
641          [<code class="option">--enable-tcache</code>]
642        </span></dt><dd><p>Thread-specific caching enabled/disabled.  When there
643        are multiple threads, each thread uses a thread-specific cache for
644        objects up to a certain size.  Thread-specific caching allows many
645        allocations to be satisfied without performing any thread
646        synchronization, at the cost of increased memory use.  See the
647        <a class="link" href="#opt.lg_tcache_max">
648    "<code class="mallctl">opt.lg_tcache_max</code>"
649  </a>
650        option for related tuning information.  This option is enabled by
651        default unless running inside <a class="ulink" href="http://valgrind.org/" target="_top">Valgrind</a>.</p></dd><dt><a name="opt.lg_tcache_max"></a><span class="term">
652
653    "<code class="mallctl">opt.lg_tcache_max</code>"
654
655          (<span class="type">size_t</span>)
656          <code class="literal">r-</code>
657          [<code class="option">--enable-tcache</code>]
658        </span></dt><dd><p>Maximum size class (log base 2) to cache in the
659        thread-specific cache.  At a minimum, all small size classes are
660        cached, and at a maximum all large size classes are cached.  The
661        default maximum is 32 KiB (2^15).</p></dd><dt><a name="opt.prof"></a><span class="term">
662
663    "<code class="mallctl">opt.prof</code>"
664
665          (<span class="type">bool</span>)
666          <code class="literal">r-</code>
667          [<code class="option">--enable-prof</code>]
668        </span></dt><dd><p>Memory profiling enabled/disabled.  If enabled, profile
669        memory allocation activity.  See the <a class="link" href="#opt.prof_active">
670    "<code class="mallctl">opt.prof_active</code>"
671  </a>
672        option for on-the-fly activation/deactivation.  See the <a class="link" href="#opt.lg_prof_sample">
673    "<code class="mallctl">opt.lg_prof_sample</code>"
674  </a>
675        option for probabilistic sampling control.  See the <a class="link" href="#opt.prof_accum">
676    "<code class="mallctl">opt.prof_accum</code>"
677  </a>
678        option for control of cumulative sample reporting.  See the <a class="link" href="#opt.lg_prof_interval">
679    "<code class="mallctl">opt.lg_prof_interval</code>"
680  </a>
681        option for information on interval-triggered profile dumping, the <a class="link" href="#opt.prof_gdump">
682    "<code class="mallctl">opt.prof_gdump</code>"
683  </a>
684        option for information on high-water-triggered profile dumping, and the
685        <a class="link" href="#opt.prof_final">
686    "<code class="mallctl">opt.prof_final</code>"
687  </a>
688        option for final profile dumping.  Profile output is compatible with
689        the included <span class="command"><strong>pprof</strong></span> Perl script, which originates
690        from the <a class="ulink" href="http://code.google.com/p/gperftools/" target="_top">gperftools
691        package</a>.</p></dd><dt><a name="opt.prof_prefix"></a><span class="term">
692
693    "<code class="mallctl">opt.prof_prefix</code>"
694
695          (<span class="type">const char *</span>)
696          <code class="literal">r-</code>
697          [<code class="option">--enable-prof</code>]
698        </span></dt><dd><p>Filename prefix for profile dumps.  If the prefix is
699        set to the empty string, no automatic dumps will occur; this is
700        primarily useful for disabling the automatic final heap dump (which
701        also disables leak reporting, if enabled).  The default prefix is
702        <code class="filename">jeprof</code>.</p></dd><dt><a name="opt.prof_active"></a><span class="term">
703
704    "<code class="mallctl">opt.prof_active</code>"
705
706          (<span class="type">bool</span>)
707          <code class="literal">rw</code>
708          [<code class="option">--enable-prof</code>]
709        </span></dt><dd><p>Profiling activated/deactivated.  This is a secondary
710        control mechanism that makes it possible to start the application with
711        profiling enabled (see the <a class="link" href="#opt.prof">
712    "<code class="mallctl">opt.prof</code>"
713  </a> option) but
714        inactive, then toggle profiling at any time during program execution
715        with the <a class="link" href="#prof.active">
716    "<code class="mallctl">prof.active</code>"
717  </a> mallctl.
718        This option is enabled by default.</p></dd><dt><a name="opt.lg_prof_sample"></a><span class="term">
719
720    "<code class="mallctl">opt.lg_prof_sample</code>"
721
722          (<span class="type">ssize_t</span>)
723          <code class="literal">r-</code>
724          [<code class="option">--enable-prof</code>]
725        </span></dt><dd><p>Average interval (log base 2) between allocation
726        samples, as measured in bytes of allocation activity.  Increasing the
727        sampling interval decreases profile fidelity, but also decreases the
728        computational overhead.  The default sample interval is 512 KiB (2^19
729        B).</p></dd><dt><a name="opt.prof_accum"></a><span class="term">
730
731    "<code class="mallctl">opt.prof_accum</code>"
732
733          (<span class="type">bool</span>)
734          <code class="literal">r-</code>
735          [<code class="option">--enable-prof</code>]
736        </span></dt><dd><p>Reporting of cumulative object/byte counts in profile
737        dumps enabled/disabled.  If this option is enabled, every unique
738        backtrace must be stored for the duration of execution.  Depending on
739        the application, this can impose a large memory overhead, and the
740        cumulative counts are not always of interest.  This option is disabled
741        by default.</p></dd><dt><a name="opt.lg_prof_interval"></a><span class="term">
742
743    "<code class="mallctl">opt.lg_prof_interval</code>"
744
745          (<span class="type">ssize_t</span>)
746          <code class="literal">r-</code>
747          [<code class="option">--enable-prof</code>]
748        </span></dt><dd><p>Average interval (log base 2) between memory profile
749        dumps, as measured in bytes of allocation activity.  The actual
750        interval between dumps may be sporadic because decentralized allocation
751        counters are used to avoid synchronization bottlenecks.  Profiles are
752        dumped to files named according to the pattern
753        <code class="filename">&lt;prefix&gt;.&lt;pid&gt;.&lt;seq&gt;.i&lt;iseq&gt;.heap</code>,
754        where <code class="literal">&lt;prefix&gt;</code> is controlled by the
755        <a class="link" href="#opt.prof_prefix">
756    "<code class="mallctl">opt.prof_prefix</code>"
757  </a>
758        option.  By default, interval-triggered profile dumping is disabled
759        (encoded as -1).
760        </p></dd><dt><a name="opt.prof_gdump"></a><span class="term">
761
762    "<code class="mallctl">opt.prof_gdump</code>"
763
764          (<span class="type">bool</span>)
765          <code class="literal">r-</code>
766          [<code class="option">--enable-prof</code>]
767        </span></dt><dd><p>Trigger a memory profile dump every time the total
768        virtual memory exceeds the previous maximum.  Profiles are dumped to
769        files named according to the pattern
770        <code class="filename">&lt;prefix&gt;.&lt;pid&gt;.&lt;seq&gt;.u&lt;useq&gt;.heap</code>,
771        where <code class="literal">&lt;prefix&gt;</code> is controlled by the <a class="link" href="#opt.prof_prefix">
772    "<code class="mallctl">opt.prof_prefix</code>"
773  </a>
774        option.  This option is disabled by default.</p></dd><dt><a name="opt.prof_final"></a><span class="term">
775
776    "<code class="mallctl">opt.prof_final</code>"
777
778          (<span class="type">bool</span>)
779          <code class="literal">r-</code>
780          [<code class="option">--enable-prof</code>]
781        </span></dt><dd><p>Use an
782        <span class="citerefentry"><span class="refentrytitle">atexit</span>(3)</span> function to dump final memory
783        usage to a file named according to the pattern
784        <code class="filename">&lt;prefix&gt;.&lt;pid&gt;.&lt;seq&gt;.f.heap</code>,
785        where <code class="literal">&lt;prefix&gt;</code> is controlled by the <a class="link" href="#opt.prof_prefix">
786    "<code class="mallctl">opt.prof_prefix</code>"
787  </a>
788        option.  This option is enabled by default.</p></dd><dt><a name="opt.prof_leak"></a><span class="term">
789
790    "<code class="mallctl">opt.prof_leak</code>"
791
792          (<span class="type">bool</span>)
793          <code class="literal">r-</code>
794          [<code class="option">--enable-prof</code>]
795        </span></dt><dd><p>Leak reporting enabled/disabled.  If enabled, use an
796        <span class="citerefentry"><span class="refentrytitle">atexit</span>(3)</span> function to report memory leaks
797        detected by allocation sampling.  See the
798        <a class="link" href="#opt.prof">
799    "<code class="mallctl">opt.prof</code>"
800  </a> option for
801        information on analyzing heap profile output.  This option is disabled
802        by default.</p></dd><dt><a name="thread.arena"></a><span class="term">
803
804    "<code class="mallctl">thread.arena</code>"
805
806          (<span class="type">unsigned</span>)
807          <code class="literal">rw</code>
808        </span></dt><dd><p>Get or set the arena associated with the calling
809        thread.  If the specified arena was not initialized beforehand (see the
810        <a class="link" href="#arenas.initialized">
811    "<code class="mallctl">arenas.initialized</code>"
812  </a>
813        mallctl), it will be automatically initialized as a side effect of
814        calling this interface.</p></dd><dt><a name="thread.allocated"></a><span class="term">
815
816    "<code class="mallctl">thread.allocated</code>"
817
818          (<span class="type">uint64_t</span>)
819          <code class="literal">r-</code>
820          [<code class="option">--enable-stats</code>]
821        </span></dt><dd><p>Get the total number of bytes ever allocated by the
822        calling thread.  This counter has the potential to wrap around; it is
823        up to the application to appropriately interpret the counter in such
824        cases.</p></dd><dt><a name="thread.allocatedp"></a><span class="term">
825
826    "<code class="mallctl">thread.allocatedp</code>"
827
828          (<span class="type">uint64_t *</span>)
829          <code class="literal">r-</code>
830          [<code class="option">--enable-stats</code>]
831        </span></dt><dd><p>Get a pointer to the the value that is returned by the
832        <a class="link" href="#thread.allocated">
833    "<code class="mallctl">thread.allocated</code>"
834  </a>
835        mallctl.  This is useful for avoiding the overhead of repeated
836        <code class="function">mallctl*</code>(<em class="parameter"><code></code></em>) calls.</p></dd><dt><a name="thread.deallocated"></a><span class="term">
837
838    "<code class="mallctl">thread.deallocated</code>"
839
840          (<span class="type">uint64_t</span>)
841          <code class="literal">r-</code>
842          [<code class="option">--enable-stats</code>]
843        </span></dt><dd><p>Get the total number of bytes ever deallocated by the
844        calling thread.  This counter has the potential to wrap around; it is
845        up to the application to appropriately interpret the counter in such
846        cases.</p></dd><dt><a name="thread.deallocatedp"></a><span class="term">
847
848    "<code class="mallctl">thread.deallocatedp</code>"
849
850          (<span class="type">uint64_t *</span>)
851          <code class="literal">r-</code>
852          [<code class="option">--enable-stats</code>]
853        </span></dt><dd><p>Get a pointer to the the value that is returned by the
854        <a class="link" href="#thread.deallocated">
855    "<code class="mallctl">thread.deallocated</code>"
856  </a>
857        mallctl.  This is useful for avoiding the overhead of repeated
858        <code class="function">mallctl*</code>(<em class="parameter"><code></code></em>) calls.</p></dd><dt><a name="thread.tcache.enabled"></a><span class="term">
859
860    "<code class="mallctl">thread.tcache.enabled</code>"
861
862          (<span class="type">bool</span>)
863          <code class="literal">rw</code>
864          [<code class="option">--enable-tcache</code>]
865        </span></dt><dd><p>Enable/disable calling thread's tcache.  The tcache is
866        implicitly flushed as a side effect of becoming
867        disabled (see
868    "<code class="mallctl">thread.tcache.flush</code>"
869  ).
870        </p></dd><dt><a name="thread.tcache.flush"></a><span class="term">
871
872    "<code class="mallctl">thread.tcache.flush</code>"
873
874          (<span class="type">void</span>)
875          <code class="literal">--</code>
876          [<code class="option">--enable-tcache</code>]
877        </span></dt><dd><p>Flush calling thread's tcache.  This interface releases
878        all cached objects and internal data structures associated with the
879        calling thread's thread-specific cache.  Ordinarily, this interface
880        need not be called, since automatic periodic incremental garbage
881        collection occurs, and the thread cache is automatically discarded when
882        a thread exits.  However, garbage collection is triggered by allocation
883        activity, so it is possible for a thread that stops
884        allocating/deallocating to retain its cache indefinitely, in which case
885        the developer may find manual flushing useful.</p></dd><dt><a name="arena.i.purge"></a><span class="term">
886
887    "<code class="mallctl">arena.&lt;i&gt;.purge</code>"
888
889          (<span class="type">unsigned</span>)
890          <code class="literal">--</code>
891        </span></dt><dd><p>Purge unused dirty pages for arena &lt;i&gt;, or for
892        all arenas if &lt;i&gt; equals <a class="link" href="#arenas.narenas">
893    "<code class="mallctl">arenas.narenas</code>"
894  </a>.
895        </p></dd><dt><a name="arena.i.dss"></a><span class="term">
896
897    "<code class="mallctl">arena.&lt;i&gt;.dss</code>"
898
899          (<span class="type">const char *</span>)
900          <code class="literal">rw</code>
901        </span></dt><dd><p>Set the precedence of dss allocation as related to mmap
902        allocation for arena &lt;i&gt;, or for all arenas if &lt;i&gt; equals
903        <a class="link" href="#arenas.narenas">
904    "<code class="mallctl">arenas.narenas</code>"
905  </a>.  Note
906        that even during huge allocation this setting is read from the arena
907        that would be chosen for small or large allocation so that applications
908        can depend on consistent dss versus mmap allocation regardless of
909        allocation size.  See <a class="link" href="#opt.dss">
910    "<code class="mallctl">opt.dss</code>"
911  </a> for supported
912        settings.
913        </p></dd><dt><a name="arenas.narenas"></a><span class="term">
914
915    "<code class="mallctl">arenas.narenas</code>"
916
917          (<span class="type">unsigned</span>)
918          <code class="literal">r-</code>
919        </span></dt><dd><p>Current limit on number of arenas.</p></dd><dt><a name="arenas.initialized"></a><span class="term">
920
921    "<code class="mallctl">arenas.initialized</code>"
922
923          (<span class="type">bool *</span>)
924          <code class="literal">r-</code>
925        </span></dt><dd><p>An array of <a class="link" href="#arenas.narenas">
926    "<code class="mallctl">arenas.narenas</code>"
927  </a>
928        booleans.  Each boolean indicates whether the corresponding arena is
929        initialized.</p></dd><dt><a name="arenas.quantum"></a><span class="term">
930
931    "<code class="mallctl">arenas.quantum</code>"
932
933          (<span class="type">size_t</span>)
934          <code class="literal">r-</code>
935        </span></dt><dd><p>Quantum size.</p></dd><dt><a name="arenas.page"></a><span class="term">
936
937    "<code class="mallctl">arenas.page</code>"
938
939          (<span class="type">size_t</span>)
940          <code class="literal">r-</code>
941        </span></dt><dd><p>Page size.</p></dd><dt><a name="arenas.tcache_max"></a><span class="term">
942
943    "<code class="mallctl">arenas.tcache_max</code>"
944
945          (<span class="type">size_t</span>)
946          <code class="literal">r-</code>
947          [<code class="option">--enable-tcache</code>]
948        </span></dt><dd><p>Maximum thread-cached size class.</p></dd><dt><a name="arenas.nbins"></a><span class="term">
949
950    "<code class="mallctl">arenas.nbins</code>"
951
952          (<span class="type">unsigned</span>)
953          <code class="literal">r-</code>
954        </span></dt><dd><p>Number of bin size classes.</p></dd><dt><a name="arenas.nhbins"></a><span class="term">
955
956    "<code class="mallctl">arenas.nhbins</code>"
957
958          (<span class="type">unsigned</span>)
959          <code class="literal">r-</code>
960          [<code class="option">--enable-tcache</code>]
961        </span></dt><dd><p>Total number of thread cache bin size
962        classes.</p></dd><dt><a name="arenas.bin.i.size"></a><span class="term">
963
964    "<code class="mallctl">arenas.bin.&lt;i&gt;.size</code>"
965
966          (<span class="type">size_t</span>)
967          <code class="literal">r-</code>
968        </span></dt><dd><p>Maximum size supported by size class.</p></dd><dt><a name="arenas.bin.i.nregs"></a><span class="term">
969
970    "<code class="mallctl">arenas.bin.&lt;i&gt;.nregs</code>"
971
972          (<span class="type">uint32_t</span>)
973          <code class="literal">r-</code>
974        </span></dt><dd><p>Number of regions per page run.</p></dd><dt><a name="arenas.bin.i.run_size"></a><span class="term">
975
976    "<code class="mallctl">arenas.bin.&lt;i&gt;.run_size</code>"
977
978          (<span class="type">size_t</span>)
979          <code class="literal">r-</code>
980        </span></dt><dd><p>Number of bytes per page run.</p></dd><dt><a name="arenas.nlruns"></a><span class="term">
981
982    "<code class="mallctl">arenas.nlruns</code>"
983
984          (<span class="type">size_t</span>)
985          <code class="literal">r-</code>
986        </span></dt><dd><p>Total number of large size classes.</p></dd><dt><a name="arenas.lrun.i.size"></a><span class="term">
987
988    "<code class="mallctl">arenas.lrun.&lt;i&gt;.size</code>"
989
990          (<span class="type">size_t</span>)
991          <code class="literal">r-</code>
992        </span></dt><dd><p>Maximum size supported by this large size
993        class.</p></dd><dt><a name="arenas.purge"></a><span class="term">
994
995    "<code class="mallctl">arenas.purge</code>"
996
997          (<span class="type">unsigned</span>)
998          <code class="literal">-w</code>
999        </span></dt><dd><p>Purge unused dirty pages for the specified arena, or
1000        for all arenas if none is specified.</p></dd><dt><a name="arenas.extend"></a><span class="term">
1001
1002    "<code class="mallctl">arenas.extend</code>"
1003
1004          (<span class="type">unsigned</span>)
1005          <code class="literal">r-</code>
1006        </span></dt><dd><p>Extend the array of arenas by appending a new arena,
1007        and returning the new arena index.</p></dd><dt><a name="prof.active"></a><span class="term">
1008
1009    "<code class="mallctl">prof.active</code>"
1010
1011          (<span class="type">bool</span>)
1012          <code class="literal">rw</code>
1013          [<code class="option">--enable-prof</code>]
1014        </span></dt><dd><p>Control whether sampling is currently active.  See the
1015        <a class="link" href="#opt.prof_active">
1016    "<code class="mallctl">opt.prof_active</code>"
1017  </a>
1018        option for additional information.
1019        </p></dd><dt><a name="prof.dump"></a><span class="term">
1020
1021    "<code class="mallctl">prof.dump</code>"
1022
1023          (<span class="type">const char *</span>)
1024          <code class="literal">-w</code>
1025          [<code class="option">--enable-prof</code>]
1026        </span></dt><dd><p>Dump a memory profile to the specified file, or if NULL
1027        is specified, to a file according to the pattern
1028        <code class="filename">&lt;prefix&gt;.&lt;pid&gt;.&lt;seq&gt;.m&lt;mseq&gt;.heap</code>,
1029        where <code class="literal">&lt;prefix&gt;</code> is controlled by the
1030        <a class="link" href="#opt.prof_prefix">
1031    "<code class="mallctl">opt.prof_prefix</code>"
1032  </a>
1033        option.</p></dd><dt><a name="prof.interval"></a><span class="term">
1034
1035    "<code class="mallctl">prof.interval</code>"
1036
1037          (<span class="type">uint64_t</span>)
1038          <code class="literal">r-</code>
1039          [<code class="option">--enable-prof</code>]
1040        </span></dt><dd><p>Average number of bytes allocated between
1041        inverval-based profile dumps.  See the
1042        <a class="link" href="#opt.lg_prof_interval">
1043    "<code class="mallctl">opt.lg_prof_interval</code>"
1044  </a>
1045        option for additional information.</p></dd><dt><a name="stats.cactive"></a><span class="term">
1046
1047    "<code class="mallctl">stats.cactive</code>"
1048
1049          (<span class="type">size_t *</span>)
1050          <code class="literal">r-</code>
1051          [<code class="option">--enable-stats</code>]
1052        </span></dt><dd><p>Pointer to a counter that contains an approximate count
1053        of the current number of bytes in active pages.  The estimate may be
1054        high, but never low, because each arena rounds up to the nearest
1055        multiple of the chunk size when computing its contribution to the
1056        counter.  Note that the <a class="link" href="#epoch">
1057    "<code class="mallctl">epoch</code>"
1058  </a> mallctl has no bearing
1059        on this counter.  Furthermore, counter consistency is maintained via
1060        atomic operations, so it is necessary to use an atomic operation in
1061        order to guarantee a consistent read when dereferencing the pointer.
1062        </p></dd><dt><a name="stats.allocated"></a><span class="term">
1063
1064    "<code class="mallctl">stats.allocated</code>"
1065
1066          (<span class="type">size_t</span>)
1067          <code class="literal">r-</code>
1068          [<code class="option">--enable-stats</code>]
1069        </span></dt><dd><p>Total number of bytes allocated by the
1070        application.</p></dd><dt><a name="stats.active"></a><span class="term">
1071
1072    "<code class="mallctl">stats.active</code>"
1073
1074          (<span class="type">size_t</span>)
1075          <code class="literal">r-</code>
1076          [<code class="option">--enable-stats</code>]
1077        </span></dt><dd><p>Total number of bytes in active pages allocated by the
1078        application.  This is a multiple of the page size, and greater than or
1079        equal to <a class="link" href="#stats.allocated">
1080    "<code class="mallctl">stats.allocated</code>"
1081  </a>.
1082        This does not include <a class="link" href="#stats.arenas.i.pdirty">
1083
1084    "<code class="mallctl">stats.arenas.&lt;i&gt;.pdirty</code>"
1085  </a> and pages
1086        entirely devoted to allocator metadata.</p></dd><dt><a name="stats.mapped"></a><span class="term">
1087
1088    "<code class="mallctl">stats.mapped</code>"
1089
1090          (<span class="type">size_t</span>)
1091          <code class="literal">r-</code>
1092          [<code class="option">--enable-stats</code>]
1093        </span></dt><dd><p>Total number of bytes in chunks mapped on behalf of the
1094        application.  This is a multiple of the chunk size, and is at least as
1095        large as <a class="link" href="#stats.active">
1096    "<code class="mallctl">stats.active</code>"
1097  </a>.  This
1098        does not include inactive chunks.</p></dd><dt><a name="stats.chunks.current"></a><span class="term">
1099
1100    "<code class="mallctl">stats.chunks.current</code>"
1101
1102          (<span class="type">size_t</span>)
1103          <code class="literal">r-</code>
1104          [<code class="option">--enable-stats</code>]
1105        </span></dt><dd><p>Total number of chunks actively mapped on behalf of the
1106        application.  This does not include inactive chunks.
1107        </p></dd><dt><a name="stats.chunks.total"></a><span class="term">
1108
1109    "<code class="mallctl">stats.chunks.total</code>"
1110
1111          (<span class="type">uint64_t</span>)
1112          <code class="literal">r-</code>
1113          [<code class="option">--enable-stats</code>]
1114        </span></dt><dd><p>Cumulative number of chunks allocated.</p></dd><dt><a name="stats.chunks.high"></a><span class="term">
1115
1116    "<code class="mallctl">stats.chunks.high</code>"
1117
1118          (<span class="type">size_t</span>)
1119          <code class="literal">r-</code>
1120          [<code class="option">--enable-stats</code>]
1121        </span></dt><dd><p>Maximum number of active chunks at any time thus far.
1122        </p></dd><dt><a name="stats.huge.allocated"></a><span class="term">
1123
1124    "<code class="mallctl">stats.huge.allocated</code>"
1125
1126          (<span class="type">size_t</span>)
1127          <code class="literal">r-</code>
1128          [<code class="option">--enable-stats</code>]
1129        </span></dt><dd><p>Number of bytes currently allocated by huge objects.
1130        </p></dd><dt><a name="stats.huge.nmalloc"></a><span class="term">
1131
1132    "<code class="mallctl">stats.huge.nmalloc</code>"
1133
1134          (<span class="type">uint64_t</span>)
1135          <code class="literal">r-</code>
1136          [<code class="option">--enable-stats</code>]
1137        </span></dt><dd><p>Cumulative number of huge allocation requests.
1138        </p></dd><dt><a name="stats.huge.ndalloc"></a><span class="term">
1139
1140    "<code class="mallctl">stats.huge.ndalloc</code>"
1141
1142          (<span class="type">uint64_t</span>)
1143          <code class="literal">r-</code>
1144          [<code class="option">--enable-stats</code>]
1145        </span></dt><dd><p>Cumulative number of huge deallocation requests.
1146        </p></dd><dt><a name="stats.arenas.i.dss"></a><span class="term">
1147
1148    "<code class="mallctl">stats.arenas.&lt;i&gt;.dss</code>"
1149
1150          (<span class="type">const char *</span>)
1151          <code class="literal">r-</code>
1152        </span></dt><dd><p>dss (<span class="citerefentry"><span class="refentrytitle">sbrk</span>(2)</span>) allocation precedence as
1153        related to <span class="citerefentry"><span class="refentrytitle">mmap</span>(2)</span> allocation.  See <a class="link" href="#opt.dss">
1154    "<code class="mallctl">opt.dss</code>"
1155  </a> for details.
1156        </p></dd><dt><a name="stats.arenas.i.nthreads"></a><span class="term">
1157
1158    "<code class="mallctl">stats.arenas.&lt;i&gt;.nthreads</code>"
1159
1160          (<span class="type">unsigned</span>)
1161          <code class="literal">r-</code>
1162        </span></dt><dd><p>Number of threads currently assigned to
1163        arena.</p></dd><dt><a name="stats.arenas.i.pactive"></a><span class="term">
1164
1165    "<code class="mallctl">stats.arenas.&lt;i&gt;.pactive</code>"
1166
1167          (<span class="type">size_t</span>)
1168          <code class="literal">r-</code>
1169        </span></dt><dd><p>Number of pages in active runs.</p></dd><dt><a name="stats.arenas.i.pdirty"></a><span class="term">
1170
1171    "<code class="mallctl">stats.arenas.&lt;i&gt;.pdirty</code>"
1172
1173          (<span class="type">size_t</span>)
1174          <code class="literal">r-</code>
1175        </span></dt><dd><p>Number of pages within unused runs that are potentially
1176        dirty, and for which <code class="function">madvise</code>(<em class="parameter"><code>...</code></em>,
1177        <em class="parameter"><code><code class="constant">MADV_DONTNEED</code></code></em>) or
1178        similar has not been called.</p></dd><dt><a name="stats.arenas.i.mapped"></a><span class="term">
1179
1180    "<code class="mallctl">stats.arenas.&lt;i&gt;.mapped</code>"
1181
1182          (<span class="type">size_t</span>)
1183          <code class="literal">r-</code>
1184          [<code class="option">--enable-stats</code>]
1185        </span></dt><dd><p>Number of mapped bytes.</p></dd><dt><a name="stats.arenas.i.npurge"></a><span class="term">
1186
1187    "<code class="mallctl">stats.arenas.&lt;i&gt;.npurge</code>"
1188
1189          (<span class="type">uint64_t</span>)
1190          <code class="literal">r-</code>
1191          [<code class="option">--enable-stats</code>]
1192        </span></dt><dd><p>Number of dirty page purge sweeps performed.
1193        </p></dd><dt><a name="stats.arenas.i.nmadvise"></a><span class="term">
1194
1195    "<code class="mallctl">stats.arenas.&lt;i&gt;.nmadvise</code>"
1196
1197          (<span class="type">uint64_t</span>)
1198          <code class="literal">r-</code>
1199          [<code class="option">--enable-stats</code>]
1200        </span></dt><dd><p>Number of <code class="function">madvise</code>(<em class="parameter"><code>...</code></em>,
1201        <em class="parameter"><code><code class="constant">MADV_DONTNEED</code></code></em>) or
1202        similar calls made to purge dirty pages.</p></dd><dt><a name="stats.arenas.i.purged"></a><span class="term">
1203
1204    "<code class="mallctl">stats.arenas.&lt;i&gt;.purged</code>"
1205
1206          (<span class="type">uint64_t</span>)
1207          <code class="literal">r-</code>
1208          [<code class="option">--enable-stats</code>]
1209        </span></dt><dd><p>Number of pages purged.</p></dd><dt><a name="stats.arenas.i.small.allocated"></a><span class="term">
1210
1211    "<code class="mallctl">stats.arenas.&lt;i&gt;.small.allocated</code>"
1212
1213          (<span class="type">size_t</span>)
1214          <code class="literal">r-</code>
1215          [<code class="option">--enable-stats</code>]
1216        </span></dt><dd><p>Number of bytes currently allocated by small objects.
1217        </p></dd><dt><a name="stats.arenas.i.small.nmalloc"></a><span class="term">
1218
1219    "<code class="mallctl">stats.arenas.&lt;i&gt;.small.nmalloc</code>"
1220
1221          (<span class="type">uint64_t</span>)
1222          <code class="literal">r-</code>
1223          [<code class="option">--enable-stats</code>]
1224        </span></dt><dd><p>Cumulative number of allocation requests served by
1225        small bins.</p></dd><dt><a name="stats.arenas.i.small.ndalloc"></a><span class="term">
1226
1227    "<code class="mallctl">stats.arenas.&lt;i&gt;.small.ndalloc</code>"
1228
1229          (<span class="type">uint64_t</span>)
1230          <code class="literal">r-</code>
1231          [<code class="option">--enable-stats</code>]
1232        </span></dt><dd><p>Cumulative number of small objects returned to bins.
1233        </p></dd><dt><a name="stats.arenas.i.small.nrequests"></a><span class="term">
1234
1235    "<code class="mallctl">stats.arenas.&lt;i&gt;.small.nrequests</code>"
1236
1237          (<span class="type">uint64_t</span>)
1238          <code class="literal">r-</code>
1239          [<code class="option">--enable-stats</code>]
1240        </span></dt><dd><p>Cumulative number of small allocation requests.
1241        </p></dd><dt><a name="stats.arenas.i.large.allocated"></a><span class="term">
1242
1243    "<code class="mallctl">stats.arenas.&lt;i&gt;.large.allocated</code>"
1244
1245          (<span class="type">size_t</span>)
1246          <code class="literal">r-</code>
1247          [<code class="option">--enable-stats</code>]
1248        </span></dt><dd><p>Number of bytes currently allocated by large objects.
1249        </p></dd><dt><a name="stats.arenas.i.large.nmalloc"></a><span class="term">
1250
1251    "<code class="mallctl">stats.arenas.&lt;i&gt;.large.nmalloc</code>"
1252
1253          (<span class="type">uint64_t</span>)
1254          <code class="literal">r-</code>
1255          [<code class="option">--enable-stats</code>]
1256        </span></dt><dd><p>Cumulative number of large allocation requests served
1257        directly by the arena.</p></dd><dt><a name="stats.arenas.i.large.ndalloc"></a><span class="term">
1258
1259    "<code class="mallctl">stats.arenas.&lt;i&gt;.large.ndalloc</code>"
1260
1261          (<span class="type">uint64_t</span>)
1262          <code class="literal">r-</code>
1263          [<code class="option">--enable-stats</code>]
1264        </span></dt><dd><p>Cumulative number of large deallocation requests served
1265        directly by the arena.</p></dd><dt><a name="stats.arenas.i.large.nrequests"></a><span class="term">
1266
1267    "<code class="mallctl">stats.arenas.&lt;i&gt;.large.nrequests</code>"
1268
1269          (<span class="type">uint64_t</span>)
1270          <code class="literal">r-</code>
1271          [<code class="option">--enable-stats</code>]
1272        </span></dt><dd><p>Cumulative number of large allocation requests.
1273        </p></dd><dt><a name="stats.arenas.i.bins.j.allocated"></a><span class="term">
1274
1275    "<code class="mallctl">stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.allocated</code>"
1276
1277          (<span class="type">size_t</span>)
1278          <code class="literal">r-</code>
1279          [<code class="option">--enable-stats</code>]
1280        </span></dt><dd><p>Current number of bytes allocated by
1281        bin.</p></dd><dt><a name="stats.arenas.i.bins.j.nmalloc"></a><span class="term">
1282
1283    "<code class="mallctl">stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.nmalloc</code>"
1284
1285          (<span class="type">uint64_t</span>)
1286          <code class="literal">r-</code>
1287          [<code class="option">--enable-stats</code>]
1288        </span></dt><dd><p>Cumulative number of allocations served by bin.
1289        </p></dd><dt><a name="stats.arenas.i.bins.j.ndalloc"></a><span class="term">
1290
1291    "<code class="mallctl">stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.ndalloc</code>"
1292
1293          (<span class="type">uint64_t</span>)
1294          <code class="literal">r-</code>
1295          [<code class="option">--enable-stats</code>]
1296        </span></dt><dd><p>Cumulative number of allocations returned to bin.
1297        </p></dd><dt><a name="stats.arenas.i.bins.j.nrequests"></a><span class="term">
1298
1299    "<code class="mallctl">stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.nrequests</code>"
1300
1301          (<span class="type">uint64_t</span>)
1302          <code class="literal">r-</code>
1303          [<code class="option">--enable-stats</code>]
1304        </span></dt><dd><p>Cumulative number of allocation
1305        requests.</p></dd><dt><a name="stats.arenas.i.bins.j.nfills"></a><span class="term">
1306
1307    "<code class="mallctl">stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.nfills</code>"
1308
1309          (<span class="type">uint64_t</span>)
1310          <code class="literal">r-</code>
1311          [<code class="option">--enable-stats</code> <code class="option">--enable-tcache</code>]
1312        </span></dt><dd><p>Cumulative number of tcache fills.</p></dd><dt><a name="stats.arenas.i.bins.j.nflushes"></a><span class="term">
1313
1314    "<code class="mallctl">stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.nflushes</code>"
1315
1316          (<span class="type">uint64_t</span>)
1317          <code class="literal">r-</code>
1318          [<code class="option">--enable-stats</code> <code class="option">--enable-tcache</code>]
1319        </span></dt><dd><p>Cumulative number of tcache flushes.</p></dd><dt><a name="stats.arenas.i.bins.j.nruns"></a><span class="term">
1320
1321    "<code class="mallctl">stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.nruns</code>"
1322
1323          (<span class="type">uint64_t</span>)
1324          <code class="literal">r-</code>
1325          [<code class="option">--enable-stats</code>]
1326        </span></dt><dd><p>Cumulative number of runs created.</p></dd><dt><a name="stats.arenas.i.bins.j.nreruns"></a><span class="term">
1327
1328    "<code class="mallctl">stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.nreruns</code>"
1329
1330          (<span class="type">uint64_t</span>)
1331          <code class="literal">r-</code>
1332          [<code class="option">--enable-stats</code>]
1333        </span></dt><dd><p>Cumulative number of times the current run from which
1334        to allocate changed.</p></dd><dt><a name="stats.arenas.i.bins.j.curruns"></a><span class="term">
1335
1336    "<code class="mallctl">stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.curruns</code>"
1337
1338          (<span class="type">size_t</span>)
1339          <code class="literal">r-</code>
1340          [<code class="option">--enable-stats</code>]
1341        </span></dt><dd><p>Current number of runs.</p></dd><dt><a name="stats.arenas.i.lruns.j.nmalloc"></a><span class="term">
1342
1343    "<code class="mallctl">stats.arenas.&lt;i&gt;.lruns.&lt;j&gt;.nmalloc</code>"
1344
1345          (<span class="type">uint64_t</span>)
1346          <code class="literal">r-</code>
1347          [<code class="option">--enable-stats</code>]
1348        </span></dt><dd><p>Cumulative number of allocation requests for this size
1349        class served directly by the arena.</p></dd><dt><a name="stats.arenas.i.lruns.j.ndalloc"></a><span class="term">
1350
1351    "<code class="mallctl">stats.arenas.&lt;i&gt;.lruns.&lt;j&gt;.ndalloc</code>"
1352
1353          (<span class="type">uint64_t</span>)
1354          <code class="literal">r-</code>
1355          [<code class="option">--enable-stats</code>]
1356        </span></dt><dd><p>Cumulative number of deallocation requests for this
1357        size class served directly by the arena.</p></dd><dt><a name="stats.arenas.i.lruns.j.nrequests"></a><span class="term">
1358
1359    "<code class="mallctl">stats.arenas.&lt;i&gt;.lruns.&lt;j&gt;.nrequests</code>"
1360
1361          (<span class="type">uint64_t</span>)
1362          <code class="literal">r-</code>
1363          [<code class="option">--enable-stats</code>]
1364        </span></dt><dd><p>Cumulative number of allocation requests for this size
1365        class.</p></dd><dt><a name="stats.arenas.i.lruns.j.curruns"></a><span class="term">
1366
1367    "<code class="mallctl">stats.arenas.&lt;i&gt;.lruns.&lt;j&gt;.curruns</code>"
1368
1369          (<span class="type">size_t</span>)
1370          <code class="literal">r-</code>
1371          [<code class="option">--enable-stats</code>]
1372        </span></dt><dd><p>Current number of runs for this size class.
1373        </p></dd></dl></div></div><div class="refsect1"><a name="debugging_malloc_problems"></a><h2>DEBUGGING MALLOC PROBLEMS</h2><p>When debugging, it is a good idea to configure/build jemalloc with
1374    the <code class="option">--enable-debug</code> and <code class="option">--enable-fill</code>
1375    options, and recompile the program with suitable options and symbols for
1376    debugger support.  When so configured, jemalloc incorporates a wide variety
1377    of run-time assertions that catch application errors such as double-free,
1378    write-after-free, etc.</p><p>Programs often accidentally depend on &#8220;uninitialized&#8221;
1379    memory actually being filled with zero bytes.  Junk filling
1380    (see the <a class="link" href="#opt.junk">
1381    "<code class="mallctl">opt.junk</code>"
1382  </a>
1383    option) tends to expose such bugs in the form of obviously incorrect
1384    results and/or coredumps.  Conversely, zero
1385    filling (see the <a class="link" href="#opt.zero">
1386    "<code class="mallctl">opt.zero</code>"
1387  </a> option) eliminates
1388    the symptoms of such bugs.  Between these two options, it is usually
1389    possible to quickly detect, diagnose, and eliminate such bugs.</p><p>This implementation does not provide much detail about the problems
1390    it detects, because the performance impact for storing such information
1391    would be prohibitive.  However, jemalloc does integrate with the most
1392    excellent <a class="ulink" href="http://valgrind.org/" target="_top">Valgrind</a> tool if the
1393    <code class="option">--enable-valgrind</code> configuration option is enabled.</p></div><div class="refsect1"><a name="diagnostic_messages"></a><h2>DIAGNOSTIC MESSAGES</h2><p>If any of the memory allocation/deallocation functions detect an
1394    error or warning condition, a message will be printed to file descriptor
1395    <code class="constant">STDERR_FILENO</code>.  Errors will result in the process
1396    dumping core.  If the <a class="link" href="#opt.abort">
1397    "<code class="mallctl">opt.abort</code>"
1398  </a> option is set, most
1399    warnings are treated as errors.</p><p>The <code class="varname">malloc_message</code> variable allows the programmer
1400    to override the function which emits the text strings forming the errors
1401    and warnings if for some reason the <code class="constant">STDERR_FILENO</code> file
1402    descriptor is not suitable for this.
1403    <code class="function">malloc_message</code>(<em class="parameter"><code></code></em>) takes the
1404    <em class="parameter"><code>cbopaque</code></em> pointer argument that is
1405    <code class="constant">NULL</code> unless overridden by the arguments in a call to
1406    <code class="function">malloc_stats_print</code>(<em class="parameter"><code></code></em>), followed by a string
1407    pointer.  Please note that doing anything which tries to allocate memory in
1408    this function is likely to result in a crash or deadlock.</p><p>All messages are prefixed by
1409    &#8220;<code class="computeroutput">&lt;jemalloc&gt;: </code>&#8221;.</p></div><div class="refsect1"><a name="return_values"></a><h2>RETURN VALUES</h2><div class="refsect2"><a name="idm316388028784"></a><h3>Standard API</h3><p>The <code class="function">malloc</code>(<em class="parameter"><code></code></em>) and
1410      <code class="function">calloc</code>(<em class="parameter"><code></code></em>) functions return a pointer to the
1411      allocated memory if successful; otherwise a <code class="constant">NULL</code>
1412      pointer is returned and <code class="varname">errno</code> is set to
1413      <span class="errorname">ENOMEM</span>.</p><p>The <code class="function">posix_memalign</code>(<em class="parameter"><code></code></em>) function
1414      returns the value 0 if successful; otherwise it returns an error value.
1415      The <code class="function">posix_memalign</code>(<em class="parameter"><code></code></em>) function will fail
1416      if:
1417        </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><span class="errorname">EINVAL</span></span></dt><dd><p>The <em class="parameter"><code>alignment</code></em> parameter is
1418            not a power of 2 at least as large as
1419            <code class="code">sizeof(<span class="type">void *</span>)</code>.
1420            </p></dd><dt><span class="term"><span class="errorname">ENOMEM</span></span></dt><dd><p>Memory allocation error.</p></dd></dl></div><p>
1421      </p><p>The <code class="function">aligned_alloc</code>(<em class="parameter"><code></code></em>) function returns
1422      a pointer to the allocated memory if successful; otherwise a
1423      <code class="constant">NULL</code> pointer is returned and
1424      <code class="varname">errno</code> is set.  The
1425      <code class="function">aligned_alloc</code>(<em class="parameter"><code></code></em>) function will fail if:
1426        </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><span class="errorname">EINVAL</span></span></dt><dd><p>The <em class="parameter"><code>alignment</code></em> parameter is
1427            not a power of 2.
1428            </p></dd><dt><span class="term"><span class="errorname">ENOMEM</span></span></dt><dd><p>Memory allocation error.</p></dd></dl></div><p>
1429      </p><p>The <code class="function">realloc</code>(<em class="parameter"><code></code></em>) function returns a
1430      pointer, possibly identical to <em class="parameter"><code>ptr</code></em>, to the
1431      allocated memory if successful; otherwise a <code class="constant">NULL</code>
1432      pointer is returned, and <code class="varname">errno</code> is set to
1433      <span class="errorname">ENOMEM</span> if the error was the result of an
1434      allocation failure.  The <code class="function">realloc</code>(<em class="parameter"><code></code></em>)
1435      function always leaves the original buffer intact when an error occurs.
1436      </p><p>The <code class="function">free</code>(<em class="parameter"><code></code></em>) function returns no
1437      value.</p></div><div class="refsect2"><a name="idm316388003104"></a><h3>Non-standard API</h3><p>The <code class="function">mallocx</code>(<em class="parameter"><code></code></em>) and
1438      <code class="function">rallocx</code>(<em class="parameter"><code></code></em>) functions return a pointer to
1439      the allocated memory if successful; otherwise a <code class="constant">NULL</code>
1440      pointer is returned to indicate insufficient contiguous memory was
1441      available to service the allocation request.  </p><p>The <code class="function">xallocx</code>(<em class="parameter"><code></code></em>) function returns the
1442      real size of the resulting resized allocation pointed to by
1443      <em class="parameter"><code>ptr</code></em>, which is a value less than
1444      <em class="parameter"><code>size</code></em> if the allocation could not be adequately
1445      grown in place.  </p><p>The <code class="function">sallocx</code>(<em class="parameter"><code></code></em>) function returns the
1446      real size of the allocation pointed to by <em class="parameter"><code>ptr</code></em>.
1447      </p><p>The <code class="function">nallocx</code>(<em class="parameter"><code></code></em>) returns the real size
1448      that would result from a successful equivalent
1449      <code class="function">mallocx</code>(<em class="parameter"><code></code></em>) function call, or zero if
1450      insufficient memory is available to perform the size computation.  </p><p>The <code class="function">mallctl</code>(<em class="parameter"><code></code></em>),
1451      <code class="function">mallctlnametomib</code>(<em class="parameter"><code></code></em>), and
1452      <code class="function">mallctlbymib</code>(<em class="parameter"><code></code></em>) functions return 0 on
1453      success; otherwise they return an error value.  The functions will fail
1454      if:
1455        </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><span class="errorname">EINVAL</span></span></dt><dd><p><em class="parameter"><code>newp</code></em> is not
1456            <code class="constant">NULL</code>, and <em class="parameter"><code>newlen</code></em> is too
1457            large or too small.  Alternatively, <em class="parameter"><code>*oldlenp</code></em>
1458            is too large or too small; in this case as much data as possible
1459            are read despite the error.</p></dd><dt><span class="term"><span class="errorname">ENOENT</span></span></dt><dd><p><em class="parameter"><code>name</code></em> or
1460            <em class="parameter"><code>mib</code></em> specifies an unknown/invalid
1461            value.</p></dd><dt><span class="term"><span class="errorname">EPERM</span></span></dt><dd><p>Attempt to read or write void value, or attempt to
1462            write read-only value.</p></dd><dt><span class="term"><span class="errorname">EAGAIN</span></span></dt><dd><p>A memory allocation failure
1463            occurred.</p></dd><dt><span class="term"><span class="errorname">EFAULT</span></span></dt><dd><p>An interface with side effects failed in some way
1464            not directly related to <code class="function">mallctl*</code>(<em class="parameter"><code></code></em>)
1465            read/write processing.</p></dd></dl></div><p>
1466      </p><p>The <code class="function">malloc_usable_size</code>(<em class="parameter"><code></code></em>) function
1467      returns the usable size of the allocation pointed to by
1468      <em class="parameter"><code>ptr</code></em>.  </p></div><div class="refsect2"><a name="idm316387973360"></a><h3>Experimental API</h3><p>The <code class="function">allocm</code>(<em class="parameter"><code></code></em>),
1469      <code class="function">rallocm</code>(<em class="parameter"><code></code></em>),
1470      <code class="function">sallocm</code>(<em class="parameter"><code></code></em>),
1471      <code class="function">dallocm</code>(<em class="parameter"><code></code></em>), and
1472      <code class="function">nallocm</code>(<em class="parameter"><code></code></em>) functions return
1473      <code class="constant">ALLOCM_SUCCESS</code> on success; otherwise they return an
1474      error value.  The <code class="function">allocm</code>(<em class="parameter"><code></code></em>),
1475      <code class="function">rallocm</code>(<em class="parameter"><code></code></em>), and
1476      <code class="function">nallocm</code>(<em class="parameter"><code></code></em>) functions will fail if:
1477        </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><span class="errorname">ALLOCM_ERR_OOM</span></span></dt><dd><p>Out of memory.  Insufficient contiguous memory was
1478            available to service the allocation request.  The
1479            <code class="function">allocm</code>(<em class="parameter"><code></code></em>) function additionally sets
1480            <em class="parameter"><code>*ptr</code></em> to <code class="constant">NULL</code>, whereas
1481            the <code class="function">rallocm</code>(<em class="parameter"><code></code></em>) function leaves
1482            <code class="constant">*ptr</code> unmodified.</p></dd></dl></div><p>
1483      The <code class="function">rallocm</code>(<em class="parameter"><code></code></em>) function will also
1484      fail if:
1485        </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><span class="errorname">ALLOCM_ERR_NOT_MOVED</span></span></dt><dd><p><code class="constant">ALLOCM_NO_MOVE</code> was specified,
1486            but the reallocation request could not be serviced without moving
1487            the object.</p></dd></dl></div><p>
1488      </p></div></div><div class="refsect1"><a name="environment"></a><h2>ENVIRONMENT</h2><p>The following environment variable affects the execution of the
1489    allocation functions:
1490      </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="envar">MALLOC_CONF</code></span></dt><dd><p>If the environment variable
1491          <code class="envar">MALLOC_CONF</code> is set, the characters it contains
1492          will be interpreted as options.</p></dd></dl></div><p>
1493    </p></div><div class="refsect1"><a name="examples"></a><h2>EXAMPLES</h2><p>To dump core whenever a problem occurs:
1494      </p><pre class="screen">ln -s 'abort:true' /etc/malloc.conf</pre><p>
1495    </p><p>To specify in the source a chunk size that is 16 MiB:
1496      </p><pre class="programlisting">
1497malloc_conf = "lg_chunk:24";</pre></div><div class="refsect1"><a name="see_also"></a><h2>SEE ALSO</h2><p><span class="citerefentry"><span class="refentrytitle">madvise</span>(2)</span>,
1498    <span class="citerefentry"><span class="refentrytitle">mmap</span>(2)</span>,
1499    <span class="citerefentry"><span class="refentrytitle">sbrk</span>(2)</span>,
1500    <span class="citerefentry"><span class="refentrytitle">utrace</span>(2)</span>,
1501    <span class="citerefentry"><span class="refentrytitle">alloca</span>(3)</span>,
1502    <span class="citerefentry"><span class="refentrytitle">atexit</span>(3)</span>,
1503    <span class="citerefentry"><span class="refentrytitle">getpagesize</span>(3)</span></p></div><div class="refsect1"><a name="standards"></a><h2>STANDARDS</h2><p>The <code class="function">malloc</code>(<em class="parameter"><code></code></em>),
1504    <code class="function">calloc</code>(<em class="parameter"><code></code></em>),
1505    <code class="function">realloc</code>(<em class="parameter"><code></code></em>), and
1506    <code class="function">free</code>(<em class="parameter"><code></code></em>) functions conform to ISO/IEC
1507    9899:1990 (&#8220;ISO C90&#8221;).</p><p>The <code class="function">posix_memalign</code>(<em class="parameter"><code></code></em>) function conforms
1508    to IEEE Std 1003.1-2001 (&#8220;POSIX.1&#8221;).</p></div></div></body></html>
1509