blob: 519ba3fab1ba6e05b194be1c63b20dbd73ee3064 [file] [log] [blame]
Jason Evansaee7fd22010-11-24 22:00:02 -08001<?xml version='1.0' encoding='UTF-8'?>
2<?xml-stylesheet type="text/xsl"
3 href="http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl"?>
4<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
5 "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
6]>
7
8<refentry>
9 <refentryinfo>
10 <title>User Manual</title>
11 <productname>jemalloc</productname>
12 <releaseinfo role="version">@jemalloc_version@</releaseinfo>
13 <authorgroup>
14 <author>
15 <firstname>Jason</firstname>
16 <surname>Evans</surname>
17 <personblurb>Author</personblurb>
18 </author>
19 </authorgroup>
20 </refentryinfo>
21 <refmeta>
22 <refentrytitle>JEMALLOC</refentrytitle>
23 <manvolnum>3</manvolnum>
24 </refmeta>
25 <refnamediv>
26 <refdescriptor>jemalloc</refdescriptor>
27 <refname>jemalloc</refname>
28 <!-- Each refname causes a man page file to be created. Only if this were
29 the system malloc(3) implementation would these files be appropriate.
30 <refname>malloc</refname>
31 <refname>calloc</refname>
32 <refname>posix_memalign</refname>
Jason Evans0a0bbf62012-03-13 12:55:21 -070033 <refname>aligned_alloc</refname>
Jason Evansaee7fd22010-11-24 22:00:02 -080034 <refname>realloc</refname>
35 <refname>free</refname>
Jason Evansd82a5e62013-12-12 22:35:52 -080036 <refname>mallocx</refname>
37 <refname>rallocx</refname>
38 <refname>xallocx</refname>
39 <refname>sallocx</refname>
40 <refname>dallocx</refname>
Daniel Micay4cfe5512014-08-28 15:41:48 -040041 <refname>sdallocx</refname>
Jason Evansd82a5e62013-12-12 22:35:52 -080042 <refname>nallocx</refname>
Jason Evansaee7fd22010-11-24 22:00:02 -080043 <refname>mallctl</refname>
44 <refname>mallctlnametomib</refname>
45 <refname>mallctlbymib</refname>
Jason Evansd82a5e62013-12-12 22:35:52 -080046 <refname>malloc_stats_print</refname>
47 <refname>malloc_usable_size</refname>
Jason Evansaee7fd22010-11-24 22:00:02 -080048 -->
49 <refpurpose>general purpose memory allocation functions</refpurpose>
50 </refnamediv>
51 <refsect1 id="library">
52 <title>LIBRARY</title>
53 <para>This manual describes jemalloc @jemalloc_version@. More information
54 can be found at the <ulink
55 url="http://www.canonware.com/jemalloc/">jemalloc website</ulink>.</para>
56 </refsect1>
57 <refsynopsisdiv>
58 <title>SYNOPSIS</title>
59 <funcsynopsis>
Jason Evanse9a3fa22014-10-05 12:05:37 -070060 <funcsynopsisinfo>#include &lt;<filename class="headerfile">jemalloc/jemalloc.h</filename>&gt;</funcsynopsisinfo>
Jason Evansaee7fd22010-11-24 22:00:02 -080061 <refsect2>
62 <title>Standard API</title>
63 <funcprototype>
64 <funcdef>void *<function>malloc</function></funcdef>
65 <paramdef>size_t <parameter>size</parameter></paramdef>
66 </funcprototype>
67 <funcprototype>
68 <funcdef>void *<function>calloc</function></funcdef>
69 <paramdef>size_t <parameter>number</parameter></paramdef>
70 <paramdef>size_t <parameter>size</parameter></paramdef>
71 </funcprototype>
72 <funcprototype>
73 <funcdef>int <function>posix_memalign</function></funcdef>
74 <paramdef>void **<parameter>ptr</parameter></paramdef>
75 <paramdef>size_t <parameter>alignment</parameter></paramdef>
76 <paramdef>size_t <parameter>size</parameter></paramdef>
77 </funcprototype>
78 <funcprototype>
Jason Evans0a0bbf62012-03-13 12:55:21 -070079 <funcdef>void *<function>aligned_alloc</function></funcdef>
80 <paramdef>size_t <parameter>alignment</parameter></paramdef>
81 <paramdef>size_t <parameter>size</parameter></paramdef>
82 </funcprototype>
83 <funcprototype>
Jason Evansaee7fd22010-11-24 22:00:02 -080084 <funcdef>void *<function>realloc</function></funcdef>
85 <paramdef>void *<parameter>ptr</parameter></paramdef>
86 <paramdef>size_t <parameter>size</parameter></paramdef>
87 </funcprototype>
88 <funcprototype>
89 <funcdef>void <function>free</function></funcdef>
90 <paramdef>void *<parameter>ptr</parameter></paramdef>
91 </funcprototype>
92 </refsect2>
93 <refsect2>
94 <title>Non-standard API</title>
95 <funcprototype>
Jason Evansd82a5e62013-12-12 22:35:52 -080096 <funcdef>void *<function>mallocx</function></funcdef>
97 <paramdef>size_t <parameter>size</parameter></paramdef>
98 <paramdef>int <parameter>flags</parameter></paramdef>
Jason Evansaee7fd22010-11-24 22:00:02 -080099 </funcprototype>
100 <funcprototype>
Jason Evansd82a5e62013-12-12 22:35:52 -0800101 <funcdef>void *<function>rallocx</function></funcdef>
102 <paramdef>void *<parameter>ptr</parameter></paramdef>
103 <paramdef>size_t <parameter>size</parameter></paramdef>
104 <paramdef>int <parameter>flags</parameter></paramdef>
105 </funcprototype>
106 <funcprototype>
107 <funcdef>size_t <function>xallocx</function></funcdef>
108 <paramdef>void *<parameter>ptr</parameter></paramdef>
109 <paramdef>size_t <parameter>size</parameter></paramdef>
110 <paramdef>size_t <parameter>extra</parameter></paramdef>
111 <paramdef>int <parameter>flags</parameter></paramdef>
112 </funcprototype>
113 <funcprototype>
114 <funcdef>size_t <function>sallocx</function></funcdef>
115 <paramdef>void *<parameter>ptr</parameter></paramdef>
116 <paramdef>int <parameter>flags</parameter></paramdef>
117 </funcprototype>
118 <funcprototype>
119 <funcdef>void <function>dallocx</function></funcdef>
120 <paramdef>void *<parameter>ptr</parameter></paramdef>
121 <paramdef>int <parameter>flags</parameter></paramdef>
122 </funcprototype>
123 <funcprototype>
Daniel Micay4cfe5512014-08-28 15:41:48 -0400124 <funcdef>void <function>sdallocx</function></funcdef>
125 <paramdef>void *<parameter>ptr</parameter></paramdef>
126 <paramdef>size_t <parameter>size</parameter></paramdef>
127 <paramdef>int <parameter>flags</parameter></paramdef>
128 </funcprototype>
129 <funcprototype>
Jason Evansd82a5e62013-12-12 22:35:52 -0800130 <funcdef>size_t <function>nallocx</function></funcdef>
131 <paramdef>size_t <parameter>size</parameter></paramdef>
132 <paramdef>int <parameter>flags</parameter></paramdef>
Jason Evansaee7fd22010-11-24 22:00:02 -0800133 </funcprototype>
134 <funcprototype>
135 <funcdef>int <function>mallctl</function></funcdef>
136 <paramdef>const char *<parameter>name</parameter></paramdef>
137 <paramdef>void *<parameter>oldp</parameter></paramdef>
138 <paramdef>size_t *<parameter>oldlenp</parameter></paramdef>
139 <paramdef>void *<parameter>newp</parameter></paramdef>
140 <paramdef>size_t <parameter>newlen</parameter></paramdef>
141 </funcprototype>
142 <funcprototype>
143 <funcdef>int <function>mallctlnametomib</function></funcdef>
144 <paramdef>const char *<parameter>name</parameter></paramdef>
145 <paramdef>size_t *<parameter>mibp</parameter></paramdef>
146 <paramdef>size_t *<parameter>miblenp</parameter></paramdef>
147 </funcprototype>
148 <funcprototype>
149 <funcdef>int <function>mallctlbymib</function></funcdef>
150 <paramdef>const size_t *<parameter>mib</parameter></paramdef>
151 <paramdef>size_t <parameter>miblen</parameter></paramdef>
152 <paramdef>void *<parameter>oldp</parameter></paramdef>
153 <paramdef>size_t *<parameter>oldlenp</parameter></paramdef>
154 <paramdef>void *<parameter>newp</parameter></paramdef>
155 <paramdef>size_t <parameter>newlen</parameter></paramdef>
156 </funcprototype>
157 <funcprototype>
Jason Evansd82a5e62013-12-12 22:35:52 -0800158 <funcdef>void <function>malloc_stats_print</function></funcdef>
159 <paramdef>void <parameter>(*write_cb)</parameter>
160 <funcparams>void *, const char *</funcparams>
161 </paramdef>
162 <paramdef>void *<parameter>cbopaque</parameter></paramdef>
163 <paramdef>const char *<parameter>opts</parameter></paramdef>
164 </funcprototype>
165 <funcprototype>
166 <funcdef>size_t <function>malloc_usable_size</function></funcdef>
167 <paramdef>const void *<parameter>ptr</parameter></paramdef>
168 </funcprototype>
169 <funcprototype>
Jason Evansaee7fd22010-11-24 22:00:02 -0800170 <funcdef>void <function>(*malloc_message)</function></funcdef>
171 <paramdef>void *<parameter>cbopaque</parameter></paramdef>
172 <paramdef>const char *<parameter>s</parameter></paramdef>
173 </funcprototype>
174 <para><type>const char *</type><varname>malloc_conf</varname>;</para>
175 </refsect2>
Jason Evansaee7fd22010-11-24 22:00:02 -0800176 </funcsynopsis>
177 </refsynopsisdiv>
178 <refsect1 id="description">
179 <title>DESCRIPTION</title>
180 <refsect2>
181 <title>Standard API</title>
182
183 <para>The <function>malloc<parameter/></function> function allocates
184 <parameter>size</parameter> bytes of uninitialized memory. The allocated
185 space is suitably aligned (after possible pointer coercion) for storage
186 of any type of object.</para>
187
188 <para>The <function>calloc<parameter/></function> function allocates
189 space for <parameter>number</parameter> objects, each
190 <parameter>size</parameter> bytes in length. The result is identical to
191 calling <function>malloc<parameter/></function> with an argument of
192 <parameter>number</parameter> * <parameter>size</parameter>, with the
193 exception that the allocated memory is explicitly initialized to zero
194 bytes.</para>
195
196 <para>The <function>posix_memalign<parameter/></function> function
197 allocates <parameter>size</parameter> bytes of memory such that the
Jason Evansb4d62cd2014-05-15 22:46:24 -0700198 allocation's base address is a multiple of
Jason Evansaee7fd22010-11-24 22:00:02 -0800199 <parameter>alignment</parameter>, and returns the allocation in the value
200 pointed to by <parameter>ptr</parameter>. The requested
Jason Evansb4d62cd2014-05-15 22:46:24 -0700201 <parameter>alignment</parameter> must be a power of 2 at least as large as
202 <code language="C">sizeof(<type>void *</type>)</code>.</para>
Jason Evansaee7fd22010-11-24 22:00:02 -0800203
Jason Evans0a0bbf62012-03-13 12:55:21 -0700204 <para>The <function>aligned_alloc<parameter/></function> function
205 allocates <parameter>size</parameter> bytes of memory such that the
Jason Evansb4d62cd2014-05-15 22:46:24 -0700206 allocation's base address is a multiple of
Jason Evans0a0bbf62012-03-13 12:55:21 -0700207 <parameter>alignment</parameter>. The requested
208 <parameter>alignment</parameter> must be a power of 2. Behavior is
209 undefined if <parameter>size</parameter> is not an integral multiple of
210 <parameter>alignment</parameter>.</para>
211
Jason Evansaee7fd22010-11-24 22:00:02 -0800212 <para>The <function>realloc<parameter/></function> function changes the
213 size of the previously allocated memory referenced by
214 <parameter>ptr</parameter> to <parameter>size</parameter> bytes. The
215 contents of the memory are unchanged up to the lesser of the new and old
216 sizes. If the new size is larger, the contents of the newly allocated
217 portion of the memory are undefined. Upon success, the memory referenced
218 by <parameter>ptr</parameter> is freed and a pointer to the newly
219 allocated memory is returned. Note that
220 <function>realloc<parameter/></function> may move the memory allocation,
221 resulting in a different return value than <parameter>ptr</parameter>.
222 If <parameter>ptr</parameter> is <constant>NULL</constant>, the
223 <function>realloc<parameter/></function> function behaves identically to
224 <function>malloc<parameter/></function> for the specified size.</para>
225
226 <para>The <function>free<parameter/></function> function causes the
227 allocated memory referenced by <parameter>ptr</parameter> to be made
228 available for future allocations. If <parameter>ptr</parameter> is
229 <constant>NULL</constant>, no action occurs.</para>
230 </refsect2>
231 <refsect2>
232 <title>Non-standard API</title>
Jason Evansd82a5e62013-12-12 22:35:52 -0800233 <para>The <function>mallocx<parameter/></function>,
234 <function>rallocx<parameter/></function>,
235 <function>xallocx<parameter/></function>,
236 <function>sallocx<parameter/></function>,
Daniel Micay4cfe5512014-08-28 15:41:48 -0400237 <function>dallocx<parameter/></function>,
238 <function>sdallocx<parameter/></function>, and
Jason Evansd82a5e62013-12-12 22:35:52 -0800239 <function>nallocx<parameter/></function> functions all have a
240 <parameter>flags</parameter> argument that can be used to specify
241 options. The functions only check the options that are contextually
242 relevant. Use bitwise or (<code language="C">|</code>) operations to
243 specify one or more of the following:
244 <variablelist>
Jason Evans1cb181e2015-01-29 15:30:47 -0800245 <varlistentry id="MALLOCX_LG_ALIGN">
Jason Evansd82a5e62013-12-12 22:35:52 -0800246 <term><constant>MALLOCX_LG_ALIGN(<parameter>la</parameter>)
247 </constant></term>
Jason Evansaee7fd22010-11-24 22:00:02 -0800248
Jason Evansd82a5e62013-12-12 22:35:52 -0800249 <listitem><para>Align the memory allocation to start at an address
250 that is a multiple of <code language="C">(1 &lt;&lt;
251 <parameter>la</parameter>)</code>. This macro does not validate
252 that <parameter>la</parameter> is within the valid
253 range.</para></listitem>
254 </varlistentry>
Jason Evans1cb181e2015-01-29 15:30:47 -0800255 <varlistentry id="MALLOCX_ALIGN">
Jason Evansd82a5e62013-12-12 22:35:52 -0800256 <term><constant>MALLOCX_ALIGN(<parameter>a</parameter>)
257 </constant></term>
258
259 <listitem><para>Align the memory allocation to start at an address
260 that is a multiple of <parameter>a</parameter>, where
261 <parameter>a</parameter> is a power of two. This macro does not
262 validate that <parameter>a</parameter> is a power of 2.
263 </para></listitem>
264 </varlistentry>
Jason Evans1cb181e2015-01-29 15:30:47 -0800265 <varlistentry id="MALLOCX_ZERO">
Jason Evansd82a5e62013-12-12 22:35:52 -0800266 <term><constant>MALLOCX_ZERO</constant></term>
267
268 <listitem><para>Initialize newly allocated memory to contain zero
269 bytes. In the growing reallocation case, the real size prior to
270 reallocation defines the boundary between untouched bytes and those
271 that are initialized to contain zero bytes. If this macro is
272 absent, newly allocated memory is uninitialized.</para></listitem>
273 </varlistentry>
Jason Evans1cb181e2015-01-29 15:30:47 -0800274 <varlistentry id="MALLOCX_TCACHE">
275 <term><constant>MALLOCX_TCACHE(<parameter>tc</parameter>)
276 </constant></term>
277
278 <listitem><para>Use the thread-specific cache (tcache) specified by
279 the identifier <parameter>tc</parameter>, which must have been
280 acquired via the <link
281 linkend="tcache.create"><mallctl>tcache.create</mallctl></link>
282 mallctl. This macro does not validate that
283 <parameter>tc</parameter> specifies a valid
284 identifier.</para></listitem>
285 </varlistentry>
286 <varlistentry id="MALLOC_TCACHE_NONE">
287 <term><constant>MALLOCX_TCACHE_NONE</constant></term>
288
289 <listitem><para>Do not use a thread-specific cache (tcache). Unless
290 <constant>MALLOCX_TCACHE(<parameter>tc</parameter>)</constant> or
291 <constant>MALLOCX_TCACHE_NONE</constant> is specified, an
292 automatically managed tcache will be used under many circumstances.
293 This macro cannot be used in the same <parameter>flags</parameter>
294 argument as
295 <constant>MALLOCX_TCACHE(<parameter>tc</parameter>)</constant>.</para></listitem>
296 </varlistentry>
297 <varlistentry id="MALLOCX_ARENA">
Jason Evansd82a5e62013-12-12 22:35:52 -0800298 <term><constant>MALLOCX_ARENA(<parameter>a</parameter>)
299 </constant></term>
300
301 <listitem><para>Use the arena specified by the index
Jason Evans1cb181e2015-01-29 15:30:47 -0800302 <parameter>a</parameter>. This macro has no effect for regions that
303 were allocated via an arena other than the one specified. This
304 macro does not validate that <parameter>a</parameter> specifies an
305 arena index in the valid range.</para></listitem>
Jason Evansd82a5e62013-12-12 22:35:52 -0800306 </varlistentry>
307 </variablelist>
Jason Evansaee7fd22010-11-24 22:00:02 -0800308 </para>
309
Jason Evansd82a5e62013-12-12 22:35:52 -0800310 <para>The <function>mallocx<parameter/></function> function allocates at
311 least <parameter>size</parameter> bytes of memory, and returns a pointer
312 to the base address of the allocation. Behavior is undefined if
Jason Evansb2c31662014-01-12 15:05:44 -0800313 <parameter>size</parameter> is <constant>0</constant>, or if request size
314 overflows due to size class and/or alignment constraints.</para>
Jason Evansd82a5e62013-12-12 22:35:52 -0800315
316 <para>The <function>rallocx<parameter/></function> function resizes the
317 allocation at <parameter>ptr</parameter> to be at least
318 <parameter>size</parameter> bytes, and returns a pointer to the base
319 address of the resulting allocation, which may or may not have moved from
320 its original location. Behavior is undefined if
Jason Evansb2c31662014-01-12 15:05:44 -0800321 <parameter>size</parameter> is <constant>0</constant>, or if request size
322 overflows due to size class and/or alignment constraints.</para>
Jason Evansd82a5e62013-12-12 22:35:52 -0800323
324 <para>The <function>xallocx<parameter/></function> function resizes the
325 allocation at <parameter>ptr</parameter> in place to be at least
326 <parameter>size</parameter> bytes, and returns the real size of the
327 allocation. If <parameter>extra</parameter> is non-zero, an attempt is
328 made to resize the allocation to be at least <code
329 language="C">(<parameter>size</parameter> +
330 <parameter>extra</parameter>)</code> bytes, though inability to allocate
331 the extra byte(s) will not by itself result in failure to resize.
332 Behavior is undefined if <parameter>size</parameter> is
333 <constant>0</constant>, or if <code
334 language="C">(<parameter>size</parameter> + <parameter>extra</parameter>
335 &gt; <constant>SIZE_T_MAX</constant>)</code>.</para>
336
337 <para>The <function>sallocx<parameter/></function> function returns the
338 real size of the allocation at <parameter>ptr</parameter>.</para>
339
340 <para>The <function>dallocx<parameter/></function> function causes the
341 memory referenced by <parameter>ptr</parameter> to be made available for
342 future allocations.</para>
343
Daniel Micay4cfe5512014-08-28 15:41:48 -0400344 <para>The <function>sdallocx<parameter/></function> function is an
345 extension of <function>dallocx<parameter/></function> with a
346 <parameter>size</parameter> parameter to allow the caller to pass in the
347 allocation size as an optimization. The minimum valid input size is the
348 original requested size of the allocation, and the maximum valid input
349 size is the corresponding value returned by
350 <function>nallocx<parameter/></function> or
351 <function>sallocx<parameter/></function>.</para>
352
Jason Evansd82a5e62013-12-12 22:35:52 -0800353 <para>The <function>nallocx<parameter/></function> function allocates no
354 memory, but it performs the same size computation as the
355 <function>mallocx<parameter/></function> function, and returns the real
356 size of the allocation that would result from the equivalent
357 <function>mallocx<parameter/></function> function call. Behavior is
Jason Evansb2c31662014-01-12 15:05:44 -0800358 undefined if <parameter>size</parameter> is <constant>0</constant>, or if
359 request size overflows due to size class and/or alignment
360 constraints.</para>
Jason Evansaee7fd22010-11-24 22:00:02 -0800361
362 <para>The <function>mallctl<parameter/></function> function provides a
363 general interface for introspecting the memory allocator, as well as
364 setting modifiable parameters and triggering actions. The
365 period-separated <parameter>name</parameter> argument specifies a
366 location in a tree-structured namespace; see the <xref
367 linkend="mallctl_namespace" xrefstyle="template:%t"/> section for
368 documentation on the tree contents. To read a value, pass a pointer via
369 <parameter>oldp</parameter> to adequate space to contain the value, and a
370 pointer to its length via <parameter>oldlenp</parameter>; otherwise pass
371 <constant>NULL</constant> and <constant>NULL</constant>. Similarly, to
372 write a value, pass a pointer to the value via
373 <parameter>newp</parameter>, and its length via
374 <parameter>newlen</parameter>; otherwise pass <constant>NULL</constant>
375 and <constant>0</constant>.</para>
376
377 <para>The <function>mallctlnametomib<parameter/></function> function
378 provides a way to avoid repeated name lookups for applications that
379 repeatedly query the same portion of the namespace, by translating a name
380 to a &ldquo;Management Information Base&rdquo; (MIB) that can be passed
381 repeatedly to <function>mallctlbymib<parameter/></function>. Upon
382 successful return from <function>mallctlnametomib<parameter/></function>,
383 <parameter>mibp</parameter> contains an array of
384 <parameter>*miblenp</parameter> integers, where
385 <parameter>*miblenp</parameter> is the lesser of the number of components
386 in <parameter>name</parameter> and the input value of
387 <parameter>*miblenp</parameter>. Thus it is possible to pass a
388 <parameter>*miblenp</parameter> that is smaller than the number of
389 period-separated name components, which results in a partial MIB that can
390 be used as the basis for constructing a complete MIB. For name
391 components that are integers (e.g. the 2 in
392 <link
393 linkend="arenas.bin.i.size"><mallctl>arenas.bin.2.size</mallctl></link>),
394 the corresponding MIB component will always be that integer. Therefore,
395 it is legitimate to construct code like the following: <programlisting
396 language="C"><![CDATA[
397unsigned nbins, i;
Jason Evansde732962013-12-18 23:21:42 -0800398size_t mib[4];
Jason Evansaee7fd22010-11-24 22:00:02 -0800399size_t len, miblen;
400
401len = sizeof(nbins);
402mallctl("arenas.nbins", &nbins, &len, NULL, 0);
403
404miblen = 4;
Jason Evansde732962013-12-18 23:21:42 -0800405mallctlnametomib("arenas.bin.0.size", mib, &miblen);
Jason Evansaee7fd22010-11-24 22:00:02 -0800406for (i = 0; i < nbins; i++) {
407 size_t bin_size;
408
409 mib[2] = i;
410 len = sizeof(bin_size);
411 mallctlbymib(mib, miblen, &bin_size, &len, NULL, 0);
412 /* Do something with bin_size... */
413}]]></programlisting></para>
Jason Evansd82a5e62013-12-12 22:35:52 -0800414
415 <para>The <function>malloc_stats_print<parameter/></function> function
416 writes human-readable summary statistics via the
417 <parameter>write_cb</parameter> callback function pointer and
418 <parameter>cbopaque</parameter> data passed to
419 <parameter>write_cb</parameter>, or
420 <function>malloc_message<parameter/></function> if
421 <parameter>write_cb</parameter> is <constant>NULL</constant>. This
422 function can be called repeatedly. General information that never
423 changes during execution can be omitted by specifying "g" as a character
424 within the <parameter>opts</parameter> string. Note that
425 <function>malloc_message<parameter/></function> uses the
426 <function>mallctl*<parameter/></function> functions internally, so
427 inconsistent statistics can be reported if multiple threads use these
428 functions simultaneously. If <option>--enable-stats</option> is
429 specified during configuration, &ldquo;m&rdquo; and &ldquo;a&rdquo; can
430 be specified to omit merged arena and per arena statistics, respectively;
Jason Evans3c4d92e2014-10-12 22:53:59 -0700431 &ldquo;b&rdquo;, &ldquo;l&rdquo;, and &ldquo;h&rdquo; can be specified to
432 omit per size class statistics for bins, large objects, and huge objects,
433 respectively. Unrecognized characters are silently ignored. Note that
434 thread caching may prevent some statistics from being completely up to
435 date, since extra locking would be required to merge counters that track
436 thread cache operations.
Jason Evansd82a5e62013-12-12 22:35:52 -0800437 </para>
438
439 <para>The <function>malloc_usable_size<parameter/></function> function
440 returns the usable size of the allocation pointed to by
441 <parameter>ptr</parameter>. The return value may be larger than the size
442 that was requested during allocation. The
443 <function>malloc_usable_size<parameter/></function> function is not a
444 mechanism for in-place <function>realloc<parameter/></function>; rather
445 it is provided solely as a tool for introspection purposes. Any
446 discrepancy between the requested allocation size and the size reported
447 by <function>malloc_usable_size<parameter/></function> should not be
448 depended on, since such behavior is entirely implementation-dependent.
449 </para>
Jason Evansaee7fd22010-11-24 22:00:02 -0800450 </refsect2>
Jason Evansaee7fd22010-11-24 22:00:02 -0800451 </refsect1>
452 <refsect1 id="tuning">
453 <title>TUNING</title>
454 <para>Once, when the first call is made to one of the memory allocation
455 routines, the allocator initializes its internals based in part on various
456 options that can be specified at compile- or run-time.</para>
457
458 <para>The string pointed to by the global variable
459 <varname>malloc_conf</varname>, the &ldquo;name&rdquo; of the file
460 referenced by the symbolic link named <filename
461 class="symlink">/etc/malloc.conf</filename>, and the value of the
462 environment variable <envar>MALLOC_CONF</envar>, will be interpreted, in
Jason Evans705328c2013-03-19 16:28:41 -0700463 that order, from left to right as options. Note that
464 <varname>malloc_conf</varname> may be read before
465 <function>main<parameter/></function> is entered, so the declaration of
466 <varname>malloc_conf</varname> should specify an initializer that contains
467 the final value to be read by jemalloc. <varname>malloc_conf</varname> is
468 a compile-time setting, whereas <filename
469 class="symlink">/etc/malloc.conf</filename> and <envar>MALLOC_CONF</envar>
470 can be safely set any time prior to program invocation.</para>
Jason Evansaee7fd22010-11-24 22:00:02 -0800471
472 <para>An options string is a comma-separated list of option:value pairs.
473 There is one key corresponding to each <link
474 linkend="opt.abort"><mallctl>opt.*</mallctl></link> mallctl (see the <xref
475 linkend="mallctl_namespace" xrefstyle="template:%t"/> section for options
476 documentation). For example, <literal>abort:true,narenas:1</literal> sets
477 the <link linkend="opt.abort"><mallctl>opt.abort</mallctl></link> and <link
478 linkend="opt.narenas"><mallctl>opt.narenas</mallctl></link> options. Some
479 options have boolean values (true/false), others have integer values (base
480 8, 10, or 16, depending on prefix), and yet others have raw string
481 values.</para>
482 </refsect1>
483 <refsect1 id="implementation_notes">
484 <title>IMPLEMENTATION NOTES</title>
485 <para>Traditionally, allocators have used
486 <citerefentry><refentrytitle>sbrk</refentrytitle>
487 <manvolnum>2</manvolnum></citerefentry> to obtain memory, which is
488 suboptimal for several reasons, including race conditions, increased
489 fragmentation, and artificial limitations on maximum usable memory. If
Jason Evans4d434ad2014-04-15 12:09:48 -0700490 <citerefentry><refentrytitle>sbrk</refentrytitle>
491 <manvolnum>2</manvolnum></citerefentry> is supported by the operating
492 system, this allocator uses both
493 <citerefentry><refentrytitle>mmap</refentrytitle>
Jason Evansaee7fd22010-11-24 22:00:02 -0800494 <manvolnum>2</manvolnum></citerefentry> and
Jason Evans8f0e0eb2012-04-21 13:33:48 -0700495 <citerefentry><refentrytitle>sbrk</refentrytitle>
Jason Evansaee7fd22010-11-24 22:00:02 -0800496 <manvolnum>2</manvolnum></citerefentry>, in that order of preference;
497 otherwise only <citerefentry><refentrytitle>mmap</refentrytitle>
498 <manvolnum>2</manvolnum></citerefentry> is used.</para>
499
500 <para>This allocator uses multiple arenas in order to reduce lock
501 contention for threaded programs on multi-processor systems. This works
502 well with regard to threading scalability, but incurs some costs. There is
503 a small fixed per-arena overhead, and additionally, arenas manage memory
504 completely independently of each other, which means a small fixed increase
505 in overall memory fragmentation. These overheads are not generally an
506 issue, given the number of arenas normally used. Note that using
507 substantially more arenas than the default is not likely to improve
508 performance, mainly due to reduced cache performance. However, it may make
509 sense to reduce the number of arenas if an application does not make much
510 use of the allocation functions.</para>
511
512 <para>In addition to multiple arenas, unless
513 <option>--disable-tcache</option> is specified during configuration, this
514 allocator supports thread-specific caching for small and large objects, in
515 order to make it possible to completely avoid synchronization for most
516 allocation requests. Such caching allows very fast allocation in the
517 common case, but it increases memory usage and fragmentation, since a
518 bounded number of objects can remain allocated in each thread cache.</para>
519
520 <para>Memory is conceptually broken into equal-sized chunks, where the
521 chunk size is a power of two that is greater than the page size. Chunks
522 are always aligned to multiples of the chunk size. This alignment makes it
523 possible to find metadata for user objects very quickly.</para>
524
525 <para>User objects are broken into three categories according to size:
Jason Evans0cdabd22014-10-14 22:19:21 -0700526 small, large, and huge. Small and large objects are managed entirely by
527 arenas; huge objects are additionally aggregated in a single data structure
528 that is shared by all threads. Huge objects are typically used by
529 applications infrequently enough that this single data structure is not a
530 scalability issue.</para>
Jason Evansaee7fd22010-11-24 22:00:02 -0800531
532 <para>Each chunk that is managed by an arena tracks its contents as runs of
533 contiguous pages (unused, backing a set of small objects, or backing one
534 large object). The combination of chunk alignment and chunk page maps
535 makes it possible to determine all metadata regarding small and large
536 allocations in constant time.</para>
537
538 <para>Small objects are managed in groups by page runs. Each run maintains
Jason Evans0cdabd22014-10-14 22:19:21 -0700539 a bitmap to track which regions are in use. Allocation requests that are no
540 more than half the quantum (8 or 16, depending on architecture) are rounded
541 up to the nearest power of two that is at least <code
542 language="C">sizeof(<type>double</type>)</code>. All other object size
543 classes are multiples of the quantum, spaced such that there are four size
544 classes for each doubling in size, which limits internal fragmentation to
545 approximately 20% for all but the smallest size classes. Small size classes
546 are smaller than four times the page size, large size classes are smaller
547 than the chunk size (see the <link
548 linkend="opt.lg_chunk"><mallctl>opt.lg_chunk</mallctl></link> option), and
549 huge size classes extend from the chunk size up to one size class less than
550 the full address space size.</para>
Jason Evansaee7fd22010-11-24 22:00:02 -0800551
552 <para>Allocations are packed tightly together, which can be an issue for
553 multi-threaded applications. If you need to assure that allocations do not
554 suffer from cacheline sharing, round your allocation requests up to the
555 nearest multiple of the cacheline size, or specify cacheline alignment when
556 allocating.</para>
557
Jason Evans228b2e92015-01-22 15:28:25 -0800558 <para>The <function>realloc<parameter/></function>,
559 <function>rallocx<parameter/></function>, and
560 <function>xallocx<parameter/></function> functions may resize allocations
561 without moving them under limited circumstances. Unlike the
562 <function>*allocx<parameter/></function> API, the standard API does not
563 officially round up the usable size of an allocation to the nearest size
564 class, so technically it is necessary to call
565 <function>realloc<parameter/></function> to grow e.g. a 9-byte allocation to
566 16 bytes, or shrink a 16-byte allocation to 9 bytes. Growth and shrinkage
567 trivially succeeds in place as long as the pre-size and post-size both round
568 up to the same size class. No other API guarantees are made regarding
569 in-place resizing, but the current implementation also tries to resize large
570 and huge allocations in place, as long as the pre-size and post-size are
Jason Evans38f86492015-08-14 00:55:44 -0700571 both large or both huge. In such cases shrinkage always succeeds for large
572 size classes, but for huge size classes the chunk allocator must support
573 splitting (see <link
574 linkend="arena.i.chunk_hooks"><mallctl>arena.&lt;i&gt;.chunk_hooks</mallctl></link>).
575 Growth only succeeds if the trailing memory is currently available, and
576 additionally for huge size classes the chunk allocator must support
577 merging.</para>
Jason Evans228b2e92015-01-22 15:28:25 -0800578
Jason Evansa5dbaef2015-08-14 00:35:11 -0700579 <para>Assuming 2 MiB chunks, 4 KiB pages, and a 16-byte quantum on a
Jason Evansf044bb22015-03-06 20:05:16 -0800580 64-bit system, the size classes in each category are as shown in <xref
Jason Evansaee7fd22010-11-24 22:00:02 -0800581 linkend="size_classes" xrefstyle="template:Table %n"/>.</para>
582
583 <table xml:id="size_classes" frame="all">
584 <title>Size classes</title>
Jason Evans7091b412012-03-19 09:36:44 -0700585 <tgroup cols="3" colsep="1" rowsep="1">
586 <colspec colname="c1" align="left"/>
587 <colspec colname="c2" align="right"/>
588 <colspec colname="c3" align="left"/>
Jason Evansaee7fd22010-11-24 22:00:02 -0800589 <thead>
590 <row>
591 <entry>Category</entry>
Jason Evans7091b412012-03-19 09:36:44 -0700592 <entry>Spacing</entry>
Jason Evansaee7fd22010-11-24 22:00:02 -0800593 <entry>Size</entry>
594 </row>
595 </thead>
596 <tbody>
597 <row>
Jason Evans0cdabd22014-10-14 22:19:21 -0700598 <entry morerows="8">Small</entry>
Jason Evans7091b412012-03-19 09:36:44 -0700599 <entry>lg</entry>
Jason Evansaee7fd22010-11-24 22:00:02 -0800600 <entry>[8]</entry>
601 </row>
602 <row>
Jason Evans7091b412012-03-19 09:36:44 -0700603 <entry>16</entry>
Jason Evans0cdabd22014-10-14 22:19:21 -0700604 <entry>[16, 32, 48, 64, 80, 96, 112, 128]</entry>
Jason Evansaee7fd22010-11-24 22:00:02 -0800605 </row>
606 <row>
Jason Evans7091b412012-03-19 09:36:44 -0700607 <entry>32</entry>
Jason Evansb1726102012-02-28 16:50:47 -0800608 <entry>[160, 192, 224, 256]</entry>
Jason Evansaee7fd22010-11-24 22:00:02 -0800609 </row>
610 <row>
Jason Evans7091b412012-03-19 09:36:44 -0700611 <entry>64</entry>
Jason Evansb1726102012-02-28 16:50:47 -0800612 <entry>[320, 384, 448, 512]</entry>
613 </row>
614 <row>
Jason Evans7091b412012-03-19 09:36:44 -0700615 <entry>128</entry>
Jason Evansb1726102012-02-28 16:50:47 -0800616 <entry>[640, 768, 896, 1024]</entry>
617 </row>
618 <row>
Jason Evans7091b412012-03-19 09:36:44 -0700619 <entry>256</entry>
Jason Evansb1726102012-02-28 16:50:47 -0800620 <entry>[1280, 1536, 1792, 2048]</entry>
621 </row>
622 <row>
Jason Evans7091b412012-03-19 09:36:44 -0700623 <entry>512</entry>
Jason Evans0cdabd22014-10-14 22:19:21 -0700624 <entry>[2560, 3072, 3584, 4096]</entry>
Jason Evansaee7fd22010-11-24 22:00:02 -0800625 </row>
626 <row>
Jason Evans0cdabd22014-10-14 22:19:21 -0700627 <entry>1 KiB</entry>
628 <entry>[5 KiB, 6 KiB, 7 KiB, 8 KiB]</entry>
629 </row>
630 <row>
631 <entry>2 KiB</entry>
632 <entry>[10 KiB, 12 KiB, 14 KiB]</entry>
633 </row>
634 <row>
Jason Evansa5dbaef2015-08-14 00:35:11 -0700635 <entry morerows="7">Large</entry>
Jason Evans0cdabd22014-10-14 22:19:21 -0700636 <entry>2 KiB</entry>
637 <entry>[16 KiB]</entry>
638 </row>
639 <row>
Jason Evans7091b412012-03-19 09:36:44 -0700640 <entry>4 KiB</entry>
Jason Evans0cdabd22014-10-14 22:19:21 -0700641 <entry>[20 KiB, 24 KiB, 28 KiB, 32 KiB]</entry>
Jason Evansaee7fd22010-11-24 22:00:02 -0800642 </row>
643 <row>
Jason Evans0cdabd22014-10-14 22:19:21 -0700644 <entry>8 KiB</entry>
645 <entry>[40 KiB, 48 KiB, 54 KiB, 64 KiB]</entry>
646 </row>
647 <row>
648 <entry>16 KiB</entry>
649 <entry>[80 KiB, 96 KiB, 112 KiB, 128 KiB]</entry>
650 </row>
651 <row>
652 <entry>32 KiB</entry>
Jason Evansa5dbaef2015-08-14 00:35:11 -0700653 <entry>[160 KiB, 192 KiB, 224 KiB, 256 KiB]</entry>
Jason Evans0cdabd22014-10-14 22:19:21 -0700654 </row>
655 <row>
656 <entry>64 KiB</entry>
657 <entry>[320 KiB, 384 KiB, 448 KiB, 512 KiB]</entry>
658 </row>
659 <row>
660 <entry>128 KiB</entry>
Jason Evansf044bb22015-03-06 20:05:16 -0800661 <entry>[640 KiB, 768 KiB, 896 KiB, 1 MiB]</entry>
Jason Evans0cdabd22014-10-14 22:19:21 -0700662 </row>
663 <row>
664 <entry>256 KiB</entry>
Jason Evansa5dbaef2015-08-14 00:35:11 -0700665 <entry>[1280 KiB, 1536 KiB, 1792 KiB]</entry>
666 </row>
667 <row>
668 <entry morerows="6">Huge</entry>
669 <entry>256 KiB</entry>
670 <entry>[2 MiB]</entry>
Jason Evans0cdabd22014-10-14 22:19:21 -0700671 </row>
672 <row>
673 <entry>512 KiB</entry>
Jason Evansf044bb22015-03-06 20:05:16 -0800674 <entry>[2560 KiB, 3 MiB, 3584 KiB, 4 MiB]</entry>
Jason Evans0cdabd22014-10-14 22:19:21 -0700675 </row>
676 <row>
677 <entry>1 MiB</entry>
678 <entry>[5 MiB, 6 MiB, 7 MiB, 8 MiB]</entry>
679 </row>
680 <row>
681 <entry>2 MiB</entry>
682 <entry>[10 MiB, 12 MiB, 14 MiB, 16 MiB]</entry>
683 </row>
684 <row>
Jason Evans7091b412012-03-19 09:36:44 -0700685 <entry>4 MiB</entry>
Jason Evans0cdabd22014-10-14 22:19:21 -0700686 <entry>[20 MiB, 24 MiB, 28 MiB, 32 MiB]</entry>
687 </row>
688 <row>
689 <entry>8 MiB</entry>
690 <entry>[40 MiB, 48 MiB, 56 MiB, 64 MiB]</entry>
691 </row>
692 <row>
693 <entry>...</entry>
694 <entry>...</entry>
Jason Evansaee7fd22010-11-24 22:00:02 -0800695 </row>
696 </tbody>
697 </tgroup>
698 </table>
699 </refsect1>
700 <refsect1 id="mallctl_namespace">
701 <title>MALLCTL NAMESPACE</title>
702 <para>The following names are defined in the namespace accessible via the
703 <function>mallctl*<parameter/></function> functions. Value types are
704 specified in parentheses, their readable/writable statuses are encoded as
705 <literal>rw</literal>, <literal>r-</literal>, <literal>-w</literal>, or
706 <literal>--</literal>, and required build configuration flags follow, if
707 any. A name element encoded as <literal>&lt;i&gt;</literal> or
708 <literal>&lt;j&gt;</literal> indicates an integer component, where the
709 integer varies from 0 to some upper value that must be determined via
710 introspection. In the case of <mallctl>stats.arenas.&lt;i&gt;.*</mallctl>,
711 <literal>&lt;i&gt;</literal> equal to <link
712 linkend="arenas.narenas"><mallctl>arenas.narenas</mallctl></link> can be
713 used to access the summation of statistics from all arenas. Take special
714 note of the <link linkend="epoch"><mallctl>epoch</mallctl></link> mallctl,
715 which controls refreshing of cached dynamic statistics.</para>
716
717 <variablelist>
Jason Evansaabaf852013-10-30 14:52:09 -0700718 <varlistentry id="version">
Jason Evansaee7fd22010-11-24 22:00:02 -0800719 <term>
720 <mallctl>version</mallctl>
721 (<type>const char *</type>)
722 <literal>r-</literal>
723 </term>
724 <listitem><para>Return the jemalloc version string.</para></listitem>
725 </varlistentry>
726
727 <varlistentry id="epoch">
728 <term>
729 <mallctl>epoch</mallctl>
730 (<type>uint64_t</type>)
731 <literal>rw</literal>
732 </term>
733 <listitem><para>If a value is passed in, refresh the data from which
734 the <function>mallctl*<parameter/></function> functions report values,
735 and increment the epoch. Return the current epoch. This is useful for
736 detecting whether another thread caused a refresh.</para></listitem>
737 </varlistentry>
738
Jason Evansf2bc8522015-07-17 16:38:25 -0700739 <varlistentry id="config.cache_oblivious">
740 <term>
741 <mallctl>config.cache_oblivious</mallctl>
742 (<type>bool</type>)
743 <literal>r-</literal>
744 </term>
745 <listitem><para><option>--enable-cache-oblivious</option> was specified
746 during build configuration.</para></listitem>
747 </varlistentry>
748
Jason Evansaabaf852013-10-30 14:52:09 -0700749 <varlistentry id="config.debug">
Jason Evansaee7fd22010-11-24 22:00:02 -0800750 <term>
751 <mallctl>config.debug</mallctl>
752 (<type>bool</type>)
753 <literal>r-</literal>
754 </term>
755 <listitem><para><option>--enable-debug</option> was specified during
756 build configuration.</para></listitem>
757 </varlistentry>
758
Jason Evansaabaf852013-10-30 14:52:09 -0700759 <varlistentry id="config.fill">
Jason Evansaee7fd22010-11-24 22:00:02 -0800760 <term>
Jason Evansaee7fd22010-11-24 22:00:02 -0800761 <mallctl>config.fill</mallctl>
762 (<type>bool</type>)
763 <literal>r-</literal>
764 </term>
765 <listitem><para><option>--enable-fill</option> was specified during
766 build configuration.</para></listitem>
767 </varlistentry>
768
Jason Evansaabaf852013-10-30 14:52:09 -0700769 <varlistentry id="config.lazy_lock">
Jason Evansaee7fd22010-11-24 22:00:02 -0800770 <term>
771 <mallctl>config.lazy_lock</mallctl>
772 (<type>bool</type>)
773 <literal>r-</literal>
774 </term>
775 <listitem><para><option>--enable-lazy-lock</option> was specified
776 during build configuration.</para></listitem>
777 </varlistentry>
778
Jason Evansaabaf852013-10-30 14:52:09 -0700779 <varlistentry id="config.munmap">
Jason Evans2e671ff2012-05-09 16:12:00 -0700780 <term>
Jason Evans59ae2762012-04-16 17:52:27 -0700781 <mallctl>config.munmap</mallctl>
782 (<type>bool</type>)
783 <literal>r-</literal>
784 </term>
785 <listitem><para><option>--enable-munmap</option> was specified during
786 build configuration.</para></listitem>
787 </varlistentry>
788
Jason Evansaabaf852013-10-30 14:52:09 -0700789 <varlistentry id="config.prof">
Jason Evans59ae2762012-04-16 17:52:27 -0700790 <term>
Jason Evansaee7fd22010-11-24 22:00:02 -0800791 <mallctl>config.prof</mallctl>
792 (<type>bool</type>)
793 <literal>r-</literal>
794 </term>
795 <listitem><para><option>--enable-prof</option> was specified during
796 build configuration.</para></listitem>
797 </varlistentry>
798
Jason Evansaabaf852013-10-30 14:52:09 -0700799 <varlistentry id="config.prof_libgcc">
Jason Evansaee7fd22010-11-24 22:00:02 -0800800 <term>
801 <mallctl>config.prof_libgcc</mallctl>
802 (<type>bool</type>)
803 <literal>r-</literal>
804 </term>
805 <listitem><para><option>--disable-prof-libgcc</option> was not
806 specified during build configuration.</para></listitem>
807 </varlistentry>
808
Jason Evansaabaf852013-10-30 14:52:09 -0700809 <varlistentry id="config.prof_libunwind">
Jason Evansaee7fd22010-11-24 22:00:02 -0800810 <term>
811 <mallctl>config.prof_libunwind</mallctl>
812 (<type>bool</type>)
813 <literal>r-</literal>
814 </term>
815 <listitem><para><option>--enable-prof-libunwind</option> was specified
816 during build configuration.</para></listitem>
817 </varlistentry>
818
Jason Evansaabaf852013-10-30 14:52:09 -0700819 <varlistentry id="config.stats">
Jason Evansaee7fd22010-11-24 22:00:02 -0800820 <term>
821 <mallctl>config.stats</mallctl>
822 (<type>bool</type>)
823 <literal>r-</literal>
824 </term>
825 <listitem><para><option>--enable-stats</option> was specified during
826 build configuration.</para></listitem>
827 </varlistentry>
828
Jason Evansaabaf852013-10-30 14:52:09 -0700829 <varlistentry id="config.tcache">
Jason Evansaee7fd22010-11-24 22:00:02 -0800830 <term>
Jason Evansaee7fd22010-11-24 22:00:02 -0800831 <mallctl>config.tcache</mallctl>
832 (<type>bool</type>)
833 <literal>r-</literal>
834 </term>
835 <listitem><para><option>--disable-tcache</option> was not specified
836 during build configuration.</para></listitem>
837 </varlistentry>
838
Jason Evansaabaf852013-10-30 14:52:09 -0700839 <varlistentry id="config.tls">
Jason Evansaee7fd22010-11-24 22:00:02 -0800840 <term>
Jason Evansaee7fd22010-11-24 22:00:02 -0800841 <mallctl>config.tls</mallctl>
842 (<type>bool</type>)
843 <literal>r-</literal>
844 </term>
845 <listitem><para><option>--disable-tls</option> was not specified during
846 build configuration.</para></listitem>
847 </varlistentry>
848
Jason Evansaabaf852013-10-30 14:52:09 -0700849 <varlistentry id="config.utrace">
Jason Evansaee7fd22010-11-24 22:00:02 -0800850 <term>
Jason Evansb1476112012-04-05 13:36:17 -0700851 <mallctl>config.utrace</mallctl>
852 (<type>bool</type>)
853 <literal>r-</literal>
854 </term>
855 <listitem><para><option>--enable-utrace</option> was specified during
856 build configuration.</para></listitem>
857 </varlistentry>
858
Jason Evansaabaf852013-10-30 14:52:09 -0700859 <varlistentry id="config.valgrind">
Jason Evansb1476112012-04-05 13:36:17 -0700860 <term>
Jason Evans122449b2012-04-06 00:35:09 -0700861 <mallctl>config.valgrind</mallctl>
862 (<type>bool</type>)
863 <literal>r-</literal>
864 </term>
865 <listitem><para><option>--enable-valgrind</option> was specified during
866 build configuration.</para></listitem>
867 </varlistentry>
868
Jason Evansaabaf852013-10-30 14:52:09 -0700869 <varlistentry id="config.xmalloc">
Jason Evans122449b2012-04-06 00:35:09 -0700870 <term>
Jason Evansaee7fd22010-11-24 22:00:02 -0800871 <mallctl>config.xmalloc</mallctl>
872 (<type>bool</type>)
873 <literal>r-</literal>
874 </term>
875 <listitem><para><option>--enable-xmalloc</option> was specified during
876 build configuration.</para></listitem>
877 </varlistentry>
878
879 <varlistentry id="opt.abort">
880 <term>
881 <mallctl>opt.abort</mallctl>
882 (<type>bool</type>)
883 <literal>r-</literal>
884 </term>
885 <listitem><para>Abort-on-warning enabled/disabled. If true, most
886 warnings are fatal. The process will call
887 <citerefentry><refentrytitle>abort</refentrytitle>
888 <manvolnum>3</manvolnum></citerefentry> in these cases. This option is
889 disabled by default unless <option>--enable-debug</option> is
890 specified during configuration, in which case it is enabled by default.
891 </para></listitem>
892 </varlistentry>
893
Jason Evans609ae592012-10-11 13:53:15 -0700894 <varlistentry id="opt.dss">
895 <term>
896 <mallctl>opt.dss</mallctl>
897 (<type>const char *</type>)
898 <literal>r-</literal>
899 </term>
900 <listitem><para>dss (<citerefentry><refentrytitle>sbrk</refentrytitle>
901 <manvolnum>2</manvolnum></citerefentry>) allocation precedence as
902 related to <citerefentry><refentrytitle>mmap</refentrytitle>
903 <manvolnum>2</manvolnum></citerefentry> allocation. The following
Jason Evans4d434ad2014-04-15 12:09:48 -0700904 settings are supported if
905 <citerefentry><refentrytitle>sbrk</refentrytitle>
906 <manvolnum>2</manvolnum></citerefentry> is supported by the operating
907 system: &ldquo;disabled&rdquo;, &ldquo;primary&rdquo;, and
908 &ldquo;secondary&rdquo;; otherwise only &ldquo;disabled&rdquo; is
909 supported. The default is &ldquo;secondary&rdquo; if
910 <citerefentry><refentrytitle>sbrk</refentrytitle>
911 <manvolnum>2</manvolnum></citerefentry> is supported by the operating
912 system; &ldquo;disabled&rdquo; otherwise.
Jason Evansd8a39002013-12-19 21:40:41 -0800913 </para></listitem>
914 </varlistentry>
915
916 <varlistentry id="opt.lg_chunk">
917 <term>
918 <mallctl>opt.lg_chunk</mallctl>
919 (<type>size_t</type>)
920 <literal>r-</literal>
921 </term>
922 <listitem><para>Virtual memory chunk size (log base 2). If a chunk
923 size outside the supported size range is specified, the size is
924 silently clipped to the minimum/maximum supported size. The default
Jason Evans5bd87962015-07-15 17:15:26 -0700925 chunk size is 2 MiB (2^21).
Jason Evansd8a39002013-12-19 21:40:41 -0800926 </para></listitem>
Jason Evans609ae592012-10-11 13:53:15 -0700927 </varlistentry>
928
Jason Evansaee7fd22010-11-24 22:00:02 -0800929 <varlistentry id="opt.narenas">
930 <term>
931 <mallctl>opt.narenas</mallctl>
932 (<type>size_t</type>)
933 <literal>r-</literal>
934 </term>
Jason Evans609ae592012-10-11 13:53:15 -0700935 <listitem><para>Maximum number of arenas to use for automatic
936 multiplexing of threads and arenas. The default is four times the
937 number of CPUs, or one if there is a single CPU.</para></listitem>
Jason Evansaee7fd22010-11-24 22:00:02 -0800938 </varlistentry>
939
940 <varlistentry id="opt.lg_dirty_mult">
941 <term>
942 <mallctl>opt.lg_dirty_mult</mallctl>
943 (<type>ssize_t</type>)
944 <literal>r-</literal>
945 </term>
946 <listitem><para>Per-arena minimum ratio (log base 2) of active to dirty
947 pages. Some dirty unused pages may be allowed to accumulate, within
948 the limit set by the ratio (or one chunk worth of dirty pages,
949 whichever is greater), before informing the kernel about some of those
950 pages via <citerefentry><refentrytitle>madvise</refentrytitle>
951 <manvolnum>2</manvolnum></citerefentry> or a similar system call. This
952 provides the kernel with sufficient information to recycle dirty pages
953 if physical memory becomes scarce and the pages remain unused. The
Jason Evanse3d13062012-10-30 15:42:37 -0700954 default minimum ratio is 8:1 (2^3:1); an option value of -1 will
Jason Evans8d6a3e82015-03-18 18:55:33 -0700955 disable dirty page purging. See <link
956 linkend="arenas.lg_dirty_mult"><mallctl>arenas.lg_dirty_mult</mallctl></link>
957 and <link
958 linkend="arena.i.lg_dirty_mult"><mallctl>arena.&lt;i&gt;.lg_dirty_mult</mallctl></link>
959 for related dynamic control options.</para></listitem>
Jason Evansaee7fd22010-11-24 22:00:02 -0800960 </varlistentry>
961
962 <varlistentry id="opt.stats_print">
963 <term>
964 <mallctl>opt.stats_print</mallctl>
965 (<type>bool</type>)
966 <literal>r-</literal>
967 </term>
968 <listitem><para>Enable/disable statistics printing at exit. If
969 enabled, the <function>malloc_stats_print<parameter/></function>
970 function is called at program exit via an
971 <citerefentry><refentrytitle>atexit</refentrytitle>
972 <manvolnum>3</manvolnum></citerefentry> function. If
973 <option>--enable-stats</option> is specified during configuration, this
974 has the potential to cause deadlock for a multi-threaded process that
975 exits while one or more threads are executing in the memory allocation
Jason Evans57efa7b2014-10-08 17:57:19 -0700976 functions. Furthermore, <function>atexit<parameter/></function> may
977 allocate memory during application initialization and then deadlock
978 internally when jemalloc in turn calls
979 <function>atexit<parameter/></function>, so this option is not
980 univerally usable (though the application can register its own
981 <function>atexit<parameter/></function> function with equivalent
982 functionality). Therefore, this option should only be used with care;
983 it is primarily intended as a performance tuning aid during application
Jason Evansaee7fd22010-11-24 22:00:02 -0800984 development. This option is disabled by default.</para></listitem>
985 </varlistentry>
986
987 <varlistentry id="opt.junk">
988 <term>
989 <mallctl>opt.junk</mallctl>
Guilherme Goncalves2c5cb612014-12-08 19:12:41 -0200990 (<type>const char *</type>)
Jason Evansaee7fd22010-11-24 22:00:02 -0800991 <literal>r-</literal>
992 [<option>--enable-fill</option>]
993 </term>
Guilherme Goncalves2c5cb612014-12-08 19:12:41 -0200994 <listitem><para>Junk filling. If set to "alloc", each byte of
995 uninitialized allocated memory will be initialized to
996 <literal>0xa5</literal>. If set to "free", all deallocated memory will
997 be initialized to <literal>0x5a</literal>. If set to "true", both
998 allocated and deallocated memory will be initialized, and if set to
999 "false", junk filling be disabled entirely. This is intended for
1000 debugging and will impact performance negatively. This option is
1001 "false" by default unless <option>--enable-debug</option> is specified
1002 during configuration, in which case it is "true" by default unless
1003 running inside <ulink
Jason Evans781fe752012-05-15 14:48:14 -07001004 url="http://valgrind.org/">Valgrind</ulink>.</para></listitem>
Jason Evansaee7fd22010-11-24 22:00:02 -08001005 </varlistentry>
1006
Jason Evans122449b2012-04-06 00:35:09 -07001007 <varlistentry id="opt.quarantine">
1008 <term>
1009 <mallctl>opt.quarantine</mallctl>
1010 (<type>size_t</type>)
1011 <literal>r-</literal>
1012 [<option>--enable-fill</option>]
1013 </term>
1014 <listitem><para>Per thread quarantine size in bytes. If non-zero, each
1015 thread maintains a FIFO object quarantine that stores up to the
1016 specified number of bytes of memory. The quarantined memory is not
1017 freed until it is released from quarantine, though it is immediately
1018 junk-filled if the <link
1019 linkend="opt.junk"><mallctl>opt.junk</mallctl></link> option is
1020 enabled. This feature is of particular use in combination with <ulink
Jason Evansd926c902012-04-25 23:17:57 -07001021 url="http://valgrind.org/">Valgrind</ulink>, which can detect attempts
1022 to access quarantined objects. This is intended for debugging and will
Jason Evans781fe752012-05-15 14:48:14 -07001023 impact performance negatively. The default quarantine size is 0 unless
1024 running inside Valgrind, in which case the default is 16
1025 MiB.</para></listitem>
Jason Evans122449b2012-04-06 00:35:09 -07001026 </varlistentry>
1027
1028 <varlistentry id="opt.redzone">
1029 <term>
1030 <mallctl>opt.redzone</mallctl>
1031 (<type>bool</type>)
1032 <literal>r-</literal>
1033 [<option>--enable-fill</option>]
1034 </term>
1035 <listitem><para>Redzones enabled/disabled. If enabled, small
1036 allocations have redzones before and after them. Furthermore, if the
1037 <link linkend="opt.junk"><mallctl>opt.junk</mallctl></link> option is
1038 enabled, the redzones are checked for corruption during deallocation.
1039 However, the primary intended purpose of this feature is to be used in
Jason Evansd926c902012-04-25 23:17:57 -07001040 combination with <ulink url="http://valgrind.org/">Valgrind</ulink>,
1041 which needs redzones in order to do effective buffer overflow/underflow
1042 detection. This option is intended for debugging and will impact
1043 performance negatively. This option is disabled by
Jason Evans781fe752012-05-15 14:48:14 -07001044 default unless running inside Valgrind.</para></listitem>
Jason Evans122449b2012-04-06 00:35:09 -07001045 </varlistentry>
1046
Jason Evansaee7fd22010-11-24 22:00:02 -08001047 <varlistentry id="opt.zero">
1048 <term>
1049 <mallctl>opt.zero</mallctl>
1050 (<type>bool</type>)
1051 <literal>r-</literal>
1052 [<option>--enable-fill</option>]
1053 </term>
1054 <listitem><para>Zero filling enabled/disabled. If enabled, each byte
1055 of uninitialized allocated memory will be initialized to 0. Note that
1056 this initialization only happens once for each byte, so
Jason Evans9790b962014-04-14 22:32:31 -07001057 <function>realloc<parameter/></function> and
1058 <function>rallocx<parameter/></function> calls do not zero memory that
Jason Evansaee7fd22010-11-24 22:00:02 -08001059 was previously allocated. This is intended for debugging and will
1060 impact performance negatively. This option is disabled by default.
1061 </para></listitem>
1062 </varlistentry>
1063
Jason Evansb1476112012-04-05 13:36:17 -07001064 <varlistentry id="opt.utrace">
1065 <term>
1066 <mallctl>opt.utrace</mallctl>
1067 (<type>bool</type>)
1068 <literal>r-</literal>
1069 [<option>--enable-utrace</option>]
1070 </term>
1071 <listitem><para>Allocation tracing based on
1072 <citerefentry><refentrytitle>utrace</refentrytitle>
1073 <manvolnum>2</manvolnum></citerefentry> enabled/disabled. This option
1074 is disabled by default.</para></listitem>
1075 </varlistentry>
1076
Jason Evansaee7fd22010-11-24 22:00:02 -08001077 <varlistentry id="opt.xmalloc">
1078 <term>
1079 <mallctl>opt.xmalloc</mallctl>
1080 (<type>bool</type>)
1081 <literal>r-</literal>
1082 [<option>--enable-xmalloc</option>]
1083 </term>
1084 <listitem><para>Abort-on-out-of-memory enabled/disabled. If enabled,
1085 rather than returning failure for any allocation function, display a
1086 diagnostic message on <constant>STDERR_FILENO</constant> and cause the
1087 program to drop core (using
1088 <citerefentry><refentrytitle>abort</refentrytitle>
1089 <manvolnum>3</manvolnum></citerefentry>). If an application is
1090 designed to depend on this behavior, set the option at compile time by
1091 including the following in the source code:
1092 <programlisting language="C"><![CDATA[
1093malloc_conf = "xmalloc:true";]]></programlisting>
1094 This option is disabled by default.</para></listitem>
1095 </varlistentry>
1096
1097 <varlistentry id="opt.tcache">
1098 <term>
1099 <mallctl>opt.tcache</mallctl>
1100 (<type>bool</type>)
1101 <literal>r-</literal>
1102 [<option>--enable-tcache</option>]
1103 </term>
Jason Evans1cb181e2015-01-29 15:30:47 -08001104 <listitem><para>Thread-specific caching (tcache) enabled/disabled. When
1105 there are multiple threads, each thread uses a tcache for objects up to
1106 a certain size. Thread-specific caching allows many allocations to be
1107 satisfied without performing any thread synchronization, at the cost of
1108 increased memory use. See the <link
Jason Evansaee7fd22010-11-24 22:00:02 -08001109 linkend="opt.lg_tcache_max"><mallctl>opt.lg_tcache_max</mallctl></link>
Jason Evans4507f342012-03-05 14:34:37 -08001110 option for related tuning information. This option is enabled by
Jason Evans174b70e2012-05-15 23:31:53 -07001111 default unless running inside <ulink
Jason Evansbd87b012014-04-15 16:35:08 -07001112 url="http://valgrind.org/">Valgrind</ulink>, in which case it is
1113 forcefully disabled.</para></listitem>
Jason Evansaee7fd22010-11-24 22:00:02 -08001114 </varlistentry>
1115
Jason Evansaee7fd22010-11-24 22:00:02 -08001116 <varlistentry id="opt.lg_tcache_max">
1117 <term>
1118 <mallctl>opt.lg_tcache_max</mallctl>
1119 (<type>size_t</type>)
1120 <literal>r-</literal>
1121 [<option>--enable-tcache</option>]
1122 </term>
1123 <listitem><para>Maximum size class (log base 2) to cache in the
Jason Evans1cb181e2015-01-29 15:30:47 -08001124 thread-specific cache (tcache). At a minimum, all small size classes
1125 are cached, and at a maximum all large size classes are cached. The
Jason Evansaee7fd22010-11-24 22:00:02 -08001126 default maximum is 32 KiB (2^15).</para></listitem>
1127 </varlistentry>
1128
1129 <varlistentry id="opt.prof">
1130 <term>
1131 <mallctl>opt.prof</mallctl>
1132 (<type>bool</type>)
1133 <literal>r-</literal>
1134 [<option>--enable-prof</option>]
1135 </term>
1136 <listitem><para>Memory profiling enabled/disabled. If enabled, profile
Jason Evans0b25fe72012-04-17 16:39:33 -07001137 memory allocation activity. See the <link
Jason Evansaee7fd22010-11-24 22:00:02 -08001138 linkend="opt.prof_active"><mallctl>opt.prof_active</mallctl></link>
1139 option for on-the-fly activation/deactivation. See the <link
1140 linkend="opt.lg_prof_sample"><mallctl>opt.lg_prof_sample</mallctl></link>
1141 option for probabilistic sampling control. See the <link
1142 linkend="opt.prof_accum"><mallctl>opt.prof_accum</mallctl></link>
1143 option for control of cumulative sample reporting. See the <link
Jason Evansaee7fd22010-11-24 22:00:02 -08001144 linkend="opt.lg_prof_interval"><mallctl>opt.lg_prof_interval</mallctl></link>
Jason Evans0b25fe72012-04-17 16:39:33 -07001145 option for information on interval-triggered profile dumping, the <link
1146 linkend="opt.prof_gdump"><mallctl>opt.prof_gdump</mallctl></link>
1147 option for information on high-water-triggered profile dumping, and the
1148 <link linkend="opt.prof_final"><mallctl>opt.prof_final</mallctl></link>
1149 option for final profile dumping. Profile output is compatible with
Jason Evans70417202015-05-01 12:31:12 -07001150 the <command>jeprof</command> command, which is based on the
1151 <command>pprof</command> that is developed as part of the <ulink
1152 url="http://code.google.com/p/gperftools/">gperftools
Jason Evansaee7fd22010-11-24 22:00:02 -08001153 package</ulink>.</para></listitem>
1154 </varlistentry>
1155
1156 <varlistentry id="opt.prof_prefix">
1157 <term>
1158 <mallctl>opt.prof_prefix</mallctl>
1159 (<type>const char *</type>)
1160 <literal>r-</literal>
1161 [<option>--enable-prof</option>]
1162 </term>
1163 <listitem><para>Filename prefix for profile dumps. If the prefix is
1164 set to the empty string, no automatic dumps will occur; this is
1165 primarily useful for disabling the automatic final heap dump (which
1166 also disables leak reporting, if enabled). The default prefix is
1167 <filename>jeprof</filename>.</para></listitem>
1168 </varlistentry>
1169
Jason Evansaee7fd22010-11-24 22:00:02 -08001170 <varlistentry id="opt.prof_active">
1171 <term>
1172 <mallctl>opt.prof_active</mallctl>
1173 (<type>bool</type>)
Jason Evans8d6a3e82015-03-18 18:55:33 -07001174 <literal>r-</literal>
Jason Evansaee7fd22010-11-24 22:00:02 -08001175 [<option>--enable-prof</option>]
1176 </term>
1177 <listitem><para>Profiling activated/deactivated. This is a secondary
1178 control mechanism that makes it possible to start the application with
1179 profiling enabled (see the <link
1180 linkend="opt.prof"><mallctl>opt.prof</mallctl></link> option) but
1181 inactive, then toggle profiling at any time during program execution
1182 with the <link
1183 linkend="prof.active"><mallctl>prof.active</mallctl></link> mallctl.
1184 This option is enabled by default.</para></listitem>
1185 </varlistentry>
1186
Jason Evansfc12c0b2014-10-03 23:25:30 -07001187 <varlistentry id="opt.prof_thread_active_init">
1188 <term>
1189 <mallctl>opt.prof_thread_active_init</mallctl>
1190 (<type>bool</type>)
1191 <literal>r-</literal>
1192 [<option>--enable-prof</option>]
1193 </term>
1194 <listitem><para>Initial setting for <link
1195 linkend="thread.prof.active"><mallctl>thread.prof.active</mallctl></link>
1196 in newly created threads. The initial setting for newly created threads
1197 can also be changed during execution via the <link
1198 linkend="prof.thread_active_init"><mallctl>prof.thread_active_init</mallctl></link>
1199 mallctl. This option is enabled by default.</para></listitem>
1200 </varlistentry>
1201
Jason Evansaee7fd22010-11-24 22:00:02 -08001202 <varlistentry id="opt.lg_prof_sample">
1203 <term>
1204 <mallctl>opt.lg_prof_sample</mallctl>
Jason Evans602c8e02014-08-18 16:22:13 -07001205 (<type>size_t</type>)
Jason Evansaee7fd22010-11-24 22:00:02 -08001206 <literal>r-</literal>
1207 [<option>--enable-prof</option>]
1208 </term>
1209 <listitem><para>Average interval (log base 2) between allocation
1210 samples, as measured in bytes of allocation activity. Increasing the
1211 sampling interval decreases profile fidelity, but also decreases the
Jason Evans0b25fe72012-04-17 16:39:33 -07001212 computational overhead. The default sample interval is 512 KiB (2^19
1213 B).</para></listitem>
Jason Evansaee7fd22010-11-24 22:00:02 -08001214 </varlistentry>
1215
1216 <varlistentry id="opt.prof_accum">
1217 <term>
1218 <mallctl>opt.prof_accum</mallctl>
1219 (<type>bool</type>)
1220 <literal>r-</literal>
1221 [<option>--enable-prof</option>]
1222 </term>
1223 <listitem><para>Reporting of cumulative object/byte counts in profile
1224 dumps enabled/disabled. If this option is enabled, every unique
1225 backtrace must be stored for the duration of execution. Depending on
1226 the application, this can impose a large memory overhead, and the
Jason Evans0b25fe72012-04-17 16:39:33 -07001227 cumulative counts are not always of interest. This option is disabled
Jason Evans0b526ff2012-02-13 18:04:26 -08001228 by default.</para></listitem>
Jason Evansaee7fd22010-11-24 22:00:02 -08001229 </varlistentry>
1230
1231 <varlistentry id="opt.lg_prof_interval">
1232 <term>
1233 <mallctl>opt.lg_prof_interval</mallctl>
1234 (<type>ssize_t</type>)
1235 <literal>r-</literal>
1236 [<option>--enable-prof</option>]
1237 </term>
1238 <listitem><para>Average interval (log base 2) between memory profile
1239 dumps, as measured in bytes of allocation activity. The actual
1240 interval between dumps may be sporadic because decentralized allocation
1241 counters are used to avoid synchronization bottlenecks. Profiles are
1242 dumped to files named according to the pattern
1243 <filename>&lt;prefix&gt;.&lt;pid&gt;.&lt;seq&gt;.i&lt;iseq&gt;.heap</filename>,
1244 where <literal>&lt;prefix&gt;</literal> is controlled by the
1245 <link
1246 linkend="opt.prof_prefix"><mallctl>opt.prof_prefix</mallctl></link>
1247 option. By default, interval-triggered profile dumping is disabled
1248 (encoded as -1).
1249 </para></listitem>
1250 </varlistentry>
1251
1252 <varlistentry id="opt.prof_gdump">
1253 <term>
1254 <mallctl>opt.prof_gdump</mallctl>
1255 (<type>bool</type>)
1256 <literal>r-</literal>
1257 [<option>--enable-prof</option>]
1258 </term>
Jason Evans5b8ed5b2015-01-25 21:16:57 -08001259 <listitem><para>Set the initial state of <link
1260 linkend="prof.gdump"><mallctl>prof.gdump</mallctl></link>, which when
1261 enabled triggers a memory profile dump every time the total virtual
1262 memory exceeds the previous maximum. This option is disabled by
1263 default.</para></listitem>
Jason Evansaee7fd22010-11-24 22:00:02 -08001264 </varlistentry>
1265
Jason Evans0b25fe72012-04-17 16:39:33 -07001266 <varlistentry id="opt.prof_final">
1267 <term>
1268 <mallctl>opt.prof_final</mallctl>
1269 (<type>bool</type>)
1270 <literal>r-</literal>
1271 [<option>--enable-prof</option>]
1272 </term>
1273 <listitem><para>Use an
1274 <citerefentry><refentrytitle>atexit</refentrytitle>
1275 <manvolnum>3</manvolnum></citerefentry> function to dump final memory
1276 usage to a file named according to the pattern
1277 <filename>&lt;prefix&gt;.&lt;pid&gt;.&lt;seq&gt;.f.heap</filename>,
1278 where <literal>&lt;prefix&gt;</literal> is controlled by the <link
1279 linkend="opt.prof_prefix"><mallctl>opt.prof_prefix</mallctl></link>
Jason Evans57efa7b2014-10-08 17:57:19 -07001280 option. Note that <function>atexit<parameter/></function> may allocate
1281 memory during application initialization and then deadlock internally
1282 when jemalloc in turn calls <function>atexit<parameter/></function>, so
1283 this option is not univerally usable (though the application can
1284 register its own <function>atexit<parameter/></function> function with
1285 equivalent functionality). This option is disabled by
1286 default.</para></listitem>
Jason Evans0b25fe72012-04-17 16:39:33 -07001287 </varlistentry>
1288
Jason Evansaee7fd22010-11-24 22:00:02 -08001289 <varlistentry id="opt.prof_leak">
1290 <term>
1291 <mallctl>opt.prof_leak</mallctl>
1292 (<type>bool</type>)
1293 <literal>r-</literal>
1294 [<option>--enable-prof</option>]
1295 </term>
1296 <listitem><para>Leak reporting enabled/disabled. If enabled, use an
1297 <citerefentry><refentrytitle>atexit</refentrytitle>
1298 <manvolnum>3</manvolnum></citerefentry> function to report memory leaks
1299 detected by allocation sampling. See the
Jason Evansaee7fd22010-11-24 22:00:02 -08001300 <link linkend="opt.prof"><mallctl>opt.prof</mallctl></link> option for
1301 information on analyzing heap profile output. This option is disabled
1302 by default.</para></listitem>
1303 </varlistentry>
1304
Jason Evansaabaf852013-10-30 14:52:09 -07001305 <varlistentry id="thread.arena">
Jason Evansaee7fd22010-11-24 22:00:02 -08001306 <term>
Jason Evansaee7fd22010-11-24 22:00:02 -08001307 <mallctl>thread.arena</mallctl>
1308 (<type>unsigned</type>)
1309 <literal>rw</literal>
1310 </term>
1311 <listitem><para>Get or set the arena associated with the calling
Jason Evans609ae592012-10-11 13:53:15 -07001312 thread. If the specified arena was not initialized beforehand (see the
1313 <link
Jason Evansaee7fd22010-11-24 22:00:02 -08001314 linkend="arenas.initialized"><mallctl>arenas.initialized</mallctl></link>
1315 mallctl), it will be automatically initialized as a side effect of
1316 calling this interface.</para></listitem>
1317 </varlistentry>
1318
Jason Evansecf229a2010-12-03 15:55:47 -08001319 <varlistentry id="thread.allocated">
Jason Evansaee7fd22010-11-24 22:00:02 -08001320 <term>
1321 <mallctl>thread.allocated</mallctl>
1322 (<type>uint64_t</type>)
1323 <literal>r-</literal>
1324 [<option>--enable-stats</option>]
1325 </term>
1326 <listitem><para>Get the total number of bytes ever allocated by the
1327 calling thread. This counter has the potential to wrap around; it is
1328 up to the application to appropriately interpret the counter in such
1329 cases.</para></listitem>
1330 </varlistentry>
1331
Jason Evansaabaf852013-10-30 14:52:09 -07001332 <varlistentry id="thread.allocatedp">
Jason Evansaee7fd22010-11-24 22:00:02 -08001333 <term>
Jason Evansecf229a2010-12-03 15:55:47 -08001334 <mallctl>thread.allocatedp</mallctl>
1335 (<type>uint64_t *</type>)
1336 <literal>r-</literal>
1337 [<option>--enable-stats</option>]
1338 </term>
1339 <listitem><para>Get a pointer to the the value that is returned by the
1340 <link
1341 linkend="thread.allocated"><mallctl>thread.allocated</mallctl></link>
1342 mallctl. This is useful for avoiding the overhead of repeated
1343 <function>mallctl*<parameter/></function> calls.</para></listitem>
1344 </varlistentry>
1345
1346 <varlistentry id="thread.deallocated">
1347 <term>
Jason Evansaee7fd22010-11-24 22:00:02 -08001348 <mallctl>thread.deallocated</mallctl>
1349 (<type>uint64_t</type>)
1350 <literal>r-</literal>
1351 [<option>--enable-stats</option>]
1352 </term>
1353 <listitem><para>Get the total number of bytes ever deallocated by the
1354 calling thread. This counter has the potential to wrap around; it is
1355 up to the application to appropriately interpret the counter in such
1356 cases.</para></listitem>
1357 </varlistentry>
1358
Jason Evansaabaf852013-10-30 14:52:09 -07001359 <varlistentry id="thread.deallocatedp">
Jason Evansecf229a2010-12-03 15:55:47 -08001360 <term>
1361 <mallctl>thread.deallocatedp</mallctl>
1362 (<type>uint64_t *</type>)
1363 <literal>r-</literal>
1364 [<option>--enable-stats</option>]
1365 </term>
1366 <listitem><para>Get a pointer to the the value that is returned by the
1367 <link
1368 linkend="thread.deallocated"><mallctl>thread.deallocated</mallctl></link>
1369 mallctl. This is useful for avoiding the overhead of repeated
1370 <function>mallctl*<parameter/></function> calls.</para></listitem>
1371 </varlistentry>
1372
Jason Evansaabaf852013-10-30 14:52:09 -07001373 <varlistentry id="thread.tcache.enabled">
Jason Evanse7b8fa12012-03-16 17:09:32 -07001374 <term>
Jason Evansd4be8b72012-03-26 18:54:44 -07001375 <mallctl>thread.tcache.enabled</mallctl>
1376 (<type>bool</type>)
1377 <literal>rw</literal>
1378 [<option>--enable-tcache</option>]
1379 </term>
1380 <listitem><para>Enable/disable calling thread's tcache. The tcache is
1381 implicitly flushed as a side effect of becoming
1382 disabled (see <link
Jason Evans1cb181e2015-01-29 15:30:47 -08001383 linkend="thread.tcache.flush"><mallctl>thread.tcache.flush</mallctl></link>).
Jason Evansd4be8b72012-03-26 18:54:44 -07001384 </para></listitem>
1385 </varlistentry>
1386
Jason Evansaabaf852013-10-30 14:52:09 -07001387 <varlistentry id="thread.tcache.flush">
Jason Evansd4be8b72012-03-26 18:54:44 -07001388 <term>
Jason Evanse7b8fa12012-03-16 17:09:32 -07001389 <mallctl>thread.tcache.flush</mallctl>
1390 (<type>void</type>)
1391 <literal>--</literal>
1392 [<option>--enable-tcache</option>]
1393 </term>
Jason Evans1cb181e2015-01-29 15:30:47 -08001394 <listitem><para>Flush calling thread's thread-specific cache (tcache).
1395 This interface releases all cached objects and internal data structures
1396 associated with the calling thread's tcache. Ordinarily, this interface
Jason Evanse7b8fa12012-03-16 17:09:32 -07001397 need not be called, since automatic periodic incremental garbage
1398 collection occurs, and the thread cache is automatically discarded when
1399 a thread exits. However, garbage collection is triggered by allocation
1400 activity, so it is possible for a thread that stops
1401 allocating/deallocating to retain its cache indefinitely, in which case
1402 the developer may find manual flushing useful.</para></listitem>
1403 </varlistentry>
1404
Jason Evans602c8e02014-08-18 16:22:13 -07001405 <varlistentry id="thread.prof.name">
1406 <term>
1407 <mallctl>thread.prof.name</mallctl>
1408 (<type>const char *</type>)
Jason Evansfc12c0b2014-10-03 23:25:30 -07001409 <literal>r-</literal> or
1410 <literal>-w</literal>
Jason Evans602c8e02014-08-18 16:22:13 -07001411 [<option>--enable-prof</option>]
1412 </term>
1413 <listitem><para>Get/set the descriptive name associated with the calling
1414 thread in memory profile dumps. An internal copy of the name string is
1415 created, so the input string need not be maintained after this interface
1416 completes execution. The output string of this interface should be
1417 copied for non-ephemeral uses, because multiple implementation details
Jason Evansfc12c0b2014-10-03 23:25:30 -07001418 can cause asynchronous string deallocation. Furthermore, each
1419 invocation of this interface can only read or write; simultaneous
1420 read/write is not supported due to string lifetime limitations. The
Jason Evansea7449f2015-10-19 16:56:05 -04001421 name string must be nil-terminated and comprised only of characters in
1422 the sets recognized
Jason Evansfc12c0b2014-10-03 23:25:30 -07001423 by <citerefentry><refentrytitle>isgraph</refentrytitle>
1424 <manvolnum>3</manvolnum></citerefentry> and
1425 <citerefentry><refentrytitle>isblank</refentrytitle>
1426 <manvolnum>3</manvolnum></citerefentry>.</para></listitem>
Jason Evans602c8e02014-08-18 16:22:13 -07001427 </varlistentry>
1428
1429 <varlistentry id="thread.prof.active">
1430 <term>
1431 <mallctl>thread.prof.active</mallctl>
1432 (<type>bool</type>)
1433 <literal>rw</literal>
1434 [<option>--enable-prof</option>]
1435 </term>
1436 <listitem><para>Control whether sampling is currently active for the
Jason Evansfc12c0b2014-10-03 23:25:30 -07001437 calling thread. This is an activation mechanism in addition to <link
Jason Evans602c8e02014-08-18 16:22:13 -07001438 linkend="prof.active"><mallctl>prof.active</mallctl></link>; both must
1439 be active for the calling thread to sample. This flag is enabled by
1440 default.</para></listitem>
1441 </varlistentry>
1442
Jason Evans1cb181e2015-01-29 15:30:47 -08001443 <varlistentry id="tcache.create">
1444 <term>
1445 <mallctl>tcache.create</mallctl>
1446 (<type>unsigned</type>)
1447 <literal>r-</literal>
1448 [<option>--enable-tcache</option>]
1449 </term>
1450 <listitem><para>Create an explicit thread-specific cache (tcache) and
1451 return an identifier that can be passed to the <link
1452 linkend="MALLOCX_TCACHE"><constant>MALLOCX_TCACHE(<parameter>tc</parameter>)</constant></link>
1453 macro to explicitly use the specified cache rather than the
1454 automatically managed one that is used by default. Each explicit cache
1455 can be used by only one thread at a time; the application must assure
1456 that this constraint holds.
1457 </para></listitem>
1458 </varlistentry>
1459
1460 <varlistentry id="tcache.flush">
1461 <term>
1462 <mallctl>tcache.flush</mallctl>
1463 (<type>unsigned</type>)
1464 <literal>-w</literal>
1465 [<option>--enable-tcache</option>]
1466 </term>
1467 <listitem><para>Flush the specified thread-specific cache (tcache). The
1468 same considerations apply to this interface as to <link
1469 linkend="thread.tcache.flush"><mallctl>thread.tcache.flush</mallctl></link>,
Jason Evans109712b2016-02-19 12:08:14 -08001470 except that the tcache will never be automatically discarded.
Jason Evans1cb181e2015-01-29 15:30:47 -08001471 </para></listitem>
1472 </varlistentry>
1473
1474 <varlistentry id="tcache.destroy">
1475 <term>
1476 <mallctl>tcache.destroy</mallctl>
1477 (<type>unsigned</type>)
1478 <literal>-w</literal>
1479 [<option>--enable-tcache</option>]
1480 </term>
1481 <listitem><para>Flush the specified thread-specific cache (tcache) and
1482 make the identifier available for use during a future tcache creation.
1483 </para></listitem>
1484 </varlistentry>
1485
Jason Evans609ae592012-10-11 13:53:15 -07001486 <varlistentry id="arena.i.purge">
1487 <term>
1488 <mallctl>arena.&lt;i&gt;.purge</mallctl>
Jason Evansa2c719b2014-04-15 12:46:28 -07001489 (<type>void</type>)
Jason Evans609ae592012-10-11 13:53:15 -07001490 <literal>--</literal>
1491 </term>
1492 <listitem><para>Purge unused dirty pages for arena &lt;i&gt;, or for
1493 all arenas if &lt;i&gt; equals <link
1494 linkend="arenas.narenas"><mallctl>arenas.narenas</mallctl></link>.
1495 </para></listitem>
1496 </varlistentry>
1497
1498 <varlistentry id="arena.i.dss">
1499 <term>
1500 <mallctl>arena.&lt;i&gt;.dss</mallctl>
1501 (<type>const char *</type>)
1502 <literal>rw</literal>
1503 </term>
1504 <listitem><para>Set the precedence of dss allocation as related to mmap
1505 allocation for arena &lt;i&gt;, or for all arenas if &lt;i&gt; equals
1506 <link
Jason Evanse2deab72014-05-15 22:22:27 -07001507 linkend="arenas.narenas"><mallctl>arenas.narenas</mallctl></link>. See
1508 <link linkend="opt.dss"><mallctl>opt.dss</mallctl></link> for supported
1509 settings.</para></listitem>
Jason Evans609ae592012-10-11 13:53:15 -07001510 </varlistentry>
1511
Jason Evans8d6a3e82015-03-18 18:55:33 -07001512 <varlistentry id="arena.i.lg_dirty_mult">
1513 <term>
1514 <mallctl>arena.&lt;i&gt;.lg_dirty_mult</mallctl>
1515 (<type>ssize_t</type>)
1516 <literal>rw</literal>
1517 </term>
1518 <listitem><para>Current per-arena minimum ratio (log base 2) of active
1519 to dirty pages for arena &lt;i&gt;. Each time this interface is set and
1520 the ratio is increased, pages are synchronously purged as necessary to
1521 impose the new ratio. See <link
1522 linkend="opt.lg_dirty_mult"><mallctl>opt.lg_dirty_mult</mallctl></link>
1523 for additional information.</para></listitem>
1524 </varlistentry>
1525
Jason Evansb49a3342015-07-28 11:28:19 -04001526 <varlistentry id="arena.i.chunk_hooks">
aravindfb7fe502014-05-05 15:16:56 -07001527 <term>
Jason Evansb49a3342015-07-28 11:28:19 -04001528 <mallctl>arena.&lt;i&gt;.chunk_hooks</mallctl>
1529 (<type>chunk_hooks_t</type>)
aravindfb7fe502014-05-05 15:16:56 -07001530 <literal>rw</literal>
1531 </term>
Jason Evansb49a3342015-07-28 11:28:19 -04001532 <listitem><para>Get or set the chunk management hook functions for arena
1533 &lt;i&gt;. The functions must be capable of operating on all extant
1534 chunks associated with arena &lt;i&gt;, usually by passing unknown
1535 chunks to the replaced functions. In practice, it is feasible to
1536 control allocation for arenas created via <link
1537 linkend="arenas.extend"><mallctl>arenas.extend</mallctl></link> such
1538 that all chunks originate from an application-supplied chunk allocator
1539 (by setting custom chunk hook functions just after arena creation), but
1540 the automatically created arenas may have already created chunks prior
1541 to the application having an opportunity to take over chunk
1542 allocation.</para>
1543
Jason Evans92e96e32015-08-14 13:46:08 -07001544 <programlisting language="C"><![CDATA[
Jason Evansb49a3342015-07-28 11:28:19 -04001545typedef struct {
1546 chunk_alloc_t *alloc;
1547 chunk_dalloc_t *dalloc;
1548 chunk_commit_t *commit;
1549 chunk_decommit_t *decommit;
1550 chunk_purge_t *purge;
1551 chunk_split_t *split;
1552 chunk_merge_t *merge;
1553} chunk_hooks_t;]]></programlisting>
Jason Evans92e96e32015-08-14 13:46:08 -07001554 <para>The <type>chunk_hooks_t</type> structure comprises function
1555 pointers which are described individually below. jemalloc uses these
Jason Evansb49a3342015-07-28 11:28:19 -04001556 functions to manage chunk lifetime, which starts off with allocation of
1557 mapped committed memory, in the simplest case followed by deallocation.
1558 However, there are performance and platform reasons to retain chunks for
1559 later reuse. Cleanup attempts cascade from deallocation to decommit to
1560 purging, which gives the chunk management functions opportunities to
1561 reject the most permanent cleanup operations in favor of less permanent
1562 (and often less costly) operations. The chunk splitting and merging
1563 operations can also be opted out of, but this is mainly intended to
1564 support platforms on which virtual memory mappings provided by the
Jason Evans38f86492015-08-14 00:55:44 -07001565 operating system kernel do not automatically coalesce and split, e.g.
1566 Windows.</para>
Jason Evansb49a3342015-07-28 11:28:19 -04001567
Jason Evans92e96e32015-08-14 13:46:08 -07001568 <funcsynopsis><funcprototype>
aravindfb7fe502014-05-05 15:16:56 -07001569 <funcdef>typedef void *<function>(chunk_alloc_t)</function></funcdef>
Daniel Micaya95018e2014-10-04 01:39:32 -04001570 <paramdef>void *<parameter>chunk</parameter></paramdef>
aravindfb7fe502014-05-05 15:16:56 -07001571 <paramdef>size_t <parameter>size</parameter></paramdef>
1572 <paramdef>size_t <parameter>alignment</parameter></paramdef>
1573 <paramdef>bool *<parameter>zero</parameter></paramdef>
Jason Evans8fadb1a2015-08-04 10:49:46 -07001574 <paramdef>bool *<parameter>commit</parameter></paramdef>
aravindfb7fe502014-05-05 15:16:56 -07001575 <paramdef>unsigned <parameter>arena_ind</parameter></paramdef>
Jason Evans3c3b3b12014-10-05 14:48:44 -07001576 </funcprototype></funcsynopsis>
Jason Evans92e96e32015-08-14 13:46:08 -07001577 <literallayout></literallayout>
1578 <para>A chunk allocation function conforms to the
1579 <type>chunk_alloc_t</type> type and upon success returns a pointer to
1580 <parameter>size</parameter> bytes of mapped memory on behalf of arena
Jason Evansb49a3342015-07-28 11:28:19 -04001581 <parameter>arena_ind</parameter> such that the chunk's base address is a
1582 multiple of <parameter>alignment</parameter>, as well as setting
Jason Evans8fadb1a2015-08-04 10:49:46 -07001583 <parameter>*zero</parameter> to indicate whether the chunk is zeroed and
1584 <parameter>*commit</parameter> to indicate whether the chunk is
1585 committed. Upon error the function returns <constant>NULL</constant>
1586 and leaves <parameter>*zero</parameter> and
1587 <parameter>*commit</parameter> unmodified. The
aravindfb7fe502014-05-05 15:16:56 -07001588 <parameter>size</parameter> parameter is always a multiple of the chunk
1589 size. The <parameter>alignment</parameter> parameter is always a power
1590 of two at least as large as the chunk size. Zeroing is mandatory if
Jason Evans8fadb1a2015-08-04 10:49:46 -07001591 <parameter>*zero</parameter> is true upon function entry. Committing is
1592 mandatory if <parameter>*commit</parameter> is true upon function entry.
1593 If <parameter>chunk</parameter> is not <constant>NULL</constant>, the
Jason Evansb49a3342015-07-28 11:28:19 -04001594 returned pointer must be <parameter>chunk</parameter> on success or
1595 <constant>NULL</constant> on error. Committed memory may be committed
1596 in absolute terms as on a system that does not overcommit, or in
1597 implicit terms as on a system that overcommits and satisfies physical
1598 memory needs on demand via soft page faults. Note that replacing the
1599 default chunk allocation function makes the arena's <link
Jason Evanse2deab72014-05-15 22:22:27 -07001600 linkend="arena.i.dss"><mallctl>arena.&lt;i&gt;.dss</mallctl></link>
Jason Evansb49a3342015-07-28 11:28:19 -04001601 setting irrelevant.</para>
aravindfb7fe502014-05-05 15:16:56 -07001602
Jason Evans92e96e32015-08-14 13:46:08 -07001603 <funcsynopsis><funcprototype>
Jason Evans8d6a3e82015-03-18 18:55:33 -07001604 <funcdef>typedef bool <function>(chunk_dalloc_t)</function></funcdef>
aravindfb7fe502014-05-05 15:16:56 -07001605 <paramdef>void *<parameter>chunk</parameter></paramdef>
1606 <paramdef>size_t <parameter>size</parameter></paramdef>
Jason Evans8fadb1a2015-08-04 10:49:46 -07001607 <paramdef>bool <parameter>committed</parameter></paramdef>
aravindfb7fe502014-05-05 15:16:56 -07001608 <paramdef>unsigned <parameter>arena_ind</parameter></paramdef>
Jason Evans3c3b3b12014-10-05 14:48:44 -07001609 </funcprototype></funcsynopsis>
Jason Evans92e96e32015-08-14 13:46:08 -07001610 <literallayout></literallayout>
1611 <para>
aravindfb7fe502014-05-05 15:16:56 -07001612 A chunk deallocation function conforms to the
Jason Evanse2deab72014-05-15 22:22:27 -07001613 <type>chunk_dalloc_t</type> type and deallocates a
Jason Evans8fadb1a2015-08-04 10:49:46 -07001614 <parameter>chunk</parameter> of given <parameter>size</parameter> with
1615 <parameter>committed</parameter>/decommited memory as indicated, on
Jason Evans8d6a3e82015-03-18 18:55:33 -07001616 behalf of arena <parameter>arena_ind</parameter>, returning false upon
Jason Evansb49a3342015-07-28 11:28:19 -04001617 success. If the function returns true, this indicates opt-out from
1618 deallocation; the virtual memory mapping associated with the chunk
Jason Evans8fadb1a2015-08-04 10:49:46 -07001619 remains mapped, in the same commit state, and available for future use,
1620 in which case it will be automatically retained for later reuse.</para>
Jason Evans8d6a3e82015-03-18 18:55:33 -07001621
Jason Evans92e96e32015-08-14 13:46:08 -07001622 <funcsynopsis><funcprototype>
Jason Evansb49a3342015-07-28 11:28:19 -04001623 <funcdef>typedef bool <function>(chunk_commit_t)</function></funcdef>
1624 <paramdef>void *<parameter>chunk</parameter></paramdef>
1625 <paramdef>size_t <parameter>size</parameter></paramdef>
Jason Evans8fadb1a2015-08-04 10:49:46 -07001626 <paramdef>size_t <parameter>offset</parameter></paramdef>
1627 <paramdef>size_t <parameter>length</parameter></paramdef>
Jason Evansb49a3342015-07-28 11:28:19 -04001628 <paramdef>unsigned <parameter>arena_ind</parameter></paramdef>
1629 </funcprototype></funcsynopsis>
Jason Evans92e96e32015-08-14 13:46:08 -07001630 <literallayout></literallayout>
1631 <para>A chunk commit function conforms to the
1632 <type>chunk_commit_t</type> type and commits zeroed physical memory to
1633 back pages within a <parameter>chunk</parameter> of given
1634 <parameter>size</parameter> at <parameter>offset</parameter> bytes,
1635 extending for <parameter>length</parameter> on behalf of arena
Jason Evans8fadb1a2015-08-04 10:49:46 -07001636 <parameter>arena_ind</parameter>, returning false upon success.
1637 Committed memory may be committed in absolute terms as on a system that
1638 does not overcommit, or in implicit terms as on a system that
1639 overcommits and satisfies physical memory needs on demand via soft page
1640 faults. If the function returns true, this indicates insufficient
Jason Evansb49a3342015-07-28 11:28:19 -04001641 physical memory to satisfy the request.</para>
1642
Jason Evans92e96e32015-08-14 13:46:08 -07001643 <funcsynopsis><funcprototype>
Jason Evansb49a3342015-07-28 11:28:19 -04001644 <funcdef>typedef bool <function>(chunk_decommit_t)</function></funcdef>
1645 <paramdef>void *<parameter>chunk</parameter></paramdef>
1646 <paramdef>size_t <parameter>size</parameter></paramdef>
Jason Evans8fadb1a2015-08-04 10:49:46 -07001647 <paramdef>size_t <parameter>offset</parameter></paramdef>
1648 <paramdef>size_t <parameter>length</parameter></paramdef>
Jason Evansb49a3342015-07-28 11:28:19 -04001649 <paramdef>unsigned <parameter>arena_ind</parameter></paramdef>
1650 </funcprototype></funcsynopsis>
Jason Evans92e96e32015-08-14 13:46:08 -07001651 <literallayout></literallayout>
1652 <para>A chunk decommit function conforms to the
1653 <type>chunk_decommit_t</type> type and decommits any physical memory
1654 that is backing pages within a <parameter>chunk</parameter> of given
1655 <parameter>size</parameter> at <parameter>offset</parameter> bytes,
1656 extending for <parameter>length</parameter> on behalf of arena
Jason Evans8fadb1a2015-08-04 10:49:46 -07001657 <parameter>arena_ind</parameter>, returning false upon success, in which
1658 case the pages will be committed via the chunk commit function before
1659 being reused. If the function returns true, this indicates opt-out from
1660 decommit; the memory remains committed and available for future use, in
1661 which case it will be automatically retained for later reuse.</para>
Jason Evansb49a3342015-07-28 11:28:19 -04001662
Jason Evans92e96e32015-08-14 13:46:08 -07001663 <funcsynopsis><funcprototype>
Jason Evans8d6a3e82015-03-18 18:55:33 -07001664 <funcdef>typedef bool <function>(chunk_purge_t)</function></funcdef>
1665 <paramdef>void *<parameter>chunk</parameter></paramdef>
Jason Evansb49a3342015-07-28 11:28:19 -04001666 <paramdef>size_t<parameter>size</parameter></paramdef>
Jason Evans8d6a3e82015-03-18 18:55:33 -07001667 <paramdef>size_t <parameter>offset</parameter></paramdef>
1668 <paramdef>size_t <parameter>length</parameter></paramdef>
1669 <paramdef>unsigned <parameter>arena_ind</parameter></paramdef>
1670 </funcprototype></funcsynopsis>
Jason Evans92e96e32015-08-14 13:46:08 -07001671 <literallayout></literallayout>
1672 <para>A chunk purge function conforms to the <type>chunk_purge_t</type>
1673 type and optionally discards physical pages within the virtual memory
1674 mapping associated with <parameter>chunk</parameter> of given
Jason Evansb49a3342015-07-28 11:28:19 -04001675 <parameter>size</parameter> at <parameter>offset</parameter> bytes,
1676 extending for <parameter>length</parameter> on behalf of arena
Jason Evans8d6a3e82015-03-18 18:55:33 -07001677 <parameter>arena_ind</parameter>, returning false if pages within the
1678 purged virtual memory range will be zero-filled the next time they are
Jason Evansb49a3342015-07-28 11:28:19 -04001679 accessed.</para>
1680
Jason Evans92e96e32015-08-14 13:46:08 -07001681 <funcsynopsis><funcprototype>
Jason Evansb49a3342015-07-28 11:28:19 -04001682 <funcdef>typedef bool <function>(chunk_split_t)</function></funcdef>
1683 <paramdef>void *<parameter>chunk</parameter></paramdef>
1684 <paramdef>size_t <parameter>size</parameter></paramdef>
1685 <paramdef>size_t <parameter>size_a</parameter></paramdef>
1686 <paramdef>size_t <parameter>size_b</parameter></paramdef>
1687 <paramdef>bool <parameter>committed</parameter></paramdef>
1688 <paramdef>unsigned <parameter>arena_ind</parameter></paramdef>
1689 </funcprototype></funcsynopsis>
Jason Evans92e96e32015-08-14 13:46:08 -07001690 <literallayout></literallayout>
1691 <para>A chunk split function conforms to the <type>chunk_split_t</type>
1692 type and optionally splits <parameter>chunk</parameter> of given
Jason Evansb49a3342015-07-28 11:28:19 -04001693 <parameter>size</parameter> into two adjacent chunks, the first of
1694 <parameter>size_a</parameter> bytes, and the second of
1695 <parameter>size_b</parameter> bytes, operating on
1696 <parameter>committed</parameter>/decommitted memory as indicated, on
1697 behalf of arena <parameter>arena_ind</parameter>, returning false upon
1698 success. If the function returns true, this indicates that the chunk
1699 remains unsplit and therefore should continue to be operated on as a
1700 whole.</para>
1701
Jason Evans92e96e32015-08-14 13:46:08 -07001702 <funcsynopsis><funcprototype>
Jason Evansb49a3342015-07-28 11:28:19 -04001703 <funcdef>typedef bool <function>(chunk_merge_t)</function></funcdef>
1704 <paramdef>void *<parameter>chunk_a</parameter></paramdef>
1705 <paramdef>size_t <parameter>size_a</parameter></paramdef>
1706 <paramdef>void *<parameter>chunk_b</parameter></paramdef>
1707 <paramdef>size_t <parameter>size_b</parameter></paramdef>
1708 <paramdef>bool <parameter>committed</parameter></paramdef>
1709 <paramdef>unsigned <parameter>arena_ind</parameter></paramdef>
1710 </funcprototype></funcsynopsis>
Jason Evans92e96e32015-08-14 13:46:08 -07001711 <literallayout></literallayout>
1712 <para>A chunk merge function conforms to the <type>chunk_merge_t</type>
1713 type and optionally merges adjacent chunks,
1714 <parameter>chunk_a</parameter> of given <parameter>size_a</parameter>
1715 and <parameter>chunk_b</parameter> of given
1716 <parameter>size_b</parameter> into one contiguous chunk, operating on
1717 <parameter>committed</parameter>/decommitted memory as indicated, on
1718 behalf of arena <parameter>arena_ind</parameter>, returning false upon
1719 success. If the function returns true, this indicates that the chunks
1720 remain distinct mappings and therefore should continue to be operated on
1721 independently.</para>
Jason Evansb49a3342015-07-28 11:28:19 -04001722 </listitem>
aravindfb7fe502014-05-05 15:16:56 -07001723 </varlistentry>
1724
Jason Evansaee7fd22010-11-24 22:00:02 -08001725 <varlistentry id="arenas.narenas">
1726 <term>
1727 <mallctl>arenas.narenas</mallctl>
1728 (<type>unsigned</type>)
1729 <literal>r-</literal>
1730 </term>
Jason Evans609ae592012-10-11 13:53:15 -07001731 <listitem><para>Current limit on number of arenas.</para></listitem>
Jason Evansaee7fd22010-11-24 22:00:02 -08001732 </varlistentry>
1733
1734 <varlistentry id="arenas.initialized">
1735 <term>
1736 <mallctl>arenas.initialized</mallctl>
1737 (<type>bool *</type>)
1738 <literal>r-</literal>
1739 </term>
1740 <listitem><para>An array of <link
1741 linkend="arenas.narenas"><mallctl>arenas.narenas</mallctl></link>
1742 booleans. Each boolean indicates whether the corresponding arena is
1743 initialized.</para></listitem>
1744 </varlistentry>
1745
Jason Evans8d6a3e82015-03-18 18:55:33 -07001746 <varlistentry id="arenas.lg_dirty_mult">
1747 <term>
1748 <mallctl>arenas.lg_dirty_mult</mallctl>
1749 (<type>ssize_t</type>)
1750 <literal>rw</literal>
1751 </term>
1752 <listitem><para>Current default per-arena minimum ratio (log base 2) of
1753 active to dirty pages, used to initialize <link
1754 linkend="arena.i.lg_dirty_mult"><mallctl>arena.&lt;i&gt;.lg_dirty_mult</mallctl></link>
1755 during arena creation. See <link
1756 linkend="opt.lg_dirty_mult"><mallctl>opt.lg_dirty_mult</mallctl></link>
1757 for additional information.</para></listitem>
1758 </varlistentry>
1759
Jason Evansaabaf852013-10-30 14:52:09 -07001760 <varlistentry id="arenas.quantum">
Jason Evansaee7fd22010-11-24 22:00:02 -08001761 <term>
1762 <mallctl>arenas.quantum</mallctl>
1763 (<type>size_t</type>)
1764 <literal>r-</literal>
1765 </term>
1766 <listitem><para>Quantum size.</para></listitem>
1767 </varlistentry>
1768
Jason Evansaabaf852013-10-30 14:52:09 -07001769 <varlistentry id="arenas.page">
Jason Evansaee7fd22010-11-24 22:00:02 -08001770 <term>
Jason Evansae4c7b42012-04-02 07:04:34 -07001771 <mallctl>arenas.page</mallctl>
Jason Evansaee7fd22010-11-24 22:00:02 -08001772 (<type>size_t</type>)
1773 <literal>r-</literal>
1774 </term>
1775 <listitem><para>Page size.</para></listitem>
1776 </varlistentry>
1777
Jason Evansaabaf852013-10-30 14:52:09 -07001778 <varlistentry id="arenas.tcache_max">
Jason Evansaee7fd22010-11-24 22:00:02 -08001779 <term>
Jason Evansaee7fd22010-11-24 22:00:02 -08001780 <mallctl>arenas.tcache_max</mallctl>
1781 (<type>size_t</type>)
1782 <literal>r-</literal>
1783 [<option>--enable-tcache</option>]
1784 </term>
1785 <listitem><para>Maximum thread-cached size class.</para></listitem>
1786 </varlistentry>
1787
Jason Evansaabaf852013-10-30 14:52:09 -07001788 <varlistentry id="arenas.nbins">
Jason Evansaee7fd22010-11-24 22:00:02 -08001789 <term>
Jason Evansaee7fd22010-11-24 22:00:02 -08001790 <mallctl>arenas.nbins</mallctl>
1791 (<type>unsigned</type>)
1792 <literal>r-</literal>
1793 </term>
Jason Evansb1726102012-02-28 16:50:47 -08001794 <listitem><para>Number of bin size classes.</para></listitem>
Jason Evansaee7fd22010-11-24 22:00:02 -08001795 </varlistentry>
1796
Jason Evansaabaf852013-10-30 14:52:09 -07001797 <varlistentry id="arenas.nhbins">
Jason Evansaee7fd22010-11-24 22:00:02 -08001798 <term>
1799 <mallctl>arenas.nhbins</mallctl>
1800 (<type>unsigned</type>)
1801 <literal>r-</literal>
1802 [<option>--enable-tcache</option>]
1803 </term>
1804 <listitem><para>Total number of thread cache bin size
1805 classes.</para></listitem>
1806 </varlistentry>
1807
1808 <varlistentry id="arenas.bin.i.size">
1809 <term>
1810 <mallctl>arenas.bin.&lt;i&gt;.size</mallctl>
1811 (<type>size_t</type>)
1812 <literal>r-</literal>
1813 </term>
1814 <listitem><para>Maximum size supported by size class.</para></listitem>
1815 </varlistentry>
1816
Jason Evansaabaf852013-10-30 14:52:09 -07001817 <varlistentry id="arenas.bin.i.nregs">
Jason Evansaee7fd22010-11-24 22:00:02 -08001818 <term>
1819 <mallctl>arenas.bin.&lt;i&gt;.nregs</mallctl>
1820 (<type>uint32_t</type>)
1821 <literal>r-</literal>
1822 </term>
1823 <listitem><para>Number of regions per page run.</para></listitem>
1824 </varlistentry>
1825
Jason Evansaabaf852013-10-30 14:52:09 -07001826 <varlistentry id="arenas.bin.i.run_size">
Jason Evansaee7fd22010-11-24 22:00:02 -08001827 <term>
1828 <mallctl>arenas.bin.&lt;i&gt;.run_size</mallctl>
1829 (<type>size_t</type>)
1830 <literal>r-</literal>
1831 </term>
1832 <listitem><para>Number of bytes per page run.</para></listitem>
1833 </varlistentry>
1834
Jason Evansaabaf852013-10-30 14:52:09 -07001835 <varlistentry id="arenas.nlruns">
Jason Evansaee7fd22010-11-24 22:00:02 -08001836 <term>
1837 <mallctl>arenas.nlruns</mallctl>
Jason Evans3c4d92e2014-10-12 22:53:59 -07001838 (<type>unsigned</type>)
Jason Evansaee7fd22010-11-24 22:00:02 -08001839 <literal>r-</literal>
1840 </term>
1841 <listitem><para>Total number of large size classes.</para></listitem>
1842 </varlistentry>
1843
Jason Evansaabaf852013-10-30 14:52:09 -07001844 <varlistentry id="arenas.lrun.i.size">
Jason Evansaee7fd22010-11-24 22:00:02 -08001845 <term>
1846 <mallctl>arenas.lrun.&lt;i&gt;.size</mallctl>
1847 (<type>size_t</type>)
1848 <literal>r-</literal>
1849 </term>
1850 <listitem><para>Maximum size supported by this large size
1851 class.</para></listitem>
1852 </varlistentry>
1853
Jason Evans3c4d92e2014-10-12 22:53:59 -07001854 <varlistentry id="arenas.nhchunks">
1855 <term>
1856 <mallctl>arenas.nhchunks</mallctl>
1857 (<type>unsigned</type>)
1858 <literal>r-</literal>
1859 </term>
1860 <listitem><para>Total number of huge size classes.</para></listitem>
1861 </varlistentry>
1862
Qinfan Wu89750352015-04-21 16:57:42 -07001863 <varlistentry id="arenas.hchunk.i.size">
Jason Evans3c4d92e2014-10-12 22:53:59 -07001864 <term>
Qinfan Wu89750352015-04-21 16:57:42 -07001865 <mallctl>arenas.hchunk.&lt;i&gt;.size</mallctl>
Jason Evans3c4d92e2014-10-12 22:53:59 -07001866 (<type>size_t</type>)
1867 <literal>r-</literal>
1868 </term>
1869 <listitem><para>Maximum size supported by this huge size
1870 class.</para></listitem>
1871 </varlistentry>
1872
Jason Evansaabaf852013-10-30 14:52:09 -07001873 <varlistentry id="arenas.extend">
Jason Evans609ae592012-10-11 13:53:15 -07001874 <term>
1875 <mallctl>arenas.extend</mallctl>
1876 (<type>unsigned</type>)
1877 <literal>r-</literal>
1878 </term>
1879 <listitem><para>Extend the array of arenas by appending a new arena,
1880 and returning the new arena index.</para></listitem>
1881 </varlistentry>
1882
Jason Evansfc12c0b2014-10-03 23:25:30 -07001883 <varlistentry id="prof.thread_active_init">
1884 <term>
1885 <mallctl>prof.thread_active_init</mallctl>
1886 (<type>bool</type>)
1887 <literal>rw</literal>
1888 [<option>--enable-prof</option>]
1889 </term>
1890 <listitem><para>Control the initial setting for <link
1891 linkend="thread.prof.active"><mallctl>thread.prof.active</mallctl></link>
1892 in newly created threads. See the <link
1893 linkend="opt.prof_thread_active_init"><mallctl>opt.prof_thread_active_init</mallctl></link>
1894 option for additional information.</para></listitem>
1895 </varlistentry>
1896
Jason Evansaee7fd22010-11-24 22:00:02 -08001897 <varlistentry id="prof.active">
1898 <term>
1899 <mallctl>prof.active</mallctl>
1900 (<type>bool</type>)
1901 <literal>rw</literal>
1902 [<option>--enable-prof</option>]
1903 </term>
1904 <listitem><para>Control whether sampling is currently active. See the
1905 <link
1906 linkend="opt.prof_active"><mallctl>opt.prof_active</mallctl></link>
Jason Evansfc12c0b2014-10-03 23:25:30 -07001907 option for additional information, as well as the interrelated <link
1908 linkend="thread.prof.active"><mallctl>thread.prof.active</mallctl></link>
1909 mallctl.</para></listitem>
Jason Evansaee7fd22010-11-24 22:00:02 -08001910 </varlistentry>
1911
Jason Evansaabaf852013-10-30 14:52:09 -07001912 <varlistentry id="prof.dump">
Jason Evansaee7fd22010-11-24 22:00:02 -08001913 <term>
1914 <mallctl>prof.dump</mallctl>
1915 (<type>const char *</type>)
1916 <literal>-w</literal>
1917 [<option>--enable-prof</option>]
1918 </term>
1919 <listitem><para>Dump a memory profile to the specified file, or if NULL
1920 is specified, to a file according to the pattern
1921 <filename>&lt;prefix&gt;.&lt;pid&gt;.&lt;seq&gt;.m&lt;mseq&gt;.heap</filename>,
1922 where <literal>&lt;prefix&gt;</literal> is controlled by the
1923 <link
1924 linkend="opt.prof_prefix"><mallctl>opt.prof_prefix</mallctl></link>
1925 option.</para></listitem>
1926 </varlistentry>
1927
Jason Evans5b8ed5b2015-01-25 21:16:57 -08001928 <varlistentry id="prof.gdump">
1929 <term>
1930 <mallctl>prof.gdump</mallctl>
1931 (<type>bool</type>)
1932 <literal>rw</literal>
1933 [<option>--enable-prof</option>]
1934 </term>
1935 <listitem><para>When enabled, trigger a memory profile dump every time
1936 the total virtual memory exceeds the previous maximum. Profiles are
1937 dumped to files named according to the pattern
1938 <filename>&lt;prefix&gt;.&lt;pid&gt;.&lt;seq&gt;.u&lt;useq&gt;.heap</filename>,
1939 where <literal>&lt;prefix&gt;</literal> is controlled by the <link
1940 linkend="opt.prof_prefix"><mallctl>opt.prof_prefix</mallctl></link>
1941 option.</para></listitem>
1942 </varlistentry>
1943
Jason Evans602c8e02014-08-18 16:22:13 -07001944 <varlistentry id="prof.reset">
1945 <term>
1946 <mallctl>prof.reset</mallctl>
1947 (<type>size_t</type>)
1948 <literal>-w</literal>
1949 [<option>--enable-prof</option>]
1950 </term>
1951 <listitem><para>Reset all memory profile statistics, and optionally
1952 update the sample rate (see <link
Jason Evans20c31de2014-10-02 23:01:10 -07001953 linkend="opt.lg_prof_sample"><mallctl>opt.lg_prof_sample</mallctl></link>
Jason Evansfc12c0b2014-10-03 23:25:30 -07001954 and <link
1955 linkend="prof.lg_sample"><mallctl>prof.lg_sample</mallctl></link>).
Jason Evans602c8e02014-08-18 16:22:13 -07001956 </para></listitem>
1957 </varlistentry>
1958
1959 <varlistentry id="prof.lg_sample">
1960 <term>
1961 <mallctl>prof.lg_sample</mallctl>
1962 (<type>size_t</type>)
1963 <literal>r-</literal>
1964 [<option>--enable-prof</option>]
1965 </term>
Jason Evans20c31de2014-10-02 23:01:10 -07001966 <listitem><para>Get the current sample rate (see <link
Jason Evans602c8e02014-08-18 16:22:13 -07001967 linkend="opt.lg_prof_sample"><mallctl>opt.lg_prof_sample</mallctl></link>).
1968 </para></listitem>
1969 </varlistentry>
1970
Jason Evansaabaf852013-10-30 14:52:09 -07001971 <varlistentry id="prof.interval">
Jason Evansaee7fd22010-11-24 22:00:02 -08001972 <term>
1973 <mallctl>prof.interval</mallctl>
1974 (<type>uint64_t</type>)
1975 <literal>r-</literal>
1976 [<option>--enable-prof</option>]
1977 </term>
1978 <listitem><para>Average number of bytes allocated between
1979 inverval-based profile dumps. See the
1980 <link
1981 linkend="opt.lg_prof_interval"><mallctl>opt.lg_prof_interval</mallctl></link>
1982 option for additional information.</para></listitem>
1983 </varlistentry>
1984
Jason Evans0657f122011-03-18 17:56:14 -07001985 <varlistentry id="stats.cactive">
1986 <term>
1987 <mallctl>stats.cactive</mallctl>
1988 (<type>size_t *</type>)
1989 <literal>r-</literal>
1990 [<option>--enable-stats</option>]
1991 </term>
1992 <listitem><para>Pointer to a counter that contains an approximate count
1993 of the current number of bytes in active pages. The estimate may be
Jason Evans9b41ac92014-10-14 22:20:00 -07001994 high, but never low, because each arena rounds up when computing its
1995 contribution to the counter. Note that the <link
Jason Evans0657f122011-03-18 17:56:14 -07001996 linkend="epoch"><mallctl>epoch</mallctl></link> mallctl has no bearing
1997 on this counter. Furthermore, counter consistency is maintained via
1998 atomic operations, so it is necessary to use an atomic operation in
1999 order to guarantee a consistent read when dereferencing the pointer.
2000 </para></listitem>
2001 </varlistentry>
2002
Jason Evansaee7fd22010-11-24 22:00:02 -08002003 <varlistentry id="stats.allocated">
2004 <term>
2005 <mallctl>stats.allocated</mallctl>
2006 (<type>size_t</type>)
2007 <literal>r-</literal>
2008 [<option>--enable-stats</option>]
2009 </term>
2010 <listitem><para>Total number of bytes allocated by the
2011 application.</para></listitem>
2012 </varlistentry>
2013
2014 <varlistentry id="stats.active">
2015 <term>
2016 <mallctl>stats.active</mallctl>
2017 (<type>size_t</type>)
2018 <literal>r-</literal>
2019 [<option>--enable-stats</option>]
2020 </term>
2021 <listitem><para>Total number of bytes in active pages allocated by the
2022 application. This is a multiple of the page size, and greater than or
2023 equal to <link
2024 linkend="stats.allocated"><mallctl>stats.allocated</mallctl></link>.
Jan Beiched90c972012-10-18 00:06:32 +04002025 This does not include <link linkend="stats.arenas.i.pdirty">
Jason Evanscbf3a6d2015-02-11 12:24:27 -08002026 <mallctl>stats.arenas.&lt;i&gt;.pdirty</mallctl></link>, nor pages
Jan Beiched90c972012-10-18 00:06:32 +04002027 entirely devoted to allocator metadata.</para></listitem>
Jason Evansaee7fd22010-11-24 22:00:02 -08002028 </varlistentry>
2029
Jason Evans4581b972014-11-27 17:22:36 -02002030 <varlistentry id="stats.metadata">
2031 <term>
2032 <mallctl>stats.metadata</mallctl>
2033 (<type>size_t</type>)
2034 <literal>r-</literal>
2035 [<option>--enable-stats</option>]
2036 </term>
2037 <listitem><para>Total number of bytes dedicated to metadata, which
2038 comprise base allocations used for bootstrap-sensitive internal
2039 allocator data structures, arena chunk headers (see <link
2040 linkend="stats.arenas.i.metadata.mapped"><mallctl>stats.arenas.&lt;i&gt;.metadata.mapped</mallctl></link>),
2041 and internal allocations (see <link
2042 linkend="stats.arenas.i.metadata.allocated"><mallctl>stats.arenas.&lt;i&gt;.metadata.allocated</mallctl></link>).</para></listitem>
2043 </varlistentry>
2044
Jason Evans4acd75a2015-03-23 17:25:57 -07002045 <varlistentry id="stats.resident">
2046 <term>
2047 <mallctl>stats.resident</mallctl>
2048 (<type>size_t</type>)
2049 <literal>r-</literal>
2050 [<option>--enable-stats</option>]
2051 </term>
2052 <listitem><para>Maximum number of bytes in physically resident data
2053 pages mapped by the allocator, comprising all pages dedicated to
2054 allocator metadata, pages backing active allocations, and unused dirty
2055 pages. This is a maximum rather than precise because pages may not
2056 actually be physically resident if they correspond to demand-zeroed
2057 virtual memory that has not yet been touched. This is a multiple of the
2058 page size, and is larger than <link
2059 linkend="stats.active"><mallctl>stats.active</mallctl></link>.</para></listitem>
2060 </varlistentry>
2061
Jason Evansaabaf852013-10-30 14:52:09 -07002062 <varlistentry id="stats.mapped">
Jason Evansaee7fd22010-11-24 22:00:02 -08002063 <term>
2064 <mallctl>stats.mapped</mallctl>
2065 (<type>size_t</type>)
2066 <literal>r-</literal>
2067 [<option>--enable-stats</option>]
2068 </term>
Jason Evans4acd75a2015-03-23 17:25:57 -07002069 <listitem><para>Total number of bytes in active chunks mapped by the
Jason Evans56048ba2015-05-28 15:03:58 -07002070 allocator. This is a multiple of the chunk size, and is larger than
2071 <link linkend="stats.active"><mallctl>stats.active</mallctl></link>.
2072 This does not include inactive chunks, even those that contain unused
2073 dirty pages, which means that there is no strict ordering between this
2074 and <link
2075 linkend="stats.resident"><mallctl>stats.resident</mallctl></link>.</para></listitem>
Jason Evansaee7fd22010-11-24 22:00:02 -08002076 </varlistentry>
2077
Jason Evansaabaf852013-10-30 14:52:09 -07002078 <varlistentry id="stats.arenas.i.dss">
Jason Evansaee7fd22010-11-24 22:00:02 -08002079 <term>
Jason Evans609ae592012-10-11 13:53:15 -07002080 <mallctl>stats.arenas.&lt;i&gt;.dss</mallctl>
2081 (<type>const char *</type>)
2082 <literal>r-</literal>
2083 </term>
2084 <listitem><para>dss (<citerefentry><refentrytitle>sbrk</refentrytitle>
2085 <manvolnum>2</manvolnum></citerefentry>) allocation precedence as
2086 related to <citerefentry><refentrytitle>mmap</refentrytitle>
2087 <manvolnum>2</manvolnum></citerefentry> allocation. See <link
2088 linkend="opt.dss"><mallctl>opt.dss</mallctl></link> for details.
2089 </para></listitem>
2090 </varlistentry>
2091
Jason Evans562d2662015-03-24 16:36:12 -07002092 <varlistentry id="stats.arenas.i.lg_dirty_mult">
2093 <term>
2094 <mallctl>stats.arenas.&lt;i&gt;.lg_dirty_mult</mallctl>
2095 (<type>ssize_t</type>)
2096 <literal>r-</literal>
2097 </term>
2098 <listitem><para>Minimum ratio (log base 2) of active to dirty pages.
2099 See <link
2100 linkend="opt.lg_dirty_mult"><mallctl>opt.lg_dirty_mult</mallctl></link>
2101 for details.</para></listitem>
2102 </varlistentry>
2103
Jason Evansaabaf852013-10-30 14:52:09 -07002104 <varlistentry id="stats.arenas.i.nthreads">
Jason Evans609ae592012-10-11 13:53:15 -07002105 <term>
Jason Evans597632b2011-03-18 13:41:33 -07002106 <mallctl>stats.arenas.&lt;i&gt;.nthreads</mallctl>
2107 (<type>unsigned</type>)
2108 <literal>r-</literal>
2109 </term>
2110 <listitem><para>Number of threads currently assigned to
2111 arena.</para></listitem>
2112 </varlistentry>
2113
Jason Evansaabaf852013-10-30 14:52:09 -07002114 <varlistentry id="stats.arenas.i.pactive">
Jason Evans597632b2011-03-18 13:41:33 -07002115 <term>
Jason Evansaee7fd22010-11-24 22:00:02 -08002116 <mallctl>stats.arenas.&lt;i&gt;.pactive</mallctl>
2117 (<type>size_t</type>)
2118 <literal>r-</literal>
2119 </term>
2120 <listitem><para>Number of pages in active runs.</para></listitem>
2121 </varlistentry>
2122
Jan Beiched90c972012-10-18 00:06:32 +04002123 <varlistentry id="stats.arenas.i.pdirty">
Jason Evansaee7fd22010-11-24 22:00:02 -08002124 <term>
2125 <mallctl>stats.arenas.&lt;i&gt;.pdirty</mallctl>
2126 (<type>size_t</type>)
2127 <literal>r-</literal>
2128 </term>
2129 <listitem><para>Number of pages within unused runs that are potentially
2130 dirty, and for which <function>madvise<parameter>...</parameter>
2131 <parameter><constant>MADV_DONTNEED</constant></parameter></function> or
2132 similar has not been called.</para></listitem>
2133 </varlistentry>
2134
Jason Evansaabaf852013-10-30 14:52:09 -07002135 <varlistentry id="stats.arenas.i.mapped">
Jason Evansaee7fd22010-11-24 22:00:02 -08002136 <term>
2137 <mallctl>stats.arenas.&lt;i&gt;.mapped</mallctl>
2138 (<type>size_t</type>)
2139 <literal>r-</literal>
2140 [<option>--enable-stats</option>]
2141 </term>
2142 <listitem><para>Number of mapped bytes.</para></listitem>
2143 </varlistentry>
2144
Jason Evans4581b972014-11-27 17:22:36 -02002145 <varlistentry id="stats.arenas.i.metadata.mapped">
2146 <term>
2147 <mallctl>stats.arenas.&lt;i&gt;.metadata.mapped</mallctl>
2148 (<type>size_t</type>)
2149 <literal>r-</literal>
2150 [<option>--enable-stats</option>]
2151 </term>
2152 <listitem><para>Number of mapped bytes in arena chunk headers, which
2153 track the states of the non-metadata pages.</para></listitem>
2154 </varlistentry>
2155
2156 <varlistentry id="stats.arenas.i.metadata.allocated">
2157 <term>
2158 <mallctl>stats.arenas.&lt;i&gt;.metadata.allocated</mallctl>
2159 (<type>size_t</type>)
2160 <literal>r-</literal>
2161 [<option>--enable-stats</option>]
2162 </term>
2163 <listitem><para>Number of bytes dedicated to internal allocations.
2164 Internal allocations differ from application-originated allocations in
2165 that they are for internal use, and that they are omitted from heap
2166 profiles. This statistic is reported separately from <link
2167 linkend="stats.metadata"><mallctl>stats.metadata</mallctl></link> and
2168 <link
2169 linkend="stats.arenas.i.metadata.mapped"><mallctl>stats.arenas.&lt;i&gt;.metadata.mapped</mallctl></link>
2170 because it overlaps with e.g. the <link
2171 linkend="stats.allocated"><mallctl>stats.allocated</mallctl></link> and
2172 <link linkend="stats.active"><mallctl>stats.active</mallctl></link>
2173 statistics, whereas the other metadata statistics do
2174 not.</para></listitem>
2175 </varlistentry>
2176
Jason Evansaabaf852013-10-30 14:52:09 -07002177 <varlistentry id="stats.arenas.i.npurge">
Jason Evansaee7fd22010-11-24 22:00:02 -08002178 <term>
2179 <mallctl>stats.arenas.&lt;i&gt;.npurge</mallctl>
2180 (<type>uint64_t</type>)
2181 <literal>r-</literal>
2182 [<option>--enable-stats</option>]
2183 </term>
2184 <listitem><para>Number of dirty page purge sweeps performed.
2185 </para></listitem>
2186 </varlistentry>
2187
Jason Evansaabaf852013-10-30 14:52:09 -07002188 <varlistentry id="stats.arenas.i.nmadvise">
Jason Evansaee7fd22010-11-24 22:00:02 -08002189 <term>
2190 <mallctl>stats.arenas.&lt;i&gt;.nmadvise</mallctl>
2191 (<type>uint64_t</type>)
2192 <literal>r-</literal>
2193 [<option>--enable-stats</option>]
2194 </term>
2195 <listitem><para>Number of <function>madvise<parameter>...</parameter>
2196 <parameter><constant>MADV_DONTNEED</constant></parameter></function> or
2197 similar calls made to purge dirty pages.</para></listitem>
2198 </varlistentry>
2199
Jason Evansd8a39002013-12-19 21:40:41 -08002200 <varlistentry id="stats.arenas.i.purged">
Jason Evansaee7fd22010-11-24 22:00:02 -08002201 <term>
Jason Evansd8a39002013-12-19 21:40:41 -08002202 <mallctl>stats.arenas.&lt;i&gt;.purged</mallctl>
Jason Evansaee7fd22010-11-24 22:00:02 -08002203 (<type>uint64_t</type>)
2204 <literal>r-</literal>
2205 [<option>--enable-stats</option>]
2206 </term>
2207 <listitem><para>Number of pages purged.</para></listitem>
2208 </varlistentry>
2209
Jason Evansaabaf852013-10-30 14:52:09 -07002210 <varlistentry id="stats.arenas.i.small.allocated">
Jason Evansaee7fd22010-11-24 22:00:02 -08002211 <term>
2212 <mallctl>stats.arenas.&lt;i&gt;.small.allocated</mallctl>
2213 (<type>size_t</type>)
2214 <literal>r-</literal>
2215 [<option>--enable-stats</option>]
2216 </term>
2217 <listitem><para>Number of bytes currently allocated by small objects.
2218 </para></listitem>
2219 </varlistentry>
2220
Jason Evansaabaf852013-10-30 14:52:09 -07002221 <varlistentry id="stats.arenas.i.small.nmalloc">
Jason Evansaee7fd22010-11-24 22:00:02 -08002222 <term>
2223 <mallctl>stats.arenas.&lt;i&gt;.small.nmalloc</mallctl>
2224 (<type>uint64_t</type>)
2225 <literal>r-</literal>
2226 [<option>--enable-stats</option>]
2227 </term>
2228 <listitem><para>Cumulative number of allocation requests served by
2229 small bins.</para></listitem>
2230 </varlistentry>
2231
Jason Evansaabaf852013-10-30 14:52:09 -07002232 <varlistentry id="stats.arenas.i.small.ndalloc">
Jason Evansaee7fd22010-11-24 22:00:02 -08002233 <term>
2234 <mallctl>stats.arenas.&lt;i&gt;.small.ndalloc</mallctl>
2235 (<type>uint64_t</type>)
2236 <literal>r-</literal>
2237 [<option>--enable-stats</option>]
2238 </term>
2239 <listitem><para>Cumulative number of small objects returned to bins.
2240 </para></listitem>
2241 </varlistentry>
2242
Jason Evansaabaf852013-10-30 14:52:09 -07002243 <varlistentry id="stats.arenas.i.small.nrequests">
Jason Evansaee7fd22010-11-24 22:00:02 -08002244 <term>
2245 <mallctl>stats.arenas.&lt;i&gt;.small.nrequests</mallctl>
2246 (<type>uint64_t</type>)
2247 <literal>r-</literal>
2248 [<option>--enable-stats</option>]
2249 </term>
2250 <listitem><para>Cumulative number of small allocation requests.
2251 </para></listitem>
2252 </varlistentry>
2253
Jason Evansaabaf852013-10-30 14:52:09 -07002254 <varlistentry id="stats.arenas.i.large.allocated">
Jason Evansaee7fd22010-11-24 22:00:02 -08002255 <term>
2256 <mallctl>stats.arenas.&lt;i&gt;.large.allocated</mallctl>
2257 (<type>size_t</type>)
2258 <literal>r-</literal>
2259 [<option>--enable-stats</option>]
2260 </term>
2261 <listitem><para>Number of bytes currently allocated by large objects.
2262 </para></listitem>
2263 </varlistentry>
2264
Jason Evansaabaf852013-10-30 14:52:09 -07002265 <varlistentry id="stats.arenas.i.large.nmalloc">
Jason Evansaee7fd22010-11-24 22:00:02 -08002266 <term>
2267 <mallctl>stats.arenas.&lt;i&gt;.large.nmalloc</mallctl>
2268 (<type>uint64_t</type>)
2269 <literal>r-</literal>
2270 [<option>--enable-stats</option>]
2271 </term>
2272 <listitem><para>Cumulative number of large allocation requests served
2273 directly by the arena.</para></listitem>
2274 </varlistentry>
2275
Jason Evansaabaf852013-10-30 14:52:09 -07002276 <varlistentry id="stats.arenas.i.large.ndalloc">
Jason Evansaee7fd22010-11-24 22:00:02 -08002277 <term>
2278 <mallctl>stats.arenas.&lt;i&gt;.large.ndalloc</mallctl>
2279 (<type>uint64_t</type>)
2280 <literal>r-</literal>
2281 [<option>--enable-stats</option>]
2282 </term>
2283 <listitem><para>Cumulative number of large deallocation requests served
2284 directly by the arena.</para></listitem>
2285 </varlistentry>
2286
Jason Evansaabaf852013-10-30 14:52:09 -07002287 <varlistentry id="stats.arenas.i.large.nrequests">
Jason Evansaee7fd22010-11-24 22:00:02 -08002288 <term>
2289 <mallctl>stats.arenas.&lt;i&gt;.large.nrequests</mallctl>
2290 (<type>uint64_t</type>)
2291 <literal>r-</literal>
2292 [<option>--enable-stats</option>]
2293 </term>
2294 <listitem><para>Cumulative number of large allocation requests.
2295 </para></listitem>
2296 </varlistentry>
2297
Jason Evanse2deab72014-05-15 22:22:27 -07002298 <varlistentry id="stats.arenas.i.huge.allocated">
2299 <term>
2300 <mallctl>stats.arenas.&lt;i&gt;.huge.allocated</mallctl>
2301 (<type>size_t</type>)
2302 <literal>r-</literal>
2303 [<option>--enable-stats</option>]
2304 </term>
2305 <listitem><para>Number of bytes currently allocated by huge objects.
2306 </para></listitem>
2307 </varlistentry>
2308
2309 <varlistentry id="stats.arenas.i.huge.nmalloc">
2310 <term>
2311 <mallctl>stats.arenas.&lt;i&gt;.huge.nmalloc</mallctl>
2312 (<type>uint64_t</type>)
2313 <literal>r-</literal>
2314 [<option>--enable-stats</option>]
2315 </term>
2316 <listitem><para>Cumulative number of huge allocation requests served
2317 directly by the arena.</para></listitem>
2318 </varlistentry>
2319
2320 <varlistentry id="stats.arenas.i.huge.ndalloc">
2321 <term>
2322 <mallctl>stats.arenas.&lt;i&gt;.huge.ndalloc</mallctl>
2323 (<type>uint64_t</type>)
2324 <literal>r-</literal>
2325 [<option>--enable-stats</option>]
2326 </term>
2327 <listitem><para>Cumulative number of huge deallocation requests served
2328 directly by the arena.</para></listitem>
2329 </varlistentry>
2330
2331 <varlistentry id="stats.arenas.i.huge.nrequests">
2332 <term>
2333 <mallctl>stats.arenas.&lt;i&gt;.huge.nrequests</mallctl>
2334 (<type>uint64_t</type>)
2335 <literal>r-</literal>
2336 [<option>--enable-stats</option>]
2337 </term>
2338 <listitem><para>Cumulative number of huge allocation requests.
2339 </para></listitem>
2340 </varlistentry>
2341
Jason Evansaabaf852013-10-30 14:52:09 -07002342 <varlistentry id="stats.arenas.i.bins.j.nmalloc">
Jason Evansaee7fd22010-11-24 22:00:02 -08002343 <term>
2344 <mallctl>stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.nmalloc</mallctl>
2345 (<type>uint64_t</type>)
2346 <literal>r-</literal>
2347 [<option>--enable-stats</option>]
2348 </term>
2349 <listitem><para>Cumulative number of allocations served by bin.
2350 </para></listitem>
2351 </varlistentry>
2352
Jason Evansaabaf852013-10-30 14:52:09 -07002353 <varlistentry id="stats.arenas.i.bins.j.ndalloc">
Jason Evansaee7fd22010-11-24 22:00:02 -08002354 <term>
2355 <mallctl>stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.ndalloc</mallctl>
2356 (<type>uint64_t</type>)
2357 <literal>r-</literal>
2358 [<option>--enable-stats</option>]
2359 </term>
2360 <listitem><para>Cumulative number of allocations returned to bin.
2361 </para></listitem>
2362 </varlistentry>
2363
Jason Evansaabaf852013-10-30 14:52:09 -07002364 <varlistentry id="stats.arenas.i.bins.j.nrequests">
Jason Evansaee7fd22010-11-24 22:00:02 -08002365 <term>
2366 <mallctl>stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.nrequests</mallctl>
2367 (<type>uint64_t</type>)
2368 <literal>r-</literal>
2369 [<option>--enable-stats</option>]
2370 </term>
2371 <listitem><para>Cumulative number of allocation
2372 requests.</para></listitem>
2373 </varlistentry>
2374
Jason Evans3c4d92e2014-10-12 22:53:59 -07002375 <varlistentry id="stats.arenas.i.bins.j.curregs">
2376 <term>
2377 <mallctl>stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.curregs</mallctl>
2378 (<type>size_t</type>)
2379 <literal>r-</literal>
2380 [<option>--enable-stats</option>]
2381 </term>
2382 <listitem><para>Current number of regions for this size
2383 class.</para></listitem>
2384 </varlistentry>
2385
Jason Evansaabaf852013-10-30 14:52:09 -07002386 <varlistentry id="stats.arenas.i.bins.j.nfills">
Jason Evansaee7fd22010-11-24 22:00:02 -08002387 <term>
2388 <mallctl>stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.nfills</mallctl>
2389 (<type>uint64_t</type>)
2390 <literal>r-</literal>
2391 [<option>--enable-stats</option> <option>--enable-tcache</option>]
2392 </term>
2393 <listitem><para>Cumulative number of tcache fills.</para></listitem>
2394 </varlistentry>
2395
Jason Evansaabaf852013-10-30 14:52:09 -07002396 <varlistentry id="stats.arenas.i.bins.j.nflushes">
Jason Evansaee7fd22010-11-24 22:00:02 -08002397 <term>
2398 <mallctl>stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.nflushes</mallctl>
2399 (<type>uint64_t</type>)
2400 <literal>r-</literal>
2401 [<option>--enable-stats</option> <option>--enable-tcache</option>]
2402 </term>
2403 <listitem><para>Cumulative number of tcache flushes.</para></listitem>
2404 </varlistentry>
2405
Jason Evansaabaf852013-10-30 14:52:09 -07002406 <varlistentry id="stats.arenas.i.bins.j.nruns">
Jason Evansaee7fd22010-11-24 22:00:02 -08002407 <term>
2408 <mallctl>stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.nruns</mallctl>
2409 (<type>uint64_t</type>)
2410 <literal>r-</literal>
2411 [<option>--enable-stats</option>]
2412 </term>
2413 <listitem><para>Cumulative number of runs created.</para></listitem>
2414 </varlistentry>
2415
Jason Evansaabaf852013-10-30 14:52:09 -07002416 <varlistentry id="stats.arenas.i.bins.j.nreruns">
Jason Evansaee7fd22010-11-24 22:00:02 -08002417 <term>
2418 <mallctl>stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.nreruns</mallctl>
2419 (<type>uint64_t</type>)
2420 <literal>r-</literal>
2421 [<option>--enable-stats</option>]
2422 </term>
2423 <listitem><para>Cumulative number of times the current run from which
2424 to allocate changed.</para></listitem>
2425 </varlistentry>
2426
Jason Evansaabaf852013-10-30 14:52:09 -07002427 <varlistentry id="stats.arenas.i.bins.j.curruns">
Jason Evansaee7fd22010-11-24 22:00:02 -08002428 <term>
Jason Evansaee7fd22010-11-24 22:00:02 -08002429 <mallctl>stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.curruns</mallctl>
2430 (<type>size_t</type>)
2431 <literal>r-</literal>
2432 [<option>--enable-stats</option>]
2433 </term>
2434 <listitem><para>Current number of runs.</para></listitem>
2435 </varlistentry>
2436
Jason Evansaabaf852013-10-30 14:52:09 -07002437 <varlistentry id="stats.arenas.i.lruns.j.nmalloc">
Jason Evansaee7fd22010-11-24 22:00:02 -08002438 <term>
2439 <mallctl>stats.arenas.&lt;i&gt;.lruns.&lt;j&gt;.nmalloc</mallctl>
2440 (<type>uint64_t</type>)
2441 <literal>r-</literal>
2442 [<option>--enable-stats</option>]
2443 </term>
2444 <listitem><para>Cumulative number of allocation requests for this size
2445 class served directly by the arena.</para></listitem>
2446 </varlistentry>
2447
Jason Evansaabaf852013-10-30 14:52:09 -07002448 <varlistentry id="stats.arenas.i.lruns.j.ndalloc">
Jason Evansaee7fd22010-11-24 22:00:02 -08002449 <term>
2450 <mallctl>stats.arenas.&lt;i&gt;.lruns.&lt;j&gt;.ndalloc</mallctl>
2451 (<type>uint64_t</type>)
2452 <literal>r-</literal>
2453 [<option>--enable-stats</option>]
2454 </term>
2455 <listitem><para>Cumulative number of deallocation requests for this
2456 size class served directly by the arena.</para></listitem>
2457 </varlistentry>
2458
Jason Evansaabaf852013-10-30 14:52:09 -07002459 <varlistentry id="stats.arenas.i.lruns.j.nrequests">
Jason Evansaee7fd22010-11-24 22:00:02 -08002460 <term>
2461 <mallctl>stats.arenas.&lt;i&gt;.lruns.&lt;j&gt;.nrequests</mallctl>
2462 (<type>uint64_t</type>)
2463 <literal>r-</literal>
2464 [<option>--enable-stats</option>]
2465 </term>
2466 <listitem><para>Cumulative number of allocation requests for this size
2467 class.</para></listitem>
2468 </varlistentry>
2469
Jason Evansaabaf852013-10-30 14:52:09 -07002470 <varlistentry id="stats.arenas.i.lruns.j.curruns">
Jason Evansaee7fd22010-11-24 22:00:02 -08002471 <term>
Jason Evansaee7fd22010-11-24 22:00:02 -08002472 <mallctl>stats.arenas.&lt;i&gt;.lruns.&lt;j&gt;.curruns</mallctl>
2473 (<type>size_t</type>)
2474 <literal>r-</literal>
2475 [<option>--enable-stats</option>]
2476 </term>
2477 <listitem><para>Current number of runs for this size class.
2478 </para></listitem>
2479 </varlistentry>
Jason Evans3c4d92e2014-10-12 22:53:59 -07002480
2481 <varlistentry id="stats.arenas.i.hchunks.j.nmalloc">
2482 <term>
2483 <mallctl>stats.arenas.&lt;i&gt;.hchunks.&lt;j&gt;.nmalloc</mallctl>
2484 (<type>uint64_t</type>)
2485 <literal>r-</literal>
2486 [<option>--enable-stats</option>]
2487 </term>
2488 <listitem><para>Cumulative number of allocation requests for this size
2489 class served directly by the arena.</para></listitem>
2490 </varlistentry>
2491
2492 <varlistentry id="stats.arenas.i.hchunks.j.ndalloc">
2493 <term>
2494 <mallctl>stats.arenas.&lt;i&gt;.hchunks.&lt;j&gt;.ndalloc</mallctl>
2495 (<type>uint64_t</type>)
2496 <literal>r-</literal>
2497 [<option>--enable-stats</option>]
2498 </term>
2499 <listitem><para>Cumulative number of deallocation requests for this
2500 size class served directly by the arena.</para></listitem>
2501 </varlistentry>
2502
2503 <varlistentry id="stats.arenas.i.hchunks.j.nrequests">
2504 <term>
2505 <mallctl>stats.arenas.&lt;i&gt;.hchunks.&lt;j&gt;.nrequests</mallctl>
2506 (<type>uint64_t</type>)
2507 <literal>r-</literal>
2508 [<option>--enable-stats</option>]
2509 </term>
2510 <listitem><para>Cumulative number of allocation requests for this size
2511 class.</para></listitem>
2512 </varlistentry>
2513
2514 <varlistentry id="stats.arenas.i.hchunks.j.curhchunks">
2515 <term>
2516 <mallctl>stats.arenas.&lt;i&gt;.hchunks.&lt;j&gt;.curhchunks</mallctl>
2517 (<type>size_t</type>)
2518 <literal>r-</literal>
2519 [<option>--enable-stats</option>]
2520 </term>
2521 <listitem><para>Current number of huge allocations for this size class.
2522 </para></listitem>
2523 </varlistentry>
Jason Evansaee7fd22010-11-24 22:00:02 -08002524 </variablelist>
2525 </refsect1>
2526 <refsect1 id="debugging_malloc_problems">
2527 <title>DEBUGGING MALLOC PROBLEMS</title>
2528 <para>When debugging, it is a good idea to configure/build jemalloc with
2529 the <option>--enable-debug</option> and <option>--enable-fill</option>
2530 options, and recompile the program with suitable options and symbols for
2531 debugger support. When so configured, jemalloc incorporates a wide variety
2532 of run-time assertions that catch application errors such as double-free,
2533 write-after-free, etc.</para>
2534
2535 <para>Programs often accidentally depend on &ldquo;uninitialized&rdquo;
2536 memory actually being filled with zero bytes. Junk filling
2537 (see the <link linkend="opt.junk"><mallctl>opt.junk</mallctl></link>
2538 option) tends to expose such bugs in the form of obviously incorrect
2539 results and/or coredumps. Conversely, zero
2540 filling (see the <link
2541 linkend="opt.zero"><mallctl>opt.zero</mallctl></link> option) eliminates
2542 the symptoms of such bugs. Between these two options, it is usually
2543 possible to quickly detect, diagnose, and eliminate such bugs.</para>
2544
2545 <para>This implementation does not provide much detail about the problems
2546 it detects, because the performance impact for storing such information
Jason Evans122449b2012-04-06 00:35:09 -07002547 would be prohibitive. However, jemalloc does integrate with the most
Jason Evansd926c902012-04-25 23:17:57 -07002548 excellent <ulink url="http://valgrind.org/">Valgrind</ulink> tool if the
Jason Evans781fe752012-05-15 14:48:14 -07002549 <option>--enable-valgrind</option> configuration option is enabled.</para>
Jason Evansaee7fd22010-11-24 22:00:02 -08002550 </refsect1>
2551 <refsect1 id="diagnostic_messages">
2552 <title>DIAGNOSTIC MESSAGES</title>
2553 <para>If any of the memory allocation/deallocation functions detect an
2554 error or warning condition, a message will be printed to file descriptor
2555 <constant>STDERR_FILENO</constant>. Errors will result in the process
2556 dumping core. If the <link
2557 linkend="opt.abort"><mallctl>opt.abort</mallctl></link> option is set, most
2558 warnings are treated as errors.</para>
2559
2560 <para>The <varname>malloc_message</varname> variable allows the programmer
2561 to override the function which emits the text strings forming the errors
2562 and warnings if for some reason the <constant>STDERR_FILENO</constant> file
2563 descriptor is not suitable for this.
2564 <function>malloc_message<parameter/></function> takes the
2565 <parameter>cbopaque</parameter> pointer argument that is
2566 <constant>NULL</constant> unless overridden by the arguments in a call to
2567 <function>malloc_stats_print<parameter/></function>, followed by a string
2568 pointer. Please note that doing anything which tries to allocate memory in
2569 this function is likely to result in a crash or deadlock.</para>
2570
2571 <para>All messages are prefixed by
2572 &ldquo;<computeroutput>&lt;jemalloc&gt;: </computeroutput>&rdquo;.</para>
2573 </refsect1>
2574 <refsect1 id="return_values">
2575 <title>RETURN VALUES</title>
2576 <refsect2>
2577 <title>Standard API</title>
2578 <para>The <function>malloc<parameter/></function> and
2579 <function>calloc<parameter/></function> functions return a pointer to the
2580 allocated memory if successful; otherwise a <constant>NULL</constant>
2581 pointer is returned and <varname>errno</varname> is set to
2582 <errorname>ENOMEM</errorname>.</para>
2583
2584 <para>The <function>posix_memalign<parameter/></function> function
2585 returns the value 0 if successful; otherwise it returns an error value.
2586 The <function>posix_memalign<parameter/></function> function will fail
2587 if:
2588 <variablelist>
2589 <varlistentry>
2590 <term><errorname>EINVAL</errorname></term>
2591
2592 <listitem><para>The <parameter>alignment</parameter> parameter is
2593 not a power of 2 at least as large as
2594 <code language="C">sizeof(<type>void *</type>)</code>.
2595 </para></listitem>
2596 </varlistentry>
2597 <varlistentry>
2598 <term><errorname>ENOMEM</errorname></term>
2599
2600 <listitem><para>Memory allocation error.</para></listitem>
2601 </varlistentry>
2602 </variablelist>
2603 </para>
2604
Jason Evans0a0bbf62012-03-13 12:55:21 -07002605 <para>The <function>aligned_alloc<parameter/></function> function returns
2606 a pointer to the allocated memory if successful; otherwise a
2607 <constant>NULL</constant> pointer is returned and
2608 <varname>errno</varname> is set. The
2609 <function>aligned_alloc<parameter/></function> function will fail if:
2610 <variablelist>
2611 <varlistentry>
2612 <term><errorname>EINVAL</errorname></term>
2613
2614 <listitem><para>The <parameter>alignment</parameter> parameter is
2615 not a power of 2.
2616 </para></listitem>
2617 </varlistentry>
2618 <varlistentry>
2619 <term><errorname>ENOMEM</errorname></term>
2620
2621 <listitem><para>Memory allocation error.</para></listitem>
2622 </varlistentry>
2623 </variablelist>
2624 </para>
2625
Jason Evansaee7fd22010-11-24 22:00:02 -08002626 <para>The <function>realloc<parameter/></function> function returns a
2627 pointer, possibly identical to <parameter>ptr</parameter>, to the
2628 allocated memory if successful; otherwise a <constant>NULL</constant>
2629 pointer is returned, and <varname>errno</varname> is set to
2630 <errorname>ENOMEM</errorname> if the error was the result of an
2631 allocation failure. The <function>realloc<parameter/></function>
2632 function always leaves the original buffer intact when an error occurs.
2633 </para>
2634
2635 <para>The <function>free<parameter/></function> function returns no
2636 value.</para>
2637 </refsect2>
2638 <refsect2>
2639 <title>Non-standard API</title>
Jason Evansd82a5e62013-12-12 22:35:52 -08002640 <para>The <function>mallocx<parameter/></function> and
2641 <function>rallocx<parameter/></function> functions return a pointer to
2642 the allocated memory if successful; otherwise a <constant>NULL</constant>
2643 pointer is returned to indicate insufficient contiguous memory was
2644 available to service the allocation request. </para>
2645
2646 <para>The <function>xallocx<parameter/></function> function returns the
2647 real size of the resulting resized allocation pointed to by
2648 <parameter>ptr</parameter>, which is a value less than
2649 <parameter>size</parameter> if the allocation could not be adequately
2650 grown in place. </para>
2651
2652 <para>The <function>sallocx<parameter/></function> function returns the
2653 real size of the allocation pointed to by <parameter>ptr</parameter>.
2654 </para>
2655
2656 <para>The <function>nallocx<parameter/></function> returns the real size
2657 that would result from a successful equivalent
2658 <function>mallocx<parameter/></function> function call, or zero if
2659 insufficient memory is available to perform the size computation. </para>
Jason Evansaee7fd22010-11-24 22:00:02 -08002660
2661 <para>The <function>mallctl<parameter/></function>,
2662 <function>mallctlnametomib<parameter/></function>, and
2663 <function>mallctlbymib<parameter/></function> functions return 0 on
2664 success; otherwise they return an error value. The functions will fail
2665 if:
2666 <variablelist>
2667 <varlistentry>
2668 <term><errorname>EINVAL</errorname></term>
2669
2670 <listitem><para><parameter>newp</parameter> is not
2671 <constant>NULL</constant>, and <parameter>newlen</parameter> is too
2672 large or too small. Alternatively, <parameter>*oldlenp</parameter>
2673 is too large or too small; in this case as much data as possible
2674 are read despite the error.</para></listitem>
2675 </varlistentry>
2676 <varlistentry>
Jason Evansaee7fd22010-11-24 22:00:02 -08002677 <term><errorname>ENOENT</errorname></term>
2678
2679 <listitem><para><parameter>name</parameter> or
2680 <parameter>mib</parameter> specifies an unknown/invalid
2681 value.</para></listitem>
2682 </varlistentry>
2683 <varlistentry>
2684 <term><errorname>EPERM</errorname></term>
2685
2686 <listitem><para>Attempt to read or write void value, or attempt to
2687 write read-only value.</para></listitem>
2688 </varlistentry>
2689 <varlistentry>
2690 <term><errorname>EAGAIN</errorname></term>
2691
2692 <listitem><para>A memory allocation failure
2693 occurred.</para></listitem>
2694 </varlistentry>
2695 <varlistentry>
2696 <term><errorname>EFAULT</errorname></term>
2697
2698 <listitem><para>An interface with side effects failed in some way
2699 not directly related to <function>mallctl*<parameter/></function>
2700 read/write processing.</para></listitem>
2701 </varlistentry>
2702 </variablelist>
2703 </para>
Jason Evansd82a5e62013-12-12 22:35:52 -08002704
2705 <para>The <function>malloc_usable_size<parameter/></function> function
2706 returns the usable size of the allocation pointed to by
2707 <parameter>ptr</parameter>. </para>
Jason Evansaee7fd22010-11-24 22:00:02 -08002708 </refsect2>
Jason Evansaee7fd22010-11-24 22:00:02 -08002709 </refsect1>
2710 <refsect1 id="environment">
2711 <title>ENVIRONMENT</title>
2712 <para>The following environment variable affects the execution of the
2713 allocation functions:
2714 <variablelist>
2715 <varlistentry>
2716 <term><envar>MALLOC_CONF</envar></term>
2717
2718 <listitem><para>If the environment variable
2719 <envar>MALLOC_CONF</envar> is set, the characters it contains
2720 will be interpreted as options.</para></listitem>
2721 </varlistentry>
2722 </variablelist>
2723 </para>
2724 </refsect1>
2725 <refsect1 id="examples">
2726 <title>EXAMPLES</title>
2727 <para>To dump core whenever a problem occurs:
2728 <screen>ln -s 'abort:true' /etc/malloc.conf</screen>
2729 </para>
2730 <para>To specify in the source a chunk size that is 16 MiB:
2731 <programlisting language="C"><![CDATA[
2732malloc_conf = "lg_chunk:24";]]></programlisting></para>
2733 </refsect1>
2734 <refsect1 id="see_also">
2735 <title>SEE ALSO</title>
2736 <para><citerefentry><refentrytitle>madvise</refentrytitle>
2737 <manvolnum>2</manvolnum></citerefentry>,
2738 <citerefentry><refentrytitle>mmap</refentrytitle>
2739 <manvolnum>2</manvolnum></citerefentry>,
2740 <citerefentry><refentrytitle>sbrk</refentrytitle>
2741 <manvolnum>2</manvolnum></citerefentry>,
Jason Evansb1476112012-04-05 13:36:17 -07002742 <citerefentry><refentrytitle>utrace</refentrytitle>
2743 <manvolnum>2</manvolnum></citerefentry>,
Jason Evansaee7fd22010-11-24 22:00:02 -08002744 <citerefentry><refentrytitle>alloca</refentrytitle>
2745 <manvolnum>3</manvolnum></citerefentry>,
2746 <citerefentry><refentrytitle>atexit</refentrytitle>
2747 <manvolnum>3</manvolnum></citerefentry>,
2748 <citerefentry><refentrytitle>getpagesize</refentrytitle>
2749 <manvolnum>3</manvolnum></citerefentry></para>
2750 </refsect1>
2751 <refsect1 id="standards">
2752 <title>STANDARDS</title>
2753 <para>The <function>malloc<parameter/></function>,
2754 <function>calloc<parameter/></function>,
2755 <function>realloc<parameter/></function>, and
2756 <function>free<parameter/></function> functions conform to ISO/IEC
2757 9899:1990 (&ldquo;ISO C90&rdquo;).</para>
2758
2759 <para>The <function>posix_memalign<parameter/></function> function conforms
2760 to IEEE Std 1003.1-2001 (&ldquo;POSIX.1&rdquo;).</para>
2761 </refsect1>
2762</refentry>