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