blob: bc5dbd1d7a9f60930ce92dc3c1ae0941320088d6 [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
Christopher Ferrise4294032016-03-02 14:33:02 -0800313 <parameter>size</parameter> is <constant>0</constant>.</para>
Jason Evansd82a5e62013-12-12 22:35:52 -0800314
315 <para>The <function>rallocx<parameter/></function> function resizes the
316 allocation at <parameter>ptr</parameter> to be at least
317 <parameter>size</parameter> bytes, and returns a pointer to the base
318 address of the resulting allocation, which may or may not have moved from
319 its original location. Behavior is undefined if
Christopher Ferrise4294032016-03-02 14:33:02 -0800320 <parameter>size</parameter> is <constant>0</constant>.</para>
Jason Evansd82a5e62013-12-12 22:35:52 -0800321
322 <para>The <function>xallocx<parameter/></function> function resizes the
323 allocation at <parameter>ptr</parameter> in place to be at least
324 <parameter>size</parameter> bytes, and returns the real size of the
325 allocation. If <parameter>extra</parameter> is non-zero, an attempt is
326 made to resize the allocation to be at least <code
327 language="C">(<parameter>size</parameter> +
328 <parameter>extra</parameter>)</code> bytes, though inability to allocate
329 the extra byte(s) will not by itself result in failure to resize.
330 Behavior is undefined if <parameter>size</parameter> is
331 <constant>0</constant>, or if <code
332 language="C">(<parameter>size</parameter> + <parameter>extra</parameter>
333 &gt; <constant>SIZE_T_MAX</constant>)</code>.</para>
334
335 <para>The <function>sallocx<parameter/></function> function returns the
336 real size of the allocation at <parameter>ptr</parameter>.</para>
337
338 <para>The <function>dallocx<parameter/></function> function causes the
339 memory referenced by <parameter>ptr</parameter> to be made available for
340 future allocations.</para>
341
Daniel Micay4cfe5512014-08-28 15:41:48 -0400342 <para>The <function>sdallocx<parameter/></function> function is an
343 extension of <function>dallocx<parameter/></function> with a
344 <parameter>size</parameter> parameter to allow the caller to pass in the
345 allocation size as an optimization. The minimum valid input size is the
346 original requested size of the allocation, and the maximum valid input
347 size is the corresponding value returned by
348 <function>nallocx<parameter/></function> or
349 <function>sallocx<parameter/></function>.</para>
350
Jason Evansd82a5e62013-12-12 22:35:52 -0800351 <para>The <function>nallocx<parameter/></function> function allocates no
352 memory, but it performs the same size computation as the
353 <function>mallocx<parameter/></function> function, and returns the real
354 size of the allocation that would result from the equivalent
Christopher Ferrise4294032016-03-02 14:33:02 -0800355 <function>mallocx<parameter/></function> function call, or
356 <constant>0</constant> if the inputs exceed the maximum supported size
357 class and/or alignment. Behavior is undefined if
358 <parameter>size</parameter> is <constant>0</constant>.</para>
Jason Evansaee7fd22010-11-24 22:00:02 -0800359
360 <para>The <function>mallctl<parameter/></function> function provides a
361 general interface for introspecting the memory allocator, as well as
362 setting modifiable parameters and triggering actions. The
363 period-separated <parameter>name</parameter> argument specifies a
364 location in a tree-structured namespace; see the <xref
365 linkend="mallctl_namespace" xrefstyle="template:%t"/> section for
366 documentation on the tree contents. To read a value, pass a pointer via
367 <parameter>oldp</parameter> to adequate space to contain the value, and a
368 pointer to its length via <parameter>oldlenp</parameter>; otherwise pass
369 <constant>NULL</constant> and <constant>NULL</constant>. Similarly, to
370 write a value, pass a pointer to the value via
371 <parameter>newp</parameter>, and its length via
372 <parameter>newlen</parameter>; otherwise pass <constant>NULL</constant>
373 and <constant>0</constant>.</para>
374
375 <para>The <function>mallctlnametomib<parameter/></function> function
376 provides a way to avoid repeated name lookups for applications that
377 repeatedly query the same portion of the namespace, by translating a name
378 to a &ldquo;Management Information Base&rdquo; (MIB) that can be passed
379 repeatedly to <function>mallctlbymib<parameter/></function>. Upon
380 successful return from <function>mallctlnametomib<parameter/></function>,
381 <parameter>mibp</parameter> contains an array of
382 <parameter>*miblenp</parameter> integers, where
383 <parameter>*miblenp</parameter> is the lesser of the number of components
384 in <parameter>name</parameter> and the input value of
385 <parameter>*miblenp</parameter>. Thus it is possible to pass a
386 <parameter>*miblenp</parameter> that is smaller than the number of
387 period-separated name components, which results in a partial MIB that can
388 be used as the basis for constructing a complete MIB. For name
389 components that are integers (e.g. the 2 in
390 <link
391 linkend="arenas.bin.i.size"><mallctl>arenas.bin.2.size</mallctl></link>),
392 the corresponding MIB component will always be that integer. Therefore,
393 it is legitimate to construct code like the following: <programlisting
394 language="C"><![CDATA[
395unsigned nbins, i;
Jason Evansde732962013-12-18 23:21:42 -0800396size_t mib[4];
Jason Evansaee7fd22010-11-24 22:00:02 -0800397size_t len, miblen;
398
399len = sizeof(nbins);
400mallctl("arenas.nbins", &nbins, &len, NULL, 0);
401
402miblen = 4;
Jason Evansde732962013-12-18 23:21:42 -0800403mallctlnametomib("arenas.bin.0.size", mib, &miblen);
Jason Evansaee7fd22010-11-24 22:00:02 -0800404for (i = 0; i < nbins; i++) {
405 size_t bin_size;
406
407 mib[2] = i;
408 len = sizeof(bin_size);
409 mallctlbymib(mib, miblen, &bin_size, &len, NULL, 0);
410 /* Do something with bin_size... */
411}]]></programlisting></para>
Jason Evansd82a5e62013-12-12 22:35:52 -0800412
413 <para>The <function>malloc_stats_print<parameter/></function> function
414 writes human-readable summary statistics via the
415 <parameter>write_cb</parameter> callback function pointer and
416 <parameter>cbopaque</parameter> data passed to
417 <parameter>write_cb</parameter>, or
418 <function>malloc_message<parameter/></function> if
419 <parameter>write_cb</parameter> is <constant>NULL</constant>. This
420 function can be called repeatedly. General information that never
421 changes during execution can be omitted by specifying "g" as a character
422 within the <parameter>opts</parameter> string. Note that
423 <function>malloc_message<parameter/></function> uses the
424 <function>mallctl*<parameter/></function> functions internally, so
425 inconsistent statistics can be reported if multiple threads use these
426 functions simultaneously. If <option>--enable-stats</option> is
427 specified during configuration, &ldquo;m&rdquo; and &ldquo;a&rdquo; can
428 be specified to omit merged arena and per arena statistics, respectively;
Jason Evans3c4d92e2014-10-12 22:53:59 -0700429 &ldquo;b&rdquo;, &ldquo;l&rdquo;, and &ldquo;h&rdquo; can be specified to
430 omit per size class statistics for bins, large objects, and huge objects,
431 respectively. Unrecognized characters are silently ignored. Note that
432 thread caching may prevent some statistics from being completely up to
433 date, since extra locking would be required to merge counters that track
434 thread cache operations.
Jason Evansd82a5e62013-12-12 22:35:52 -0800435 </para>
436
437 <para>The <function>malloc_usable_size<parameter/></function> function
438 returns the usable size of the allocation pointed to by
439 <parameter>ptr</parameter>. The return value may be larger than the size
440 that was requested during allocation. The
441 <function>malloc_usable_size<parameter/></function> function is not a
442 mechanism for in-place <function>realloc<parameter/></function>; rather
443 it is provided solely as a tool for introspection purposes. Any
444 discrepancy between the requested allocation size and the size reported
445 by <function>malloc_usable_size<parameter/></function> should not be
446 depended on, since such behavior is entirely implementation-dependent.
447 </para>
Jason Evansaee7fd22010-11-24 22:00:02 -0800448 </refsect2>
Jason Evansaee7fd22010-11-24 22:00:02 -0800449 </refsect1>
450 <refsect1 id="tuning">
451 <title>TUNING</title>
452 <para>Once, when the first call is made to one of the memory allocation
453 routines, the allocator initializes its internals based in part on various
454 options that can be specified at compile- or run-time.</para>
455
Christopher Ferrise4294032016-03-02 14:33:02 -0800456 <para>The string specified via <option>--with-malloc-conf</option>, the
457 string pointed to by the global variable <varname>malloc_conf</varname>, the
458 &ldquo;name&rdquo; of the file referenced by the symbolic link named
459 <filename class="symlink">/etc/malloc.conf</filename>, and the value of the
Jason Evansaee7fd22010-11-24 22:00:02 -0800460 environment variable <envar>MALLOC_CONF</envar>, will be interpreted, in
Jason Evans705328c2013-03-19 16:28:41 -0700461 that order, from left to right as options. Note that
462 <varname>malloc_conf</varname> may be read before
463 <function>main<parameter/></function> is entered, so the declaration of
464 <varname>malloc_conf</varname> should specify an initializer that contains
Christopher Ferrise4294032016-03-02 14:33:02 -0800465 the final value to be read by jemalloc. <option>--with-malloc-conf</option>
466 and <varname>malloc_conf</varname> are compile-time mechanisms, whereas
467 <filename class="symlink">/etc/malloc.conf</filename> and
468 <envar>MALLOC_CONF</envar> can be safely set any time prior to program
469 invocation.</para>
Jason Evansaee7fd22010-11-24 22:00:02 -0800470
471 <para>An options string is a comma-separated list of option:value pairs.
472 There is one key corresponding to each <link
473 linkend="opt.abort"><mallctl>opt.*</mallctl></link> mallctl (see the <xref
474 linkend="mallctl_namespace" xrefstyle="template:%t"/> section for options
475 documentation). For example, <literal>abort:true,narenas:1</literal> sets
476 the <link linkend="opt.abort"><mallctl>opt.abort</mallctl></link> and <link
477 linkend="opt.narenas"><mallctl>opt.narenas</mallctl></link> options. Some
478 options have boolean values (true/false), others have integer values (base
479 8, 10, or 16, depending on prefix), and yet others have raw string
480 values.</para>
481 </refsect1>
482 <refsect1 id="implementation_notes">
483 <title>IMPLEMENTATION NOTES</title>
484 <para>Traditionally, allocators have used
485 <citerefentry><refentrytitle>sbrk</refentrytitle>
486 <manvolnum>2</manvolnum></citerefentry> to obtain memory, which is
487 suboptimal for several reasons, including race conditions, increased
488 fragmentation, and artificial limitations on maximum usable memory. If
Jason Evans4d434ad2014-04-15 12:09:48 -0700489 <citerefentry><refentrytitle>sbrk</refentrytitle>
490 <manvolnum>2</manvolnum></citerefentry> is supported by the operating
491 system, this allocator uses both
492 <citerefentry><refentrytitle>mmap</refentrytitle>
Jason Evansaee7fd22010-11-24 22:00:02 -0800493 <manvolnum>2</manvolnum></citerefentry> and
Jason Evans8f0e0eb2012-04-21 13:33:48 -0700494 <citerefentry><refentrytitle>sbrk</refentrytitle>
Jason Evansaee7fd22010-11-24 22:00:02 -0800495 <manvolnum>2</manvolnum></citerefentry>, in that order of preference;
496 otherwise only <citerefentry><refentrytitle>mmap</refentrytitle>
497 <manvolnum>2</manvolnum></citerefentry> is used.</para>
498
499 <para>This allocator uses multiple arenas in order to reduce lock
500 contention for threaded programs on multi-processor systems. This works
501 well with regard to threading scalability, but incurs some costs. There is
502 a small fixed per-arena overhead, and additionally, arenas manage memory
503 completely independently of each other, which means a small fixed increase
504 in overall memory fragmentation. These overheads are not generally an
505 issue, given the number of arenas normally used. Note that using
506 substantially more arenas than the default is not likely to improve
507 performance, mainly due to reduced cache performance. However, it may make
508 sense to reduce the number of arenas if an application does not make much
509 use of the allocation functions.</para>
510
511 <para>In addition to multiple arenas, unless
512 <option>--disable-tcache</option> is specified during configuration, this
513 allocator supports thread-specific caching for small and large objects, in
514 order to make it possible to completely avoid synchronization for most
515 allocation requests. Such caching allows very fast allocation in the
516 common case, but it increases memory usage and fragmentation, since a
517 bounded number of objects can remain allocated in each thread cache.</para>
518
Christopher Ferrise4294032016-03-02 14:33:02 -0800519 <para>Memory is conceptually broken into equal-sized chunks, where the chunk
520 size is a power of two that is greater than the page size. Chunks are
521 always aligned to multiples of the chunk size. This alignment makes it
522 possible to find metadata for user objects very quickly. User objects are
523 broken into three categories according to size: small, large, and huge.
524 Multiple small and large objects can reside within a single chunk, whereas
525 huge objects each have one or more chunks backing them. Each chunk that
526 contains small and/or large objects tracks its contents as runs of
Jason Evansaee7fd22010-11-24 22:00:02 -0800527 contiguous pages (unused, backing a set of small objects, or backing one
Christopher Ferrise4294032016-03-02 14:33:02 -0800528 large object). The combination of chunk alignment and chunk page maps makes
529 it possible to determine all metadata regarding small and large allocations
530 in constant time.</para>
Jason Evansaee7fd22010-11-24 22:00:02 -0800531
532 <para>Small objects are managed in groups by page runs. Each run maintains
Jason Evans0cdabd22014-10-14 22:19:21 -0700533 a bitmap to track which regions are in use. Allocation requests that are no
534 more than half the quantum (8 or 16, depending on architecture) are rounded
535 up to the nearest power of two that is at least <code
536 language="C">sizeof(<type>double</type>)</code>. All other object size
537 classes are multiples of the quantum, spaced such that there are four size
538 classes for each doubling in size, which limits internal fragmentation to
539 approximately 20% for all but the smallest size classes. Small size classes
540 are smaller than four times the page size, large size classes are smaller
541 than the chunk size (see the <link
542 linkend="opt.lg_chunk"><mallctl>opt.lg_chunk</mallctl></link> option), and
543 huge size classes extend from the chunk size up to one size class less than
544 the full address space size.</para>
Jason Evansaee7fd22010-11-24 22:00:02 -0800545
546 <para>Allocations are packed tightly together, which can be an issue for
547 multi-threaded applications. If you need to assure that allocations do not
548 suffer from cacheline sharing, round your allocation requests up to the
549 nearest multiple of the cacheline size, or specify cacheline alignment when
550 allocating.</para>
551
Jason Evans228b2e92015-01-22 15:28:25 -0800552 <para>The <function>realloc<parameter/></function>,
553 <function>rallocx<parameter/></function>, and
554 <function>xallocx<parameter/></function> functions may resize allocations
555 without moving them under limited circumstances. Unlike the
556 <function>*allocx<parameter/></function> API, the standard API does not
557 officially round up the usable size of an allocation to the nearest size
558 class, so technically it is necessary to call
559 <function>realloc<parameter/></function> to grow e.g. a 9-byte allocation to
560 16 bytes, or shrink a 16-byte allocation to 9 bytes. Growth and shrinkage
561 trivially succeeds in place as long as the pre-size and post-size both round
562 up to the same size class. No other API guarantees are made regarding
563 in-place resizing, but the current implementation also tries to resize large
564 and huge allocations in place, as long as the pre-size and post-size are
Jason Evans38f86492015-08-14 00:55:44 -0700565 both large or both huge. In such cases shrinkage always succeeds for large
566 size classes, but for huge size classes the chunk allocator must support
567 splitting (see <link
568 linkend="arena.i.chunk_hooks"><mallctl>arena.&lt;i&gt;.chunk_hooks</mallctl></link>).
569 Growth only succeeds if the trailing memory is currently available, and
570 additionally for huge size classes the chunk allocator must support
571 merging.</para>
Jason Evans228b2e92015-01-22 15:28:25 -0800572
Jason Evansa5dbaef2015-08-14 00:35:11 -0700573 <para>Assuming 2 MiB chunks, 4 KiB pages, and a 16-byte quantum on a
Jason Evansf044bb22015-03-06 20:05:16 -0800574 64-bit system, the size classes in each category are as shown in <xref
Jason Evansaee7fd22010-11-24 22:00:02 -0800575 linkend="size_classes" xrefstyle="template:Table %n"/>.</para>
576
577 <table xml:id="size_classes" frame="all">
578 <title>Size classes</title>
Jason Evans7091b412012-03-19 09:36:44 -0700579 <tgroup cols="3" colsep="1" rowsep="1">
580 <colspec colname="c1" align="left"/>
581 <colspec colname="c2" align="right"/>
582 <colspec colname="c3" align="left"/>
Jason Evansaee7fd22010-11-24 22:00:02 -0800583 <thead>
584 <row>
585 <entry>Category</entry>
Jason Evans7091b412012-03-19 09:36:44 -0700586 <entry>Spacing</entry>
Jason Evansaee7fd22010-11-24 22:00:02 -0800587 <entry>Size</entry>
588 </row>
589 </thead>
590 <tbody>
591 <row>
Jason Evans0cdabd22014-10-14 22:19:21 -0700592 <entry morerows="8">Small</entry>
Jason Evans7091b412012-03-19 09:36:44 -0700593 <entry>lg</entry>
Jason Evansaee7fd22010-11-24 22:00:02 -0800594 <entry>[8]</entry>
595 </row>
596 <row>
Jason Evans7091b412012-03-19 09:36:44 -0700597 <entry>16</entry>
Jason Evans0cdabd22014-10-14 22:19:21 -0700598 <entry>[16, 32, 48, 64, 80, 96, 112, 128]</entry>
Jason Evansaee7fd22010-11-24 22:00:02 -0800599 </row>
600 <row>
Jason Evans7091b412012-03-19 09:36:44 -0700601 <entry>32</entry>
Jason Evansb1726102012-02-28 16:50:47 -0800602 <entry>[160, 192, 224, 256]</entry>
Jason Evansaee7fd22010-11-24 22:00:02 -0800603 </row>
604 <row>
Jason Evans7091b412012-03-19 09:36:44 -0700605 <entry>64</entry>
Jason Evansb1726102012-02-28 16:50:47 -0800606 <entry>[320, 384, 448, 512]</entry>
607 </row>
608 <row>
Jason Evans7091b412012-03-19 09:36:44 -0700609 <entry>128</entry>
Jason Evansb1726102012-02-28 16:50:47 -0800610 <entry>[640, 768, 896, 1024]</entry>
611 </row>
612 <row>
Jason Evans7091b412012-03-19 09:36:44 -0700613 <entry>256</entry>
Jason Evansb1726102012-02-28 16:50:47 -0800614 <entry>[1280, 1536, 1792, 2048]</entry>
615 </row>
616 <row>
Jason Evans7091b412012-03-19 09:36:44 -0700617 <entry>512</entry>
Jason Evans0cdabd22014-10-14 22:19:21 -0700618 <entry>[2560, 3072, 3584, 4096]</entry>
Jason Evansaee7fd22010-11-24 22:00:02 -0800619 </row>
620 <row>
Jason Evans0cdabd22014-10-14 22:19:21 -0700621 <entry>1 KiB</entry>
622 <entry>[5 KiB, 6 KiB, 7 KiB, 8 KiB]</entry>
623 </row>
624 <row>
625 <entry>2 KiB</entry>
626 <entry>[10 KiB, 12 KiB, 14 KiB]</entry>
627 </row>
628 <row>
Jason Evansa5dbaef2015-08-14 00:35:11 -0700629 <entry morerows="7">Large</entry>
Jason Evans0cdabd22014-10-14 22:19:21 -0700630 <entry>2 KiB</entry>
631 <entry>[16 KiB]</entry>
632 </row>
633 <row>
Jason Evans7091b412012-03-19 09:36:44 -0700634 <entry>4 KiB</entry>
Jason Evans0cdabd22014-10-14 22:19:21 -0700635 <entry>[20 KiB, 24 KiB, 28 KiB, 32 KiB]</entry>
Jason Evansaee7fd22010-11-24 22:00:02 -0800636 </row>
637 <row>
Jason Evans0cdabd22014-10-14 22:19:21 -0700638 <entry>8 KiB</entry>
639 <entry>[40 KiB, 48 KiB, 54 KiB, 64 KiB]</entry>
640 </row>
641 <row>
642 <entry>16 KiB</entry>
643 <entry>[80 KiB, 96 KiB, 112 KiB, 128 KiB]</entry>
644 </row>
645 <row>
646 <entry>32 KiB</entry>
Jason Evansa5dbaef2015-08-14 00:35:11 -0700647 <entry>[160 KiB, 192 KiB, 224 KiB, 256 KiB]</entry>
Jason Evans0cdabd22014-10-14 22:19:21 -0700648 </row>
649 <row>
650 <entry>64 KiB</entry>
651 <entry>[320 KiB, 384 KiB, 448 KiB, 512 KiB]</entry>
652 </row>
653 <row>
654 <entry>128 KiB</entry>
Jason Evansf044bb22015-03-06 20:05:16 -0800655 <entry>[640 KiB, 768 KiB, 896 KiB, 1 MiB]</entry>
Jason Evans0cdabd22014-10-14 22:19:21 -0700656 </row>
657 <row>
658 <entry>256 KiB</entry>
Jason Evansa5dbaef2015-08-14 00:35:11 -0700659 <entry>[1280 KiB, 1536 KiB, 1792 KiB]</entry>
660 </row>
661 <row>
662 <entry morerows="6">Huge</entry>
663 <entry>256 KiB</entry>
664 <entry>[2 MiB]</entry>
Jason Evans0cdabd22014-10-14 22:19:21 -0700665 </row>
666 <row>
667 <entry>512 KiB</entry>
Jason Evansf044bb22015-03-06 20:05:16 -0800668 <entry>[2560 KiB, 3 MiB, 3584 KiB, 4 MiB]</entry>
Jason Evans0cdabd22014-10-14 22:19:21 -0700669 </row>
670 <row>
671 <entry>1 MiB</entry>
672 <entry>[5 MiB, 6 MiB, 7 MiB, 8 MiB]</entry>
673 </row>
674 <row>
675 <entry>2 MiB</entry>
676 <entry>[10 MiB, 12 MiB, 14 MiB, 16 MiB]</entry>
677 </row>
678 <row>
Jason Evans7091b412012-03-19 09:36:44 -0700679 <entry>4 MiB</entry>
Jason Evans0cdabd22014-10-14 22:19:21 -0700680 <entry>[20 MiB, 24 MiB, 28 MiB, 32 MiB]</entry>
681 </row>
682 <row>
683 <entry>8 MiB</entry>
684 <entry>[40 MiB, 48 MiB, 56 MiB, 64 MiB]</entry>
685 </row>
686 <row>
687 <entry>...</entry>
688 <entry>...</entry>
Jason Evansaee7fd22010-11-24 22:00:02 -0800689 </row>
690 </tbody>
691 </tgroup>
692 </table>
693 </refsect1>
694 <refsect1 id="mallctl_namespace">
695 <title>MALLCTL NAMESPACE</title>
696 <para>The following names are defined in the namespace accessible via the
697 <function>mallctl*<parameter/></function> functions. Value types are
698 specified in parentheses, their readable/writable statuses are encoded as
699 <literal>rw</literal>, <literal>r-</literal>, <literal>-w</literal>, or
700 <literal>--</literal>, and required build configuration flags follow, if
701 any. A name element encoded as <literal>&lt;i&gt;</literal> or
702 <literal>&lt;j&gt;</literal> indicates an integer component, where the
703 integer varies from 0 to some upper value that must be determined via
704 introspection. In the case of <mallctl>stats.arenas.&lt;i&gt;.*</mallctl>,
705 <literal>&lt;i&gt;</literal> equal to <link
706 linkend="arenas.narenas"><mallctl>arenas.narenas</mallctl></link> can be
707 used to access the summation of statistics from all arenas. Take special
708 note of the <link linkend="epoch"><mallctl>epoch</mallctl></link> mallctl,
709 which controls refreshing of cached dynamic statistics.</para>
710
711 <variablelist>
Jason Evansaabaf852013-10-30 14:52:09 -0700712 <varlistentry id="version">
Jason Evansaee7fd22010-11-24 22:00:02 -0800713 <term>
714 <mallctl>version</mallctl>
715 (<type>const char *</type>)
716 <literal>r-</literal>
717 </term>
718 <listitem><para>Return the jemalloc version string.</para></listitem>
719 </varlistentry>
720
721 <varlistentry id="epoch">
722 <term>
723 <mallctl>epoch</mallctl>
724 (<type>uint64_t</type>)
725 <literal>rw</literal>
726 </term>
727 <listitem><para>If a value is passed in, refresh the data from which
728 the <function>mallctl*<parameter/></function> functions report values,
729 and increment the epoch. Return the current epoch. This is useful for
730 detecting whether another thread caused a refresh.</para></listitem>
731 </varlistentry>
732
Jason Evansf2bc8522015-07-17 16:38:25 -0700733 <varlistentry id="config.cache_oblivious">
734 <term>
735 <mallctl>config.cache_oblivious</mallctl>
736 (<type>bool</type>)
737 <literal>r-</literal>
738 </term>
739 <listitem><para><option>--enable-cache-oblivious</option> was specified
740 during build configuration.</para></listitem>
741 </varlistentry>
742
Jason Evansaabaf852013-10-30 14:52:09 -0700743 <varlistentry id="config.debug">
Jason Evansaee7fd22010-11-24 22:00:02 -0800744 <term>
745 <mallctl>config.debug</mallctl>
746 (<type>bool</type>)
747 <literal>r-</literal>
748 </term>
749 <listitem><para><option>--enable-debug</option> was specified during
750 build configuration.</para></listitem>
751 </varlistentry>
752
Jason Evansaabaf852013-10-30 14:52:09 -0700753 <varlistentry id="config.fill">
Jason Evansaee7fd22010-11-24 22:00:02 -0800754 <term>
Jason Evansaee7fd22010-11-24 22:00:02 -0800755 <mallctl>config.fill</mallctl>
756 (<type>bool</type>)
757 <literal>r-</literal>
758 </term>
759 <listitem><para><option>--enable-fill</option> was specified during
760 build configuration.</para></listitem>
761 </varlistentry>
762
Jason Evansaabaf852013-10-30 14:52:09 -0700763 <varlistentry id="config.lazy_lock">
Jason Evansaee7fd22010-11-24 22:00:02 -0800764 <term>
765 <mallctl>config.lazy_lock</mallctl>
766 (<type>bool</type>)
767 <literal>r-</literal>
768 </term>
769 <listitem><para><option>--enable-lazy-lock</option> was specified
770 during build configuration.</para></listitem>
771 </varlistentry>
772
Christopher Ferrise4294032016-03-02 14:33:02 -0800773 <varlistentry id="config.malloc_conf">
774 <term>
775 <mallctl>config.malloc_conf</mallctl>
776 (<type>const char *</type>)
777 <literal>r-</literal>
778 </term>
779 <listitem><para>Embedded configure-time-specified run-time options
780 string, empty unless <option>--with-malloc-conf</option> was specified
781 during build configuration.</para></listitem>
782 </varlistentry>
783
Jason Evansaabaf852013-10-30 14:52:09 -0700784 <varlistentry id="config.munmap">
Jason Evans2e671ff2012-05-09 16:12:00 -0700785 <term>
Jason Evans59ae2762012-04-16 17:52:27 -0700786 <mallctl>config.munmap</mallctl>
787 (<type>bool</type>)
788 <literal>r-</literal>
789 </term>
790 <listitem><para><option>--enable-munmap</option> was specified during
791 build configuration.</para></listitem>
792 </varlistentry>
793
Jason Evansaabaf852013-10-30 14:52:09 -0700794 <varlistentry id="config.prof">
Jason Evans59ae2762012-04-16 17:52:27 -0700795 <term>
Jason Evansaee7fd22010-11-24 22:00:02 -0800796 <mallctl>config.prof</mallctl>
797 (<type>bool</type>)
798 <literal>r-</literal>
799 </term>
800 <listitem><para><option>--enable-prof</option> was specified during
801 build configuration.</para></listitem>
802 </varlistentry>
803
Jason Evansaabaf852013-10-30 14:52:09 -0700804 <varlistentry id="config.prof_libgcc">
Jason Evansaee7fd22010-11-24 22:00:02 -0800805 <term>
806 <mallctl>config.prof_libgcc</mallctl>
807 (<type>bool</type>)
808 <literal>r-</literal>
809 </term>
810 <listitem><para><option>--disable-prof-libgcc</option> was not
811 specified during build configuration.</para></listitem>
812 </varlistentry>
813
Jason Evansaabaf852013-10-30 14:52:09 -0700814 <varlistentry id="config.prof_libunwind">
Jason Evansaee7fd22010-11-24 22:00:02 -0800815 <term>
816 <mallctl>config.prof_libunwind</mallctl>
817 (<type>bool</type>)
818 <literal>r-</literal>
819 </term>
820 <listitem><para><option>--enable-prof-libunwind</option> was specified
821 during build configuration.</para></listitem>
822 </varlistentry>
823
Jason Evansaabaf852013-10-30 14:52:09 -0700824 <varlistentry id="config.stats">
Jason Evansaee7fd22010-11-24 22:00:02 -0800825 <term>
826 <mallctl>config.stats</mallctl>
827 (<type>bool</type>)
828 <literal>r-</literal>
829 </term>
830 <listitem><para><option>--enable-stats</option> was specified during
831 build configuration.</para></listitem>
832 </varlistentry>
833
Jason Evansaabaf852013-10-30 14:52:09 -0700834 <varlistentry id="config.tcache">
Jason Evansaee7fd22010-11-24 22:00:02 -0800835 <term>
Jason Evansaee7fd22010-11-24 22:00:02 -0800836 <mallctl>config.tcache</mallctl>
837 (<type>bool</type>)
838 <literal>r-</literal>
839 </term>
840 <listitem><para><option>--disable-tcache</option> was not specified
841 during build configuration.</para></listitem>
842 </varlistentry>
843
Jason Evansaabaf852013-10-30 14:52:09 -0700844 <varlistentry id="config.tls">
Jason Evansaee7fd22010-11-24 22:00:02 -0800845 <term>
Jason Evansaee7fd22010-11-24 22:00:02 -0800846 <mallctl>config.tls</mallctl>
847 (<type>bool</type>)
848 <literal>r-</literal>
849 </term>
850 <listitem><para><option>--disable-tls</option> was not specified during
851 build configuration.</para></listitem>
852 </varlistentry>
853
Jason Evansaabaf852013-10-30 14:52:09 -0700854 <varlistentry id="config.utrace">
Jason Evansaee7fd22010-11-24 22:00:02 -0800855 <term>
Jason Evansb1476112012-04-05 13:36:17 -0700856 <mallctl>config.utrace</mallctl>
857 (<type>bool</type>)
858 <literal>r-</literal>
859 </term>
860 <listitem><para><option>--enable-utrace</option> was specified during
861 build configuration.</para></listitem>
862 </varlistentry>
863
Jason Evansaabaf852013-10-30 14:52:09 -0700864 <varlistentry id="config.valgrind">
Jason Evansb1476112012-04-05 13:36:17 -0700865 <term>
Jason Evans122449b2012-04-06 00:35:09 -0700866 <mallctl>config.valgrind</mallctl>
867 (<type>bool</type>)
868 <literal>r-</literal>
869 </term>
870 <listitem><para><option>--enable-valgrind</option> was specified during
871 build configuration.</para></listitem>
872 </varlistentry>
873
Jason Evansaabaf852013-10-30 14:52:09 -0700874 <varlistentry id="config.xmalloc">
Jason Evans122449b2012-04-06 00:35:09 -0700875 <term>
Jason Evansaee7fd22010-11-24 22:00:02 -0800876 <mallctl>config.xmalloc</mallctl>
877 (<type>bool</type>)
878 <literal>r-</literal>
879 </term>
880 <listitem><para><option>--enable-xmalloc</option> was specified during
881 build configuration.</para></listitem>
882 </varlistentry>
883
884 <varlistentry id="opt.abort">
885 <term>
886 <mallctl>opt.abort</mallctl>
887 (<type>bool</type>)
888 <literal>r-</literal>
889 </term>
890 <listitem><para>Abort-on-warning enabled/disabled. If true, most
891 warnings are fatal. The process will call
892 <citerefentry><refentrytitle>abort</refentrytitle>
893 <manvolnum>3</manvolnum></citerefentry> in these cases. This option is
894 disabled by default unless <option>--enable-debug</option> is
895 specified during configuration, in which case it is enabled by default.
896 </para></listitem>
897 </varlistentry>
898
Jason Evans609ae592012-10-11 13:53:15 -0700899 <varlistentry id="opt.dss">
900 <term>
901 <mallctl>opt.dss</mallctl>
902 (<type>const char *</type>)
903 <literal>r-</literal>
904 </term>
905 <listitem><para>dss (<citerefentry><refentrytitle>sbrk</refentrytitle>
906 <manvolnum>2</manvolnum></citerefentry>) allocation precedence as
907 related to <citerefentry><refentrytitle>mmap</refentrytitle>
908 <manvolnum>2</manvolnum></citerefentry> allocation. The following
Jason Evans4d434ad2014-04-15 12:09:48 -0700909 settings are supported if
910 <citerefentry><refentrytitle>sbrk</refentrytitle>
911 <manvolnum>2</manvolnum></citerefentry> is supported by the operating
912 system: &ldquo;disabled&rdquo;, &ldquo;primary&rdquo;, and
913 &ldquo;secondary&rdquo;; otherwise only &ldquo;disabled&rdquo; is
914 supported. The default is &ldquo;secondary&rdquo; if
915 <citerefentry><refentrytitle>sbrk</refentrytitle>
916 <manvolnum>2</manvolnum></citerefentry> is supported by the operating
917 system; &ldquo;disabled&rdquo; otherwise.
Jason Evansd8a39002013-12-19 21:40:41 -0800918 </para></listitem>
919 </varlistentry>
920
921 <varlistentry id="opt.lg_chunk">
922 <term>
923 <mallctl>opt.lg_chunk</mallctl>
924 (<type>size_t</type>)
925 <literal>r-</literal>
926 </term>
927 <listitem><para>Virtual memory chunk size (log base 2). If a chunk
928 size outside the supported size range is specified, the size is
929 silently clipped to the minimum/maximum supported size. The default
Jason Evans5bd87962015-07-15 17:15:26 -0700930 chunk size is 2 MiB (2^21).
Jason Evansd8a39002013-12-19 21:40:41 -0800931 </para></listitem>
Jason Evans609ae592012-10-11 13:53:15 -0700932 </varlistentry>
933
Jason Evansaee7fd22010-11-24 22:00:02 -0800934 <varlistentry id="opt.narenas">
935 <term>
936 <mallctl>opt.narenas</mallctl>
Christopher Ferrise4294032016-03-02 14:33:02 -0800937 (<type>unsigned</type>)
Jason Evansaee7fd22010-11-24 22:00:02 -0800938 <literal>r-</literal>
939 </term>
Jason Evans609ae592012-10-11 13:53:15 -0700940 <listitem><para>Maximum number of arenas to use for automatic
941 multiplexing of threads and arenas. The default is four times the
942 number of CPUs, or one if there is a single CPU.</para></listitem>
Jason Evansaee7fd22010-11-24 22:00:02 -0800943 </varlistentry>
944
Christopher Ferrise4294032016-03-02 14:33:02 -0800945 <varlistentry id="opt.purge">
946 <term>
947 <mallctl>opt.purge</mallctl>
948 (<type>const char *</type>)
949 <literal>r-</literal>
950 </term>
951 <listitem><para>Purge mode is &ldquo;ratio&rdquo; (default) or
952 &ldquo;decay&rdquo;. See <link
953 linkend="opt.lg_dirty_mult"><mallctl>opt.lg_dirty_mult</mallctl></link>
954 for details of the ratio mode. See <link
955 linkend="opt.decay_time"><mallctl>opt.decay_time</mallctl></link> for
956 details of the decay mode.</para></listitem>
957 </varlistentry>
958
Jason Evansaee7fd22010-11-24 22:00:02 -0800959 <varlistentry id="opt.lg_dirty_mult">
960 <term>
961 <mallctl>opt.lg_dirty_mult</mallctl>
962 (<type>ssize_t</type>)
963 <literal>r-</literal>
964 </term>
965 <listitem><para>Per-arena minimum ratio (log base 2) of active to dirty
966 pages. Some dirty unused pages may be allowed to accumulate, within
967 the limit set by the ratio (or one chunk worth of dirty pages,
968 whichever is greater), before informing the kernel about some of those
969 pages via <citerefentry><refentrytitle>madvise</refentrytitle>
970 <manvolnum>2</manvolnum></citerefentry> or a similar system call. This
971 provides the kernel with sufficient information to recycle dirty pages
972 if physical memory becomes scarce and the pages remain unused. The
Jason Evanse3d13062012-10-30 15:42:37 -0700973 default minimum ratio is 8:1 (2^3:1); an option value of -1 will
Jason Evans8d6a3e82015-03-18 18:55:33 -0700974 disable dirty page purging. See <link
975 linkend="arenas.lg_dirty_mult"><mallctl>arenas.lg_dirty_mult</mallctl></link>
976 and <link
977 linkend="arena.i.lg_dirty_mult"><mallctl>arena.&lt;i&gt;.lg_dirty_mult</mallctl></link>
978 for related dynamic control options.</para></listitem>
Jason Evansaee7fd22010-11-24 22:00:02 -0800979 </varlistentry>
980
Christopher Ferrise4294032016-03-02 14:33:02 -0800981 <varlistentry id="opt.decay_time">
982 <term>
983 <mallctl>opt.decay_time</mallctl>
984 (<type>ssize_t</type>)
985 <literal>r-</literal>
986 </term>
987 <listitem><para>Approximate time in seconds from the creation of a set
988 of unused dirty pages until an equivalent set of unused dirty pages is
989 purged and/or reused. The pages are incrementally purged according to a
990 sigmoidal decay curve that starts and ends with zero purge rate. A
991 decay time of 0 causes all unused dirty pages to be purged immediately
992 upon creation. A decay time of -1 disables purging. The default decay
993 time is 10 seconds. See <link
994 linkend="arenas.decay_time"><mallctl>arenas.decay_time</mallctl></link>
995 and <link
996 linkend="arena.i.decay_time"><mallctl>arena.&lt;i&gt;.decay_time</mallctl></link>
997 for related dynamic control options.
998 </para></listitem>
999 </varlistentry>
1000
Jason Evansaee7fd22010-11-24 22:00:02 -08001001 <varlistentry id="opt.stats_print">
1002 <term>
1003 <mallctl>opt.stats_print</mallctl>
1004 (<type>bool</type>)
1005 <literal>r-</literal>
1006 </term>
1007 <listitem><para>Enable/disable statistics printing at exit. If
1008 enabled, the <function>malloc_stats_print<parameter/></function>
1009 function is called at program exit via an
1010 <citerefentry><refentrytitle>atexit</refentrytitle>
1011 <manvolnum>3</manvolnum></citerefentry> function. If
1012 <option>--enable-stats</option> is specified during configuration, this
1013 has the potential to cause deadlock for a multi-threaded process that
1014 exits while one or more threads are executing in the memory allocation
Jason Evans57efa7b2014-10-08 17:57:19 -07001015 functions. Furthermore, <function>atexit<parameter/></function> may
1016 allocate memory during application initialization and then deadlock
1017 internally when jemalloc in turn calls
1018 <function>atexit<parameter/></function>, so this option is not
1019 univerally usable (though the application can register its own
1020 <function>atexit<parameter/></function> function with equivalent
1021 functionality). Therefore, this option should only be used with care;
1022 it is primarily intended as a performance tuning aid during application
Jason Evansaee7fd22010-11-24 22:00:02 -08001023 development. This option is disabled by default.</para></listitem>
1024 </varlistentry>
1025
1026 <varlistentry id="opt.junk">
1027 <term>
1028 <mallctl>opt.junk</mallctl>
Guilherme Goncalves2c5cb612014-12-08 19:12:41 -02001029 (<type>const char *</type>)
Jason Evansaee7fd22010-11-24 22:00:02 -08001030 <literal>r-</literal>
1031 [<option>--enable-fill</option>]
1032 </term>
Guilherme Goncalves2c5cb612014-12-08 19:12:41 -02001033 <listitem><para>Junk filling. If set to "alloc", each byte of
1034 uninitialized allocated memory will be initialized to
1035 <literal>0xa5</literal>. If set to "free", all deallocated memory will
1036 be initialized to <literal>0x5a</literal>. If set to "true", both
1037 allocated and deallocated memory will be initialized, and if set to
1038 "false", junk filling be disabled entirely. This is intended for
1039 debugging and will impact performance negatively. This option is
1040 "false" by default unless <option>--enable-debug</option> is specified
1041 during configuration, in which case it is "true" by default unless
1042 running inside <ulink
Jason Evans781fe752012-05-15 14:48:14 -07001043 url="http://valgrind.org/">Valgrind</ulink>.</para></listitem>
Jason Evansaee7fd22010-11-24 22:00:02 -08001044 </varlistentry>
1045
Jason Evans122449b2012-04-06 00:35:09 -07001046 <varlistentry id="opt.quarantine">
1047 <term>
1048 <mallctl>opt.quarantine</mallctl>
1049 (<type>size_t</type>)
1050 <literal>r-</literal>
1051 [<option>--enable-fill</option>]
1052 </term>
1053 <listitem><para>Per thread quarantine size in bytes. If non-zero, each
1054 thread maintains a FIFO object quarantine that stores up to the
1055 specified number of bytes of memory. The quarantined memory is not
1056 freed until it is released from quarantine, though it is immediately
1057 junk-filled if the <link
1058 linkend="opt.junk"><mallctl>opt.junk</mallctl></link> option is
1059 enabled. This feature is of particular use in combination with <ulink
Jason Evansd926c902012-04-25 23:17:57 -07001060 url="http://valgrind.org/">Valgrind</ulink>, which can detect attempts
1061 to access quarantined objects. This is intended for debugging and will
Jason Evans781fe752012-05-15 14:48:14 -07001062 impact performance negatively. The default quarantine size is 0 unless
1063 running inside Valgrind, in which case the default is 16
1064 MiB.</para></listitem>
Jason Evans122449b2012-04-06 00:35:09 -07001065 </varlistentry>
1066
1067 <varlistentry id="opt.redzone">
1068 <term>
1069 <mallctl>opt.redzone</mallctl>
1070 (<type>bool</type>)
1071 <literal>r-</literal>
1072 [<option>--enable-fill</option>]
1073 </term>
1074 <listitem><para>Redzones enabled/disabled. If enabled, small
1075 allocations have redzones before and after them. Furthermore, if the
1076 <link linkend="opt.junk"><mallctl>opt.junk</mallctl></link> option is
1077 enabled, the redzones are checked for corruption during deallocation.
1078 However, the primary intended purpose of this feature is to be used in
Jason Evansd926c902012-04-25 23:17:57 -07001079 combination with <ulink url="http://valgrind.org/">Valgrind</ulink>,
1080 which needs redzones in order to do effective buffer overflow/underflow
1081 detection. This option is intended for debugging and will impact
1082 performance negatively. This option is disabled by
Jason Evans781fe752012-05-15 14:48:14 -07001083 default unless running inside Valgrind.</para></listitem>
Jason Evans122449b2012-04-06 00:35:09 -07001084 </varlistentry>
1085
Jason Evansaee7fd22010-11-24 22:00:02 -08001086 <varlistentry id="opt.zero">
1087 <term>
1088 <mallctl>opt.zero</mallctl>
1089 (<type>bool</type>)
1090 <literal>r-</literal>
1091 [<option>--enable-fill</option>]
1092 </term>
1093 <listitem><para>Zero filling enabled/disabled. If enabled, each byte
1094 of uninitialized allocated memory will be initialized to 0. Note that
1095 this initialization only happens once for each byte, so
Jason Evans9790b962014-04-14 22:32:31 -07001096 <function>realloc<parameter/></function> and
1097 <function>rallocx<parameter/></function> calls do not zero memory that
Jason Evansaee7fd22010-11-24 22:00:02 -08001098 was previously allocated. This is intended for debugging and will
1099 impact performance negatively. This option is disabled by default.
1100 </para></listitem>
1101 </varlistentry>
1102
Jason Evansb1476112012-04-05 13:36:17 -07001103 <varlistentry id="opt.utrace">
1104 <term>
1105 <mallctl>opt.utrace</mallctl>
1106 (<type>bool</type>)
1107 <literal>r-</literal>
1108 [<option>--enable-utrace</option>]
1109 </term>
1110 <listitem><para>Allocation tracing based on
1111 <citerefentry><refentrytitle>utrace</refentrytitle>
1112 <manvolnum>2</manvolnum></citerefentry> enabled/disabled. This option
1113 is disabled by default.</para></listitem>
1114 </varlistentry>
1115
Jason Evansaee7fd22010-11-24 22:00:02 -08001116 <varlistentry id="opt.xmalloc">
1117 <term>
1118 <mallctl>opt.xmalloc</mallctl>
1119 (<type>bool</type>)
1120 <literal>r-</literal>
1121 [<option>--enable-xmalloc</option>]
1122 </term>
1123 <listitem><para>Abort-on-out-of-memory enabled/disabled. If enabled,
1124 rather than returning failure for any allocation function, display a
1125 diagnostic message on <constant>STDERR_FILENO</constant> and cause the
1126 program to drop core (using
1127 <citerefentry><refentrytitle>abort</refentrytitle>
1128 <manvolnum>3</manvolnum></citerefentry>). If an application is
1129 designed to depend on this behavior, set the option at compile time by
1130 including the following in the source code:
1131 <programlisting language="C"><![CDATA[
1132malloc_conf = "xmalloc:true";]]></programlisting>
1133 This option is disabled by default.</para></listitem>
1134 </varlistentry>
1135
1136 <varlistentry id="opt.tcache">
1137 <term>
1138 <mallctl>opt.tcache</mallctl>
1139 (<type>bool</type>)
1140 <literal>r-</literal>
1141 [<option>--enable-tcache</option>]
1142 </term>
Jason Evans1cb181e2015-01-29 15:30:47 -08001143 <listitem><para>Thread-specific caching (tcache) enabled/disabled. When
1144 there are multiple threads, each thread uses a tcache for objects up to
1145 a certain size. Thread-specific caching allows many allocations to be
1146 satisfied without performing any thread synchronization, at the cost of
1147 increased memory use. See the <link
Jason Evansaee7fd22010-11-24 22:00:02 -08001148 linkend="opt.lg_tcache_max"><mallctl>opt.lg_tcache_max</mallctl></link>
Jason Evans4507f342012-03-05 14:34:37 -08001149 option for related tuning information. This option is enabled by
Jason Evans174b70e2012-05-15 23:31:53 -07001150 default unless running inside <ulink
Jason Evansbd87b012014-04-15 16:35:08 -07001151 url="http://valgrind.org/">Valgrind</ulink>, in which case it is
1152 forcefully disabled.</para></listitem>
Jason Evansaee7fd22010-11-24 22:00:02 -08001153 </varlistentry>
1154
Jason Evansaee7fd22010-11-24 22:00:02 -08001155 <varlistentry id="opt.lg_tcache_max">
1156 <term>
1157 <mallctl>opt.lg_tcache_max</mallctl>
1158 (<type>size_t</type>)
1159 <literal>r-</literal>
1160 [<option>--enable-tcache</option>]
1161 </term>
1162 <listitem><para>Maximum size class (log base 2) to cache in the
Jason Evans1cb181e2015-01-29 15:30:47 -08001163 thread-specific cache (tcache). At a minimum, all small size classes
1164 are cached, and at a maximum all large size classes are cached. The
Jason Evansaee7fd22010-11-24 22:00:02 -08001165 default maximum is 32 KiB (2^15).</para></listitem>
1166 </varlistentry>
1167
1168 <varlistentry id="opt.prof">
1169 <term>
1170 <mallctl>opt.prof</mallctl>
1171 (<type>bool</type>)
1172 <literal>r-</literal>
1173 [<option>--enable-prof</option>]
1174 </term>
1175 <listitem><para>Memory profiling enabled/disabled. If enabled, profile
Jason Evans0b25fe72012-04-17 16:39:33 -07001176 memory allocation activity. See the <link
Jason Evansaee7fd22010-11-24 22:00:02 -08001177 linkend="opt.prof_active"><mallctl>opt.prof_active</mallctl></link>
1178 option for on-the-fly activation/deactivation. See the <link
1179 linkend="opt.lg_prof_sample"><mallctl>opt.lg_prof_sample</mallctl></link>
1180 option for probabilistic sampling control. See the <link
1181 linkend="opt.prof_accum"><mallctl>opt.prof_accum</mallctl></link>
1182 option for control of cumulative sample reporting. See the <link
Jason Evansaee7fd22010-11-24 22:00:02 -08001183 linkend="opt.lg_prof_interval"><mallctl>opt.lg_prof_interval</mallctl></link>
Jason Evans0b25fe72012-04-17 16:39:33 -07001184 option for information on interval-triggered profile dumping, the <link
1185 linkend="opt.prof_gdump"><mallctl>opt.prof_gdump</mallctl></link>
1186 option for information on high-water-triggered profile dumping, and the
1187 <link linkend="opt.prof_final"><mallctl>opt.prof_final</mallctl></link>
1188 option for final profile dumping. Profile output is compatible with
Jason Evans70417202015-05-01 12:31:12 -07001189 the <command>jeprof</command> command, which is based on the
1190 <command>pprof</command> that is developed as part of the <ulink
1191 url="http://code.google.com/p/gperftools/">gperftools
Christopher Ferrise4294032016-03-02 14:33:02 -08001192 package</ulink>. See <link linkend="heap_profile_format">HEAP PROFILE
1193 FORMAT</link> for heap profile format documentation.</para></listitem>
Jason Evansaee7fd22010-11-24 22:00:02 -08001194 </varlistentry>
1195
1196 <varlistentry id="opt.prof_prefix">
1197 <term>
1198 <mallctl>opt.prof_prefix</mallctl>
1199 (<type>const char *</type>)
1200 <literal>r-</literal>
1201 [<option>--enable-prof</option>]
1202 </term>
1203 <listitem><para>Filename prefix for profile dumps. If the prefix is
1204 set to the empty string, no automatic dumps will occur; this is
1205 primarily useful for disabling the automatic final heap dump (which
1206 also disables leak reporting, if enabled). The default prefix is
1207 <filename>jeprof</filename>.</para></listitem>
1208 </varlistentry>
1209
Jason Evansaee7fd22010-11-24 22:00:02 -08001210 <varlistentry id="opt.prof_active">
1211 <term>
1212 <mallctl>opt.prof_active</mallctl>
1213 (<type>bool</type>)
Jason Evans8d6a3e82015-03-18 18:55:33 -07001214 <literal>r-</literal>
Jason Evansaee7fd22010-11-24 22:00:02 -08001215 [<option>--enable-prof</option>]
1216 </term>
1217 <listitem><para>Profiling activated/deactivated. This is a secondary
1218 control mechanism that makes it possible to start the application with
1219 profiling enabled (see the <link
1220 linkend="opt.prof"><mallctl>opt.prof</mallctl></link> option) but
1221 inactive, then toggle profiling at any time during program execution
1222 with the <link
1223 linkend="prof.active"><mallctl>prof.active</mallctl></link> mallctl.
1224 This option is enabled by default.</para></listitem>
1225 </varlistentry>
1226
Jason Evansfc12c0b2014-10-03 23:25:30 -07001227 <varlistentry id="opt.prof_thread_active_init">
1228 <term>
1229 <mallctl>opt.prof_thread_active_init</mallctl>
1230 (<type>bool</type>)
1231 <literal>r-</literal>
1232 [<option>--enable-prof</option>]
1233 </term>
1234 <listitem><para>Initial setting for <link
1235 linkend="thread.prof.active"><mallctl>thread.prof.active</mallctl></link>
1236 in newly created threads. The initial setting for newly created threads
1237 can also be changed during execution via the <link
1238 linkend="prof.thread_active_init"><mallctl>prof.thread_active_init</mallctl></link>
1239 mallctl. This option is enabled by default.</para></listitem>
1240 </varlistentry>
1241
Jason Evansaee7fd22010-11-24 22:00:02 -08001242 <varlistentry id="opt.lg_prof_sample">
1243 <term>
1244 <mallctl>opt.lg_prof_sample</mallctl>
Jason Evans602c8e02014-08-18 16:22:13 -07001245 (<type>size_t</type>)
Jason Evansaee7fd22010-11-24 22:00:02 -08001246 <literal>r-</literal>
1247 [<option>--enable-prof</option>]
1248 </term>
1249 <listitem><para>Average interval (log base 2) between allocation
1250 samples, as measured in bytes of allocation activity. Increasing the
1251 sampling interval decreases profile fidelity, but also decreases the
Jason Evans0b25fe72012-04-17 16:39:33 -07001252 computational overhead. The default sample interval is 512 KiB (2^19
1253 B).</para></listitem>
Jason Evansaee7fd22010-11-24 22:00:02 -08001254 </varlistentry>
1255
1256 <varlistentry id="opt.prof_accum">
1257 <term>
1258 <mallctl>opt.prof_accum</mallctl>
1259 (<type>bool</type>)
1260 <literal>r-</literal>
1261 [<option>--enable-prof</option>]
1262 </term>
1263 <listitem><para>Reporting of cumulative object/byte counts in profile
1264 dumps enabled/disabled. If this option is enabled, every unique
1265 backtrace must be stored for the duration of execution. Depending on
1266 the application, this can impose a large memory overhead, and the
Jason Evans0b25fe72012-04-17 16:39:33 -07001267 cumulative counts are not always of interest. This option is disabled
Jason Evans0b526ff2012-02-13 18:04:26 -08001268 by default.</para></listitem>
Jason Evansaee7fd22010-11-24 22:00:02 -08001269 </varlistentry>
1270
1271 <varlistentry id="opt.lg_prof_interval">
1272 <term>
1273 <mallctl>opt.lg_prof_interval</mallctl>
1274 (<type>ssize_t</type>)
1275 <literal>r-</literal>
1276 [<option>--enable-prof</option>]
1277 </term>
1278 <listitem><para>Average interval (log base 2) between memory profile
1279 dumps, as measured in bytes of allocation activity. The actual
1280 interval between dumps may be sporadic because decentralized allocation
1281 counters are used to avoid synchronization bottlenecks. Profiles are
1282 dumped to files named according to the pattern
1283 <filename>&lt;prefix&gt;.&lt;pid&gt;.&lt;seq&gt;.i&lt;iseq&gt;.heap</filename>,
1284 where <literal>&lt;prefix&gt;</literal> is controlled by the
1285 <link
1286 linkend="opt.prof_prefix"><mallctl>opt.prof_prefix</mallctl></link>
1287 option. By default, interval-triggered profile dumping is disabled
1288 (encoded as -1).
1289 </para></listitem>
1290 </varlistentry>
1291
1292 <varlistentry id="opt.prof_gdump">
1293 <term>
1294 <mallctl>opt.prof_gdump</mallctl>
1295 (<type>bool</type>)
1296 <literal>r-</literal>
1297 [<option>--enable-prof</option>]
1298 </term>
Jason Evans5b8ed5b2015-01-25 21:16:57 -08001299 <listitem><para>Set the initial state of <link
1300 linkend="prof.gdump"><mallctl>prof.gdump</mallctl></link>, which when
1301 enabled triggers a memory profile dump every time the total virtual
1302 memory exceeds the previous maximum. This option is disabled by
1303 default.</para></listitem>
Jason Evansaee7fd22010-11-24 22:00:02 -08001304 </varlistentry>
1305
Jason Evans0b25fe72012-04-17 16:39:33 -07001306 <varlistentry id="opt.prof_final">
1307 <term>
1308 <mallctl>opt.prof_final</mallctl>
1309 (<type>bool</type>)
1310 <literal>r-</literal>
1311 [<option>--enable-prof</option>]
1312 </term>
1313 <listitem><para>Use an
1314 <citerefentry><refentrytitle>atexit</refentrytitle>
1315 <manvolnum>3</manvolnum></citerefentry> function to dump final memory
1316 usage to a file named according to the pattern
1317 <filename>&lt;prefix&gt;.&lt;pid&gt;.&lt;seq&gt;.f.heap</filename>,
1318 where <literal>&lt;prefix&gt;</literal> is controlled by the <link
1319 linkend="opt.prof_prefix"><mallctl>opt.prof_prefix</mallctl></link>
Jason Evans57efa7b2014-10-08 17:57:19 -07001320 option. Note that <function>atexit<parameter/></function> may allocate
1321 memory during application initialization and then deadlock internally
1322 when jemalloc in turn calls <function>atexit<parameter/></function>, so
1323 this option is not univerally usable (though the application can
1324 register its own <function>atexit<parameter/></function> function with
1325 equivalent functionality). This option is disabled by
1326 default.</para></listitem>
Jason Evans0b25fe72012-04-17 16:39:33 -07001327 </varlistentry>
1328
Jason Evansaee7fd22010-11-24 22:00:02 -08001329 <varlistentry id="opt.prof_leak">
1330 <term>
1331 <mallctl>opt.prof_leak</mallctl>
1332 (<type>bool</type>)
1333 <literal>r-</literal>
1334 [<option>--enable-prof</option>]
1335 </term>
1336 <listitem><para>Leak reporting enabled/disabled. If enabled, use an
1337 <citerefentry><refentrytitle>atexit</refentrytitle>
1338 <manvolnum>3</manvolnum></citerefentry> function to report memory leaks
1339 detected by allocation sampling. See the
Jason Evansaee7fd22010-11-24 22:00:02 -08001340 <link linkend="opt.prof"><mallctl>opt.prof</mallctl></link> option for
1341 information on analyzing heap profile output. This option is disabled
1342 by default.</para></listitem>
1343 </varlistentry>
1344
Jason Evansaabaf852013-10-30 14:52:09 -07001345 <varlistentry id="thread.arena">
Jason Evansaee7fd22010-11-24 22:00:02 -08001346 <term>
Jason Evansaee7fd22010-11-24 22:00:02 -08001347 <mallctl>thread.arena</mallctl>
1348 (<type>unsigned</type>)
1349 <literal>rw</literal>
1350 </term>
1351 <listitem><para>Get or set the arena associated with the calling
Jason Evans609ae592012-10-11 13:53:15 -07001352 thread. If the specified arena was not initialized beforehand (see the
1353 <link
Jason Evansaee7fd22010-11-24 22:00:02 -08001354 linkend="arenas.initialized"><mallctl>arenas.initialized</mallctl></link>
1355 mallctl), it will be automatically initialized as a side effect of
1356 calling this interface.</para></listitem>
1357 </varlistentry>
1358
Jason Evansecf229a2010-12-03 15:55:47 -08001359 <varlistentry id="thread.allocated">
Jason Evansaee7fd22010-11-24 22:00:02 -08001360 <term>
1361 <mallctl>thread.allocated</mallctl>
1362 (<type>uint64_t</type>)
1363 <literal>r-</literal>
1364 [<option>--enable-stats</option>]
1365 </term>
1366 <listitem><para>Get the total number of bytes ever allocated by the
1367 calling thread. This counter has the potential to wrap around; it is
1368 up to the application to appropriately interpret the counter in such
1369 cases.</para></listitem>
1370 </varlistentry>
1371
Jason Evansaabaf852013-10-30 14:52:09 -07001372 <varlistentry id="thread.allocatedp">
Jason Evansaee7fd22010-11-24 22:00:02 -08001373 <term>
Jason Evansecf229a2010-12-03 15:55:47 -08001374 <mallctl>thread.allocatedp</mallctl>
1375 (<type>uint64_t *</type>)
1376 <literal>r-</literal>
1377 [<option>--enable-stats</option>]
1378 </term>
1379 <listitem><para>Get a pointer to the the value that is returned by the
1380 <link
1381 linkend="thread.allocated"><mallctl>thread.allocated</mallctl></link>
1382 mallctl. This is useful for avoiding the overhead of repeated
1383 <function>mallctl*<parameter/></function> calls.</para></listitem>
1384 </varlistentry>
1385
1386 <varlistentry id="thread.deallocated">
1387 <term>
Jason Evansaee7fd22010-11-24 22:00:02 -08001388 <mallctl>thread.deallocated</mallctl>
1389 (<type>uint64_t</type>)
1390 <literal>r-</literal>
1391 [<option>--enable-stats</option>]
1392 </term>
1393 <listitem><para>Get the total number of bytes ever deallocated by the
1394 calling thread. This counter has the potential to wrap around; it is
1395 up to the application to appropriately interpret the counter in such
1396 cases.</para></listitem>
1397 </varlistentry>
1398
Jason Evansaabaf852013-10-30 14:52:09 -07001399 <varlistentry id="thread.deallocatedp">
Jason Evansecf229a2010-12-03 15:55:47 -08001400 <term>
1401 <mallctl>thread.deallocatedp</mallctl>
1402 (<type>uint64_t *</type>)
1403 <literal>r-</literal>
1404 [<option>--enable-stats</option>]
1405 </term>
1406 <listitem><para>Get a pointer to the the value that is returned by the
1407 <link
1408 linkend="thread.deallocated"><mallctl>thread.deallocated</mallctl></link>
1409 mallctl. This is useful for avoiding the overhead of repeated
1410 <function>mallctl*<parameter/></function> calls.</para></listitem>
1411 </varlistentry>
1412
Jason Evansaabaf852013-10-30 14:52:09 -07001413 <varlistentry id="thread.tcache.enabled">
Jason Evanse7b8fa12012-03-16 17:09:32 -07001414 <term>
Jason Evansd4be8b72012-03-26 18:54:44 -07001415 <mallctl>thread.tcache.enabled</mallctl>
1416 (<type>bool</type>)
1417 <literal>rw</literal>
1418 [<option>--enable-tcache</option>]
1419 </term>
1420 <listitem><para>Enable/disable calling thread's tcache. The tcache is
1421 implicitly flushed as a side effect of becoming
1422 disabled (see <link
Jason Evans1cb181e2015-01-29 15:30:47 -08001423 linkend="thread.tcache.flush"><mallctl>thread.tcache.flush</mallctl></link>).
Jason Evansd4be8b72012-03-26 18:54:44 -07001424 </para></listitem>
1425 </varlistentry>
1426
Jason Evansaabaf852013-10-30 14:52:09 -07001427 <varlistentry id="thread.tcache.flush">
Jason Evansd4be8b72012-03-26 18:54:44 -07001428 <term>
Jason Evanse7b8fa12012-03-16 17:09:32 -07001429 <mallctl>thread.tcache.flush</mallctl>
1430 (<type>void</type>)
1431 <literal>--</literal>
1432 [<option>--enable-tcache</option>]
1433 </term>
Jason Evans1cb181e2015-01-29 15:30:47 -08001434 <listitem><para>Flush calling thread's thread-specific cache (tcache).
1435 This interface releases all cached objects and internal data structures
1436 associated with the calling thread's tcache. Ordinarily, this interface
Jason Evanse7b8fa12012-03-16 17:09:32 -07001437 need not be called, since automatic periodic incremental garbage
1438 collection occurs, and the thread cache is automatically discarded when
1439 a thread exits. However, garbage collection is triggered by allocation
1440 activity, so it is possible for a thread that stops
1441 allocating/deallocating to retain its cache indefinitely, in which case
1442 the developer may find manual flushing useful.</para></listitem>
1443 </varlistentry>
1444
Jason Evans602c8e02014-08-18 16:22:13 -07001445 <varlistentry id="thread.prof.name">
1446 <term>
1447 <mallctl>thread.prof.name</mallctl>
1448 (<type>const char *</type>)
Jason Evansfc12c0b2014-10-03 23:25:30 -07001449 <literal>r-</literal> or
1450 <literal>-w</literal>
Jason Evans602c8e02014-08-18 16:22:13 -07001451 [<option>--enable-prof</option>]
1452 </term>
1453 <listitem><para>Get/set the descriptive name associated with the calling
1454 thread in memory profile dumps. An internal copy of the name string is
1455 created, so the input string need not be maintained after this interface
1456 completes execution. The output string of this interface should be
1457 copied for non-ephemeral uses, because multiple implementation details
Jason Evansfc12c0b2014-10-03 23:25:30 -07001458 can cause asynchronous string deallocation. Furthermore, each
1459 invocation of this interface can only read or write; simultaneous
1460 read/write is not supported due to string lifetime limitations. The
Jason Evansea7449f2015-10-19 16:56:05 -04001461 name string must be nil-terminated and comprised only of characters in
1462 the sets recognized
Jason Evansfc12c0b2014-10-03 23:25:30 -07001463 by <citerefentry><refentrytitle>isgraph</refentrytitle>
1464 <manvolnum>3</manvolnum></citerefentry> and
1465 <citerefentry><refentrytitle>isblank</refentrytitle>
1466 <manvolnum>3</manvolnum></citerefentry>.</para></listitem>
Jason Evans602c8e02014-08-18 16:22:13 -07001467 </varlistentry>
1468
1469 <varlistentry id="thread.prof.active">
1470 <term>
1471 <mallctl>thread.prof.active</mallctl>
1472 (<type>bool</type>)
1473 <literal>rw</literal>
1474 [<option>--enable-prof</option>]
1475 </term>
1476 <listitem><para>Control whether sampling is currently active for the
Jason Evansfc12c0b2014-10-03 23:25:30 -07001477 calling thread. This is an activation mechanism in addition to <link
Jason Evans602c8e02014-08-18 16:22:13 -07001478 linkend="prof.active"><mallctl>prof.active</mallctl></link>; both must
1479 be active for the calling thread to sample. This flag is enabled by
1480 default.</para></listitem>
1481 </varlistentry>
1482
Jason Evans1cb181e2015-01-29 15:30:47 -08001483 <varlistentry id="tcache.create">
1484 <term>
1485 <mallctl>tcache.create</mallctl>
1486 (<type>unsigned</type>)
1487 <literal>r-</literal>
1488 [<option>--enable-tcache</option>]
1489 </term>
1490 <listitem><para>Create an explicit thread-specific cache (tcache) and
1491 return an identifier that can be passed to the <link
1492 linkend="MALLOCX_TCACHE"><constant>MALLOCX_TCACHE(<parameter>tc</parameter>)</constant></link>
1493 macro to explicitly use the specified cache rather than the
1494 automatically managed one that is used by default. Each explicit cache
1495 can be used by only one thread at a time; the application must assure
1496 that this constraint holds.
1497 </para></listitem>
1498 </varlistentry>
1499
1500 <varlistentry id="tcache.flush">
1501 <term>
1502 <mallctl>tcache.flush</mallctl>
1503 (<type>unsigned</type>)
1504 <literal>-w</literal>
1505 [<option>--enable-tcache</option>]
1506 </term>
1507 <listitem><para>Flush the specified thread-specific cache (tcache). The
1508 same considerations apply to this interface as to <link
1509 linkend="thread.tcache.flush"><mallctl>thread.tcache.flush</mallctl></link>,
Christopher Ferrise4294032016-03-02 14:33:02 -08001510 except that the tcache will never be automatically discarded.
Jason Evans1cb181e2015-01-29 15:30:47 -08001511 </para></listitem>
1512 </varlistentry>
1513
1514 <varlistentry id="tcache.destroy">
1515 <term>
1516 <mallctl>tcache.destroy</mallctl>
1517 (<type>unsigned</type>)
1518 <literal>-w</literal>
1519 [<option>--enable-tcache</option>]
1520 </term>
1521 <listitem><para>Flush the specified thread-specific cache (tcache) and
1522 make the identifier available for use during a future tcache creation.
1523 </para></listitem>
1524 </varlistentry>
1525
Jason Evans609ae592012-10-11 13:53:15 -07001526 <varlistentry id="arena.i.purge">
1527 <term>
1528 <mallctl>arena.&lt;i&gt;.purge</mallctl>
Jason Evansa2c719b2014-04-15 12:46:28 -07001529 (<type>void</type>)
Jason Evans609ae592012-10-11 13:53:15 -07001530 <literal>--</literal>
1531 </term>
Christopher Ferrise4294032016-03-02 14:33:02 -08001532 <listitem><para>Purge all unused dirty pages for arena &lt;i&gt;, or for
Jason Evans609ae592012-10-11 13:53:15 -07001533 all arenas if &lt;i&gt; equals <link
1534 linkend="arenas.narenas"><mallctl>arenas.narenas</mallctl></link>.
1535 </para></listitem>
1536 </varlistentry>
1537
Christopher Ferrise4294032016-03-02 14:33:02 -08001538 <varlistentry id="arena.i.decay">
1539 <term>
1540 <mallctl>arena.&lt;i&gt;.decay</mallctl>
1541 (<type>void</type>)
1542 <literal>--</literal>
1543 </term>
1544 <listitem><para>Trigger decay-based purging of unused dirty pages for
1545 arena &lt;i&gt;, or for all arenas if &lt;i&gt; equals <link
1546 linkend="arenas.narenas"><mallctl>arenas.narenas</mallctl></link>.
1547 The proportion of unused dirty pages to be purged depends on the current
1548 time; see <link
1549 linkend="opt.decay_time"><mallctl>opt.decay_time</mallctl></link> for
1550 details.</para></listitem>
1551 </varlistentry>
1552
Jason Evans609ae592012-10-11 13:53:15 -07001553 <varlistentry id="arena.i.dss">
1554 <term>
1555 <mallctl>arena.&lt;i&gt;.dss</mallctl>
1556 (<type>const char *</type>)
1557 <literal>rw</literal>
1558 </term>
1559 <listitem><para>Set the precedence of dss allocation as related to mmap
1560 allocation for arena &lt;i&gt;, or for all arenas if &lt;i&gt; equals
1561 <link
Jason Evanse2deab72014-05-15 22:22:27 -07001562 linkend="arenas.narenas"><mallctl>arenas.narenas</mallctl></link>. See
1563 <link linkend="opt.dss"><mallctl>opt.dss</mallctl></link> for supported
1564 settings.</para></listitem>
Jason Evans609ae592012-10-11 13:53:15 -07001565 </varlistentry>
1566
Jason Evans8d6a3e82015-03-18 18:55:33 -07001567 <varlistentry id="arena.i.lg_dirty_mult">
1568 <term>
1569 <mallctl>arena.&lt;i&gt;.lg_dirty_mult</mallctl>
1570 (<type>ssize_t</type>)
1571 <literal>rw</literal>
1572 </term>
1573 <listitem><para>Current per-arena minimum ratio (log base 2) of active
1574 to dirty pages for arena &lt;i&gt;. Each time this interface is set and
1575 the ratio is increased, pages are synchronously purged as necessary to
1576 impose the new ratio. See <link
1577 linkend="opt.lg_dirty_mult"><mallctl>opt.lg_dirty_mult</mallctl></link>
1578 for additional information.</para></listitem>
1579 </varlistentry>
1580
Christopher Ferrise4294032016-03-02 14:33:02 -08001581 <varlistentry id="arena.i.decay_time">
1582 <term>
1583 <mallctl>arena.&lt;i&gt;.decay_time</mallctl>
1584 (<type>ssize_t</type>)
1585 <literal>rw</literal>
1586 </term>
1587 <listitem><para>Current per-arena approximate time in seconds from the
1588 creation of a set of unused dirty pages until an equivalent set of
1589 unused dirty pages is purged and/or reused. Each time this interface is
1590 set, all currently unused dirty pages are considered to have fully
1591 decayed, which causes immediate purging of all unused dirty pages unless
1592 the decay time is set to -1 (i.e. purging disabled). See <link
1593 linkend="opt.decay_time"><mallctl>opt.decay_time</mallctl></link> for
1594 additional information.</para></listitem>
1595 </varlistentry>
1596
Jason Evansb49a3342015-07-28 11:28:19 -04001597 <varlistentry id="arena.i.chunk_hooks">
aravindfb7fe502014-05-05 15:16:56 -07001598 <term>
Jason Evansb49a3342015-07-28 11:28:19 -04001599 <mallctl>arena.&lt;i&gt;.chunk_hooks</mallctl>
1600 (<type>chunk_hooks_t</type>)
aravindfb7fe502014-05-05 15:16:56 -07001601 <literal>rw</literal>
1602 </term>
Jason Evansb49a3342015-07-28 11:28:19 -04001603 <listitem><para>Get or set the chunk management hook functions for arena
1604 &lt;i&gt;. The functions must be capable of operating on all extant
1605 chunks associated with arena &lt;i&gt;, usually by passing unknown
1606 chunks to the replaced functions. In practice, it is feasible to
1607 control allocation for arenas created via <link
1608 linkend="arenas.extend"><mallctl>arenas.extend</mallctl></link> such
1609 that all chunks originate from an application-supplied chunk allocator
1610 (by setting custom chunk hook functions just after arena creation), but
1611 the automatically created arenas may have already created chunks prior
1612 to the application having an opportunity to take over chunk
1613 allocation.</para>
1614
Jason Evans92e96e32015-08-14 13:46:08 -07001615 <programlisting language="C"><![CDATA[
Jason Evansb49a3342015-07-28 11:28:19 -04001616typedef struct {
1617 chunk_alloc_t *alloc;
1618 chunk_dalloc_t *dalloc;
1619 chunk_commit_t *commit;
1620 chunk_decommit_t *decommit;
1621 chunk_purge_t *purge;
1622 chunk_split_t *split;
1623 chunk_merge_t *merge;
1624} chunk_hooks_t;]]></programlisting>
Jason Evans92e96e32015-08-14 13:46:08 -07001625 <para>The <type>chunk_hooks_t</type> structure comprises function
1626 pointers which are described individually below. jemalloc uses these
Jason Evansb49a3342015-07-28 11:28:19 -04001627 functions to manage chunk lifetime, which starts off with allocation of
1628 mapped committed memory, in the simplest case followed by deallocation.
1629 However, there are performance and platform reasons to retain chunks for
1630 later reuse. Cleanup attempts cascade from deallocation to decommit to
1631 purging, which gives the chunk management functions opportunities to
1632 reject the most permanent cleanup operations in favor of less permanent
1633 (and often less costly) operations. The chunk splitting and merging
1634 operations can also be opted out of, but this is mainly intended to
1635 support platforms on which virtual memory mappings provided by the
Jason Evans38f86492015-08-14 00:55:44 -07001636 operating system kernel do not automatically coalesce and split, e.g.
1637 Windows.</para>
Jason Evansb49a3342015-07-28 11:28:19 -04001638
Jason Evans92e96e32015-08-14 13:46:08 -07001639 <funcsynopsis><funcprototype>
aravindfb7fe502014-05-05 15:16:56 -07001640 <funcdef>typedef void *<function>(chunk_alloc_t)</function></funcdef>
Daniel Micaya95018e2014-10-04 01:39:32 -04001641 <paramdef>void *<parameter>chunk</parameter></paramdef>
aravindfb7fe502014-05-05 15:16:56 -07001642 <paramdef>size_t <parameter>size</parameter></paramdef>
1643 <paramdef>size_t <parameter>alignment</parameter></paramdef>
1644 <paramdef>bool *<parameter>zero</parameter></paramdef>
Jason Evans8fadb1a2015-08-04 10:49:46 -07001645 <paramdef>bool *<parameter>commit</parameter></paramdef>
aravindfb7fe502014-05-05 15:16:56 -07001646 <paramdef>unsigned <parameter>arena_ind</parameter></paramdef>
Jason Evans3c3b3b12014-10-05 14:48:44 -07001647 </funcprototype></funcsynopsis>
Jason Evans92e96e32015-08-14 13:46:08 -07001648 <literallayout></literallayout>
1649 <para>A chunk allocation function conforms to the
1650 <type>chunk_alloc_t</type> type and upon success returns a pointer to
1651 <parameter>size</parameter> bytes of mapped memory on behalf of arena
Jason Evansb49a3342015-07-28 11:28:19 -04001652 <parameter>arena_ind</parameter> such that the chunk's base address is a
1653 multiple of <parameter>alignment</parameter>, as well as setting
Jason Evans8fadb1a2015-08-04 10:49:46 -07001654 <parameter>*zero</parameter> to indicate whether the chunk is zeroed and
1655 <parameter>*commit</parameter> to indicate whether the chunk is
1656 committed. Upon error the function returns <constant>NULL</constant>
1657 and leaves <parameter>*zero</parameter> and
1658 <parameter>*commit</parameter> unmodified. The
aravindfb7fe502014-05-05 15:16:56 -07001659 <parameter>size</parameter> parameter is always a multiple of the chunk
1660 size. The <parameter>alignment</parameter> parameter is always a power
1661 of two at least as large as the chunk size. Zeroing is mandatory if
Jason Evans8fadb1a2015-08-04 10:49:46 -07001662 <parameter>*zero</parameter> is true upon function entry. Committing is
1663 mandatory if <parameter>*commit</parameter> is true upon function entry.
1664 If <parameter>chunk</parameter> is not <constant>NULL</constant>, the
Jason Evansb49a3342015-07-28 11:28:19 -04001665 returned pointer must be <parameter>chunk</parameter> on success or
1666 <constant>NULL</constant> on error. Committed memory may be committed
1667 in absolute terms as on a system that does not overcommit, or in
1668 implicit terms as on a system that overcommits and satisfies physical
1669 memory needs on demand via soft page faults. Note that replacing the
1670 default chunk allocation function makes the arena's <link
Jason Evanse2deab72014-05-15 22:22:27 -07001671 linkend="arena.i.dss"><mallctl>arena.&lt;i&gt;.dss</mallctl></link>
Jason Evansb49a3342015-07-28 11:28:19 -04001672 setting irrelevant.</para>
aravindfb7fe502014-05-05 15:16:56 -07001673
Jason Evans92e96e32015-08-14 13:46:08 -07001674 <funcsynopsis><funcprototype>
Jason Evans8d6a3e82015-03-18 18:55:33 -07001675 <funcdef>typedef bool <function>(chunk_dalloc_t)</function></funcdef>
aravindfb7fe502014-05-05 15:16:56 -07001676 <paramdef>void *<parameter>chunk</parameter></paramdef>
1677 <paramdef>size_t <parameter>size</parameter></paramdef>
Jason Evans8fadb1a2015-08-04 10:49:46 -07001678 <paramdef>bool <parameter>committed</parameter></paramdef>
aravindfb7fe502014-05-05 15:16:56 -07001679 <paramdef>unsigned <parameter>arena_ind</parameter></paramdef>
Jason Evans3c3b3b12014-10-05 14:48:44 -07001680 </funcprototype></funcsynopsis>
Jason Evans92e96e32015-08-14 13:46:08 -07001681 <literallayout></literallayout>
1682 <para>
aravindfb7fe502014-05-05 15:16:56 -07001683 A chunk deallocation function conforms to the
Jason Evanse2deab72014-05-15 22:22:27 -07001684 <type>chunk_dalloc_t</type> type and deallocates a
Jason Evans8fadb1a2015-08-04 10:49:46 -07001685 <parameter>chunk</parameter> of given <parameter>size</parameter> with
1686 <parameter>committed</parameter>/decommited memory as indicated, on
Jason Evans8d6a3e82015-03-18 18:55:33 -07001687 behalf of arena <parameter>arena_ind</parameter>, returning false upon
Jason Evansb49a3342015-07-28 11:28:19 -04001688 success. If the function returns true, this indicates opt-out from
1689 deallocation; the virtual memory mapping associated with the chunk
Jason Evans8fadb1a2015-08-04 10:49:46 -07001690 remains mapped, in the same commit state, and available for future use,
1691 in which case it will be automatically retained for later reuse.</para>
Jason Evans8d6a3e82015-03-18 18:55:33 -07001692
Jason Evans92e96e32015-08-14 13:46:08 -07001693 <funcsynopsis><funcprototype>
Jason Evansb49a3342015-07-28 11:28:19 -04001694 <funcdef>typedef bool <function>(chunk_commit_t)</function></funcdef>
1695 <paramdef>void *<parameter>chunk</parameter></paramdef>
1696 <paramdef>size_t <parameter>size</parameter></paramdef>
Jason Evans8fadb1a2015-08-04 10:49:46 -07001697 <paramdef>size_t <parameter>offset</parameter></paramdef>
1698 <paramdef>size_t <parameter>length</parameter></paramdef>
Jason Evansb49a3342015-07-28 11:28:19 -04001699 <paramdef>unsigned <parameter>arena_ind</parameter></paramdef>
1700 </funcprototype></funcsynopsis>
Jason Evans92e96e32015-08-14 13:46:08 -07001701 <literallayout></literallayout>
1702 <para>A chunk commit function conforms to the
1703 <type>chunk_commit_t</type> type and commits zeroed physical memory to
1704 back pages within a <parameter>chunk</parameter> of given
1705 <parameter>size</parameter> at <parameter>offset</parameter> bytes,
1706 extending for <parameter>length</parameter> on behalf of arena
Jason Evans8fadb1a2015-08-04 10:49:46 -07001707 <parameter>arena_ind</parameter>, returning false upon success.
1708 Committed memory may be committed in absolute terms as on a system that
1709 does not overcommit, or in implicit terms as on a system that
1710 overcommits and satisfies physical memory needs on demand via soft page
1711 faults. If the function returns true, this indicates insufficient
Jason Evansb49a3342015-07-28 11:28:19 -04001712 physical memory to satisfy the request.</para>
1713
Jason Evans92e96e32015-08-14 13:46:08 -07001714 <funcsynopsis><funcprototype>
Jason Evansb49a3342015-07-28 11:28:19 -04001715 <funcdef>typedef bool <function>(chunk_decommit_t)</function></funcdef>
1716 <paramdef>void *<parameter>chunk</parameter></paramdef>
1717 <paramdef>size_t <parameter>size</parameter></paramdef>
Jason Evans8fadb1a2015-08-04 10:49:46 -07001718 <paramdef>size_t <parameter>offset</parameter></paramdef>
1719 <paramdef>size_t <parameter>length</parameter></paramdef>
Jason Evansb49a3342015-07-28 11:28:19 -04001720 <paramdef>unsigned <parameter>arena_ind</parameter></paramdef>
1721 </funcprototype></funcsynopsis>
Jason Evans92e96e32015-08-14 13:46:08 -07001722 <literallayout></literallayout>
1723 <para>A chunk decommit function conforms to the
1724 <type>chunk_decommit_t</type> type and decommits any physical memory
1725 that is backing pages within a <parameter>chunk</parameter> of given
1726 <parameter>size</parameter> at <parameter>offset</parameter> bytes,
1727 extending for <parameter>length</parameter> on behalf of arena
Jason Evans8fadb1a2015-08-04 10:49:46 -07001728 <parameter>arena_ind</parameter>, returning false upon success, in which
1729 case the pages will be committed via the chunk commit function before
1730 being reused. If the function returns true, this indicates opt-out from
1731 decommit; the memory remains committed and available for future use, in
1732 which case it will be automatically retained for later reuse.</para>
Jason Evansb49a3342015-07-28 11:28:19 -04001733
Jason Evans92e96e32015-08-14 13:46:08 -07001734 <funcsynopsis><funcprototype>
Jason Evans8d6a3e82015-03-18 18:55:33 -07001735 <funcdef>typedef bool <function>(chunk_purge_t)</function></funcdef>
1736 <paramdef>void *<parameter>chunk</parameter></paramdef>
Jason Evansb49a3342015-07-28 11:28:19 -04001737 <paramdef>size_t<parameter>size</parameter></paramdef>
Jason Evans8d6a3e82015-03-18 18:55:33 -07001738 <paramdef>size_t <parameter>offset</parameter></paramdef>
1739 <paramdef>size_t <parameter>length</parameter></paramdef>
1740 <paramdef>unsigned <parameter>arena_ind</parameter></paramdef>
1741 </funcprototype></funcsynopsis>
Jason Evans92e96e32015-08-14 13:46:08 -07001742 <literallayout></literallayout>
1743 <para>A chunk purge function conforms to the <type>chunk_purge_t</type>
1744 type and optionally discards physical pages within the virtual memory
1745 mapping associated with <parameter>chunk</parameter> of given
Jason Evansb49a3342015-07-28 11:28:19 -04001746 <parameter>size</parameter> at <parameter>offset</parameter> bytes,
1747 extending for <parameter>length</parameter> on behalf of arena
Jason Evans8d6a3e82015-03-18 18:55:33 -07001748 <parameter>arena_ind</parameter>, returning false if pages within the
1749 purged virtual memory range will be zero-filled the next time they are
Jason Evansb49a3342015-07-28 11:28:19 -04001750 accessed.</para>
1751
Jason Evans92e96e32015-08-14 13:46:08 -07001752 <funcsynopsis><funcprototype>
Jason Evansb49a3342015-07-28 11:28:19 -04001753 <funcdef>typedef bool <function>(chunk_split_t)</function></funcdef>
1754 <paramdef>void *<parameter>chunk</parameter></paramdef>
1755 <paramdef>size_t <parameter>size</parameter></paramdef>
1756 <paramdef>size_t <parameter>size_a</parameter></paramdef>
1757 <paramdef>size_t <parameter>size_b</parameter></paramdef>
1758 <paramdef>bool <parameter>committed</parameter></paramdef>
1759 <paramdef>unsigned <parameter>arena_ind</parameter></paramdef>
1760 </funcprototype></funcsynopsis>
Jason Evans92e96e32015-08-14 13:46:08 -07001761 <literallayout></literallayout>
1762 <para>A chunk split function conforms to the <type>chunk_split_t</type>
1763 type and optionally splits <parameter>chunk</parameter> of given
Jason Evansb49a3342015-07-28 11:28:19 -04001764 <parameter>size</parameter> into two adjacent chunks, the first of
1765 <parameter>size_a</parameter> bytes, and the second of
1766 <parameter>size_b</parameter> bytes, operating on
1767 <parameter>committed</parameter>/decommitted memory as indicated, on
1768 behalf of arena <parameter>arena_ind</parameter>, returning false upon
1769 success. If the function returns true, this indicates that the chunk
1770 remains unsplit and therefore should continue to be operated on as a
1771 whole.</para>
1772
Jason Evans92e96e32015-08-14 13:46:08 -07001773 <funcsynopsis><funcprototype>
Jason Evansb49a3342015-07-28 11:28:19 -04001774 <funcdef>typedef bool <function>(chunk_merge_t)</function></funcdef>
1775 <paramdef>void *<parameter>chunk_a</parameter></paramdef>
1776 <paramdef>size_t <parameter>size_a</parameter></paramdef>
1777 <paramdef>void *<parameter>chunk_b</parameter></paramdef>
1778 <paramdef>size_t <parameter>size_b</parameter></paramdef>
1779 <paramdef>bool <parameter>committed</parameter></paramdef>
1780 <paramdef>unsigned <parameter>arena_ind</parameter></paramdef>
1781 </funcprototype></funcsynopsis>
Jason Evans92e96e32015-08-14 13:46:08 -07001782 <literallayout></literallayout>
1783 <para>A chunk merge function conforms to the <type>chunk_merge_t</type>
1784 type and optionally merges adjacent chunks,
1785 <parameter>chunk_a</parameter> of given <parameter>size_a</parameter>
1786 and <parameter>chunk_b</parameter> of given
1787 <parameter>size_b</parameter> into one contiguous chunk, operating on
1788 <parameter>committed</parameter>/decommitted memory as indicated, on
1789 behalf of arena <parameter>arena_ind</parameter>, returning false upon
1790 success. If the function returns true, this indicates that the chunks
1791 remain distinct mappings and therefore should continue to be operated on
1792 independently.</para>
Jason Evansb49a3342015-07-28 11:28:19 -04001793 </listitem>
aravindfb7fe502014-05-05 15:16:56 -07001794 </varlistentry>
1795
Jason Evansaee7fd22010-11-24 22:00:02 -08001796 <varlistentry id="arenas.narenas">
1797 <term>
1798 <mallctl>arenas.narenas</mallctl>
1799 (<type>unsigned</type>)
1800 <literal>r-</literal>
1801 </term>
Jason Evans609ae592012-10-11 13:53:15 -07001802 <listitem><para>Current limit on number of arenas.</para></listitem>
Jason Evansaee7fd22010-11-24 22:00:02 -08001803 </varlistentry>
1804
1805 <varlistentry id="arenas.initialized">
1806 <term>
1807 <mallctl>arenas.initialized</mallctl>
1808 (<type>bool *</type>)
1809 <literal>r-</literal>
1810 </term>
1811 <listitem><para>An array of <link
1812 linkend="arenas.narenas"><mallctl>arenas.narenas</mallctl></link>
1813 booleans. Each boolean indicates whether the corresponding arena is
1814 initialized.</para></listitem>
1815 </varlistentry>
1816
Jason Evans8d6a3e82015-03-18 18:55:33 -07001817 <varlistentry id="arenas.lg_dirty_mult">
1818 <term>
1819 <mallctl>arenas.lg_dirty_mult</mallctl>
1820 (<type>ssize_t</type>)
1821 <literal>rw</literal>
1822 </term>
1823 <listitem><para>Current default per-arena minimum ratio (log base 2) of
1824 active to dirty pages, used to initialize <link
1825 linkend="arena.i.lg_dirty_mult"><mallctl>arena.&lt;i&gt;.lg_dirty_mult</mallctl></link>
1826 during arena creation. See <link
1827 linkend="opt.lg_dirty_mult"><mallctl>opt.lg_dirty_mult</mallctl></link>
1828 for additional information.</para></listitem>
1829 </varlistentry>
1830
Christopher Ferrise4294032016-03-02 14:33:02 -08001831 <varlistentry id="arenas.decay_time">
1832 <term>
1833 <mallctl>arenas.decay_time</mallctl>
1834 (<type>ssize_t</type>)
1835 <literal>rw</literal>
1836 </term>
1837 <listitem><para>Current default per-arena approximate time in seconds
1838 from the creation of a set of unused dirty pages until an equivalent set
1839 of unused dirty pages is purged and/or reused, used to initialize <link
1840 linkend="arena.i.decay_time"><mallctl>arena.&lt;i&gt;.decay_time</mallctl></link>
1841 during arena creation. See <link
1842 linkend="opt.decay_time"><mallctl>opt.decay_time</mallctl></link> for
1843 additional information.</para></listitem>
1844 </varlistentry>
1845
Jason Evansaabaf852013-10-30 14:52:09 -07001846 <varlistentry id="arenas.quantum">
Jason Evansaee7fd22010-11-24 22:00:02 -08001847 <term>
1848 <mallctl>arenas.quantum</mallctl>
1849 (<type>size_t</type>)
1850 <literal>r-</literal>
1851 </term>
1852 <listitem><para>Quantum size.</para></listitem>
1853 </varlistentry>
1854
Jason Evansaabaf852013-10-30 14:52:09 -07001855 <varlistentry id="arenas.page">
Jason Evansaee7fd22010-11-24 22:00:02 -08001856 <term>
Jason Evansae4c7b42012-04-02 07:04:34 -07001857 <mallctl>arenas.page</mallctl>
Jason Evansaee7fd22010-11-24 22:00:02 -08001858 (<type>size_t</type>)
1859 <literal>r-</literal>
1860 </term>
1861 <listitem><para>Page size.</para></listitem>
1862 </varlistentry>
1863
Jason Evansaabaf852013-10-30 14:52:09 -07001864 <varlistentry id="arenas.tcache_max">
Jason Evansaee7fd22010-11-24 22:00:02 -08001865 <term>
Jason Evansaee7fd22010-11-24 22:00:02 -08001866 <mallctl>arenas.tcache_max</mallctl>
1867 (<type>size_t</type>)
1868 <literal>r-</literal>
1869 [<option>--enable-tcache</option>]
1870 </term>
1871 <listitem><para>Maximum thread-cached size class.</para></listitem>
1872 </varlistentry>
1873
Jason Evansaabaf852013-10-30 14:52:09 -07001874 <varlistentry id="arenas.nbins">
Jason Evansaee7fd22010-11-24 22:00:02 -08001875 <term>
Jason Evansaee7fd22010-11-24 22:00:02 -08001876 <mallctl>arenas.nbins</mallctl>
1877 (<type>unsigned</type>)
1878 <literal>r-</literal>
1879 </term>
Jason Evansb1726102012-02-28 16:50:47 -08001880 <listitem><para>Number of bin size classes.</para></listitem>
Jason Evansaee7fd22010-11-24 22:00:02 -08001881 </varlistentry>
1882
Jason Evansaabaf852013-10-30 14:52:09 -07001883 <varlistentry id="arenas.nhbins">
Jason Evansaee7fd22010-11-24 22:00:02 -08001884 <term>
1885 <mallctl>arenas.nhbins</mallctl>
1886 (<type>unsigned</type>)
1887 <literal>r-</literal>
1888 [<option>--enable-tcache</option>]
1889 </term>
1890 <listitem><para>Total number of thread cache bin size
1891 classes.</para></listitem>
1892 </varlistentry>
1893
1894 <varlistentry id="arenas.bin.i.size">
1895 <term>
1896 <mallctl>arenas.bin.&lt;i&gt;.size</mallctl>
1897 (<type>size_t</type>)
1898 <literal>r-</literal>
1899 </term>
1900 <listitem><para>Maximum size supported by size class.</para></listitem>
1901 </varlistentry>
1902
Jason Evansaabaf852013-10-30 14:52:09 -07001903 <varlistentry id="arenas.bin.i.nregs">
Jason Evansaee7fd22010-11-24 22:00:02 -08001904 <term>
1905 <mallctl>arenas.bin.&lt;i&gt;.nregs</mallctl>
1906 (<type>uint32_t</type>)
1907 <literal>r-</literal>
1908 </term>
1909 <listitem><para>Number of regions per page run.</para></listitem>
1910 </varlistentry>
1911
Jason Evansaabaf852013-10-30 14:52:09 -07001912 <varlistentry id="arenas.bin.i.run_size">
Jason Evansaee7fd22010-11-24 22:00:02 -08001913 <term>
1914 <mallctl>arenas.bin.&lt;i&gt;.run_size</mallctl>
1915 (<type>size_t</type>)
1916 <literal>r-</literal>
1917 </term>
1918 <listitem><para>Number of bytes per page run.</para></listitem>
1919 </varlistentry>
1920
Jason Evansaabaf852013-10-30 14:52:09 -07001921 <varlistentry id="arenas.nlruns">
Jason Evansaee7fd22010-11-24 22:00:02 -08001922 <term>
1923 <mallctl>arenas.nlruns</mallctl>
Jason Evans3c4d92e2014-10-12 22:53:59 -07001924 (<type>unsigned</type>)
Jason Evansaee7fd22010-11-24 22:00:02 -08001925 <literal>r-</literal>
1926 </term>
1927 <listitem><para>Total number of large size classes.</para></listitem>
1928 </varlistentry>
1929
Jason Evansaabaf852013-10-30 14:52:09 -07001930 <varlistentry id="arenas.lrun.i.size">
Jason Evansaee7fd22010-11-24 22:00:02 -08001931 <term>
1932 <mallctl>arenas.lrun.&lt;i&gt;.size</mallctl>
1933 (<type>size_t</type>)
1934 <literal>r-</literal>
1935 </term>
1936 <listitem><para>Maximum size supported by this large size
1937 class.</para></listitem>
1938 </varlistentry>
1939
Jason Evans3c4d92e2014-10-12 22:53:59 -07001940 <varlistentry id="arenas.nhchunks">
1941 <term>
1942 <mallctl>arenas.nhchunks</mallctl>
1943 (<type>unsigned</type>)
1944 <literal>r-</literal>
1945 </term>
1946 <listitem><para>Total number of huge size classes.</para></listitem>
1947 </varlistentry>
1948
Qinfan Wu89750352015-04-21 16:57:42 -07001949 <varlistentry id="arenas.hchunk.i.size">
Jason Evans3c4d92e2014-10-12 22:53:59 -07001950 <term>
Qinfan Wu89750352015-04-21 16:57:42 -07001951 <mallctl>arenas.hchunk.&lt;i&gt;.size</mallctl>
Jason Evans3c4d92e2014-10-12 22:53:59 -07001952 (<type>size_t</type>)
1953 <literal>r-</literal>
1954 </term>
1955 <listitem><para>Maximum size supported by this huge size
1956 class.</para></listitem>
1957 </varlistentry>
1958
Jason Evansaabaf852013-10-30 14:52:09 -07001959 <varlistentry id="arenas.extend">
Jason Evans609ae592012-10-11 13:53:15 -07001960 <term>
1961 <mallctl>arenas.extend</mallctl>
1962 (<type>unsigned</type>)
1963 <literal>r-</literal>
1964 </term>
1965 <listitem><para>Extend the array of arenas by appending a new arena,
1966 and returning the new arena index.</para></listitem>
1967 </varlistentry>
1968
Jason Evansfc12c0b2014-10-03 23:25:30 -07001969 <varlistentry id="prof.thread_active_init">
1970 <term>
1971 <mallctl>prof.thread_active_init</mallctl>
1972 (<type>bool</type>)
1973 <literal>rw</literal>
1974 [<option>--enable-prof</option>]
1975 </term>
1976 <listitem><para>Control the initial setting for <link
1977 linkend="thread.prof.active"><mallctl>thread.prof.active</mallctl></link>
1978 in newly created threads. See the <link
1979 linkend="opt.prof_thread_active_init"><mallctl>opt.prof_thread_active_init</mallctl></link>
1980 option for additional information.</para></listitem>
1981 </varlistentry>
1982
Jason Evansaee7fd22010-11-24 22:00:02 -08001983 <varlistentry id="prof.active">
1984 <term>
1985 <mallctl>prof.active</mallctl>
1986 (<type>bool</type>)
1987 <literal>rw</literal>
1988 [<option>--enable-prof</option>]
1989 </term>
1990 <listitem><para>Control whether sampling is currently active. See the
1991 <link
1992 linkend="opt.prof_active"><mallctl>opt.prof_active</mallctl></link>
Jason Evansfc12c0b2014-10-03 23:25:30 -07001993 option for additional information, as well as the interrelated <link
1994 linkend="thread.prof.active"><mallctl>thread.prof.active</mallctl></link>
1995 mallctl.</para></listitem>
Jason Evansaee7fd22010-11-24 22:00:02 -08001996 </varlistentry>
1997
Jason Evansaabaf852013-10-30 14:52:09 -07001998 <varlistentry id="prof.dump">
Jason Evansaee7fd22010-11-24 22:00:02 -08001999 <term>
2000 <mallctl>prof.dump</mallctl>
2001 (<type>const char *</type>)
2002 <literal>-w</literal>
2003 [<option>--enable-prof</option>]
2004 </term>
2005 <listitem><para>Dump a memory profile to the specified file, or if NULL
2006 is specified, to a file according to the pattern
2007 <filename>&lt;prefix&gt;.&lt;pid&gt;.&lt;seq&gt;.m&lt;mseq&gt;.heap</filename>,
2008 where <literal>&lt;prefix&gt;</literal> is controlled by the
2009 <link
2010 linkend="opt.prof_prefix"><mallctl>opt.prof_prefix</mallctl></link>
2011 option.</para></listitem>
2012 </varlistentry>
2013
Jason Evans5b8ed5b2015-01-25 21:16:57 -08002014 <varlistentry id="prof.gdump">
2015 <term>
2016 <mallctl>prof.gdump</mallctl>
2017 (<type>bool</type>)
2018 <literal>rw</literal>
2019 [<option>--enable-prof</option>]
2020 </term>
2021 <listitem><para>When enabled, trigger a memory profile dump every time
2022 the total virtual memory exceeds the previous maximum. Profiles are
2023 dumped to files named according to the pattern
2024 <filename>&lt;prefix&gt;.&lt;pid&gt;.&lt;seq&gt;.u&lt;useq&gt;.heap</filename>,
2025 where <literal>&lt;prefix&gt;</literal> is controlled by the <link
2026 linkend="opt.prof_prefix"><mallctl>opt.prof_prefix</mallctl></link>
2027 option.</para></listitem>
2028 </varlistentry>
2029
Jason Evans602c8e02014-08-18 16:22:13 -07002030 <varlistentry id="prof.reset">
2031 <term>
2032 <mallctl>prof.reset</mallctl>
2033 (<type>size_t</type>)
2034 <literal>-w</literal>
2035 [<option>--enable-prof</option>]
2036 </term>
2037 <listitem><para>Reset all memory profile statistics, and optionally
2038 update the sample rate (see <link
Jason Evans20c31de2014-10-02 23:01:10 -07002039 linkend="opt.lg_prof_sample"><mallctl>opt.lg_prof_sample</mallctl></link>
Jason Evansfc12c0b2014-10-03 23:25:30 -07002040 and <link
2041 linkend="prof.lg_sample"><mallctl>prof.lg_sample</mallctl></link>).
Jason Evans602c8e02014-08-18 16:22:13 -07002042 </para></listitem>
2043 </varlistentry>
2044
2045 <varlistentry id="prof.lg_sample">
2046 <term>
2047 <mallctl>prof.lg_sample</mallctl>
2048 (<type>size_t</type>)
2049 <literal>r-</literal>
2050 [<option>--enable-prof</option>]
2051 </term>
Jason Evans20c31de2014-10-02 23:01:10 -07002052 <listitem><para>Get the current sample rate (see <link
Jason Evans602c8e02014-08-18 16:22:13 -07002053 linkend="opt.lg_prof_sample"><mallctl>opt.lg_prof_sample</mallctl></link>).
2054 </para></listitem>
2055 </varlistentry>
2056
Jason Evansaabaf852013-10-30 14:52:09 -07002057 <varlistentry id="prof.interval">
Jason Evansaee7fd22010-11-24 22:00:02 -08002058 <term>
2059 <mallctl>prof.interval</mallctl>
2060 (<type>uint64_t</type>)
2061 <literal>r-</literal>
2062 [<option>--enable-prof</option>]
2063 </term>
2064 <listitem><para>Average number of bytes allocated between
2065 inverval-based profile dumps. See the
2066 <link
2067 linkend="opt.lg_prof_interval"><mallctl>opt.lg_prof_interval</mallctl></link>
2068 option for additional information.</para></listitem>
2069 </varlistentry>
2070
Jason Evans0657f122011-03-18 17:56:14 -07002071 <varlistentry id="stats.cactive">
2072 <term>
2073 <mallctl>stats.cactive</mallctl>
2074 (<type>size_t *</type>)
2075 <literal>r-</literal>
2076 [<option>--enable-stats</option>]
2077 </term>
2078 <listitem><para>Pointer to a counter that contains an approximate count
2079 of the current number of bytes in active pages. The estimate may be
Jason Evans9b41ac92014-10-14 22:20:00 -07002080 high, but never low, because each arena rounds up when computing its
2081 contribution to the counter. Note that the <link
Jason Evans0657f122011-03-18 17:56:14 -07002082 linkend="epoch"><mallctl>epoch</mallctl></link> mallctl has no bearing
2083 on this counter. Furthermore, counter consistency is maintained via
2084 atomic operations, so it is necessary to use an atomic operation in
2085 order to guarantee a consistent read when dereferencing the pointer.
2086 </para></listitem>
2087 </varlistentry>
2088
Jason Evansaee7fd22010-11-24 22:00:02 -08002089 <varlistentry id="stats.allocated">
2090 <term>
2091 <mallctl>stats.allocated</mallctl>
2092 (<type>size_t</type>)
2093 <literal>r-</literal>
2094 [<option>--enable-stats</option>]
2095 </term>
2096 <listitem><para>Total number of bytes allocated by the
2097 application.</para></listitem>
2098 </varlistentry>
2099
2100 <varlistentry id="stats.active">
2101 <term>
2102 <mallctl>stats.active</mallctl>
2103 (<type>size_t</type>)
2104 <literal>r-</literal>
2105 [<option>--enable-stats</option>]
2106 </term>
2107 <listitem><para>Total number of bytes in active pages allocated by the
2108 application. This is a multiple of the page size, and greater than or
2109 equal to <link
2110 linkend="stats.allocated"><mallctl>stats.allocated</mallctl></link>.
Jan Beiched90c972012-10-18 00:06:32 +04002111 This does not include <link linkend="stats.arenas.i.pdirty">
Jason Evanscbf3a6d2015-02-11 12:24:27 -08002112 <mallctl>stats.arenas.&lt;i&gt;.pdirty</mallctl></link>, nor pages
Jan Beiched90c972012-10-18 00:06:32 +04002113 entirely devoted to allocator metadata.</para></listitem>
Jason Evansaee7fd22010-11-24 22:00:02 -08002114 </varlistentry>
2115
Jason Evans4581b972014-11-27 17:22:36 -02002116 <varlistentry id="stats.metadata">
2117 <term>
2118 <mallctl>stats.metadata</mallctl>
2119 (<type>size_t</type>)
2120 <literal>r-</literal>
2121 [<option>--enable-stats</option>]
2122 </term>
2123 <listitem><para>Total number of bytes dedicated to metadata, which
2124 comprise base allocations used for bootstrap-sensitive internal
2125 allocator data structures, arena chunk headers (see <link
2126 linkend="stats.arenas.i.metadata.mapped"><mallctl>stats.arenas.&lt;i&gt;.metadata.mapped</mallctl></link>),
2127 and internal allocations (see <link
2128 linkend="stats.arenas.i.metadata.allocated"><mallctl>stats.arenas.&lt;i&gt;.metadata.allocated</mallctl></link>).</para></listitem>
2129 </varlistentry>
2130
Jason Evans4acd75a2015-03-23 17:25:57 -07002131 <varlistentry id="stats.resident">
2132 <term>
2133 <mallctl>stats.resident</mallctl>
2134 (<type>size_t</type>)
2135 <literal>r-</literal>
2136 [<option>--enable-stats</option>]
2137 </term>
2138 <listitem><para>Maximum number of bytes in physically resident data
2139 pages mapped by the allocator, comprising all pages dedicated to
2140 allocator metadata, pages backing active allocations, and unused dirty
2141 pages. This is a maximum rather than precise because pages may not
2142 actually be physically resident if they correspond to demand-zeroed
2143 virtual memory that has not yet been touched. This is a multiple of the
2144 page size, and is larger than <link
2145 linkend="stats.active"><mallctl>stats.active</mallctl></link>.</para></listitem>
2146 </varlistentry>
2147
Jason Evansaabaf852013-10-30 14:52:09 -07002148 <varlistentry id="stats.mapped">
Jason Evansaee7fd22010-11-24 22:00:02 -08002149 <term>
2150 <mallctl>stats.mapped</mallctl>
2151 (<type>size_t</type>)
2152 <literal>r-</literal>
2153 [<option>--enable-stats</option>]
2154 </term>
Jason Evans4acd75a2015-03-23 17:25:57 -07002155 <listitem><para>Total number of bytes in active chunks mapped by the
Jason Evans56048ba2015-05-28 15:03:58 -07002156 allocator. This is a multiple of the chunk size, and is larger than
2157 <link linkend="stats.active"><mallctl>stats.active</mallctl></link>.
2158 This does not include inactive chunks, even those that contain unused
2159 dirty pages, which means that there is no strict ordering between this
2160 and <link
2161 linkend="stats.resident"><mallctl>stats.resident</mallctl></link>.</para></listitem>
Jason Evansaee7fd22010-11-24 22:00:02 -08002162 </varlistentry>
2163
Jason Evansaabaf852013-10-30 14:52:09 -07002164 <varlistentry id="stats.arenas.i.dss">
Jason Evansaee7fd22010-11-24 22:00:02 -08002165 <term>
Jason Evans609ae592012-10-11 13:53:15 -07002166 <mallctl>stats.arenas.&lt;i&gt;.dss</mallctl>
2167 (<type>const char *</type>)
2168 <literal>r-</literal>
2169 </term>
2170 <listitem><para>dss (<citerefentry><refentrytitle>sbrk</refentrytitle>
2171 <manvolnum>2</manvolnum></citerefentry>) allocation precedence as
2172 related to <citerefentry><refentrytitle>mmap</refentrytitle>
2173 <manvolnum>2</manvolnum></citerefentry> allocation. See <link
2174 linkend="opt.dss"><mallctl>opt.dss</mallctl></link> for details.
2175 </para></listitem>
2176 </varlistentry>
2177
Jason Evans562d2662015-03-24 16:36:12 -07002178 <varlistentry id="stats.arenas.i.lg_dirty_mult">
2179 <term>
2180 <mallctl>stats.arenas.&lt;i&gt;.lg_dirty_mult</mallctl>
2181 (<type>ssize_t</type>)
2182 <literal>r-</literal>
2183 </term>
2184 <listitem><para>Minimum ratio (log base 2) of active to dirty pages.
2185 See <link
2186 linkend="opt.lg_dirty_mult"><mallctl>opt.lg_dirty_mult</mallctl></link>
2187 for details.</para></listitem>
2188 </varlistentry>
2189
Christopher Ferrise4294032016-03-02 14:33:02 -08002190 <varlistentry id="stats.arenas.i.decay_time">
2191 <term>
2192 <mallctl>stats.arenas.&lt;i&gt;.decay_time</mallctl>
2193 (<type>ssize_t</type>)
2194 <literal>r-</literal>
2195 </term>
2196 <listitem><para>Approximate time in seconds from the creation of a set
2197 of unused dirty pages until an equivalent set of unused dirty pages is
2198 purged and/or reused. See <link
2199 linkend="opt.decay_time"><mallctl>opt.decay_time</mallctl></link>
2200 for details.</para></listitem>
2201 </varlistentry>
2202
Jason Evansaabaf852013-10-30 14:52:09 -07002203 <varlistentry id="stats.arenas.i.nthreads">
Jason Evans609ae592012-10-11 13:53:15 -07002204 <term>
Jason Evans597632b2011-03-18 13:41:33 -07002205 <mallctl>stats.arenas.&lt;i&gt;.nthreads</mallctl>
2206 (<type>unsigned</type>)
2207 <literal>r-</literal>
2208 </term>
2209 <listitem><para>Number of threads currently assigned to
2210 arena.</para></listitem>
2211 </varlistentry>
2212
Jason Evansaabaf852013-10-30 14:52:09 -07002213 <varlistentry id="stats.arenas.i.pactive">
Jason Evans597632b2011-03-18 13:41:33 -07002214 <term>
Jason Evansaee7fd22010-11-24 22:00:02 -08002215 <mallctl>stats.arenas.&lt;i&gt;.pactive</mallctl>
2216 (<type>size_t</type>)
2217 <literal>r-</literal>
2218 </term>
2219 <listitem><para>Number of pages in active runs.</para></listitem>
2220 </varlistentry>
2221
Jan Beiched90c972012-10-18 00:06:32 +04002222 <varlistentry id="stats.arenas.i.pdirty">
Jason Evansaee7fd22010-11-24 22:00:02 -08002223 <term>
2224 <mallctl>stats.arenas.&lt;i&gt;.pdirty</mallctl>
2225 (<type>size_t</type>)
2226 <literal>r-</literal>
2227 </term>
2228 <listitem><para>Number of pages within unused runs that are potentially
2229 dirty, and for which <function>madvise<parameter>...</parameter>
2230 <parameter><constant>MADV_DONTNEED</constant></parameter></function> or
2231 similar has not been called.</para></listitem>
2232 </varlistentry>
2233
Jason Evansaabaf852013-10-30 14:52:09 -07002234 <varlistentry id="stats.arenas.i.mapped">
Jason Evansaee7fd22010-11-24 22:00:02 -08002235 <term>
2236 <mallctl>stats.arenas.&lt;i&gt;.mapped</mallctl>
2237 (<type>size_t</type>)
2238 <literal>r-</literal>
2239 [<option>--enable-stats</option>]
2240 </term>
2241 <listitem><para>Number of mapped bytes.</para></listitem>
2242 </varlistentry>
2243
Jason Evans4581b972014-11-27 17:22:36 -02002244 <varlistentry id="stats.arenas.i.metadata.mapped">
2245 <term>
2246 <mallctl>stats.arenas.&lt;i&gt;.metadata.mapped</mallctl>
2247 (<type>size_t</type>)
2248 <literal>r-</literal>
2249 [<option>--enable-stats</option>]
2250 </term>
2251 <listitem><para>Number of mapped bytes in arena chunk headers, which
2252 track the states of the non-metadata pages.</para></listitem>
2253 </varlistentry>
2254
2255 <varlistentry id="stats.arenas.i.metadata.allocated">
2256 <term>
2257 <mallctl>stats.arenas.&lt;i&gt;.metadata.allocated</mallctl>
2258 (<type>size_t</type>)
2259 <literal>r-</literal>
2260 [<option>--enable-stats</option>]
2261 </term>
2262 <listitem><para>Number of bytes dedicated to internal allocations.
2263 Internal allocations differ from application-originated allocations in
2264 that they are for internal use, and that they are omitted from heap
2265 profiles. This statistic is reported separately from <link
2266 linkend="stats.metadata"><mallctl>stats.metadata</mallctl></link> and
2267 <link
2268 linkend="stats.arenas.i.metadata.mapped"><mallctl>stats.arenas.&lt;i&gt;.metadata.mapped</mallctl></link>
2269 because it overlaps with e.g. the <link
2270 linkend="stats.allocated"><mallctl>stats.allocated</mallctl></link> and
2271 <link linkend="stats.active"><mallctl>stats.active</mallctl></link>
2272 statistics, whereas the other metadata statistics do
2273 not.</para></listitem>
2274 </varlistentry>
2275
Jason Evansaabaf852013-10-30 14:52:09 -07002276 <varlistentry id="stats.arenas.i.npurge">
Jason Evansaee7fd22010-11-24 22:00:02 -08002277 <term>
2278 <mallctl>stats.arenas.&lt;i&gt;.npurge</mallctl>
2279 (<type>uint64_t</type>)
2280 <literal>r-</literal>
2281 [<option>--enable-stats</option>]
2282 </term>
2283 <listitem><para>Number of dirty page purge sweeps performed.
2284 </para></listitem>
2285 </varlistentry>
2286
Jason Evansaabaf852013-10-30 14:52:09 -07002287 <varlistentry id="stats.arenas.i.nmadvise">
Jason Evansaee7fd22010-11-24 22:00:02 -08002288 <term>
2289 <mallctl>stats.arenas.&lt;i&gt;.nmadvise</mallctl>
2290 (<type>uint64_t</type>)
2291 <literal>r-</literal>
2292 [<option>--enable-stats</option>]
2293 </term>
2294 <listitem><para>Number of <function>madvise<parameter>...</parameter>
2295 <parameter><constant>MADV_DONTNEED</constant></parameter></function> or
2296 similar calls made to purge dirty pages.</para></listitem>
2297 </varlistentry>
2298
Jason Evansd8a39002013-12-19 21:40:41 -08002299 <varlistentry id="stats.arenas.i.purged">
Jason Evansaee7fd22010-11-24 22:00:02 -08002300 <term>
Jason Evansd8a39002013-12-19 21:40:41 -08002301 <mallctl>stats.arenas.&lt;i&gt;.purged</mallctl>
Jason Evansaee7fd22010-11-24 22:00:02 -08002302 (<type>uint64_t</type>)
2303 <literal>r-</literal>
2304 [<option>--enable-stats</option>]
2305 </term>
2306 <listitem><para>Number of pages purged.</para></listitem>
2307 </varlistentry>
2308
Jason Evansaabaf852013-10-30 14:52:09 -07002309 <varlistentry id="stats.arenas.i.small.allocated">
Jason Evansaee7fd22010-11-24 22:00:02 -08002310 <term>
2311 <mallctl>stats.arenas.&lt;i&gt;.small.allocated</mallctl>
2312 (<type>size_t</type>)
2313 <literal>r-</literal>
2314 [<option>--enable-stats</option>]
2315 </term>
2316 <listitem><para>Number of bytes currently allocated by small objects.
2317 </para></listitem>
2318 </varlistentry>
2319
Jason Evansaabaf852013-10-30 14:52:09 -07002320 <varlistentry id="stats.arenas.i.small.nmalloc">
Jason Evansaee7fd22010-11-24 22:00:02 -08002321 <term>
2322 <mallctl>stats.arenas.&lt;i&gt;.small.nmalloc</mallctl>
2323 (<type>uint64_t</type>)
2324 <literal>r-</literal>
2325 [<option>--enable-stats</option>]
2326 </term>
2327 <listitem><para>Cumulative number of allocation requests served by
2328 small bins.</para></listitem>
2329 </varlistentry>
2330
Jason Evansaabaf852013-10-30 14:52:09 -07002331 <varlistentry id="stats.arenas.i.small.ndalloc">
Jason Evansaee7fd22010-11-24 22:00:02 -08002332 <term>
2333 <mallctl>stats.arenas.&lt;i&gt;.small.ndalloc</mallctl>
2334 (<type>uint64_t</type>)
2335 <literal>r-</literal>
2336 [<option>--enable-stats</option>]
2337 </term>
2338 <listitem><para>Cumulative number of small objects returned to bins.
2339 </para></listitem>
2340 </varlistentry>
2341
Jason Evansaabaf852013-10-30 14:52:09 -07002342 <varlistentry id="stats.arenas.i.small.nrequests">
Jason Evansaee7fd22010-11-24 22:00:02 -08002343 <term>
2344 <mallctl>stats.arenas.&lt;i&gt;.small.nrequests</mallctl>
2345 (<type>uint64_t</type>)
2346 <literal>r-</literal>
2347 [<option>--enable-stats</option>]
2348 </term>
2349 <listitem><para>Cumulative number of small allocation requests.
2350 </para></listitem>
2351 </varlistentry>
2352
Jason Evansaabaf852013-10-30 14:52:09 -07002353 <varlistentry id="stats.arenas.i.large.allocated">
Jason Evansaee7fd22010-11-24 22:00:02 -08002354 <term>
2355 <mallctl>stats.arenas.&lt;i&gt;.large.allocated</mallctl>
2356 (<type>size_t</type>)
2357 <literal>r-</literal>
2358 [<option>--enable-stats</option>]
2359 </term>
2360 <listitem><para>Number of bytes currently allocated by large objects.
2361 </para></listitem>
2362 </varlistentry>
2363
Jason Evansaabaf852013-10-30 14:52:09 -07002364 <varlistentry id="stats.arenas.i.large.nmalloc">
Jason Evansaee7fd22010-11-24 22:00:02 -08002365 <term>
2366 <mallctl>stats.arenas.&lt;i&gt;.large.nmalloc</mallctl>
2367 (<type>uint64_t</type>)
2368 <literal>r-</literal>
2369 [<option>--enable-stats</option>]
2370 </term>
2371 <listitem><para>Cumulative number of large allocation requests served
2372 directly by the arena.</para></listitem>
2373 </varlistentry>
2374
Jason Evansaabaf852013-10-30 14:52:09 -07002375 <varlistentry id="stats.arenas.i.large.ndalloc">
Jason Evansaee7fd22010-11-24 22:00:02 -08002376 <term>
2377 <mallctl>stats.arenas.&lt;i&gt;.large.ndalloc</mallctl>
2378 (<type>uint64_t</type>)
2379 <literal>r-</literal>
2380 [<option>--enable-stats</option>]
2381 </term>
2382 <listitem><para>Cumulative number of large deallocation requests served
2383 directly by the arena.</para></listitem>
2384 </varlistentry>
2385
Jason Evansaabaf852013-10-30 14:52:09 -07002386 <varlistentry id="stats.arenas.i.large.nrequests">
Jason Evansaee7fd22010-11-24 22:00:02 -08002387 <term>
2388 <mallctl>stats.arenas.&lt;i&gt;.large.nrequests</mallctl>
2389 (<type>uint64_t</type>)
2390 <literal>r-</literal>
2391 [<option>--enable-stats</option>]
2392 </term>
2393 <listitem><para>Cumulative number of large allocation requests.
2394 </para></listitem>
2395 </varlistentry>
2396
Jason Evanse2deab72014-05-15 22:22:27 -07002397 <varlistentry id="stats.arenas.i.huge.allocated">
2398 <term>
2399 <mallctl>stats.arenas.&lt;i&gt;.huge.allocated</mallctl>
2400 (<type>size_t</type>)
2401 <literal>r-</literal>
2402 [<option>--enable-stats</option>]
2403 </term>
2404 <listitem><para>Number of bytes currently allocated by huge objects.
2405 </para></listitem>
2406 </varlistentry>
2407
2408 <varlistentry id="stats.arenas.i.huge.nmalloc">
2409 <term>
2410 <mallctl>stats.arenas.&lt;i&gt;.huge.nmalloc</mallctl>
2411 (<type>uint64_t</type>)
2412 <literal>r-</literal>
2413 [<option>--enable-stats</option>]
2414 </term>
2415 <listitem><para>Cumulative number of huge allocation requests served
2416 directly by the arena.</para></listitem>
2417 </varlistentry>
2418
2419 <varlistentry id="stats.arenas.i.huge.ndalloc">
2420 <term>
2421 <mallctl>stats.arenas.&lt;i&gt;.huge.ndalloc</mallctl>
2422 (<type>uint64_t</type>)
2423 <literal>r-</literal>
2424 [<option>--enable-stats</option>]
2425 </term>
2426 <listitem><para>Cumulative number of huge deallocation requests served
2427 directly by the arena.</para></listitem>
2428 </varlistentry>
2429
2430 <varlistentry id="stats.arenas.i.huge.nrequests">
2431 <term>
2432 <mallctl>stats.arenas.&lt;i&gt;.huge.nrequests</mallctl>
2433 (<type>uint64_t</type>)
2434 <literal>r-</literal>
2435 [<option>--enable-stats</option>]
2436 </term>
2437 <listitem><para>Cumulative number of huge allocation requests.
2438 </para></listitem>
2439 </varlistentry>
2440
Jason Evansaabaf852013-10-30 14:52:09 -07002441 <varlistentry id="stats.arenas.i.bins.j.nmalloc">
Jason Evansaee7fd22010-11-24 22:00:02 -08002442 <term>
2443 <mallctl>stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.nmalloc</mallctl>
2444 (<type>uint64_t</type>)
2445 <literal>r-</literal>
2446 [<option>--enable-stats</option>]
2447 </term>
2448 <listitem><para>Cumulative number of allocations served by bin.
2449 </para></listitem>
2450 </varlistentry>
2451
Jason Evansaabaf852013-10-30 14:52:09 -07002452 <varlistentry id="stats.arenas.i.bins.j.ndalloc">
Jason Evansaee7fd22010-11-24 22:00:02 -08002453 <term>
2454 <mallctl>stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.ndalloc</mallctl>
2455 (<type>uint64_t</type>)
2456 <literal>r-</literal>
2457 [<option>--enable-stats</option>]
2458 </term>
2459 <listitem><para>Cumulative number of allocations returned to bin.
2460 </para></listitem>
2461 </varlistentry>
2462
Jason Evansaabaf852013-10-30 14:52:09 -07002463 <varlistentry id="stats.arenas.i.bins.j.nrequests">
Jason Evansaee7fd22010-11-24 22:00:02 -08002464 <term>
2465 <mallctl>stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.nrequests</mallctl>
2466 (<type>uint64_t</type>)
2467 <literal>r-</literal>
2468 [<option>--enable-stats</option>]
2469 </term>
2470 <listitem><para>Cumulative number of allocation
2471 requests.</para></listitem>
2472 </varlistentry>
2473
Jason Evans3c4d92e2014-10-12 22:53:59 -07002474 <varlistentry id="stats.arenas.i.bins.j.curregs">
2475 <term>
2476 <mallctl>stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.curregs</mallctl>
2477 (<type>size_t</type>)
2478 <literal>r-</literal>
2479 [<option>--enable-stats</option>]
2480 </term>
2481 <listitem><para>Current number of regions for this size
2482 class.</para></listitem>
2483 </varlistentry>
2484
Jason Evansaabaf852013-10-30 14:52:09 -07002485 <varlistentry id="stats.arenas.i.bins.j.nfills">
Jason Evansaee7fd22010-11-24 22:00:02 -08002486 <term>
2487 <mallctl>stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.nfills</mallctl>
2488 (<type>uint64_t</type>)
2489 <literal>r-</literal>
2490 [<option>--enable-stats</option> <option>--enable-tcache</option>]
2491 </term>
2492 <listitem><para>Cumulative number of tcache fills.</para></listitem>
2493 </varlistentry>
2494
Jason Evansaabaf852013-10-30 14:52:09 -07002495 <varlistentry id="stats.arenas.i.bins.j.nflushes">
Jason Evansaee7fd22010-11-24 22:00:02 -08002496 <term>
2497 <mallctl>stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.nflushes</mallctl>
2498 (<type>uint64_t</type>)
2499 <literal>r-</literal>
2500 [<option>--enable-stats</option> <option>--enable-tcache</option>]
2501 </term>
2502 <listitem><para>Cumulative number of tcache flushes.</para></listitem>
2503 </varlistentry>
2504
Jason Evansaabaf852013-10-30 14:52:09 -07002505 <varlistentry id="stats.arenas.i.bins.j.nruns">
Jason Evansaee7fd22010-11-24 22:00:02 -08002506 <term>
2507 <mallctl>stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.nruns</mallctl>
2508 (<type>uint64_t</type>)
2509 <literal>r-</literal>
2510 [<option>--enable-stats</option>]
2511 </term>
2512 <listitem><para>Cumulative number of runs created.</para></listitem>
2513 </varlistentry>
2514
Jason Evansaabaf852013-10-30 14:52:09 -07002515 <varlistentry id="stats.arenas.i.bins.j.nreruns">
Jason Evansaee7fd22010-11-24 22:00:02 -08002516 <term>
2517 <mallctl>stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.nreruns</mallctl>
2518 (<type>uint64_t</type>)
2519 <literal>r-</literal>
2520 [<option>--enable-stats</option>]
2521 </term>
2522 <listitem><para>Cumulative number of times the current run from which
2523 to allocate changed.</para></listitem>
2524 </varlistentry>
2525
Jason Evansaabaf852013-10-30 14:52:09 -07002526 <varlistentry id="stats.arenas.i.bins.j.curruns">
Jason Evansaee7fd22010-11-24 22:00:02 -08002527 <term>
Jason Evansaee7fd22010-11-24 22:00:02 -08002528 <mallctl>stats.arenas.&lt;i&gt;.bins.&lt;j&gt;.curruns</mallctl>
2529 (<type>size_t</type>)
2530 <literal>r-</literal>
2531 [<option>--enable-stats</option>]
2532 </term>
2533 <listitem><para>Current number of runs.</para></listitem>
2534 </varlistentry>
2535
Jason Evansaabaf852013-10-30 14:52:09 -07002536 <varlistentry id="stats.arenas.i.lruns.j.nmalloc">
Jason Evansaee7fd22010-11-24 22:00:02 -08002537 <term>
2538 <mallctl>stats.arenas.&lt;i&gt;.lruns.&lt;j&gt;.nmalloc</mallctl>
2539 (<type>uint64_t</type>)
2540 <literal>r-</literal>
2541 [<option>--enable-stats</option>]
2542 </term>
2543 <listitem><para>Cumulative number of allocation requests for this size
2544 class served directly by the arena.</para></listitem>
2545 </varlistentry>
2546
Jason Evansaabaf852013-10-30 14:52:09 -07002547 <varlistentry id="stats.arenas.i.lruns.j.ndalloc">
Jason Evansaee7fd22010-11-24 22:00:02 -08002548 <term>
2549 <mallctl>stats.arenas.&lt;i&gt;.lruns.&lt;j&gt;.ndalloc</mallctl>
2550 (<type>uint64_t</type>)
2551 <literal>r-</literal>
2552 [<option>--enable-stats</option>]
2553 </term>
2554 <listitem><para>Cumulative number of deallocation requests for this
2555 size class served directly by the arena.</para></listitem>
2556 </varlistentry>
2557
Jason Evansaabaf852013-10-30 14:52:09 -07002558 <varlistentry id="stats.arenas.i.lruns.j.nrequests">
Jason Evansaee7fd22010-11-24 22:00:02 -08002559 <term>
2560 <mallctl>stats.arenas.&lt;i&gt;.lruns.&lt;j&gt;.nrequests</mallctl>
2561 (<type>uint64_t</type>)
2562 <literal>r-</literal>
2563 [<option>--enable-stats</option>]
2564 </term>
2565 <listitem><para>Cumulative number of allocation requests for this size
2566 class.</para></listitem>
2567 </varlistentry>
2568
Jason Evansaabaf852013-10-30 14:52:09 -07002569 <varlistentry id="stats.arenas.i.lruns.j.curruns">
Jason Evansaee7fd22010-11-24 22:00:02 -08002570 <term>
Jason Evansaee7fd22010-11-24 22:00:02 -08002571 <mallctl>stats.arenas.&lt;i&gt;.lruns.&lt;j&gt;.curruns</mallctl>
2572 (<type>size_t</type>)
2573 <literal>r-</literal>
2574 [<option>--enable-stats</option>]
2575 </term>
2576 <listitem><para>Current number of runs for this size class.
2577 </para></listitem>
2578 </varlistentry>
Jason Evans3c4d92e2014-10-12 22:53:59 -07002579
2580 <varlistentry id="stats.arenas.i.hchunks.j.nmalloc">
2581 <term>
2582 <mallctl>stats.arenas.&lt;i&gt;.hchunks.&lt;j&gt;.nmalloc</mallctl>
2583 (<type>uint64_t</type>)
2584 <literal>r-</literal>
2585 [<option>--enable-stats</option>]
2586 </term>
2587 <listitem><para>Cumulative number of allocation requests for this size
2588 class served directly by the arena.</para></listitem>
2589 </varlistentry>
2590
2591 <varlistentry id="stats.arenas.i.hchunks.j.ndalloc">
2592 <term>
2593 <mallctl>stats.arenas.&lt;i&gt;.hchunks.&lt;j&gt;.ndalloc</mallctl>
2594 (<type>uint64_t</type>)
2595 <literal>r-</literal>
2596 [<option>--enable-stats</option>]
2597 </term>
2598 <listitem><para>Cumulative number of deallocation requests for this
2599 size class served directly by the arena.</para></listitem>
2600 </varlistentry>
2601
2602 <varlistentry id="stats.arenas.i.hchunks.j.nrequests">
2603 <term>
2604 <mallctl>stats.arenas.&lt;i&gt;.hchunks.&lt;j&gt;.nrequests</mallctl>
2605 (<type>uint64_t</type>)
2606 <literal>r-</literal>
2607 [<option>--enable-stats</option>]
2608 </term>
2609 <listitem><para>Cumulative number of allocation requests for this size
2610 class.</para></listitem>
2611 </varlistentry>
2612
2613 <varlistentry id="stats.arenas.i.hchunks.j.curhchunks">
2614 <term>
2615 <mallctl>stats.arenas.&lt;i&gt;.hchunks.&lt;j&gt;.curhchunks</mallctl>
2616 (<type>size_t</type>)
2617 <literal>r-</literal>
2618 [<option>--enable-stats</option>]
2619 </term>
2620 <listitem><para>Current number of huge allocations for this size class.
2621 </para></listitem>
2622 </varlistentry>
Jason Evansaee7fd22010-11-24 22:00:02 -08002623 </variablelist>
2624 </refsect1>
Christopher Ferrise4294032016-03-02 14:33:02 -08002625 <refsect1 id="heap_profile_format">
2626 <title>HEAP PROFILE FORMAT</title>
2627 <para>Although the heap profiling functionality was originally designed to
2628 be compatible with the
2629 <command>pprof</command> command that is developed as part of the <ulink
2630 url="http://code.google.com/p/gperftools/">gperftools
2631 package</ulink>, the addition of per thread heap profiling functionality
2632 required a different heap profile format. The <command>jeprof</command>
2633 command is derived from <command>pprof</command>, with enhancements to
2634 support the heap profile format described here.</para>
2635
2636 <para>In the following hypothetical heap profile, <constant>[...]</constant>
2637 indicates elision for the sake of compactness. <programlisting><![CDATA[
2638heap_v2/524288
2639 t*: 28106: 56637512 [0: 0]
2640 [...]
2641 t3: 352: 16777344 [0: 0]
2642 [...]
2643 t99: 17754: 29341640 [0: 0]
2644 [...]
2645@ 0x5f86da8 0x5f5a1dc [...] 0x29e4d4e 0xa200316 0xabb2988 [...]
2646 t*: 13: 6688 [0: 0]
2647 t3: 12: 6496 [0: ]
2648 t99: 1: 192 [0: 0]
2649[...]
2650
2651MAPPED_LIBRARIES:
2652[...]]]></programlisting> The following matches the above heap profile, but most
2653tokens are replaced with <constant>&lt;description&gt;</constant> to indicate
2654descriptions of the corresponding fields. <programlisting><![CDATA[
2655<heap_profile_format_version>/<mean_sample_interval>
2656 <aggregate>: <curobjs>: <curbytes> [<cumobjs>: <cumbytes>]
2657 [...]
2658 <thread_3_aggregate>: <curobjs>: <curbytes>[<cumobjs>: <cumbytes>]
2659 [...]
2660 <thread_99_aggregate>: <curobjs>: <curbytes>[<cumobjs>: <cumbytes>]
2661 [...]
2662@ <top_frame> <frame> [...] <frame> <frame> <frame> [...]
2663 <backtrace_aggregate>: <curobjs>: <curbytes> [<cumobjs>: <cumbytes>]
2664 <backtrace_thread_3>: <curobjs>: <curbytes> [<cumobjs>: <cumbytes>]
2665 <backtrace_thread_99>: <curobjs>: <curbytes> [<cumobjs>: <cumbytes>]
2666[...]
2667
2668MAPPED_LIBRARIES:
2669</proc/<pid>/maps>]]></programlisting></para>
2670 </refsect1>
2671
Jason Evansaee7fd22010-11-24 22:00:02 -08002672 <refsect1 id="debugging_malloc_problems">
2673 <title>DEBUGGING MALLOC PROBLEMS</title>
2674 <para>When debugging, it is a good idea to configure/build jemalloc with
2675 the <option>--enable-debug</option> and <option>--enable-fill</option>
2676 options, and recompile the program with suitable options and symbols for
2677 debugger support. When so configured, jemalloc incorporates a wide variety
2678 of run-time assertions that catch application errors such as double-free,
2679 write-after-free, etc.</para>
2680
2681 <para>Programs often accidentally depend on &ldquo;uninitialized&rdquo;
2682 memory actually being filled with zero bytes. Junk filling
2683 (see the <link linkend="opt.junk"><mallctl>opt.junk</mallctl></link>
2684 option) tends to expose such bugs in the form of obviously incorrect
2685 results and/or coredumps. Conversely, zero
2686 filling (see the <link
2687 linkend="opt.zero"><mallctl>opt.zero</mallctl></link> option) eliminates
2688 the symptoms of such bugs. Between these two options, it is usually
2689 possible to quickly detect, diagnose, and eliminate such bugs.</para>
2690
2691 <para>This implementation does not provide much detail about the problems
2692 it detects, because the performance impact for storing such information
Jason Evans122449b2012-04-06 00:35:09 -07002693 would be prohibitive. However, jemalloc does integrate with the most
Jason Evansd926c902012-04-25 23:17:57 -07002694 excellent <ulink url="http://valgrind.org/">Valgrind</ulink> tool if the
Jason Evans781fe752012-05-15 14:48:14 -07002695 <option>--enable-valgrind</option> configuration option is enabled.</para>
Jason Evansaee7fd22010-11-24 22:00:02 -08002696 </refsect1>
2697 <refsect1 id="diagnostic_messages">
2698 <title>DIAGNOSTIC MESSAGES</title>
2699 <para>If any of the memory allocation/deallocation functions detect an
2700 error or warning condition, a message will be printed to file descriptor
2701 <constant>STDERR_FILENO</constant>. Errors will result in the process
2702 dumping core. If the <link
2703 linkend="opt.abort"><mallctl>opt.abort</mallctl></link> option is set, most
2704 warnings are treated as errors.</para>
2705
2706 <para>The <varname>malloc_message</varname> variable allows the programmer
2707 to override the function which emits the text strings forming the errors
2708 and warnings if for some reason the <constant>STDERR_FILENO</constant> file
2709 descriptor is not suitable for this.
2710 <function>malloc_message<parameter/></function> takes the
2711 <parameter>cbopaque</parameter> pointer argument that is
2712 <constant>NULL</constant> unless overridden by the arguments in a call to
2713 <function>malloc_stats_print<parameter/></function>, followed by a string
2714 pointer. Please note that doing anything which tries to allocate memory in
2715 this function is likely to result in a crash or deadlock.</para>
2716
2717 <para>All messages are prefixed by
2718 &ldquo;<computeroutput>&lt;jemalloc&gt;: </computeroutput>&rdquo;.</para>
2719 </refsect1>
2720 <refsect1 id="return_values">
2721 <title>RETURN VALUES</title>
2722 <refsect2>
2723 <title>Standard API</title>
2724 <para>The <function>malloc<parameter/></function> and
2725 <function>calloc<parameter/></function> functions return a pointer to the
2726 allocated memory if successful; otherwise a <constant>NULL</constant>
2727 pointer is returned and <varname>errno</varname> is set to
2728 <errorname>ENOMEM</errorname>.</para>
2729
2730 <para>The <function>posix_memalign<parameter/></function> function
2731 returns the value 0 if successful; otherwise it returns an error value.
2732 The <function>posix_memalign<parameter/></function> function will fail
2733 if:
2734 <variablelist>
2735 <varlistentry>
2736 <term><errorname>EINVAL</errorname></term>
2737
2738 <listitem><para>The <parameter>alignment</parameter> parameter is
2739 not a power of 2 at least as large as
2740 <code language="C">sizeof(<type>void *</type>)</code>.
2741 </para></listitem>
2742 </varlistentry>
2743 <varlistentry>
2744 <term><errorname>ENOMEM</errorname></term>
2745
2746 <listitem><para>Memory allocation error.</para></listitem>
2747 </varlistentry>
2748 </variablelist>
2749 </para>
2750
Jason Evans0a0bbf62012-03-13 12:55:21 -07002751 <para>The <function>aligned_alloc<parameter/></function> function returns
2752 a pointer to the allocated memory if successful; otherwise a
2753 <constant>NULL</constant> pointer is returned and
2754 <varname>errno</varname> is set. The
2755 <function>aligned_alloc<parameter/></function> function will fail if:
2756 <variablelist>
2757 <varlistentry>
2758 <term><errorname>EINVAL</errorname></term>
2759
2760 <listitem><para>The <parameter>alignment</parameter> parameter is
2761 not a power of 2.
2762 </para></listitem>
2763 </varlistentry>
2764 <varlistentry>
2765 <term><errorname>ENOMEM</errorname></term>
2766
2767 <listitem><para>Memory allocation error.</para></listitem>
2768 </varlistentry>
2769 </variablelist>
2770 </para>
2771
Jason Evansaee7fd22010-11-24 22:00:02 -08002772 <para>The <function>realloc<parameter/></function> function returns a
2773 pointer, possibly identical to <parameter>ptr</parameter>, to the
2774 allocated memory if successful; otherwise a <constant>NULL</constant>
2775 pointer is returned, and <varname>errno</varname> is set to
2776 <errorname>ENOMEM</errorname> if the error was the result of an
2777 allocation failure. The <function>realloc<parameter/></function>
2778 function always leaves the original buffer intact when an error occurs.
2779 </para>
2780
2781 <para>The <function>free<parameter/></function> function returns no
2782 value.</para>
2783 </refsect2>
2784 <refsect2>
2785 <title>Non-standard API</title>
Jason Evansd82a5e62013-12-12 22:35:52 -08002786 <para>The <function>mallocx<parameter/></function> and
2787 <function>rallocx<parameter/></function> functions return a pointer to
2788 the allocated memory if successful; otherwise a <constant>NULL</constant>
2789 pointer is returned to indicate insufficient contiguous memory was
2790 available to service the allocation request. </para>
2791
2792 <para>The <function>xallocx<parameter/></function> function returns the
2793 real size of the resulting resized allocation pointed to by
2794 <parameter>ptr</parameter>, which is a value less than
2795 <parameter>size</parameter> if the allocation could not be adequately
2796 grown in place. </para>
2797
2798 <para>The <function>sallocx<parameter/></function> function returns the
2799 real size of the allocation pointed to by <parameter>ptr</parameter>.
2800 </para>
2801
2802 <para>The <function>nallocx<parameter/></function> returns the real size
2803 that would result from a successful equivalent
2804 <function>mallocx<parameter/></function> function call, or zero if
2805 insufficient memory is available to perform the size computation. </para>
Jason Evansaee7fd22010-11-24 22:00:02 -08002806
2807 <para>The <function>mallctl<parameter/></function>,
2808 <function>mallctlnametomib<parameter/></function>, and
2809 <function>mallctlbymib<parameter/></function> functions return 0 on
2810 success; otherwise they return an error value. The functions will fail
2811 if:
2812 <variablelist>
2813 <varlistentry>
2814 <term><errorname>EINVAL</errorname></term>
2815
2816 <listitem><para><parameter>newp</parameter> is not
2817 <constant>NULL</constant>, and <parameter>newlen</parameter> is too
2818 large or too small. Alternatively, <parameter>*oldlenp</parameter>
2819 is too large or too small; in this case as much data as possible
2820 are read despite the error.</para></listitem>
2821 </varlistentry>
2822 <varlistentry>
Jason Evansaee7fd22010-11-24 22:00:02 -08002823 <term><errorname>ENOENT</errorname></term>
2824
2825 <listitem><para><parameter>name</parameter> or
2826 <parameter>mib</parameter> specifies an unknown/invalid
2827 value.</para></listitem>
2828 </varlistentry>
2829 <varlistentry>
2830 <term><errorname>EPERM</errorname></term>
2831
2832 <listitem><para>Attempt to read or write void value, or attempt to
2833 write read-only value.</para></listitem>
2834 </varlistentry>
2835 <varlistentry>
2836 <term><errorname>EAGAIN</errorname></term>
2837
2838 <listitem><para>A memory allocation failure
2839 occurred.</para></listitem>
2840 </varlistentry>
2841 <varlistentry>
2842 <term><errorname>EFAULT</errorname></term>
2843
2844 <listitem><para>An interface with side effects failed in some way
2845 not directly related to <function>mallctl*<parameter/></function>
2846 read/write processing.</para></listitem>
2847 </varlistentry>
2848 </variablelist>
2849 </para>
Jason Evansd82a5e62013-12-12 22:35:52 -08002850
2851 <para>The <function>malloc_usable_size<parameter/></function> function
2852 returns the usable size of the allocation pointed to by
2853 <parameter>ptr</parameter>. </para>
Jason Evansaee7fd22010-11-24 22:00:02 -08002854 </refsect2>
Jason Evansaee7fd22010-11-24 22:00:02 -08002855 </refsect1>
2856 <refsect1 id="environment">
2857 <title>ENVIRONMENT</title>
2858 <para>The following environment variable affects the execution of the
2859 allocation functions:
2860 <variablelist>
2861 <varlistentry>
2862 <term><envar>MALLOC_CONF</envar></term>
2863
2864 <listitem><para>If the environment variable
2865 <envar>MALLOC_CONF</envar> is set, the characters it contains
2866 will be interpreted as options.</para></listitem>
2867 </varlistentry>
2868 </variablelist>
2869 </para>
2870 </refsect1>
2871 <refsect1 id="examples">
2872 <title>EXAMPLES</title>
2873 <para>To dump core whenever a problem occurs:
2874 <screen>ln -s 'abort:true' /etc/malloc.conf</screen>
2875 </para>
2876 <para>To specify in the source a chunk size that is 16 MiB:
2877 <programlisting language="C"><![CDATA[
2878malloc_conf = "lg_chunk:24";]]></programlisting></para>
2879 </refsect1>
2880 <refsect1 id="see_also">
2881 <title>SEE ALSO</title>
2882 <para><citerefentry><refentrytitle>madvise</refentrytitle>
2883 <manvolnum>2</manvolnum></citerefentry>,
2884 <citerefentry><refentrytitle>mmap</refentrytitle>
2885 <manvolnum>2</manvolnum></citerefentry>,
2886 <citerefentry><refentrytitle>sbrk</refentrytitle>
2887 <manvolnum>2</manvolnum></citerefentry>,
Jason Evansb1476112012-04-05 13:36:17 -07002888 <citerefentry><refentrytitle>utrace</refentrytitle>
2889 <manvolnum>2</manvolnum></citerefentry>,
Jason Evansaee7fd22010-11-24 22:00:02 -08002890 <citerefentry><refentrytitle>alloca</refentrytitle>
2891 <manvolnum>3</manvolnum></citerefentry>,
2892 <citerefentry><refentrytitle>atexit</refentrytitle>
2893 <manvolnum>3</manvolnum></citerefentry>,
2894 <citerefentry><refentrytitle>getpagesize</refentrytitle>
2895 <manvolnum>3</manvolnum></citerefentry></para>
2896 </refsect1>
2897 <refsect1 id="standards">
2898 <title>STANDARDS</title>
2899 <para>The <function>malloc<parameter/></function>,
2900 <function>calloc<parameter/></function>,
2901 <function>realloc<parameter/></function>, and
2902 <function>free<parameter/></function> functions conform to ISO/IEC
2903 9899:1990 (&ldquo;ISO C90&rdquo;).</para>
2904
2905 <para>The <function>posix_memalign<parameter/></function> function conforms
2906 to IEEE Std 1003.1-2001 (&ldquo;POSIX.1&rdquo;).</para>
2907 </refsect1>
2908</refentry>