1<?xml version="1.0" encoding="utf-8"?> 2<html><head><title>JEMALLOC</title><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot"/></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="refentry"><a name="idm46057389671552"/><div class="titlepage"/><div class="refnamediv"><h2>Name</h2><p>jemalloc — general purpose memory allocation functions</p></div><div class="refsect1"><a name="library"/><h2>LIBRARY</h2><p>This manual describes jemalloc 5.3.0-0-g54eaed1d8b56b1aa528be3bdd1877e59c56fa90c. More information 3 can be found at the <a class="ulink" href="http://jemalloc.net/" target="_top">jemalloc website</a>.</p></div><div class="refsynopsisdiv"><h2>SYNOPSIS</h2><div class="funcsynopsis"><pre class="funcsynopsisinfo">#include <<code class="filename">jemalloc/jemalloc.h</code>></pre><div class="refsect2"><a name="idm46057388074960"/><h3>Standard API</h3><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">void *<b class="fsfunc">malloc</b>(</code></td><td>size_t <var class="pdparam">size</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">void *<b class="fsfunc">calloc</b>(</code></td><td>size_t <var class="pdparam">number</var>, </td></tr><tr><td> </td><td>size_t <var class="pdparam">size</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">posix_memalign</b>(</code></td><td>void **<var class="pdparam">ptr</var>, </td></tr><tr><td> </td><td>size_t <var class="pdparam">alignment</var>, </td></tr><tr><td> </td><td>size_t <var class="pdparam">size</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">void *<b class="fsfunc">aligned_alloc</b>(</code></td><td>size_t <var class="pdparam">alignment</var>, </td></tr><tr><td> </td><td>size_t <var class="pdparam">size</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">void *<b class="fsfunc">realloc</b>(</code></td><td>void *<var class="pdparam">ptr</var>, </td></tr><tr><td> </td><td>size_t <var class="pdparam">size</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">void <b class="fsfunc">free</b>(</code></td><td>void *<var class="pdparam">ptr</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div><div class="refsect2"><a name="idm46057391291888"/><h3>Non-standard API</h3><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">void *<b class="fsfunc">mallocx</b>(</code></td><td>size_t <var class="pdparam">size</var>, </td></tr><tr><td> </td><td>int <var class="pdparam">flags</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">void *<b class="fsfunc">rallocx</b>(</code></td><td>void *<var class="pdparam">ptr</var>, </td></tr><tr><td> </td><td>size_t <var class="pdparam">size</var>, </td></tr><tr><td> </td><td>int <var class="pdparam">flags</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">size_t <b class="fsfunc">xallocx</b>(</code></td><td>void *<var class="pdparam">ptr</var>, </td></tr><tr><td> </td><td>size_t <var class="pdparam">size</var>, </td></tr><tr><td> </td><td>size_t <var class="pdparam">extra</var>, </td></tr><tr><td> </td><td>int <var class="pdparam">flags</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">size_t <b class="fsfunc">sallocx</b>(</code></td><td>void *<var class="pdparam">ptr</var>, </td></tr><tr><td> </td><td>int <var class="pdparam">flags</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">void <b class="fsfunc">dallocx</b>(</code></td><td>void *<var class="pdparam">ptr</var>, </td></tr><tr><td> </td><td>int <var class="pdparam">flags</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">void <b class="fsfunc">sdallocx</b>(</code></td><td>void *<var class="pdparam">ptr</var>, </td></tr><tr><td> </td><td>size_t <var class="pdparam">size</var>, </td></tr><tr><td> </td><td>int <var class="pdparam">flags</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">size_t <b class="fsfunc">nallocx</b>(</code></td><td>size_t <var class="pdparam">size</var>, </td></tr><tr><td> </td><td>int <var class="pdparam">flags</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">mallctl</b>(</code></td><td>const char *<var class="pdparam">name</var>, </td></tr><tr><td> </td><td>void *<var class="pdparam">oldp</var>, </td></tr><tr><td> </td><td>size_t *<var class="pdparam">oldlenp</var>, </td></tr><tr><td> </td><td>void *<var class="pdparam">newp</var>, </td></tr><tr><td> </td><td>size_t <var class="pdparam">newlen</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">mallctlnametomib</b>(</code></td><td>const char *<var class="pdparam">name</var>, </td></tr><tr><td> </td><td>size_t *<var class="pdparam">mibp</var>, </td></tr><tr><td> </td><td>size_t *<var class="pdparam">miblenp</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">mallctlbymib</b>(</code></td><td>const size_t *<var class="pdparam">mib</var>, </td></tr><tr><td> </td><td>size_t <var class="pdparam">miblen</var>, </td></tr><tr><td> </td><td>void *<var class="pdparam">oldp</var>, </td></tr><tr><td> </td><td>size_t *<var class="pdparam">oldlenp</var>, </td></tr><tr><td> </td><td>void *<var class="pdparam">newp</var>, </td></tr><tr><td> </td><td>size_t <var class="pdparam">newlen</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">void <b class="fsfunc">malloc_stats_print</b>(</code></td><td>void <var class="pdparam">(*write_cb)</var> 4 <code>(</code>void *, const char *<code>)</code> 5 , </td></tr><tr><td> </td><td>void *<var class="pdparam">cbopaque</var>, </td></tr><tr><td> </td><td>const char *<var class="pdparam">opts</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">size_t <b class="fsfunc">malloc_usable_size</b>(</code></td><td>const void *<var class="pdparam">ptr</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">void <b class="fsfunc">(*malloc_message)</b>(</code></td><td>void *<var class="pdparam">cbopaque</var>, </td></tr><tr><td> </td><td>const char *<var class="pdparam">s</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><p><span class="type">const char *</span><code class="varname">malloc_conf</code>;</p></div></div></div><div class="refsect1"><a name="description"/><h2>DESCRIPTION</h2><div class="refsect2"><a name="idm46057386032448"/><h3>Standard API</h3><p>The <code class="function">malloc()</code> function allocates 6 <em class="parameter"><code>size</code></em> bytes of uninitialized memory. The allocated 7 space is suitably aligned (after possible pointer coercion) for storage 8 of any type of object.</p><p>The <code class="function">calloc()</code> function allocates 9 space for <em class="parameter"><code>number</code></em> objects, each 10 <em class="parameter"><code>size</code></em> bytes in length. The result is identical to 11 calling <code class="function">malloc()</code> with an argument of 12 <em class="parameter"><code>number</code></em> * <em class="parameter"><code>size</code></em>, with the 13 exception that the allocated memory is explicitly initialized to zero 14 bytes.</p><p>The <code class="function">posix_memalign()</code> function 15 allocates <em class="parameter"><code>size</code></em> bytes of memory such that the 16 allocation's base address is a multiple of 17 <em class="parameter"><code>alignment</code></em>, and returns the allocation in the value 18 pointed to by <em class="parameter"><code>ptr</code></em>. The requested 19 <em class="parameter"><code>alignment</code></em> must be a power of 2 at least as large as 20 <code class="code">sizeof(<span class="type">void *</span>)</code>.</p><p>The <code class="function">aligned_alloc()</code> function 21 allocates <em class="parameter"><code>size</code></em> bytes of memory such that the 22 allocation's base address is a multiple of 23 <em class="parameter"><code>alignment</code></em>. The requested 24 <em class="parameter"><code>alignment</code></em> must be a power of 2. Behavior is 25 undefined if <em class="parameter"><code>size</code></em> is not an integral multiple of 26 <em class="parameter"><code>alignment</code></em>.</p><p>The <code class="function">realloc()</code> function changes the 27 size of the previously allocated memory referenced by 28 <em class="parameter"><code>ptr</code></em> to <em class="parameter"><code>size</code></em> bytes. The 29 contents of the memory are unchanged up to the lesser of the new and old 30 sizes. If the new size is larger, the contents of the newly allocated 31 portion of the memory are undefined. Upon success, the memory referenced 32 by <em class="parameter"><code>ptr</code></em> is freed and a pointer to the newly 33 allocated memory is returned. Note that 34 <code class="function">realloc()</code> may move the memory allocation, 35 resulting in a different return value than <em class="parameter"><code>ptr</code></em>. 36 If <em class="parameter"><code>ptr</code></em> is <code class="constant">NULL</code>, the 37 <code class="function">realloc()</code> function behaves identically to 38 <code class="function">malloc()</code> for the specified size.</p><p>The <code class="function">free()</code> function causes the 39 allocated memory referenced by <em class="parameter"><code>ptr</code></em> to be made 40 available for future allocations. If <em class="parameter"><code>ptr</code></em> is 41 <code class="constant">NULL</code>, no action occurs.</p></div><div class="refsect2"><a name="idm46057386007648"/><h3>Non-standard API</h3><p>The <code class="function">mallocx()</code>, 42 <code class="function">rallocx()</code>, 43 <code class="function">xallocx()</code>, 44 <code class="function">sallocx()</code>, 45 <code class="function">dallocx()</code>, 46 <code class="function">sdallocx()</code>, and 47 <code class="function">nallocx()</code> functions all have a 48 <em class="parameter"><code>flags</code></em> argument that can be used to specify 49 options. The functions only check the options that are contextually 50 relevant. Use bitwise or (<code class="code">|</code>) operations to 51 specify one or more of the following: 52 </p><div class="variablelist"><dl class="variablelist"><dt><a name="MALLOCX_LG_ALIGN"/><span class="term"><code class="constant">MALLOCX_LG_ALIGN(<em class="parameter"><code>la</code></em>) 53 </code></span></dt><dd><p>Align the memory allocation to start at an address 54 that is a multiple of <code class="code">(1 << 55 <em class="parameter"><code>la</code></em>)</code>. This macro does not validate 56 that <em class="parameter"><code>la</code></em> is within the valid 57 range.</p></dd><dt><a name="MALLOCX_ALIGN"/><span class="term"><code class="constant">MALLOCX_ALIGN(<em class="parameter"><code>a</code></em>) 58 </code></span></dt><dd><p>Align the memory allocation to start at an address 59 that is a multiple of <em class="parameter"><code>a</code></em>, where 60 <em class="parameter"><code>a</code></em> is a power of two. This macro does not 61 validate that <em class="parameter"><code>a</code></em> is a power of 2. 62 </p></dd><dt><a name="MALLOCX_ZERO"/><span class="term"><code class="constant">MALLOCX_ZERO</code></span></dt><dd><p>Initialize newly allocated memory to contain zero 63 bytes. In the growing reallocation case, the real size prior to 64 reallocation defines the boundary between untouched bytes and those 65 that are initialized to contain zero bytes. If this macro is 66 absent, newly allocated memory is uninitialized.</p></dd><dt><a name="MALLOCX_TCACHE"/><span class="term"><code class="constant">MALLOCX_TCACHE(<em class="parameter"><code>tc</code></em>) 67 </code></span></dt><dd><p>Use the thread-specific cache (tcache) specified by 68 the identifier <em class="parameter"><code>tc</code></em>, which must have been 69 acquired via the <a class="link" href="#tcache.create"><quote><code class="mallctl">tcache.create</code></quote></a> 70 mallctl. This macro does not validate that 71 <em class="parameter"><code>tc</code></em> specifies a valid 72 identifier.</p></dd><dt><a name="MALLOC_TCACHE_NONE"/><span class="term"><code class="constant">MALLOCX_TCACHE_NONE</code></span></dt><dd><p>Do not use a thread-specific cache (tcache). Unless 73 <code class="constant">MALLOCX_TCACHE(<em class="parameter"><code>tc</code></em>)</code> or 74 <code class="constant">MALLOCX_TCACHE_NONE</code> is specified, an 75 automatically managed tcache will be used under many circumstances. 76 This macro cannot be used in the same <em class="parameter"><code>flags</code></em> 77 argument as 78 <code class="constant">MALLOCX_TCACHE(<em class="parameter"><code>tc</code></em>)</code>.</p></dd><dt><a name="MALLOCX_ARENA"/><span class="term"><code class="constant">MALLOCX_ARENA(<em class="parameter"><code>a</code></em>) 79 </code></span></dt><dd><p>Use the arena specified by the index 80 <em class="parameter"><code>a</code></em>. This macro has no effect for regions that 81 were allocated via an arena other than the one specified. This 82 macro does not validate that <em class="parameter"><code>a</code></em> specifies an 83 arena index in the valid range.</p></dd></dl></div><p> 84 </p><p>The <code class="function">mallocx()</code> function allocates at 85 least <em class="parameter"><code>size</code></em> bytes of memory, and returns a pointer 86 to the base address of the allocation. Behavior is undefined if 87 <em class="parameter"><code>size</code></em> is <code class="constant">0</code>.</p><p>The <code class="function">rallocx()</code> function resizes the 88 allocation at <em class="parameter"><code>ptr</code></em> to be at least 89 <em class="parameter"><code>size</code></em> bytes, and returns a pointer to the base 90 address of the resulting allocation, which may or may not have moved from 91 its original location. Behavior is undefined if 92 <em class="parameter"><code>size</code></em> is <code class="constant">0</code>.</p><p>The <code class="function">xallocx()</code> function resizes the 93 allocation at <em class="parameter"><code>ptr</code></em> in place to be at least 94 <em class="parameter"><code>size</code></em> bytes, and returns the real size of the 95 allocation. If <em class="parameter"><code>extra</code></em> is non-zero, an attempt is 96 made to resize the allocation to be at least <code class="code">(<em class="parameter"><code>size</code></em> + 97 <em class="parameter"><code>extra</code></em>)</code> bytes, though inability to allocate 98 the extra byte(s) will not by itself result in failure to resize. 99 Behavior is undefined if <em class="parameter"><code>size</code></em> is 100 <code class="constant">0</code>, or if <code class="code">(<em class="parameter"><code>size</code></em> + <em class="parameter"><code>extra</code></em> 101 > <code class="constant">SIZE_T_MAX</code>)</code>.</p><p>The <code class="function">sallocx()</code> function returns the 102 real size of the allocation at <em class="parameter"><code>ptr</code></em>.</p><p>The <code class="function">dallocx()</code> function causes the 103 memory referenced by <em class="parameter"><code>ptr</code></em> to be made available for 104 future allocations.</p><p>The <code class="function">sdallocx()</code> function is an 105 extension of <code class="function">dallocx()</code> with a 106 <em class="parameter"><code>size</code></em> parameter to allow the caller to pass in the 107 allocation size as an optimization. The minimum valid input size is the 108 original requested size of the allocation, and the maximum valid input 109 size is the corresponding value returned by 110 <code class="function">nallocx()</code> or 111 <code class="function">sallocx()</code>.</p><p>The <code class="function">nallocx()</code> function allocates no 112 memory, but it performs the same size computation as the 113 <code class="function">mallocx()</code> function, and returns the real 114 size of the allocation that would result from the equivalent 115 <code class="function">mallocx()</code> function call, or 116 <code class="constant">0</code> if the inputs exceed the maximum supported size 117 class and/or alignment. Behavior is undefined if 118 <em class="parameter"><code>size</code></em> is <code class="constant">0</code>.</p><p>The <code class="function">mallctl()</code> function provides a 119 general interface for introspecting the memory allocator, as well as 120 setting modifiable parameters and triggering actions. The 121 period-separated <em class="parameter"><code>name</code></em> argument specifies a 122 location in a tree-structured namespace; see the <a class="xref" href="#mallctl_namespace" title="MALLCTL NAMESPACE">MALLCTL NAMESPACE</a> section for 123 documentation on the tree contents. To read a value, pass a pointer via 124 <em class="parameter"><code>oldp</code></em> to adequate space to contain the value, and a 125 pointer to its length via <em class="parameter"><code>oldlenp</code></em>; otherwise pass 126 <code class="constant">NULL</code> and <code class="constant">NULL</code>. Similarly, to 127 write a value, pass a pointer to the value via 128 <em class="parameter"><code>newp</code></em>, and its length via 129 <em class="parameter"><code>newlen</code></em>; otherwise pass <code class="constant">NULL</code> 130 and <code class="constant">0</code>.</p><p>The <code class="function">mallctlnametomib()</code> function 131 provides a way to avoid repeated name lookups for applications that 132 repeatedly query the same portion of the namespace, by translating a name 133 to a <span class="quote">“<span class="quote">Management Information Base</span>”</span> (MIB) that can be passed 134 repeatedly to <code class="function">mallctlbymib()</code>. Upon 135 successful return from <code class="function">mallctlnametomib()</code>, 136 <em class="parameter"><code>mibp</code></em> contains an array of 137 <em class="parameter"><code>*miblenp</code></em> integers, where 138 <em class="parameter"><code>*miblenp</code></em> is the lesser of the number of components 139 in <em class="parameter"><code>name</code></em> and the input value of 140 <em class="parameter"><code>*miblenp</code></em>. Thus it is possible to pass a 141 <em class="parameter"><code>*miblenp</code></em> that is smaller than the number of 142 period-separated name components, which results in a partial MIB that can 143 be used as the basis for constructing a complete MIB. For name 144 components that are integers (e.g. the 2 in 145 <a class="link" href="#arenas.bin.i.size"><quote><code class="mallctl">arenas.bin.2.size</code></quote></a>), 146 the corresponding MIB component will always be that integer. Therefore, 147 it is legitimate to construct code like the following: </p><pre class="programlisting"> 148unsigned nbins, i; 149size_t mib[4]; 150size_t len, miblen; 151 152len = sizeof(nbins); 153mallctl("arenas.nbins", &nbins, &len, NULL, 0); 154 155miblen = 4; 156mallctlnametomib("arenas.bin.0.size", mib, &miblen); 157for (i = 0; i < nbins; i++) { 158 size_t bin_size; 159 160 mib[2] = i; 161 len = sizeof(bin_size); 162 mallctlbymib(mib, miblen, (void *)&bin_size, &len, NULL, 0); 163 /* Do something with bin_size... */ 164}</pre><dt><a name="malloc_stats_print_opts"/></dt><dd/><p>The <code class="function">malloc_stats_print()</code> function writes 165 summary statistics via the <em class="parameter"><code>write_cb</code></em> callback 166 function pointer and <em class="parameter"><code>cbopaque</code></em> data passed to 167 <em class="parameter"><code>write_cb</code></em>, or <code class="function">malloc_message()</code> 168 if <em class="parameter"><code>write_cb</code></em> is <code class="constant">NULL</code>. The 169 statistics are presented in human-readable form unless <span class="quote">“<span class="quote">J</span>”</span> is 170 specified as a character within the <em class="parameter"><code>opts</code></em> string, in 171 which case the statistics are presented in <a class="ulink" href="http://www.json.org/" target="_top">JSON format</a>. This function can be 172 called repeatedly. General information that never changes during 173 execution can be omitted by specifying <span class="quote">“<span class="quote">g</span>”</span> as a character 174 within the <em class="parameter"><code>opts</code></em> string. Note that 175 <code class="function">malloc_stats_print()</code> uses the 176 <code class="function">mallctl*()</code> functions internally, so inconsistent 177 statistics can be reported if multiple threads use these functions 178 simultaneously. If <code class="option">--enable-stats</code> is specified during 179 configuration, <span class="quote">“<span class="quote">m</span>”</span>, <span class="quote">“<span class="quote">d</span>”</span>, and <span class="quote">“<span class="quote">a</span>”</span> 180 can be specified to omit merged arena, destroyed merged arena, and per 181 arena statistics, respectively; <span class="quote">“<span class="quote">b</span>”</span> and <span class="quote">“<span class="quote">l</span>”</span> can 182 be specified to omit per size class statistics for bins and large objects, 183 respectively; <span class="quote">“<span class="quote">x</span>”</span> can be specified to omit all mutex 184 statistics; <span class="quote">“<span class="quote">e</span>”</span> can be used to omit extent statistics. 185 Unrecognized characters are silently ignored. Note that thread caching 186 may prevent some statistics from being completely up to date, since extra 187 locking would be required to merge counters that track thread cache 188 operations.</p><p>The <code class="function">malloc_usable_size()</code> function 189 returns the usable size of the allocation pointed to by 190 <em class="parameter"><code>ptr</code></em>. The return value may be larger than the size 191 that was requested during allocation. The 192 <code class="function">malloc_usable_size()</code> function is not a 193 mechanism for in-place <code class="function">realloc()</code>; rather 194 it is provided solely as a tool for introspection purposes. Any 195 discrepancy between the requested allocation size and the size reported 196 by <code class="function">malloc_usable_size()</code> should not be 197 depended on, since such behavior is entirely implementation-dependent. 198 </p></div></div><div class="refsect1"><a name="tuning"/><h2>TUNING</h2><p>Once, when the first call is made to one of the memory allocation 199 routines, the allocator initializes its internals based in part on various 200 options that can be specified at compile- or run-time.</p><p>The string specified via <code class="option">--with-malloc-conf</code>, the 201 string pointed to by the global variable <code class="varname">malloc_conf</code>, the 202 <span class="quote">“<span class="quote">name</span>”</span> of the file referenced by the symbolic link named 203 <code class="filename">/etc/malloc.conf</code>, and the value of the 204 environment variable <code class="envar">MALLOC_CONF</code>, will be interpreted, in 205 that order, from left to right as options. Note that 206 <code class="varname">malloc_conf</code> may be read before 207 <code class="function">main()</code> is entered, so the declaration of 208 <code class="varname">malloc_conf</code> should specify an initializer that contains 209 the final value to be read by jemalloc. <code class="option">--with-malloc-conf</code> 210 and <code class="varname">malloc_conf</code> are compile-time mechanisms, whereas 211 <code class="filename">/etc/malloc.conf</code> and 212 <code class="envar">MALLOC_CONF</code> can be safely set any time prior to program 213 invocation.</p><p>An options string is a comma-separated list of option:value pairs. 214 There is one key corresponding to each <a class="link" href="#opt.abort"><quote><code class="mallctl">opt.*</code></quote></a> mallctl (see the <a class="xref" href="#mallctl_namespace" title="MALLCTL NAMESPACE">MALLCTL NAMESPACE</a> section for options 215 documentation). For example, <code class="literal">abort:true,narenas:1</code> sets 216 the <a class="link" href="#opt.abort"><quote><code class="mallctl">opt.abort</code></quote></a> and <a class="link" href="#opt.narenas"><quote><code class="mallctl">opt.narenas</code></quote></a> options. Some 217 options have boolean values (true/false), others have integer values (base 218 8, 10, or 16, depending on prefix), and yet others have raw string 219 values.</p></div><div class="refsect1"><a name="implementation_notes"/><h2>IMPLEMENTATION NOTES</h2><p>Traditionally, allocators have used 220 <span class="citerefentry"><span class="refentrytitle">sbrk</span>(2)</span> to obtain memory, which is 221 suboptimal for several reasons, including race conditions, increased 222 fragmentation, and artificial limitations on maximum usable memory. If 223 <span class="citerefentry"><span class="refentrytitle">sbrk</span>(2)</span> is supported by the operating 224 system, this allocator uses both 225 <span class="citerefentry"><span class="refentrytitle">mmap</span>(2)</span> and 226 <span class="citerefentry"><span class="refentrytitle">sbrk</span>(2)</span>, in that order of preference; 227 otherwise only <span class="citerefentry"><span class="refentrytitle">mmap</span>(2)</span> is used.</p><p>This allocator uses multiple arenas in order to reduce lock 228 contention for threaded programs on multi-processor systems. This works 229 well with regard to threading scalability, but incurs some costs. There is 230 a small fixed per-arena overhead, and additionally, arenas manage memory 231 completely independently of each other, which means a small fixed increase 232 in overall memory fragmentation. These overheads are not generally an 233 issue, given the number of arenas normally used. Note that using 234 substantially more arenas than the default is not likely to improve 235 performance, mainly due to reduced cache performance. However, it may make 236 sense to reduce the number of arenas if an application does not make much 237 use of the allocation functions.</p><p>In addition to multiple arenas, this allocator supports 238 thread-specific caching, in order to make it possible to completely avoid 239 synchronization for most allocation requests. Such caching allows very fast 240 allocation in the common case, but it increases memory usage and 241 fragmentation, since a bounded number of objects can remain allocated in 242 each thread cache.</p><p>Memory is conceptually broken into extents. Extents are always 243 aligned to multiples of the page size. This alignment makes it possible to 244 find metadata for user objects quickly. User objects are broken into two 245 categories according to size: small and large. Contiguous small objects 246 comprise a slab, which resides within a single extent, whereas large objects 247 each have their own extents backing them.</p><p>Small objects are managed in groups by slabs. Each slab maintains 248 a bitmap to track which regions are in use. Allocation requests that are no 249 more than half the quantum (8 or 16, depending on architecture) are rounded 250 up to the nearest power of two that is at least <code class="code">sizeof(<span class="type">double</span>)</code>. All other object size 251 classes are multiples of the quantum, spaced such that there are four size 252 classes for each doubling in size, which limits internal fragmentation to 253 approximately 20% for all but the smallest size classes. Small size classes 254 are smaller than four times the page size, and large size classes extend 255 from four times the page size up to the largest size class that does not 256 exceed <code class="constant">PTRDIFF_MAX</code>.</p><p>Allocations are packed tightly together, which can be an issue for 257 multi-threaded applications. If you need to assure that allocations do not 258 suffer from cacheline sharing, round your allocation requests up to the 259 nearest multiple of the cacheline size, or specify cacheline alignment when 260 allocating.</p><p>The <code class="function">realloc()</code>, 261 <code class="function">rallocx()</code>, and 262 <code class="function">xallocx()</code> functions may resize allocations 263 without moving them under limited circumstances. Unlike the 264 <code class="function">*allocx()</code> API, the standard API does not 265 officially round up the usable size of an allocation to the nearest size 266 class, so technically it is necessary to call 267 <code class="function">realloc()</code> to grow e.g. a 9-byte allocation to 268 16 bytes, or shrink a 16-byte allocation to 9 bytes. Growth and shrinkage 269 trivially succeeds in place as long as the pre-size and post-size both round 270 up to the same size class. No other API guarantees are made regarding 271 in-place resizing, but the current implementation also tries to resize large 272 allocations in place, as long as the pre-size and post-size are both large. 273 For shrinkage to succeed, the extent allocator must support splitting (see 274 <a class="link" href="#arena.i.extent_hooks"><quote><code class="mallctl">arena.<i>.extent_hooks</code></quote></a>). 275 Growth only succeeds if the trailing memory is currently available, and the 276 extent allocator supports merging.</p><p>Assuming 4 KiB pages and a 16-byte quantum on a 64-bit system, the 277 size classes in each category are as shown in <a class="xref" href="#size_classes" title="Table 1. Size classes">Table 1</a>.</p><div class="table"><a name="size_classes"/><p class="title"><b>Table 1. Size classes</b></p><div class="table-contents"><table class="table" summary="Size classes" border="1"><colgroup><col align="left" class="c1"/><col align="right" class="c2"/><col align="left" class="c3"/></colgroup><thead><tr><th align="left">Category</th><th align="right">Spacing</th><th align="left">Size</th></tr></thead><tbody><tr><td rowspan="9" align="left">Small</td><td align="right">lg</td><td align="left">[8]</td></tr><tr><td align="right">16</td><td align="left">[16, 32, 48, 64, 80, 96, 112, 128]</td></tr><tr><td align="right">32</td><td align="left">[160, 192, 224, 256]</td></tr><tr><td align="right">64</td><td align="left">[320, 384, 448, 512]</td></tr><tr><td align="right">128</td><td align="left">[640, 768, 896, 1024]</td></tr><tr><td align="right">256</td><td align="left">[1280, 1536, 1792, 2048]</td></tr><tr><td align="right">512</td><td align="left">[2560, 3072, 3584, 4096]</td></tr><tr><td align="right">1 KiB</td><td align="left">[5 KiB, 6 KiB, 7 KiB, 8 KiB]</td></tr><tr><td align="right">2 KiB</td><td align="left">[10 KiB, 12 KiB, 14 KiB]</td></tr><tr><td rowspan="16" align="left">Large</td><td align="right">2 KiB</td><td align="left">[16 KiB]</td></tr><tr><td align="right">4 KiB</td><td align="left">[20 KiB, 24 KiB, 28 KiB, 32 KiB]</td></tr><tr><td align="right">8 KiB</td><td align="left">[40 KiB, 48 KiB, 56 KiB, 64 KiB]</td></tr><tr><td align="right">16 KiB</td><td align="left">[80 KiB, 96 KiB, 112 KiB, 128 KiB]</td></tr><tr><td align="right">32 KiB</td><td align="left">[160 KiB, 192 KiB, 224 KiB, 256 KiB]</td></tr><tr><td align="right">64 KiB</td><td align="left">[320 KiB, 384 KiB, 448 KiB, 512 KiB]</td></tr><tr><td align="right">128 KiB</td><td align="left">[640 KiB, 768 KiB, 896 KiB, 1 MiB]</td></tr><tr><td align="right">256 KiB</td><td align="left">[1280 KiB, 1536 KiB, 1792 KiB, 2 MiB]</td></tr><tr><td align="right">512 KiB</td><td align="left">[2560 KiB, 3 MiB, 3584 KiB, 4 MiB]</td></tr><tr><td align="right">1 MiB</td><td align="left">[5 MiB, 6 MiB, 7 MiB, 8 MiB]</td></tr><tr><td align="right">2 MiB</td><td align="left">[10 MiB, 12 MiB, 14 MiB, 16 MiB]</td></tr><tr><td align="right">4 MiB</td><td align="left">[20 MiB, 24 MiB, 28 MiB, 32 MiB]</td></tr><tr><td align="right">8 MiB</td><td align="left">[40 MiB, 48 MiB, 56 MiB, 64 MiB]</td></tr><tr><td align="right">...</td><td align="left">...</td></tr><tr><td align="right">512 PiB</td><td align="left">[2560 PiB, 3 EiB, 3584 PiB, 4 EiB]</td></tr><tr><td align="right">1 EiB</td><td align="left">[5 EiB, 6 EiB, 7 EiB]</td></tr></tbody></table></div></div><br class="table-break"/></div><div class="refsect1"><a name="mallctl_namespace"/><h2>MALLCTL NAMESPACE</h2><p>The following names are defined in the namespace accessible via the 278 <code class="function">mallctl*()</code> functions. Value types are specified in 279 parentheses, their readable/writable statuses are encoded as 280 <code class="literal">rw</code>, <code class="literal">r-</code>, <code class="literal">-w</code>, or 281 <code class="literal">--</code>, and required build configuration flags follow, if 282 any. A name element encoded as <code class="literal"><i></code> or 283 <code class="literal"><j></code> indicates an integer component, where the 284 integer varies from 0 to some upper value that must be determined via 285 introspection. In the case of <quote><code class="mallctl">stats.arenas.<i>.*</code></quote> 286 and <quote><code class="mallctl">arena.<i>.{initialized,purge,decay,dss}</code></quote>, 287 <code class="literal"><i></code> equal to 288 <code class="constant">MALLCTL_ARENAS_ALL</code> can be used to operate on all arenas 289 or access the summation of statistics from all arenas; similarly 290 <code class="literal"><i></code> equal to 291 <code class="constant">MALLCTL_ARENAS_DESTROYED</code> can be used to access the 292 summation of statistics from all destroyed arenas. These constants can be 293 utilized either via <code class="function">mallctlnametomib()</code> followed by 294 <code class="function">mallctlbymib()</code>, or via code such as the following: 295 </p><pre class="programlisting"> 296#define STRINGIFY_HELPER(x) #x 297#define STRINGIFY(x) STRINGIFY_HELPER(x) 298 299mallctl("arena." STRINGIFY(MALLCTL_ARENAS_ALL) ".decay", 300 NULL, NULL, NULL, 0);</pre><p> 301 Take special note of the <a class="link" href="#epoch"><quote><code class="mallctl">epoch</code></quote></a> mallctl, which controls 302 refreshing of cached dynamic statistics.</p><div class="variablelist"><dl class="variablelist"><dt><a name="version"/><span class="term"> 303 <quote><code class="mallctl">version</code></quote> 304 (<span class="type">const char *</span>) 305 <code class="literal">r-</code> 306 </span></dt><dd><p>Return the jemalloc version string.</p></dd><dt><a name="epoch"/><span class="term"> 307 <quote><code class="mallctl">epoch</code></quote> 308 (<span class="type">uint64_t</span>) 309 <code class="literal">rw</code> 310 </span></dt><dd><p>If a value is passed in, refresh the data from which 311 the <code class="function">mallctl*()</code> functions report values, 312 and increment the epoch. Return the current epoch. This is useful for 313 detecting whether another thread caused a refresh.</p></dd><dt><a name="background_thread"/><span class="term"> 314 <quote><code class="mallctl">background_thread</code></quote> 315 (<span class="type">bool</span>) 316 <code class="literal">rw</code> 317 </span></dt><dd><p>Enable/disable internal background worker threads. When 318 set to true, background threads are created on demand (the number of 319 background threads will be no more than the number of CPUs or active 320 arenas). Threads run periodically, and handle <a class="link" href="#arena.i.decay">purging</a> asynchronously. When switching 321 off, background threads are terminated synchronously. Note that after 322 <span class="citerefentry"><span class="refentrytitle">fork</span>(2)</span> 323 function, the state in the child process will be disabled regardless 324 the state in parent process. See <a class="link" href="#stats.background_thread.num_threads"><quote><code class="mallctl">stats.background_thread</code></quote></a> 325 for related stats. <a class="link" href="#opt.background_thread"><quote><code class="mallctl">opt.background_thread</code></quote></a> 326 can be used to set the default option. This option is only available on 327 selected pthread-based platforms.</p></dd><dt><a name="max_background_threads"/><span class="term"> 328 <quote><code class="mallctl">max_background_threads</code></quote> 329 (<span class="type">size_t</span>) 330 <code class="literal">rw</code> 331 </span></dt><dd><p>Maximum number of background worker threads that will 332 be created. This value is capped at <a class="link" href="#opt.max_background_threads"><quote><code class="mallctl">opt.max_background_threads</code></quote></a> at 333 startup.</p></dd><dt><a name="config.cache_oblivious"/><span class="term"> 334 <quote><code class="mallctl">config.cache_oblivious</code></quote> 335 (<span class="type">bool</span>) 336 <code class="literal">r-</code> 337 </span></dt><dd><p><code class="option">--enable-cache-oblivious</code> was specified 338 during build configuration.</p></dd><dt><a name="config.debug"/><span class="term"> 339 <quote><code class="mallctl">config.debug</code></quote> 340 (<span class="type">bool</span>) 341 <code class="literal">r-</code> 342 </span></dt><dd><p><code class="option">--enable-debug</code> was specified during 343 build configuration.</p></dd><dt><a name="config.fill"/><span class="term"> 344 <quote><code class="mallctl">config.fill</code></quote> 345 (<span class="type">bool</span>) 346 <code class="literal">r-</code> 347 </span></dt><dd><p><code class="option">--enable-fill</code> was specified during 348 build configuration.</p></dd><dt><a name="config.lazy_lock"/><span class="term"> 349 <quote><code class="mallctl">config.lazy_lock</code></quote> 350 (<span class="type">bool</span>) 351 <code class="literal">r-</code> 352 </span></dt><dd><p><code class="option">--enable-lazy-lock</code> was specified 353 during build configuration.</p></dd><dt><a name="config.malloc_conf"/><span class="term"> 354 <quote><code class="mallctl">config.malloc_conf</code></quote> 355 (<span class="type">const char *</span>) 356 <code class="literal">r-</code> 357 </span></dt><dd><p>Embedded configure-time-specified run-time options 358 string, empty unless <code class="option">--with-malloc-conf</code> was specified 359 during build configuration.</p></dd><dt><a name="config.prof"/><span class="term"> 360 <quote><code class="mallctl">config.prof</code></quote> 361 (<span class="type">bool</span>) 362 <code class="literal">r-</code> 363 </span></dt><dd><p><code class="option">--enable-prof</code> was specified during 364 build configuration.</p></dd><dt><a name="config.prof_libgcc"/><span class="term"> 365 <quote><code class="mallctl">config.prof_libgcc</code></quote> 366 (<span class="type">bool</span>) 367 <code class="literal">r-</code> 368 </span></dt><dd><p><code class="option">--disable-prof-libgcc</code> was not 369 specified during build configuration.</p></dd><dt><a name="config.prof_libunwind"/><span class="term"> 370 <quote><code class="mallctl">config.prof_libunwind</code></quote> 371 (<span class="type">bool</span>) 372 <code class="literal">r-</code> 373 </span></dt><dd><p><code class="option">--enable-prof-libunwind</code> was specified 374 during build configuration.</p></dd><dt><a name="config.stats"/><span class="term"> 375 <quote><code class="mallctl">config.stats</code></quote> 376 (<span class="type">bool</span>) 377 <code class="literal">r-</code> 378 </span></dt><dd><p><code class="option">--enable-stats</code> was specified during 379 build configuration.</p></dd><dt><a name="config.utrace"/><span class="term"> 380 <quote><code class="mallctl">config.utrace</code></quote> 381 (<span class="type">bool</span>) 382 <code class="literal">r-</code> 383 </span></dt><dd><p><code class="option">--enable-utrace</code> was specified during 384 build configuration.</p></dd><dt><a name="config.xmalloc"/><span class="term"> 385 <quote><code class="mallctl">config.xmalloc</code></quote> 386 (<span class="type">bool</span>) 387 <code class="literal">r-</code> 388 </span></dt><dd><p><code class="option">--enable-xmalloc</code> was specified during 389 build configuration.</p></dd><dt><a name="opt.abort"/><span class="term"> 390 <quote><code class="mallctl">opt.abort</code></quote> 391 (<span class="type">bool</span>) 392 <code class="literal">r-</code> 393 </span></dt><dd><p>Abort-on-warning enabled/disabled. If true, most 394 warnings are fatal. Note that runtime option warnings are not included 395 (see <a class="link" href="#opt.abort_conf"><quote><code class="mallctl">opt.abort_conf</code></quote></a> for 396 that). The process will call 397 <span class="citerefentry"><span class="refentrytitle">abort</span>(3)</span> in these cases. This option is 398 disabled by default unless <code class="option">--enable-debug</code> is 399 specified during configuration, in which case it is enabled by default. 400 </p></dd><dt><a name="opt.confirm_conf"/><span class="term"> 401 <quote><code class="mallctl">opt.confirm_conf</code></quote> 402 (<span class="type">bool</span>) 403 <code class="literal">r-</code> 404 </span></dt><dd><p>Confirm-runtime-options-when-program-starts 405 enabled/disabled. If true, the string specified via 406 <code class="option">--with-malloc-conf</code>, the string pointed to by the 407 global variable <code class="varname">malloc_conf</code>, the <span class="quote">“<span class="quote">name</span>”</span> 408 of the file referenced by the symbolic link named 409 <code class="filename">/etc/malloc.conf</code>, and the value of 410 the environment variable <code class="envar">MALLOC_CONF</code>, will be printed in 411 order. Then, each option being set will be individually printed. This 412 option is disabled by default.</p></dd><dt><a name="opt.abort_conf"/><span class="term"> 413 <quote><code class="mallctl">opt.abort_conf</code></quote> 414 (<span class="type">bool</span>) 415 <code class="literal">r-</code> 416 </span></dt><dd><p>Abort-on-invalid-configuration enabled/disabled. If 417 true, invalid runtime options are fatal. The process will call 418 <span class="citerefentry"><span class="refentrytitle">abort</span>(3)</span> in these cases. This option is 419 disabled by default unless <code class="option">--enable-debug</code> is 420 specified during configuration, in which case it is enabled by default. 421 </p></dd><dt><a name="opt.cache_oblivious"/><span class="term"> 422 <quote><code class="mallctl">opt.cache_oblivious</code></quote> 423 (<span class="type">bool</span>) 424 <code class="literal">r-</code> 425 </span></dt><dd><p>Enable / Disable cache-oblivious large allocation 426 alignment, for large requests with no alignment constraints. If this 427 feature is disabled, all large allocations are page-aligned as an 428 implementation artifact, which can severely harm CPU cache utilization. 429 However, the cache-oblivious layout comes at the cost of one extra page 430 per large allocation, which in the most extreme case increases physical 431 memory usage for the 16 KiB size class to 20 KiB. This option is enabled 432 by default.</p></dd><dt><a name="opt.metadata_thp"/><span class="term"> 433 <quote><code class="mallctl">opt.metadata_thp</code></quote> 434 (<span class="type">const char *</span>) 435 <code class="literal">r-</code> 436 </span></dt><dd><p>Controls whether to allow jemalloc to use transparent 437 huge page (THP) for internal metadata (see <a class="link" href="#stats.metadata">stats.metadata</a>). <span class="quote">“<span class="quote">always</span>”</span> 438 allows such usage. <span class="quote">“<span class="quote">auto</span>”</span> uses no THP initially, but may 439 begin to do so when metadata usage reaches certain level. The default 440 is <span class="quote">“<span class="quote">disabled</span>”</span>.</p></dd><dt><a name="opt.trust_madvise"/><span class="term"> 441 <quote><code class="mallctl">opt.trust_madvise</code></quote> 442 (<span class="type">bool</span>) 443 <code class="literal">r-</code> 444 </span></dt><dd><p>If true, do not perform runtime check for MADV_DONTNEED, 445 to check that it actually zeros pages. The default is disabled on Linux 446 and enabled elsewhere.</p></dd><dt><a name="opt.retain"/><span class="term"> 447 <quote><code class="mallctl">opt.retain</code></quote> 448 (<span class="type">bool</span>) 449 <code class="literal">r-</code> 450 </span></dt><dd><p>If true, retain unused virtual memory for later reuse 451 rather than discarding it by calling 452 <span class="citerefentry"><span class="refentrytitle">munmap</span>(2)</span> or equivalent (see <a class="link" href="#stats.retained">stats.retained</a> for related details). 453 It also makes jemalloc use <span class="citerefentry"><span class="refentrytitle">mmap</span>(2)</span> or equivalent in a more greedy way, mapping larger 454 chunks in one go. This option is disabled by default unless discarding 455 virtual memory is known to trigger platform-specific performance 456 problems, namely 1) for [64-bit] Linux, which has a quirk in its virtual 457 memory allocation algorithm that causes semi-permanent VM map holes 458 under normal jemalloc operation; and 2) for [64-bit] Windows, which 459 disallows split / merged regions with 460 <em class="parameter"><code><code class="constant">MEM_RELEASE</code></code></em>. Although the 461 same issues may present on 32-bit platforms as well, retaining virtual 462 memory for 32-bit Linux and Windows is disabled by default due to the 463 practical possibility of address space exhaustion. </p></dd><dt><a name="opt.dss"/><span class="term"> 464 <quote><code class="mallctl">opt.dss</code></quote> 465 (<span class="type">const char *</span>) 466 <code class="literal">r-</code> 467 </span></dt><dd><p>dss (<span class="citerefentry"><span class="refentrytitle">sbrk</span>(2)</span>) allocation precedence as 468 related to <span class="citerefentry"><span class="refentrytitle">mmap</span>(2)</span> allocation. The following 469 settings are supported if 470 <span class="citerefentry"><span class="refentrytitle">sbrk</span>(2)</span> is supported by the operating 471 system: <span class="quote">“<span class="quote">disabled</span>”</span>, <span class="quote">“<span class="quote">primary</span>”</span>, and 472 <span class="quote">“<span class="quote">secondary</span>”</span>; otherwise only <span class="quote">“<span class="quote">disabled</span>”</span> is 473 supported. The default is <span class="quote">“<span class="quote">secondary</span>”</span> if 474 <span class="citerefentry"><span class="refentrytitle">sbrk</span>(2)</span> is supported by the operating 475 system; <span class="quote">“<span class="quote">disabled</span>”</span> otherwise. 476 </p></dd><dt><a name="opt.narenas"/><span class="term"> 477 <quote><code class="mallctl">opt.narenas</code></quote> 478 (<span class="type">unsigned</span>) 479 <code class="literal">r-</code> 480 </span></dt><dd><p>Maximum number of arenas to use for automatic 481 multiplexing of threads and arenas. The default is four times the 482 number of CPUs, or one if there is a single CPU.</p></dd><dt><a name="opt.oversize_threshold"/><span class="term"> 483 <quote><code class="mallctl">opt.oversize_threshold</code></quote> 484 (<span class="type">size_t</span>) 485 <code class="literal">r-</code> 486 </span></dt><dd><p>The threshold in bytes of which requests are considered 487 oversize. Allocation requests with greater sizes are fulfilled from a 488 dedicated arena (automatically managed, however not within 489 <code class="literal">narenas</code>), in order to reduce fragmentation by not 490 mixing huge allocations with small ones. In addition, the decay API 491 guarantees on the extents greater than the specified threshold may be 492 overridden. Note that requests with arena index specified via 493 <code class="constant">MALLOCX_ARENA</code>, or threads associated with explicit 494 arenas will not be considered. The default threshold is 8MiB. Values 495 not within large size classes disables this feature.</p></dd><dt><a name="opt.percpu_arena"/><span class="term"> 496 <quote><code class="mallctl">opt.percpu_arena</code></quote> 497 (<span class="type">const char *</span>) 498 <code class="literal">r-</code> 499 </span></dt><dd><p>Per CPU arena mode. Use the <span class="quote">“<span class="quote">percpu</span>”</span> 500 setting to enable this feature, which uses number of CPUs to determine 501 number of arenas, and bind threads to arenas dynamically based on the 502 CPU the thread runs on currently. <span class="quote">“<span class="quote">phycpu</span>”</span> setting uses 503 one arena per physical CPU, which means the two hyper threads on the 504 same CPU share one arena. Note that no runtime checking regarding the 505 availability of hyper threading is done at the moment. When set to 506 <span class="quote">“<span class="quote">disabled</span>”</span>, narenas and thread to arena association will 507 not be impacted by this option. The default is <span class="quote">“<span class="quote">disabled</span>”</span>. 508 </p></dd><dt><a name="opt.background_thread"/><span class="term"> 509 <quote><code class="mallctl">opt.background_thread</code></quote> 510 (<span class="type">bool</span>) 511 <code class="literal">r-</code> 512 </span></dt><dd><p>Internal background worker threads enabled/disabled. 513 Because of potential circular dependencies, enabling background thread 514 using this option may cause crash or deadlock during initialization. For 515 a reliable way to use this feature, see <a class="link" href="#background_thread">background_thread</a> for dynamic control 516 options and details. This option is disabled by 517 default.</p></dd><dt><a name="opt.max_background_threads"/><span class="term"> 518 <quote><code class="mallctl">opt.max_background_threads</code></quote> 519 (<span class="type">size_t</span>) 520 <code class="literal">r-</code> 521 </span></dt><dd><p>Maximum number of background threads that will be created 522 if <a class="link" href="#background_thread">background_thread</a> is set. 523 Defaults to number of cpus.</p></dd><dt><a name="opt.dirty_decay_ms"/><span class="term"> 524 <quote><code class="mallctl">opt.dirty_decay_ms</code></quote> 525 (<span class="type">ssize_t</span>) 526 <code class="literal">r-</code> 527 </span></dt><dd><p>Approximate time in milliseconds from the creation of a 528 set of unused dirty pages until an equivalent set of unused dirty pages 529 is purged (i.e. converted to muzzy via e.g. 530 <code class="function">madvise(<em class="parameter"><code>...</code></em><em class="parameter"><code><code class="constant">MADV_FREE</code></code></em>)</code> 531 if supported by the operating system, or converted to clean otherwise) 532 and/or reused. Dirty pages are defined as previously having been 533 potentially written to by the application, and therefore consuming 534 physical memory, yet having no current use. The pages are incrementally 535 purged according to a sigmoidal decay curve that starts and ends with 536 zero purge rate. A decay time of 0 causes all unused dirty pages to be 537 purged immediately upon creation. A decay time of -1 disables purging. 538 The default decay time is 10 seconds. See <a class="link" href="#arenas.dirty_decay_ms"><quote><code class="mallctl">arenas.dirty_decay_ms</code></quote></a> 539 and <a class="link" href="#arena.i.dirty_decay_ms"><quote><code class="mallctl">arena.<i>.dirty_decay_ms</code></quote></a> 540 for related dynamic control options. See <a class="link" href="#opt.muzzy_decay_ms"><quote><code class="mallctl">opt.muzzy_decay_ms</code></quote></a> 541 for a description of muzzy pages.for a description of muzzy pages. Note 542 that when the <a class="link" href="#opt.oversize_threshold"><quote><code class="mallctl">oversize_threshold</code></quote></a> 543 feature is enabled, the arenas reserved for oversize requests may have 544 its own default decay settings.</p></dd><dt><a name="opt.muzzy_decay_ms"/><span class="term"> 545 <quote><code class="mallctl">opt.muzzy_decay_ms</code></quote> 546 (<span class="type">ssize_t</span>) 547 <code class="literal">r-</code> 548 </span></dt><dd><p>Approximate time in milliseconds from the creation of a 549 set of unused muzzy pages until an equivalent set of unused muzzy pages 550 is purged (i.e. converted to clean) and/or reused. Muzzy pages are 551 defined as previously having been unused dirty pages that were 552 subsequently purged in a manner that left them subject to the 553 reclamation whims of the operating system (e.g. 554 <code class="function">madvise(<em class="parameter"><code>...</code></em><em class="parameter"><code><code class="constant">MADV_FREE</code></code></em>)</code>), 555 and therefore in an indeterminate state. The pages are incrementally 556 purged according to a sigmoidal decay curve that starts and ends with 557 zero purge rate. A decay time of 0 causes all unused muzzy pages to be 558 purged immediately upon creation. A decay time of -1 disables purging. 559 The default decay time is 10 seconds. See <a class="link" href="#arenas.muzzy_decay_ms"><quote><code class="mallctl">arenas.muzzy_decay_ms</code></quote></a> 560 and <a class="link" href="#arena.i.muzzy_decay_ms"><quote><code class="mallctl">arena.<i>.muzzy_decay_ms</code></quote></a> 561 for related dynamic control options.</p></dd><dt><a name="opt.lg_extent_max_active_fit"/><span class="term"> 562 <quote><code class="mallctl">opt.lg_extent_max_active_fit</code></quote> 563 (<span class="type">size_t</span>) 564 <code class="literal">r-</code> 565 </span></dt><dd><p>When reusing dirty extents, this determines the (log 566 base 2 of the) maximum ratio between the size of the active extent 567 selected (to split off from) and the size of the requested allocation. 568 This prevents the splitting of large active extents for smaller 569 allocations, which can reduce fragmentation over the long run 570 (especially for non-active extents). Lower value may reduce 571 fragmentation, at the cost of extra active extents. The default value 572 is 6, which gives a maximum ratio of 64 (2^6).</p></dd><dt><a name="opt.stats_print"/><span class="term"> 573 <quote><code class="mallctl">opt.stats_print</code></quote> 574 (<span class="type">bool</span>) 575 <code class="literal">r-</code> 576 </span></dt><dd><p>Enable/disable statistics printing at exit. If 577 enabled, the <code class="function">malloc_stats_print()</code> 578 function is called at program exit via an 579 <span class="citerefentry"><span class="refentrytitle">atexit</span>(3)</span> function. <a class="link" href="#opt.stats_print_opts"><quote><code class="mallctl">opt.stats_print_opts</code></quote></a> 580 can be combined to specify output options. If 581 <code class="option">--enable-stats</code> is specified during configuration, this 582 has the potential to cause deadlock for a multi-threaded process that 583 exits while one or more threads are executing in the memory allocation 584 functions. Furthermore, <code class="function">atexit()</code> may 585 allocate memory during application initialization and then deadlock 586 internally when jemalloc in turn calls 587 <code class="function">atexit()</code>, so this option is not 588 universally usable (though the application can register its own 589 <code class="function">atexit()</code> function with equivalent 590 functionality). Therefore, this option should only be used with care; 591 it is primarily intended as a performance tuning aid during application 592 development. This option is disabled by default.</p></dd><dt><a name="opt.stats_print_opts"/><span class="term"> 593 <quote><code class="mallctl">opt.stats_print_opts</code></quote> 594 (<span class="type">const char *</span>) 595 <code class="literal">r-</code> 596 </span></dt><dd><p>Options (the <em class="parameter"><code>opts</code></em> string) to pass 597 to the <code class="function">malloc_stats_print()</code> at exit (enabled 598 through <a class="link" href="#opt.stats_print"><quote><code class="mallctl">opt.stats_print</code></quote></a>). See 599 available options in <a class="link" href="#malloc_stats_print_opts"><code class="function">malloc_stats_print()</code></a>. 600 Has no effect unless <a class="link" href="#opt.stats_print"><quote><code class="mallctl">opt.stats_print</code></quote></a> is 601 enabled. The default is <span class="quote">“<span class="quote"/>”</span>.</p></dd><dt><a name="opt.stats_interval"/><span class="term"> 602 <quote><code class="mallctl">opt.stats_interval</code></quote> 603 (<span class="type">int64_t</span>) 604 <code class="literal">r-</code> 605 </span></dt><dd><p>Average interval between statistics outputs, as measured 606 in bytes of allocation activity. The actual interval may be sporadic 607 because decentralized event counters are used to avoid synchronization 608 bottlenecks. The output may be triggered on any thread, which then 609 calls <code class="function">malloc_stats_print()</code>. <a class="link" href="#opt.stats_interval_opts"><quote><code class="mallctl">opt.stats_interval_opts</code></quote></a> 610 can be combined to specify output options. By default, 611 interval-triggered stats output is disabled (encoded as 612 -1).</p></dd><dt><a name="opt.stats_interval_opts"/><span class="term"> 613 <quote><code class="mallctl">opt.stats_interval_opts</code></quote> 614 (<span class="type">const char *</span>) 615 <code class="literal">r-</code> 616 </span></dt><dd><p>Options (the <em class="parameter"><code>opts</code></em> string) to pass 617 to the <code class="function">malloc_stats_print()</code> for interval based 618 statistics printing (enabled 619 through <a class="link" href="#opt.stats_interval"><quote><code class="mallctl">opt.stats_interval</code></quote></a>). See 620 available options in <a class="link" href="#malloc_stats_print_opts"><code class="function">malloc_stats_print()</code></a>. 621 Has no effect unless <a class="link" href="#opt.stats_interval"><quote><code class="mallctl">opt.stats_interval</code></quote></a> is 622 enabled. The default is <span class="quote">“<span class="quote"/>”</span>.</p></dd><dt><a name="opt.junk"/><span class="term"> 623 <quote><code class="mallctl">opt.junk</code></quote> 624 (<span class="type">const char *</span>) 625 <code class="literal">r-</code> 626 [<code class="option">--enable-fill</code>] 627 </span></dt><dd><p>Junk filling. If set to <span class="quote">“<span class="quote">alloc</span>”</span>, each byte 628 of uninitialized allocated memory will be initialized to 629 <code class="literal">0xa5</code>. If set to <span class="quote">“<span class="quote">free</span>”</span>, all deallocated 630 memory will be initialized to <code class="literal">0x5a</code>. If set to 631 <span class="quote">“<span class="quote">true</span>”</span>, both allocated and deallocated memory will be 632 initialized, and if set to <span class="quote">“<span class="quote">false</span>”</span>, junk filling be 633 disabled entirely. This is intended for debugging and will impact 634 performance negatively. This option is <span class="quote">“<span class="quote">false</span>”</span> by default 635 unless <code class="option">--enable-debug</code> is specified during 636 configuration, in which case it is <span class="quote">“<span class="quote">true</span>”</span> by 637 default.</p></dd><dt><a name="opt.zero"/><span class="term"> 638 <quote><code class="mallctl">opt.zero</code></quote> 639 (<span class="type">bool</span>) 640 <code class="literal">r-</code> 641 [<code class="option">--enable-fill</code>] 642 </span></dt><dd><p>Zero filling enabled/disabled. If enabled, each byte 643 of uninitialized allocated memory will be initialized to 0. Note that 644 this initialization only happens once for each byte, so 645 <code class="function">realloc()</code> and 646 <code class="function">rallocx()</code> calls do not zero memory that 647 was previously allocated. This is intended for debugging and will 648 impact performance negatively. This option is disabled by default. 649 </p></dd><dt><a name="opt.utrace"/><span class="term"> 650 <quote><code class="mallctl">opt.utrace</code></quote> 651 (<span class="type">bool</span>) 652 <code class="literal">r-</code> 653 [<code class="option">--enable-utrace</code>] 654 </span></dt><dd><p>Allocation tracing based on 655 <span class="citerefentry"><span class="refentrytitle">utrace</span>(2)</span> enabled/disabled. This option 656 is disabled by default.</p></dd><dt><a name="opt.xmalloc"/><span class="term"> 657 <quote><code class="mallctl">opt.xmalloc</code></quote> 658 (<span class="type">bool</span>) 659 <code class="literal">r-</code> 660 [<code class="option">--enable-xmalloc</code>] 661 </span></dt><dd><p>Abort-on-out-of-memory enabled/disabled. If enabled, 662 rather than returning failure for any allocation function, display a 663 diagnostic message on <code class="constant">STDERR_FILENO</code> and cause the 664 program to drop core (using 665 <span class="citerefentry"><span class="refentrytitle">abort</span>(3)</span>). If an application is 666 designed to depend on this behavior, set the option at compile time by 667 including the following in the source code: 668 </p><pre class="programlisting"> 669malloc_conf = "xmalloc:true";</pre><p> 670 This option is disabled by default.</p></dd><dt><a name="opt.tcache"/><span class="term"> 671 <quote><code class="mallctl">opt.tcache</code></quote> 672 (<span class="type">bool</span>) 673 <code class="literal">r-</code> 674 </span></dt><dd><p>Thread-specific caching (tcache) enabled/disabled. When 675 there are multiple threads, each thread uses a tcache for objects up to 676 a certain size. Thread-specific caching allows many allocations to be 677 satisfied without performing any thread synchronization, at the cost of 678 increased memory use. See the <a class="link" href="#opt.tcache_max"><quote><code class="mallctl">opt.tcache_max</code></quote></a> 679 option for related tuning information. This option is enabled by 680 default.</p></dd><dt><a name="opt.tcache_max"/><span class="term"> 681 <quote><code class="mallctl">opt.tcache_max</code></quote> 682 (<span class="type">size_t</span>) 683 <code class="literal">r-</code> 684 </span></dt><dd><p>Maximum size class to cache in the thread-specific cache 685 (tcache). At a minimum, the first size class is cached; and at a 686 maximum, size classes up to 8 MiB can be cached. The default maximum is 687 32 KiB (2^15). As a convenience, this may also be set by specifying 688 lg_tcache_max, which will be taken to be the base-2 logarithm of the 689 setting of tcache_max.</p></dd><dt><a name="opt.thp"/><span class="term"> 690 <quote><code class="mallctl">opt.thp</code></quote> 691 (<span class="type">const char *</span>) 692 <code class="literal">r-</code> 693 </span></dt><dd><p>Transparent hugepage (THP) mode. Settings "always", 694 "never" and "default" are available if THP is supported by the operating 695 system. The "always" setting enables transparent hugepage for all user 696 memory mappings with 697 <em class="parameter"><code><code class="constant">MADV_HUGEPAGE</code></code></em>; "never" 698 ensures no transparent hugepage with 699 <em class="parameter"><code><code class="constant">MADV_NOHUGEPAGE</code></code></em>; the default 700 setting "default" makes no changes. Note that: this option does not 701 affect THP for jemalloc internal metadata (see <a class="link" href="#opt.metadata_thp"><quote><code class="mallctl">opt.metadata_thp</code></quote></a>); 702 in addition, for arenas with customized <a class="link" href="#arena.i.extent_hooks"><quote><code class="mallctl">extent_hooks</code></quote></a>, 703 this option is bypassed as it is implemented as part of the default 704 extent hooks.</p></dd><dt><a name="opt.prof"/><span class="term"> 705 <quote><code class="mallctl">opt.prof</code></quote> 706 (<span class="type">bool</span>) 707 <code class="literal">r-</code> 708 [<code class="option">--enable-prof</code>] 709 </span></dt><dd><p>Memory profiling enabled/disabled. If enabled, profile 710 memory allocation activity. See the <a class="link" href="#opt.prof_active"><quote><code class="mallctl">opt.prof_active</code></quote></a> 711 option for on-the-fly activation/deactivation. See the <a class="link" href="#opt.lg_prof_sample"><quote><code class="mallctl">opt.lg_prof_sample</code></quote></a> 712 option for probabilistic sampling control. See the <a class="link" href="#opt.prof_accum"><quote><code class="mallctl">opt.prof_accum</code></quote></a> 713 option for control of cumulative sample reporting. See the <a class="link" href="#opt.lg_prof_interval"><quote><code class="mallctl">opt.lg_prof_interval</code></quote></a> 714 option for information on interval-triggered profile dumping, the <a class="link" href="#opt.prof_gdump"><quote><code class="mallctl">opt.prof_gdump</code></quote></a> 715 option for information on high-water-triggered profile dumping, and the 716 <a class="link" href="#opt.prof_final"><quote><code class="mallctl">opt.prof_final</code></quote></a> 717 option for final profile dumping. Profile output is compatible with 718 the <span class="command"><strong>jeprof</strong></span> command, which is based on the 719 <span class="command"><strong>pprof</strong></span> that is developed as part of the <a class="ulink" href="http://code.google.com/p/gperftools/" target="_top">gperftools 720 package</a>. See <a class="link" href="#heap_profile_format" title="HEAP PROFILE FORMAT">HEAP PROFILE 721 FORMAT</a> for heap profile format documentation.</p></dd><dt><a name="opt.prof_prefix"/><span class="term"> 722 <quote><code class="mallctl">opt.prof_prefix</code></quote> 723 (<span class="type">const char *</span>) 724 <code class="literal">r-</code> 725 [<code class="option">--enable-prof</code>] 726 </span></dt><dd><p>Filename prefix for profile dumps. If the prefix is 727 set to the empty string, no automatic dumps will occur; this is 728 primarily useful for disabling the automatic final heap dump (which 729 also disables leak reporting, if enabled). The default prefix is 730 <code class="filename">jeprof</code>. This prefix value can be overridden by 731 <a class="link" href="#prof.prefix"><quote><code class="mallctl">prof.prefix</code></quote></a>. 732 </p></dd><dt><a name="opt.prof_active"/><span class="term"> 733 <quote><code class="mallctl">opt.prof_active</code></quote> 734 (<span class="type">bool</span>) 735 <code class="literal">r-</code> 736 [<code class="option">--enable-prof</code>] 737 </span></dt><dd><p>Profiling activated/deactivated. This is a secondary 738 control mechanism that makes it possible to start the application with 739 profiling enabled (see the <a class="link" href="#opt.prof"><quote><code class="mallctl">opt.prof</code></quote></a> option) but 740 inactive, then toggle profiling at any time during program execution 741 with the <a class="link" href="#prof.active"><quote><code class="mallctl">prof.active</code></quote></a> mallctl. 742 This option is enabled by default.</p></dd><dt><a name="opt.prof_thread_active_init"/><span class="term"> 743 <quote><code class="mallctl">opt.prof_thread_active_init</code></quote> 744 (<span class="type">bool</span>) 745 <code class="literal">r-</code> 746 [<code class="option">--enable-prof</code>] 747 </span></dt><dd><p>Initial setting for <a class="link" href="#thread.prof.active"><quote><code class="mallctl">thread.prof.active</code></quote></a> 748 in newly created threads. The initial setting for newly created threads 749 can also be changed during execution via the <a class="link" href="#prof.thread_active_init"><quote><code class="mallctl">prof.thread_active_init</code></quote></a> 750 mallctl. This option is enabled by default.</p></dd><dt><a name="opt.lg_prof_sample"/><span class="term"> 751 <quote><code class="mallctl">opt.lg_prof_sample</code></quote> 752 (<span class="type">size_t</span>) 753 <code class="literal">r-</code> 754 [<code class="option">--enable-prof</code>] 755 </span></dt><dd><p>Average interval (log base 2) between allocation 756 samples, as measured in bytes of allocation activity. Increasing the 757 sampling interval decreases profile fidelity, but also decreases the 758 computational overhead. The default sample interval is 512 KiB (2^19 759 B).</p></dd><dt><a name="opt.prof_accum"/><span class="term"> 760 <quote><code class="mallctl">opt.prof_accum</code></quote> 761 (<span class="type">bool</span>) 762 <code class="literal">r-</code> 763 [<code class="option">--enable-prof</code>] 764 </span></dt><dd><p>Reporting of cumulative object/byte counts in profile 765 dumps enabled/disabled. If this option is enabled, every unique 766 backtrace must be stored for the duration of execution. Depending on 767 the application, this can impose a large memory overhead, and the 768 cumulative counts are not always of interest. This option is disabled 769 by default.</p></dd><dt><a name="opt.lg_prof_interval"/><span class="term"> 770 <quote><code class="mallctl">opt.lg_prof_interval</code></quote> 771 (<span class="type">ssize_t</span>) 772 <code class="literal">r-</code> 773 [<code class="option">--enable-prof</code>] 774 </span></dt><dd><p>Average interval (log base 2) between memory profile 775 dumps, as measured in bytes of allocation activity. The actual 776 interval between dumps may be sporadic because decentralized allocation 777 counters are used to avoid synchronization bottlenecks. Profiles are 778 dumped to files named according to the pattern 779 <code class="filename"><prefix>.<pid>.<seq>.i<iseq>.heap</code>, 780 where <code class="literal"><prefix></code> is controlled by the 781 <a class="link" href="#opt.prof_prefix"><quote><code class="mallctl">opt.prof_prefix</code></quote></a> and 782 <a class="link" href="#prof.prefix"><quote><code class="mallctl">prof.prefix</code></quote></a> 783 options. By default, interval-triggered profile dumping is disabled 784 (encoded as -1). 785 </p></dd><dt><a name="opt.prof_gdump"/><span class="term"> 786 <quote><code class="mallctl">opt.prof_gdump</code></quote> 787 (<span class="type">bool</span>) 788 <code class="literal">r-</code> 789 [<code class="option">--enable-prof</code>] 790 </span></dt><dd><p>Set the initial state of <a class="link" href="#prof.gdump"><quote><code class="mallctl">prof.gdump</code></quote></a>, which when 791 enabled triggers a memory profile dump every time the total virtual 792 memory exceeds the previous maximum. This option is disabled by 793 default.</p></dd><dt><a name="opt.prof_final"/><span class="term"> 794 <quote><code class="mallctl">opt.prof_final</code></quote> 795 (<span class="type">bool</span>) 796 <code class="literal">r-</code> 797 [<code class="option">--enable-prof</code>] 798 </span></dt><dd><p>Use an 799 <span class="citerefentry"><span class="refentrytitle">atexit</span>(3)</span> function to dump final memory 800 usage to a file named according to the pattern 801 <code class="filename"><prefix>.<pid>.<seq>.f.heap</code>, 802 where <code class="literal"><prefix></code> is controlled by the <a class="link" href="#opt.prof_prefix"><quote><code class="mallctl">opt.prof_prefix</code></quote></a> and 803 <a class="link" href="#prof.prefix"><quote><code class="mallctl">prof.prefix</code></quote></a> 804 options. Note that <code class="function">atexit()</code> may allocate 805 memory during application initialization and then deadlock internally 806 when jemalloc in turn calls <code class="function">atexit()</code>, so 807 this option is not universally usable (though the application can 808 register its own <code class="function">atexit()</code> function with 809 equivalent functionality). This option is disabled by 810 default.</p></dd><dt><a name="opt.prof_leak"/><span class="term"> 811 <quote><code class="mallctl">opt.prof_leak</code></quote> 812 (<span class="type">bool</span>) 813 <code class="literal">r-</code> 814 [<code class="option">--enable-prof</code>] 815 </span></dt><dd><p>Leak reporting enabled/disabled. If enabled, use an 816 <span class="citerefentry"><span class="refentrytitle">atexit</span>(3)</span> function to report memory leaks 817 detected by allocation sampling. See the 818 <a class="link" href="#opt.prof"><quote><code class="mallctl">opt.prof</code></quote></a> option for 819 information on analyzing heap profile output. Works only when combined 820 with <a class="link" href="#opt.prof_final"><quote><code class="mallctl">opt.prof_final</code></quote> 821 </a>, otherwise does nothing. This option is disabled by default. 822 </p></dd><dt><a name="opt.prof_leak_error"/><span class="term"> 823 <quote><code class="mallctl">opt.prof_leak_error</code></quote> 824 (<span class="type">bool</span>) 825 <code class="literal">r-</code> 826 [<code class="option">--enable-prof</code>] 827 </span></dt><dd><p>Similar to <a class="link" href="#opt.prof_leak"><quote><code class="mallctl"> 828 opt.prof_leak</code></quote></a>, but makes the process exit with error 829 code 1 if a memory leak is detected. This option supersedes 830 <a class="link" href="#opt.prof_leak"><quote><code class="mallctl">opt.prof_leak</code></quote></a>, 831 meaning that if both are specified, this option takes precedence. When 832 enabled, also enables <a class="link" href="#opt.prof_leak"><quote><code class="mallctl"> 833 opt.prof_leak</code></quote></a>. Works only when combined with 834 <a class="link" href="#opt.prof_final"><quote><code class="mallctl">opt.prof_final</code></quote></a>, 835 otherwise does nothing. This option is disabled by default. 836 </p></dd><dt><a name="opt.zero_realloc"/><span class="term"> 837 <quote><code class="mallctl">opt.zero_realloc</code></quote> 838 (<span class="type">const char *</span>) 839 <code class="literal">r-</code> 840 </span></dt><dd><p> Determines the behavior of 841 <code class="function">realloc()</code> when passed a value of zero for the new 842 size. <span class="quote">“<span class="quote">alloc</span>”</span> treats this as an allocation of size zero 843 (and returns a non-null result except in case of resource exhaustion). 844 <span class="quote">“<span class="quote">free</span>”</span> treats this as a deallocation of the pointer, and 845 returns <code class="constant">NULL</code> without setting 846 <code class="varname">errno</code>. <span class="quote">“<span class="quote">abort</span>”</span> aborts the process if 847 zero is passed. The default is <span class="quote">“<span class="quote">free</span>”</span> on Linux and 848 Windows, and <span class="quote">“<span class="quote">alloc</span>”</span> elsewhere.</p><p>There is considerable divergence of behaviors across 849 implementations in handling this case. Many have the behavior of 850 <span class="quote">“<span class="quote">free</span>”</span>. This can introduce security vulnerabilities, since 851 a <code class="constant">NULL</code> return value indicates failure, and the 852 continued validity of the passed-in pointer (per POSIX and C11). 853 <span class="quote">“<span class="quote">alloc</span>”</span> is safe, but can cause leaks in programs that 854 expect the common behavior. Programs intended to be portable and 855 leak-free cannot assume either behavior, and must therefore never call 856 realloc with a size of 0. The <span class="quote">“<span class="quote">abort</span>”</span> option enables these 857 testing this behavior.</p></dd><dt><a name="thread.arena"/><span class="term"> 858 <quote><code class="mallctl">thread.arena</code></quote> 859 (<span class="type">unsigned</span>) 860 <code class="literal">rw</code> 861 </span></dt><dd><p>Get or set the arena associated with the calling 862 thread. If the specified arena was not initialized beforehand (see the 863 <a class="link" href="#arena.i.initialized"><quote><code class="mallctl">arena.i.initialized</code></quote></a> 864 mallctl), it will be automatically initialized as a side effect of 865 calling this interface.</p></dd><dt><a name="thread.allocated"/><span class="term"> 866 <quote><code class="mallctl">thread.allocated</code></quote> 867 (<span class="type">uint64_t</span>) 868 <code class="literal">r-</code> 869 [<code class="option">--enable-stats</code>] 870 </span></dt><dd><p>Get the total number of bytes ever allocated by the 871 calling thread. This counter has the potential to wrap around; it is 872 up to the application to appropriately interpret the counter in such 873 cases.</p></dd><dt><a name="thread.allocatedp"/><span class="term"> 874 <quote><code class="mallctl">thread.allocatedp</code></quote> 875 (<span class="type">uint64_t *</span>) 876 <code class="literal">r-</code> 877 [<code class="option">--enable-stats</code>] 878 </span></dt><dd><p>Get a pointer to the the value that is returned by the 879 <a class="link" href="#thread.allocated"><quote><code class="mallctl">thread.allocated</code></quote></a> 880 mallctl. This is useful for avoiding the overhead of repeated 881 <code class="function">mallctl*()</code> calls. Note that the underlying counter 882 should not be modified by the application.</p></dd><dt><a name="thread.deallocated"/><span class="term"> 883 <quote><code class="mallctl">thread.deallocated</code></quote> 884 (<span class="type">uint64_t</span>) 885 <code class="literal">r-</code> 886 [<code class="option">--enable-stats</code>] 887 </span></dt><dd><p>Get the total number of bytes ever deallocated by the 888 calling thread. This counter has the potential to wrap around; it is 889 up to the application to appropriately interpret the counter in such 890 cases.</p></dd><dt><a name="thread.deallocatedp"/><span class="term"> 891 <quote><code class="mallctl">thread.deallocatedp</code></quote> 892 (<span class="type">uint64_t *</span>) 893 <code class="literal">r-</code> 894 [<code class="option">--enable-stats</code>] 895 </span></dt><dd><p>Get a pointer to the the value that is returned by the 896 <a class="link" href="#thread.deallocated"><quote><code class="mallctl">thread.deallocated</code></quote></a> 897 mallctl. This is useful for avoiding the overhead of repeated 898 <code class="function">mallctl*()</code> calls. Note that the underlying counter 899 should not be modified by the application.</p></dd><dt><a name="thread.peak.read"/><span class="term"> 900 <quote><code class="mallctl">thread.peak.read</code></quote> 901 (<span class="type">uint64_t</span>) 902 <code class="literal">r-</code> 903 [<code class="option">--enable-stats</code>] 904 </span></dt><dd><p>Get an approximation of the maximum value of the 905 difference between the number of bytes allocated and the number of bytes 906 deallocated by the calling thread since the last call to <a class="link" href="#thread.peak.reset"><quote><code class="mallctl">thread.peak.reset</code></quote></a>, 907 or since the thread's creation if it has not called <a class="link" href="#thread.peak.reset"><quote><code class="mallctl">thread.peak.reset</code></quote></a>. 908 No guarantees are made about the quality of the approximation, but 909 jemalloc currently endeavors to maintain accuracy to within one hundred 910 kilobytes. 911 </p></dd><dt><a name="thread.peak.reset"/><span class="term"> 912 <quote><code class="mallctl">thread.peak.reset</code></quote> 913 (<span class="type">void</span>) 914 <code class="literal">--</code> 915 [<code class="option">--enable-stats</code>] 916 </span></dt><dd><p>Resets the counter for net bytes allocated in the calling 917 thread to zero. This affects subsequent calls to <a class="link" href="#thread.peak.read"><quote><code class="mallctl">thread.peak.read</code></quote></a>, 918 but not the values returned by <a class="link" href="#thread.allocated"><quote><code class="mallctl">thread.allocated</code></quote></a> 919 or <a class="link" href="#thread.deallocated"><quote><code class="mallctl">thread.deallocated</code></quote></a>. 920 </p></dd><dt><a name="thread.tcache.enabled"/><span class="term"> 921 <quote><code class="mallctl">thread.tcache.enabled</code></quote> 922 (<span class="type">bool</span>) 923 <code class="literal">rw</code> 924 </span></dt><dd><p>Enable/disable calling thread's tcache. The tcache is 925 implicitly flushed as a side effect of becoming 926 disabled (see <a class="link" href="#thread.tcache.flush"><quote><code class="mallctl">thread.tcache.flush</code></quote></a>). 927 </p></dd><dt><a name="thread.tcache.flush"/><span class="term"> 928 <quote><code class="mallctl">thread.tcache.flush</code></quote> 929 (<span class="type">void</span>) 930 <code class="literal">--</code> 931 </span></dt><dd><p>Flush calling thread's thread-specific cache (tcache). 932 This interface releases all cached objects and internal data structures 933 associated with the calling thread's tcache. Ordinarily, this interface 934 need not be called, since automatic periodic incremental garbage 935 collection occurs, and the thread cache is automatically discarded when 936 a thread exits. However, garbage collection is triggered by allocation 937 activity, so it is possible for a thread that stops 938 allocating/deallocating to retain its cache indefinitely, in which case 939 the developer may find manual flushing useful.</p></dd><dt><a name="thread.prof.name"/><span class="term"> 940 <quote><code class="mallctl">thread.prof.name</code></quote> 941 (<span class="type">const char *</span>) 942 <code class="literal">r-</code> or 943 <code class="literal">-w</code> 944 [<code class="option">--enable-prof</code>] 945 </span></dt><dd><p>Get/set the descriptive name associated with the calling 946 thread in memory profile dumps. An internal copy of the name string is 947 created, so the input string need not be maintained after this interface 948 completes execution. The output string of this interface should be 949 copied for non-ephemeral uses, because multiple implementation details 950 can cause asynchronous string deallocation. Furthermore, each 951 invocation of this interface can only read or write; simultaneous 952 read/write is not supported due to string lifetime limitations. The 953 name string must be nil-terminated and comprised only of characters in 954 the sets recognized 955 by <span class="citerefentry"><span class="refentrytitle">isgraph</span>(3)</span> and 956 <span class="citerefentry"><span class="refentrytitle">isblank</span>(3)</span>.</p></dd><dt><a name="thread.prof.active"/><span class="term"> 957 <quote><code class="mallctl">thread.prof.active</code></quote> 958 (<span class="type">bool</span>) 959 <code class="literal">rw</code> 960 [<code class="option">--enable-prof</code>] 961 </span></dt><dd><p>Control whether sampling is currently active for the 962 calling thread. This is an activation mechanism in addition to <a class="link" href="#prof.active"><quote><code class="mallctl">prof.active</code></quote></a>; both must 963 be active for the calling thread to sample. This flag is enabled by 964 default.</p></dd><dt><a name="thread.idle"/><span class="term"> 965 <quote><code class="mallctl">thread.idle</code></quote> 966 (<span class="type">void</span>) 967 <code class="literal">--</code> 968 </span></dt><dd><p>Hints to jemalloc that the calling thread will be idle 969 for some nontrivial period of time (say, on the order of seconds), and 970 that doing some cleanup operations may be beneficial. There are no 971 guarantees as to what specific operations will be performed; currently 972 this flushes the caller's tcache and may (according to some heuristic) 973 purge its associated arena.</p><p>This is not intended to be a general-purpose background activity 974 mechanism, and threads should not wake up multiple times solely to call 975 it. Rather, a thread waiting for a task should do a timed wait first, 976 call <a class="link" href="#thread.idle"><quote><code class="mallctl">thread.idle</code></quote></a> 977 if no task appears in the timeout interval, and then do an untimed wait. 978 For such a background activity mechanism, see 979 <a class="link" href="#background_thread"><quote><code class="mallctl">background_thread</code></quote></a>. 980 </p></dd><dt><a name="tcache.create"/><span class="term"> 981 <quote><code class="mallctl">tcache.create</code></quote> 982 (<span class="type">unsigned</span>) 983 <code class="literal">r-</code> 984 </span></dt><dd><p>Create an explicit thread-specific cache (tcache) and 985 return an identifier that can be passed to the <a class="link" href="#MALLOCX_TCACHE"><code class="constant">MALLOCX_TCACHE(<em class="parameter"><code>tc</code></em>)</code></a> 986 macro to explicitly use the specified cache rather than the 987 automatically managed one that is used by default. Each explicit cache 988 can be used by only one thread at a time; the application must assure 989 that this constraint holds. 990 </p><p>If the amount of space supplied for storing the thread-specific 991 cache identifier does not equal 992 <code class="code">sizeof(<span class="type">unsigned</span>)</code>, no 993 thread-specific cache will be created, no data will be written to the 994 space pointed by <em class="parameter"><code>oldp</code></em>, and 995 <em class="parameter"><code>*oldlenp</code></em> will be set to 0. 996 </p></dd><dt><a name="tcache.flush"/><span class="term"> 997 <quote><code class="mallctl">tcache.flush</code></quote> 998 (<span class="type">unsigned</span>) 999 <code class="literal">-w</code> 1000 </span></dt><dd><p>Flush the specified thread-specific cache (tcache). The 1001 same considerations apply to this interface as to <a class="link" href="#thread.tcache.flush"><quote><code class="mallctl">thread.tcache.flush</code></quote></a>, 1002 except that the tcache will never be automatically discarded. 1003 </p></dd><dt><a name="tcache.destroy"/><span class="term"> 1004 <quote><code class="mallctl">tcache.destroy</code></quote> 1005 (<span class="type">unsigned</span>) 1006 <code class="literal">-w</code> 1007 </span></dt><dd><p>Flush the specified thread-specific cache (tcache) and 1008 make the identifier available for use during a future tcache creation. 1009 </p></dd><dt><a name="arena.i.initialized"/><span class="term"> 1010 <quote><code class="mallctl">arena.<i>.initialized</code></quote> 1011 (<span class="type">bool</span>) 1012 <code class="literal">r-</code> 1013 </span></dt><dd><p>Get whether the specified arena's statistics are 1014 initialized (i.e. the arena was initialized prior to the current epoch). 1015 This interface can also be nominally used to query whether the merged 1016 statistics corresponding to <code class="constant">MALLCTL_ARENAS_ALL</code> are 1017 initialized (always true).</p></dd><dt><a name="arena.i.decay"/><span class="term"> 1018 <quote><code class="mallctl">arena.<i>.decay</code></quote> 1019 (<span class="type">void</span>) 1020 <code class="literal">--</code> 1021 </span></dt><dd><p>Trigger decay-based purging of unused dirty/muzzy pages 1022 for arena <i>, or for all arenas if <i> equals 1023 <code class="constant">MALLCTL_ARENAS_ALL</code>. The proportion of unused 1024 dirty/muzzy pages to be purged depends on the current time; see <a class="link" href="#opt.dirty_decay_ms"><quote><code class="mallctl">opt.dirty_decay_ms</code></quote></a> 1025 and <a class="link" href="#opt.muzzy_decay_ms"><quote><code class="mallctl">opt.muzy_decay_ms</code></quote></a> 1026 for details.</p></dd><dt><a name="arena.i.purge"/><span class="term"> 1027 <quote><code class="mallctl">arena.<i>.purge</code></quote> 1028 (<span class="type">void</span>) 1029 <code class="literal">--</code> 1030 </span></dt><dd><p>Purge all unused dirty pages for arena <i>, or for 1031 all arenas if <i> equals <code class="constant">MALLCTL_ARENAS_ALL</code>. 1032 </p></dd><dt><a name="arena.i.reset"/><span class="term"> 1033 <quote><code class="mallctl">arena.<i>.reset</code></quote> 1034 (<span class="type">void</span>) 1035 <code class="literal">--</code> 1036 </span></dt><dd><p>Discard all of the arena's extant allocations. This 1037 interface can only be used with arenas explicitly created via <a class="link" href="#arenas.create"><quote><code class="mallctl">arenas.create</code></quote></a>. None 1038 of the arena's discarded/cached allocations may accessed afterward. As 1039 part of this requirement, all thread caches which were used to 1040 allocate/deallocate in conjunction with the arena must be flushed 1041 beforehand.</p></dd><dt><a name="arena.i.destroy"/><span class="term"> 1042 <quote><code class="mallctl">arena.<i>.destroy</code></quote> 1043 (<span class="type">void</span>) 1044 <code class="literal">--</code> 1045 </span></dt><dd><p>Destroy the arena. Discard all of the arena's extant 1046 allocations using the same mechanism as for <a class="link" href="#arena.i.reset"><quote><code class="mallctl">arena.<i>.reset</code></quote></a> 1047 (with all the same constraints and side effects), merge the arena stats 1048 into those accessible at arena index 1049 <code class="constant">MALLCTL_ARENAS_DESTROYED</code>, and then completely 1050 discard all metadata associated with the arena. Future calls to <a class="link" href="#arenas.create"><quote><code class="mallctl">arenas.create</code></quote></a> may 1051 recycle the arena index. Destruction will fail if any threads are 1052 currently associated with the arena as a result of calls to <a class="link" href="#thread.arena"><quote><code class="mallctl">thread.arena</code></quote></a>.</p></dd><dt><a name="arena.i.dss"/><span class="term"> 1053 <quote><code class="mallctl">arena.<i>.dss</code></quote> 1054 (<span class="type">const char *</span>) 1055 <code class="literal">rw</code> 1056 </span></dt><dd><p>Set the precedence of dss allocation as related to mmap 1057 allocation for arena <i>, or for all arenas if <i> equals 1058 <code class="constant">MALLCTL_ARENAS_ALL</code>. See <a class="link" href="#opt.dss"><quote><code class="mallctl">opt.dss</code></quote></a> for supported 1059 settings.</p></dd><dt><a name="arena.i.dirty_decay_ms"/><span class="term"> 1060 <quote><code class="mallctl">arena.<i>.dirty_decay_ms</code></quote> 1061 (<span class="type">ssize_t</span>) 1062 <code class="literal">rw</code> 1063 </span></dt><dd><p>Current per-arena approximate time in milliseconds from 1064 the creation of a set of unused dirty pages until an equivalent set of 1065 unused dirty pages is purged and/or reused. Each time this interface is 1066 set, all currently unused dirty pages are considered to have fully 1067 decayed, which causes immediate purging of all unused dirty pages unless 1068 the decay time is set to -1 (i.e. purging disabled). See <a class="link" href="#opt.dirty_decay_ms"><quote><code class="mallctl">opt.dirty_decay_ms</code></quote></a> 1069 for additional information.</p></dd><dt><a name="arena.i.muzzy_decay_ms"/><span class="term"> 1070 <quote><code class="mallctl">arena.<i>.muzzy_decay_ms</code></quote> 1071 (<span class="type">ssize_t</span>) 1072 <code class="literal">rw</code> 1073 </span></dt><dd><p>Current per-arena approximate time in milliseconds from 1074 the creation of a set of unused muzzy pages until an equivalent set of 1075 unused muzzy pages is purged and/or reused. Each time this interface is 1076 set, all currently unused muzzy pages are considered to have fully 1077 decayed, which causes immediate purging of all unused muzzy pages unless 1078 the decay time is set to -1 (i.e. purging disabled). See <a class="link" href="#opt.muzzy_decay_ms"><quote><code class="mallctl">opt.muzzy_decay_ms</code></quote></a> 1079 for additional information.</p></dd><dt><a name="arena.i.retain_grow_limit"/><span class="term"> 1080 <quote><code class="mallctl">arena.<i>.retain_grow_limit</code></quote> 1081 (<span class="type">size_t</span>) 1082 <code class="literal">rw</code> 1083 </span></dt><dd><p>Maximum size to grow retained region (only relevant when 1084 <a class="link" href="#opt.retain"><quote><code class="mallctl">opt.retain</code></quote></a> is 1085 enabled). This controls the maximum increment to expand virtual memory, 1086 or allocation through <a class="link" href="#arena.i.extent_hooks"><quote><code class="mallctl">arena.<i>extent_hooks</code></quote></a>. 1087 In particular, if customized extent hooks reserve physical memory 1088 (e.g. 1G huge pages), this is useful to control the allocation hook's 1089 input size. The default is no limit.</p></dd><dt><a name="arena.i.extent_hooks"/><span class="term"> 1090 <quote><code class="mallctl">arena.<i>.extent_hooks</code></quote> 1091 (<span class="type">extent_hooks_t *</span>) 1092 <code class="literal">rw</code> 1093 </span></dt><dd><p>Get or set the extent management hook functions for 1094 arena <i>. The functions must be capable of operating on all 1095 extant extents associated with arena <i>, usually by passing 1096 unknown extents to the replaced functions. In practice, it is feasible 1097 to control allocation for arenas explicitly created via <a class="link" href="#arenas.create"><quote><code class="mallctl">arenas.create</code></quote></a> such 1098 that all extents originate from an application-supplied extent allocator 1099 (by specifying the custom extent hook functions during arena creation). 1100 However, the API guarantees for the automatically created arenas may be 1101 relaxed -- hooks set there may be called in a "best effort" fashion; in 1102 addition there may be extents created prior to the application having an 1103 opportunity to take over extent allocation.</p><pre class="programlisting"> 1104typedef extent_hooks_s extent_hooks_t; 1105struct extent_hooks_s { 1106 extent_alloc_t *alloc; 1107 extent_dalloc_t *dalloc; 1108 extent_destroy_t *destroy; 1109 extent_commit_t *commit; 1110 extent_decommit_t *decommit; 1111 extent_purge_t *purge_lazy; 1112 extent_purge_t *purge_forced; 1113 extent_split_t *split; 1114 extent_merge_t *merge; 1115};</pre><p>The <span class="type">extent_hooks_t</span> structure comprises function 1116 pointers which are described individually below. jemalloc uses these 1117 functions to manage extent lifetime, which starts off with allocation of 1118 mapped committed memory, in the simplest case followed by deallocation. 1119 However, there are performance and platform reasons to retain extents 1120 for later reuse. Cleanup attempts cascade from deallocation to decommit 1121 to forced purging to lazy purging, which gives the extent management 1122 functions opportunities to reject the most permanent cleanup operations 1123 in favor of less permanent (and often less costly) operations. All 1124 operations except allocation can be universally opted out of by setting 1125 the hook pointers to <code class="constant">NULL</code>, or selectively opted out 1126 of by returning failure. Note that once the extent hook is set, the 1127 structure is accessed directly by the associated arenas, so it must 1128 remain valid for the entire lifetime of the arenas.</p><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">typedef void *<b class="fsfunc">(extent_alloc_t)</b>(</code></td><td>extent_hooks_t *<var class="pdparam">extent_hooks</var>, </td></tr><tr><td> </td><td>void *<var class="pdparam">new_addr</var>, </td></tr><tr><td> </td><td>size_t <var class="pdparam">size</var>, </td></tr><tr><td> </td><td>size_t <var class="pdparam">alignment</var>, </td></tr><tr><td> </td><td>bool *<var class="pdparam">zero</var>, </td></tr><tr><td> </td><td>bool *<var class="pdparam">commit</var>, </td></tr><tr><td> </td><td>unsigned <var class="pdparam">arena_ind</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div><div class="literallayout"><p/></div><p>An extent allocation function conforms to the 1129 <span class="type">extent_alloc_t</span> type and upon success returns a pointer to 1130 <em class="parameter"><code>size</code></em> bytes of mapped memory on behalf of arena 1131 <em class="parameter"><code>arena_ind</code></em> such that the extent's base address is 1132 a multiple of <em class="parameter"><code>alignment</code></em>, as well as setting 1133 <em class="parameter"><code>*zero</code></em> to indicate whether the extent is zeroed 1134 and <em class="parameter"><code>*commit</code></em> to indicate whether the extent is 1135 committed. Upon error the function returns <code class="constant">NULL</code> 1136 and leaves <em class="parameter"><code>*zero</code></em> and 1137 <em class="parameter"><code>*commit</code></em> unmodified. The 1138 <em class="parameter"><code>size</code></em> parameter is always a multiple of the page 1139 size. The <em class="parameter"><code>alignment</code></em> parameter is always a power 1140 of two at least as large as the page size. Zeroing is mandatory if 1141 <em class="parameter"><code>*zero</code></em> is true upon function entry. Committing is 1142 mandatory if <em class="parameter"><code>*commit</code></em> is true upon function entry. 1143 If <em class="parameter"><code>new_addr</code></em> is not <code class="constant">NULL</code>, the 1144 returned pointer must be <em class="parameter"><code>new_addr</code></em> on success or 1145 <code class="constant">NULL</code> on error. Committed memory may be committed 1146 in absolute terms as on a system that does not overcommit, or in 1147 implicit terms as on a system that overcommits and satisfies physical 1148 memory needs on demand via soft page faults. Note that replacing the 1149 default extent allocation function makes the arena's <a class="link" href="#arena.i.dss"><quote><code class="mallctl">arena.<i>.dss</code></quote></a> 1150 setting irrelevant.</p><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">typedef bool <b class="fsfunc">(extent_dalloc_t)</b>(</code></td><td>extent_hooks_t *<var class="pdparam">extent_hooks</var>, </td></tr><tr><td> </td><td>void *<var class="pdparam">addr</var>, </td></tr><tr><td> </td><td>size_t <var class="pdparam">size</var>, </td></tr><tr><td> </td><td>bool <var class="pdparam">committed</var>, </td></tr><tr><td> </td><td>unsigned <var class="pdparam">arena_ind</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div><div class="literallayout"><p/></div><p> 1151 An extent deallocation function conforms to the 1152 <span class="type">extent_dalloc_t</span> type and deallocates an extent at given 1153 <em class="parameter"><code>addr</code></em> and <em class="parameter"><code>size</code></em> with 1154 <em class="parameter"><code>committed</code></em>/decommited memory as indicated, on 1155 behalf of arena <em class="parameter"><code>arena_ind</code></em>, returning false upon 1156 success. If the function returns true, this indicates opt-out from 1157 deallocation; the virtual memory mapping associated with the extent 1158 remains mapped, in the same commit state, and available for future use, 1159 in which case it will be automatically retained for later reuse.</p><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">typedef void <b class="fsfunc">(extent_destroy_t)</b>(</code></td><td>extent_hooks_t *<var class="pdparam">extent_hooks</var>, </td></tr><tr><td> </td><td>void *<var class="pdparam">addr</var>, </td></tr><tr><td> </td><td>size_t <var class="pdparam">size</var>, </td></tr><tr><td> </td><td>bool <var class="pdparam">committed</var>, </td></tr><tr><td> </td><td>unsigned <var class="pdparam">arena_ind</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div><div class="literallayout"><p/></div><p> 1160 An extent destruction function conforms to the 1161 <span class="type">extent_destroy_t</span> type and unconditionally destroys an 1162 extent at given <em class="parameter"><code>addr</code></em> and 1163 <em class="parameter"><code>size</code></em> with 1164 <em class="parameter"><code>committed</code></em>/decommited memory as indicated, on 1165 behalf of arena <em class="parameter"><code>arena_ind</code></em>. This function may be 1166 called to destroy retained extents during arena destruction (see <a class="link" href="#arena.i.destroy"><quote><code class="mallctl">arena.<i>.destroy</code></quote></a>).</p><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">typedef bool <b class="fsfunc">(extent_commit_t)</b>(</code></td><td>extent_hooks_t *<var class="pdparam">extent_hooks</var>, </td></tr><tr><td> </td><td>void *<var class="pdparam">addr</var>, </td></tr><tr><td> </td><td>size_t <var class="pdparam">size</var>, </td></tr><tr><td> </td><td>size_t <var class="pdparam">offset</var>, </td></tr><tr><td> </td><td>size_t <var class="pdparam">length</var>, </td></tr><tr><td> </td><td>unsigned <var class="pdparam">arena_ind</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div><div class="literallayout"><p/></div><p>An extent commit function conforms to the 1167 <span class="type">extent_commit_t</span> type and commits zeroed physical memory to 1168 back pages within an extent at given <em class="parameter"><code>addr</code></em> and 1169 <em class="parameter"><code>size</code></em> at <em class="parameter"><code>offset</code></em> bytes, 1170 extending for <em class="parameter"><code>length</code></em> on behalf of arena 1171 <em class="parameter"><code>arena_ind</code></em>, returning false upon success. 1172 Committed memory may be committed in absolute terms as on a system that 1173 does not overcommit, or in implicit terms as on a system that 1174 overcommits and satisfies physical memory needs on demand via soft page 1175 faults. If the function returns true, this indicates insufficient 1176 physical memory to satisfy the request.</p><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">typedef bool <b class="fsfunc">(extent_decommit_t)</b>(</code></td><td>extent_hooks_t *<var class="pdparam">extent_hooks</var>, </td></tr><tr><td> </td><td>void *<var class="pdparam">addr</var>, </td></tr><tr><td> </td><td>size_t <var class="pdparam">size</var>, </td></tr><tr><td> </td><td>size_t <var class="pdparam">offset</var>, </td></tr><tr><td> </td><td>size_t <var class="pdparam">length</var>, </td></tr><tr><td> </td><td>unsigned <var class="pdparam">arena_ind</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div><div class="literallayout"><p/></div><p>An extent decommit function conforms to the 1177 <span class="type">extent_decommit_t</span> type and decommits any physical memory 1178 that is backing pages within an extent at given 1179 <em class="parameter"><code>addr</code></em> and <em class="parameter"><code>size</code></em> at 1180 <em class="parameter"><code>offset</code></em> bytes, extending for 1181 <em class="parameter"><code>length</code></em> on behalf of arena 1182 <em class="parameter"><code>arena_ind</code></em>, returning false upon success, in which 1183 case the pages will be committed via the extent commit function before 1184 being reused. If the function returns true, this indicates opt-out from 1185 decommit; the memory remains committed and available for future use, in 1186 which case it will be automatically retained for later reuse.</p><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">typedef bool <b class="fsfunc">(extent_purge_t)</b>(</code></td><td>extent_hooks_t *<var class="pdparam">extent_hooks</var>, </td></tr><tr><td> </td><td>void *<var class="pdparam">addr</var>, </td></tr><tr><td> </td><td>size_t <var class="pdparam">size</var>, </td></tr><tr><td> </td><td>size_t <var class="pdparam">offset</var>, </td></tr><tr><td> </td><td>size_t <var class="pdparam">length</var>, </td></tr><tr><td> </td><td>unsigned <var class="pdparam">arena_ind</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div><div class="literallayout"><p/></div><p>An extent purge function conforms to the 1187 <span class="type">extent_purge_t</span> type and discards physical pages 1188 within the virtual memory mapping associated with an extent at given 1189 <em class="parameter"><code>addr</code></em> and <em class="parameter"><code>size</code></em> at 1190 <em class="parameter"><code>offset</code></em> bytes, extending for 1191 <em class="parameter"><code>length</code></em> on behalf of arena 1192 <em class="parameter"><code>arena_ind</code></em>. A lazy extent purge function (e.g. 1193 implemented via 1194 <code class="function">madvise(<em class="parameter"><code>...</code></em><em class="parameter"><code><code class="constant">MADV_FREE</code></code></em>)</code>) 1195 can delay purging indefinitely and leave the pages within the purged 1196 virtual memory range in an indeterminite state, whereas a forced extent 1197 purge function immediately purges, and the pages within the virtual 1198 memory range will be zero-filled the next time they are accessed. If 1199 the function returns true, this indicates failure to purge.</p><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">typedef bool <b class="fsfunc">(extent_split_t)</b>(</code></td><td>extent_hooks_t *<var class="pdparam">extent_hooks</var>, </td></tr><tr><td> </td><td>void *<var class="pdparam">addr</var>, </td></tr><tr><td> </td><td>size_t <var class="pdparam">size</var>, </td></tr><tr><td> </td><td>size_t <var class="pdparam">size_a</var>, </td></tr><tr><td> </td><td>size_t <var class="pdparam">size_b</var>, </td></tr><tr><td> </td><td>bool <var class="pdparam">committed</var>, </td></tr><tr><td> </td><td>unsigned <var class="pdparam">arena_ind</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div><div class="literallayout"><p/></div><p>An extent split function conforms to the 1200 <span class="type">extent_split_t</span> type and optionally splits an extent at 1201 given <em class="parameter"><code>addr</code></em> and <em class="parameter"><code>size</code></em> into 1202 two adjacent extents, the first of <em class="parameter"><code>size_a</code></em> bytes, 1203 and the second of <em class="parameter"><code>size_b</code></em> bytes, operating on 1204 <em class="parameter"><code>committed</code></em>/decommitted memory as indicated, on 1205 behalf of arena <em class="parameter"><code>arena_ind</code></em>, returning false upon 1206 success. If the function returns true, this indicates that the extent 1207 remains unsplit and therefore should continue to be operated on as a 1208 whole.</p><div class="funcsynopsis"><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">typedef bool <b class="fsfunc">(extent_merge_t)</b>(</code></td><td>extent_hooks_t *<var class="pdparam">extent_hooks</var>, </td></tr><tr><td> </td><td>void *<var class="pdparam">addr_a</var>, </td></tr><tr><td> </td><td>size_t <var class="pdparam">size_a</var>, </td></tr><tr><td> </td><td>void *<var class="pdparam">addr_b</var>, </td></tr><tr><td> </td><td>size_t <var class="pdparam">size_b</var>, </td></tr><tr><td> </td><td>bool <var class="pdparam">committed</var>, </td></tr><tr><td> </td><td>unsigned <var class="pdparam">arena_ind</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div><div class="literallayout"><p/></div><p>An extent merge function conforms to the 1209 <span class="type">extent_merge_t</span> type and optionally merges adjacent extents, 1210 at given <em class="parameter"><code>addr_a</code></em> and <em class="parameter"><code>size_a</code></em> 1211 with given <em class="parameter"><code>addr_b</code></em> and 1212 <em class="parameter"><code>size_b</code></em> into one contiguous extent, operating on 1213 <em class="parameter"><code>committed</code></em>/decommitted memory as indicated, on 1214 behalf of arena <em class="parameter"><code>arena_ind</code></em>, returning false upon 1215 success. If the function returns true, this indicates that the extents 1216 remain distinct mappings and therefore should continue to be operated on 1217 independently.</p></dd><dt><a name="arenas.narenas"/><span class="term"> 1218 <quote><code class="mallctl">arenas.narenas</code></quote> 1219 (<span class="type">unsigned</span>) 1220 <code class="literal">r-</code> 1221 </span></dt><dd><p>Current limit on number of arenas.</p></dd><dt><a name="arenas.dirty_decay_ms"/><span class="term"> 1222 <quote><code class="mallctl">arenas.dirty_decay_ms</code></quote> 1223 (<span class="type">ssize_t</span>) 1224 <code class="literal">rw</code> 1225 </span></dt><dd><p>Current default per-arena approximate time in 1226 milliseconds from the creation of a set of unused dirty pages until an 1227 equivalent set of unused dirty pages is purged and/or reused, used to 1228 initialize <a class="link" href="#arena.i.dirty_decay_ms"><quote><code class="mallctl">arena.<i>.dirty_decay_ms</code></quote></a> 1229 during arena creation. See <a class="link" href="#opt.dirty_decay_ms"><quote><code class="mallctl">opt.dirty_decay_ms</code></quote></a> 1230 for additional information.</p></dd><dt><a name="arenas.muzzy_decay_ms"/><span class="term"> 1231 <quote><code class="mallctl">arenas.muzzy_decay_ms</code></quote> 1232 (<span class="type">ssize_t</span>) 1233 <code class="literal">rw</code> 1234 </span></dt><dd><p>Current default per-arena approximate time in 1235 milliseconds from the creation of a set of unused muzzy pages until an 1236 equivalent set of unused muzzy pages is purged and/or reused, used to 1237 initialize <a class="link" href="#arena.i.muzzy_decay_ms"><quote><code class="mallctl">arena.<i>.muzzy_decay_ms</code></quote></a> 1238 during arena creation. See <a class="link" href="#opt.muzzy_decay_ms"><quote><code class="mallctl">opt.muzzy_decay_ms</code></quote></a> 1239 for additional information.</p></dd><dt><a name="arenas.quantum"/><span class="term"> 1240 <quote><code class="mallctl">arenas.quantum</code></quote> 1241 (<span class="type">size_t</span>) 1242 <code class="literal">r-</code> 1243 </span></dt><dd><p>Quantum size.</p></dd><dt><a name="arenas.page"/><span class="term"> 1244 <quote><code class="mallctl">arenas.page</code></quote> 1245 (<span class="type">size_t</span>) 1246 <code class="literal">r-</code> 1247 </span></dt><dd><p>Page size.</p></dd><dt><a name="arenas.tcache_max"/><span class="term"> 1248 <quote><code class="mallctl">arenas.tcache_max</code></quote> 1249 (<span class="type">size_t</span>) 1250 <code class="literal">r-</code> 1251 </span></dt><dd><p>Maximum thread-cached size class.</p></dd><dt><a name="arenas.nbins"/><span class="term"> 1252 <quote><code class="mallctl">arenas.nbins</code></quote> 1253 (<span class="type">unsigned</span>) 1254 <code class="literal">r-</code> 1255 </span></dt><dd><p>Number of bin size classes.</p></dd><dt><a name="arenas.nhbins"/><span class="term"> 1256 <quote><code class="mallctl">arenas.nhbins</code></quote> 1257 (<span class="type">unsigned</span>) 1258 <code class="literal">r-</code> 1259 </span></dt><dd><p>Total number of thread cache bin size 1260 classes.</p></dd><dt><a name="arenas.bin.i.size"/><span class="term"> 1261 <quote><code class="mallctl">arenas.bin.<i>.size</code></quote> 1262 (<span class="type">size_t</span>) 1263 <code class="literal">r-</code> 1264 </span></dt><dd><p>Maximum size supported by size class.</p></dd><dt><a name="arenas.bin.i.nregs"/><span class="term"> 1265 <quote><code class="mallctl">arenas.bin.<i>.nregs</code></quote> 1266 (<span class="type">uint32_t</span>) 1267 <code class="literal">r-</code> 1268 </span></dt><dd><p>Number of regions per slab.</p></dd><dt><a name="arenas.bin.i.slab_size"/><span class="term"> 1269 <quote><code class="mallctl">arenas.bin.<i>.slab_size</code></quote> 1270 (<span class="type">size_t</span>) 1271 <code class="literal">r-</code> 1272 </span></dt><dd><p>Number of bytes per slab.</p></dd><dt><a name="arenas.nlextents"/><span class="term"> 1273 <quote><code class="mallctl">arenas.nlextents</code></quote> 1274 (<span class="type">unsigned</span>) 1275 <code class="literal">r-</code> 1276 </span></dt><dd><p>Total number of large size classes.</p></dd><dt><a name="arenas.lextent.i.size"/><span class="term"> 1277 <quote><code class="mallctl">arenas.lextent.<i>.size</code></quote> 1278 (<span class="type">size_t</span>) 1279 <code class="literal">r-</code> 1280 </span></dt><dd><p>Maximum size supported by this large size 1281 class.</p></dd><dt><a name="arenas.create"/><span class="term"> 1282 <quote><code class="mallctl">arenas.create</code></quote> 1283 (<span class="type">unsigned</span>, <span class="type">extent_hooks_t *</span>) 1284 <code class="literal">rw</code> 1285 </span></dt><dd><p>Explicitly create a new arena outside the range of 1286 automatically managed arenas, with optionally specified extent hooks, 1287 and return the new arena index.</p><p>If the amount of space supplied for storing the arena index does 1288 not equal <code class="code">sizeof(<span class="type">unsigned</span>)</code>, no 1289 arena will be created, no data will be written to the space pointed by 1290 <em class="parameter"><code>oldp</code></em>, and <em class="parameter"><code>*oldlenp</code></em> will 1291 be set to 0. 1292 </p></dd><dt><a name="arenas.lookup"/><span class="term"> 1293 <quote><code class="mallctl">arenas.lookup</code></quote> 1294 (<span class="type">unsigned</span>, <span class="type">void*</span>) 1295 <code class="literal">rw</code> 1296 </span></dt><dd><p>Index of the arena to which an allocation belongs to.</p></dd><dt><a name="prof.thread_active_init"/><span class="term"> 1297 <quote><code class="mallctl">prof.thread_active_init</code></quote> 1298 (<span class="type">bool</span>) 1299 <code class="literal">rw</code> 1300 [<code class="option">--enable-prof</code>] 1301 </span></dt><dd><p>Control the initial setting for <a class="link" href="#thread.prof.active"><quote><code class="mallctl">thread.prof.active</code></quote></a> 1302 in newly created threads. See the <a class="link" href="#opt.prof_thread_active_init"><quote><code class="mallctl">opt.prof_thread_active_init</code></quote></a> 1303 option for additional information.</p></dd><dt><a name="prof.active"/><span class="term"> 1304 <quote><code class="mallctl">prof.active</code></quote> 1305 (<span class="type">bool</span>) 1306 <code class="literal">rw</code> 1307 [<code class="option">--enable-prof</code>] 1308 </span></dt><dd><p>Control whether sampling is currently active. See the 1309 <a class="link" href="#opt.prof_active"><quote><code class="mallctl">opt.prof_active</code></quote></a> 1310 option for additional information, as well as the interrelated <a class="link" href="#thread.prof.active"><quote><code class="mallctl">thread.prof.active</code></quote></a> 1311 mallctl.</p></dd><dt><a name="prof.dump"/><span class="term"> 1312 <quote><code class="mallctl">prof.dump</code></quote> 1313 (<span class="type">const char *</span>) 1314 <code class="literal">-w</code> 1315 [<code class="option">--enable-prof</code>] 1316 </span></dt><dd><p>Dump a memory profile to the specified file, or if NULL 1317 is specified, to a file according to the pattern 1318 <code class="filename"><prefix>.<pid>.<seq>.m<mseq>.heap</code>, 1319 where <code class="literal"><prefix></code> is controlled by the 1320 <a class="link" href="#opt.prof_prefix"><quote><code class="mallctl">opt.prof_prefix</code></quote></a> 1321 and <a class="link" href="#prof.prefix"><quote><code class="mallctl">prof.prefix</code></quote></a> 1322 options.</p></dd><dt><a name="prof.prefix"/><span class="term"> 1323 <quote><code class="mallctl">prof.prefix</code></quote> 1324 (<span class="type">const char *</span>) 1325 <code class="literal">-w</code> 1326 [<code class="option">--enable-prof</code>] 1327 </span></dt><dd><p>Set the filename prefix for profile dumps. See 1328 <a class="link" href="#opt.prof_prefix"><quote><code class="mallctl">opt.prof_prefix</code></quote></a> 1329 for the default setting. This can be useful to differentiate profile 1330 dumps such as from forked processes. 1331 </p></dd><dt><a name="prof.gdump"/><span class="term"> 1332 <quote><code class="mallctl">prof.gdump</code></quote> 1333 (<span class="type">bool</span>) 1334 <code class="literal">rw</code> 1335 [<code class="option">--enable-prof</code>] 1336 </span></dt><dd><p>When enabled, trigger a memory profile dump every time 1337 the total virtual memory exceeds the previous maximum. Profiles are 1338 dumped to files named according to the pattern 1339 <code class="filename"><prefix>.<pid>.<seq>.u<useq>.heap</code>, 1340 where <code class="literal"><prefix></code> is controlled by the <a class="link" href="#opt.prof_prefix"><quote><code class="mallctl">opt.prof_prefix</code></quote></a> and 1341 <a class="link" href="#prof.prefix"><quote><code class="mallctl">prof.prefix</code></quote></a> 1342 options.</p></dd><dt><a name="prof.reset"/><span class="term"> 1343 <quote><code class="mallctl">prof.reset</code></quote> 1344 (<span class="type">size_t</span>) 1345 <code class="literal">-w</code> 1346 [<code class="option">--enable-prof</code>] 1347 </span></dt><dd><p>Reset all memory profile statistics, and optionally 1348 update the sample rate (see <a class="link" href="#opt.lg_prof_sample"><quote><code class="mallctl">opt.lg_prof_sample</code></quote></a> 1349 and <a class="link" href="#prof.lg_sample"><quote><code class="mallctl">prof.lg_sample</code></quote></a>). 1350 </p></dd><dt><a name="prof.lg_sample"/><span class="term"> 1351 <quote><code class="mallctl">prof.lg_sample</code></quote> 1352 (<span class="type">size_t</span>) 1353 <code class="literal">r-</code> 1354 [<code class="option">--enable-prof</code>] 1355 </span></dt><dd><p>Get the current sample rate (see <a class="link" href="#opt.lg_prof_sample"><quote><code class="mallctl">opt.lg_prof_sample</code></quote></a>). 1356 </p></dd><dt><a name="prof.interval"/><span class="term"> 1357 <quote><code class="mallctl">prof.interval</code></quote> 1358 (<span class="type">uint64_t</span>) 1359 <code class="literal">r-</code> 1360 [<code class="option">--enable-prof</code>] 1361 </span></dt><dd><p>Average number of bytes allocated between 1362 interval-based profile dumps. See the 1363 <a class="link" href="#opt.lg_prof_interval"><quote><code class="mallctl">opt.lg_prof_interval</code></quote></a> 1364 option for additional information.</p></dd><dt><a name="stats.allocated"/><span class="term"> 1365 <quote><code class="mallctl">stats.allocated</code></quote> 1366 (<span class="type">size_t</span>) 1367 <code class="literal">r-</code> 1368 [<code class="option">--enable-stats</code>] 1369 </span></dt><dd><p>Total number of bytes allocated by the 1370 application.</p></dd><dt><a name="stats.active"/><span class="term"> 1371 <quote><code class="mallctl">stats.active</code></quote> 1372 (<span class="type">size_t</span>) 1373 <code class="literal">r-</code> 1374 [<code class="option">--enable-stats</code>] 1375 </span></dt><dd><p>Total number of bytes in active pages allocated by the 1376 application. This is a multiple of the page size, and greater than or 1377 equal to <a class="link" href="#stats.allocated"><quote><code class="mallctl">stats.allocated</code></quote></a>. 1378 This does not include <a class="link" href="#stats.arenas.i.pdirty"> 1379 <quote><code class="mallctl">stats.arenas.<i>.pdirty</code></quote></a>, 1380 <a class="link" href="#stats.arenas.i.pmuzzy"> 1381 <quote><code class="mallctl">stats.arenas.<i>.pmuzzy</code></quote></a>, nor pages 1382 entirely devoted to allocator metadata.</p></dd><dt><a name="stats.metadata"/><span class="term"> 1383 <quote><code class="mallctl">stats.metadata</code></quote> 1384 (<span class="type">size_t</span>) 1385 <code class="literal">r-</code> 1386 [<code class="option">--enable-stats</code>] 1387 </span></dt><dd><p>Total number of bytes dedicated to metadata, which 1388 comprise base allocations used for bootstrap-sensitive allocator 1389 metadata structures (see <a class="link" href="#stats.arenas.i.base"><quote><code class="mallctl">stats.arenas.<i>.base</code></quote></a>) 1390 and internal allocations (see <a class="link" href="#stats.arenas.i.internal"><quote><code class="mallctl">stats.arenas.<i>.internal</code></quote></a>). 1391 Transparent huge page (enabled with <a class="link" href="#opt.metadata_thp">opt.metadata_thp</a>) usage is not 1392 considered.</p></dd><dt><a name="stats.metadata_thp"/><span class="term"> 1393 <quote><code class="mallctl">stats.metadata_thp</code></quote> 1394 (<span class="type">size_t</span>) 1395 <code class="literal">r-</code> 1396 [<code class="option">--enable-stats</code>] 1397 </span></dt><dd><p>Number of transparent huge pages (THP) used for 1398 metadata. See <a class="link" href="#stats.metadata"><quote><code class="mallctl">stats.metadata</code></quote></a> and 1399 <a class="link" href="#opt.metadata_thp">opt.metadata_thp</a>) for 1400 details.</p></dd><dt><a name="stats.resident"/><span class="term"> 1401 <quote><code class="mallctl">stats.resident</code></quote> 1402 (<span class="type">size_t</span>) 1403 <code class="literal">r-</code> 1404 [<code class="option">--enable-stats</code>] 1405 </span></dt><dd><p>Maximum number of bytes in physically resident data 1406 pages mapped by the allocator, comprising all pages dedicated to 1407 allocator metadata, pages backing active allocations, and unused dirty 1408 pages. This is a maximum rather than precise because pages may not 1409 actually be physically resident if they correspond to demand-zeroed 1410 virtual memory that has not yet been touched. This is a multiple of the 1411 page size, and is larger than <a class="link" href="#stats.active"><quote><code class="mallctl">stats.active</code></quote></a>.</p></dd><dt><a name="stats.mapped"/><span class="term"> 1412 <quote><code class="mallctl">stats.mapped</code></quote> 1413 (<span class="type">size_t</span>) 1414 <code class="literal">r-</code> 1415 [<code class="option">--enable-stats</code>] 1416 </span></dt><dd><p>Total number of bytes in active extents mapped by the 1417 allocator. This is larger than <a class="link" href="#stats.active"><quote><code class="mallctl">stats.active</code></quote></a>. This 1418 does not include inactive extents, even those that contain unused dirty 1419 pages, which means that there is no strict ordering between this and 1420 <a class="link" href="#stats.resident"><quote><code class="mallctl">stats.resident</code></quote></a>.</p></dd><dt><a name="stats.retained"/><span class="term"> 1421 <quote><code class="mallctl">stats.retained</code></quote> 1422 (<span class="type">size_t</span>) 1423 <code class="literal">r-</code> 1424 [<code class="option">--enable-stats</code>] 1425 </span></dt><dd><p>Total number of bytes in virtual memory mappings that 1426 were retained rather than being returned to the operating system via 1427 e.g. <span class="citerefentry"><span class="refentrytitle">munmap</span>(2)</span> or similar. Retained virtual 1428 memory is typically untouched, decommitted, or purged, so it has no 1429 strongly associated physical memory (see <a class="link" href="#arena.i.extent_hooks">extent hooks</a> for details). 1430 Retained memory is excluded from mapped memory statistics, e.g. <a class="link" href="#stats.mapped"><quote><code class="mallctl">stats.mapped</code></quote></a>. 1431 </p></dd><dt><a name="stats.zero_reallocs"/><span class="term"> 1432 <quote><code class="mallctl">stats.zero_reallocs</code></quote> 1433 (<span class="type">size_t</span>) 1434 <code class="literal">r-</code> 1435 [<code class="option">--enable-stats</code>] 1436 </span></dt><dd><p>Number of times that the <code class="function">realloc()</code> 1437 was called with a non-<code class="constant">NULL</code> pointer argument and a 1438 <code class="constant">0</code> size argument. This is a fundamentally unsafe 1439 pattern in portable programs; see <a class="link" href="#opt.zero_realloc"> 1440 <quote><code class="mallctl">opt.zero_realloc</code></quote></a> for details. 1441 </p></dd><dt><a name="stats.background_thread.num_threads"/><span class="term"> 1442 <quote><code class="mallctl">stats.background_thread.num_threads</code></quote> 1443 (<span class="type">size_t</span>) 1444 <code class="literal">r-</code> 1445 [<code class="option">--enable-stats</code>] 1446 </span></dt><dd><p> Number of <a class="link" href="#background_thread">background 1447 threads</a> running currently.</p></dd><dt><a name="stats.background_thread.num_runs"/><span class="term"> 1448 <quote><code class="mallctl">stats.background_thread.num_runs</code></quote> 1449 (<span class="type">uint64_t</span>) 1450 <code class="literal">r-</code> 1451 [<code class="option">--enable-stats</code>] 1452 </span></dt><dd><p> Total number of runs from all <a class="link" href="#background_thread">background threads</a>.</p></dd><dt><a name="stats.background_thread.run_interval"/><span class="term"> 1453 <quote><code class="mallctl">stats.background_thread.run_interval</code></quote> 1454 (<span class="type">uint64_t</span>) 1455 <code class="literal">r-</code> 1456 [<code class="option">--enable-stats</code>] 1457 </span></dt><dd><p> Average run interval in nanoseconds of <a class="link" href="#background_thread">background threads</a>.</p></dd><dt><a name="stats.mutexes.ctl"/><span class="term"> 1458 <quote><code class="mallctl">stats.mutexes.ctl.{counter};</code></quote> 1459 (<span class="type">counter specific type</span>) 1460 <code class="literal">r-</code> 1461 [<code class="option">--enable-stats</code>] 1462 </span></dt><dd><p>Statistics on <code class="varname">ctl</code> mutex (global 1463 scope; mallctl related). <quote><code class="mallctl">{counter}</code></quote> is one of the 1464 counters below:</p><dt><a name="mutex_counters"/></dt><dd><p><code class="varname">num_ops</code> (<span class="type">uint64_t</span>): 1465 Total number of lock acquisition operations on this mutex.</p><p><code class="varname">num_spin_acq</code> (<span class="type">uint64_t</span>): Number 1466 of times the mutex was spin-acquired. When the mutex is currently 1467 locked and cannot be acquired immediately, a short period of 1468 spin-retry within jemalloc will be performed. Acquired through spin 1469 generally means the contention was lightweight and not causing context 1470 switches.</p><p><code class="varname">num_wait</code> (<span class="type">uint64_t</span>): Number of 1471 times the mutex was wait-acquired, which means the mutex contention 1472 was not solved by spin-retry, and blocking operation was likely 1473 involved in order to acquire the mutex. This event generally implies 1474 higher cost / longer delay, and should be investigated if it happens 1475 often.</p><p><code class="varname">max_wait_time</code> (<span class="type">uint64_t</span>): 1476 Maximum length of time in nanoseconds spent on a single wait-acquired 1477 lock operation. Note that to avoid profiling overhead on the common 1478 path, this does not consider spin-acquired cases.</p><p><code class="varname">total_wait_time</code> (<span class="type">uint64_t</span>): 1479 Cumulative time in nanoseconds spent on wait-acquired lock operations. 1480 Similarly, spin-acquired cases are not considered.</p><p><code class="varname">max_num_thds</code> (<span class="type">uint32_t</span>): Maximum 1481 number of threads waiting on this mutex simultaneously. Similarly, 1482 spin-acquired cases are not considered.</p><p><code class="varname">num_owner_switch</code> (<span class="type">uint64_t</span>): 1483 Number of times the current mutex owner is different from the previous 1484 one. This event does not generally imply an issue; rather it is an 1485 indicator of how often the protected data are accessed by different 1486 threads. 1487 </p></dd></dd><dt><a name="stats.mutexes.background_thread"/><span class="term"> 1488 <quote><code class="mallctl">stats.mutexes.background_thread.{counter}</code></quote> 1489 (<span class="type">counter specific type</span>) <code class="literal">r-</code> 1490 [<code class="option">--enable-stats</code>] 1491 </span></dt><dd><p>Statistics on <code class="varname">background_thread</code> mutex 1492 (global scope; <a class="link" href="#background_thread"><quote><code class="mallctl">background_thread</code></quote></a> 1493 related). <quote><code class="mallctl">{counter}</code></quote> is one of the counters in <a class="link" href="#mutex_counters">mutex profiling 1494 counters</a>.</p></dd><dt><a name="stats.mutexes.prof"/><span class="term"> 1495 <quote><code class="mallctl">stats.mutexes.prof.{counter}</code></quote> 1496 (<span class="type">counter specific type</span>) <code class="literal">r-</code> 1497 [<code class="option">--enable-stats</code>] 1498 </span></dt><dd><p>Statistics on <code class="varname">prof</code> mutex (global 1499 scope; profiling related). <quote><code class="mallctl">{counter}</code></quote> is one of the 1500 counters in <a class="link" href="#mutex_counters">mutex profiling 1501 counters</a>.</p></dd><dt><a name="stats.mutexes.prof_thds_data"/><span class="term"> 1502 <quote><code class="mallctl">stats.mutexes.prof_thds_data.{counter}</code></quote> 1503 (<span class="type">counter specific type</span>) <code class="literal">r-</code> 1504 [<code class="option">--enable-stats</code>] 1505 </span></dt><dd><p>Statistics on <code class="varname">prof</code> threads data mutex 1506 (global scope; profiling related). <quote><code class="mallctl">{counter}</code></quote> is one 1507 of the counters in <a class="link" href="#mutex_counters">mutex profiling 1508 counters</a>.</p></dd><dt><a name="stats.mutexes.prof_dump"/><span class="term"> 1509 <quote><code class="mallctl">stats.mutexes.prof_dump.{counter}</code></quote> 1510 (<span class="type">counter specific type</span>) <code class="literal">r-</code> 1511 [<code class="option">--enable-stats</code>] 1512 </span></dt><dd><p>Statistics on <code class="varname">prof</code> dumping mutex 1513 (global scope; profiling related). <quote><code class="mallctl">{counter}</code></quote> is one 1514 of the counters in <a class="link" href="#mutex_counters">mutex profiling 1515 counters</a>.</p></dd><dt><a name="stats.mutexes.reset"/><span class="term"> 1516 <quote><code class="mallctl">stats.mutexes.reset</code></quote> 1517 (<span class="type">void</span>) <code class="literal">--</code> 1518 [<code class="option">--enable-stats</code>] 1519 </span></dt><dd><p>Reset all mutex profile statistics, including global 1520 mutexes, arena mutexes and bin mutexes.</p></dd><dt><a name="stats.arenas.i.dss"/><span class="term"> 1521 <quote><code class="mallctl">stats.arenas.<i>.dss</code></quote> 1522 (<span class="type">const char *</span>) 1523 <code class="literal">r-</code> 1524 </span></dt><dd><p>dss (<span class="citerefentry"><span class="refentrytitle">sbrk</span>(2)</span>) allocation precedence as 1525 related to <span class="citerefentry"><span class="refentrytitle">mmap</span>(2)</span> allocation. See <a class="link" href="#opt.dss"><quote><code class="mallctl">opt.dss</code></quote></a> for details. 1526 </p></dd><dt><a name="stats.arenas.i.dirty_decay_ms"/><span class="term"> 1527 <quote><code class="mallctl">stats.arenas.<i>.dirty_decay_ms</code></quote> 1528 (<span class="type">ssize_t</span>) 1529 <code class="literal">r-</code> 1530 </span></dt><dd><p>Approximate time in milliseconds from the creation of a 1531 set of unused dirty pages until an equivalent set of unused dirty pages 1532 is purged and/or reused. See <a class="link" href="#opt.dirty_decay_ms"><quote><code class="mallctl">opt.dirty_decay_ms</code></quote></a> 1533 for details.</p></dd><dt><a name="stats.arenas.i.muzzy_decay_ms"/><span class="term"> 1534 <quote><code class="mallctl">stats.arenas.<i>.muzzy_decay_ms</code></quote> 1535 (<span class="type">ssize_t</span>) 1536 <code class="literal">r-</code> 1537 </span></dt><dd><p>Approximate time in milliseconds from the creation of a 1538 set of unused muzzy pages until an equivalent set of unused muzzy pages 1539 is purged and/or reused. See <a class="link" href="#opt.muzzy_decay_ms"><quote><code class="mallctl">opt.muzzy_decay_ms</code></quote></a> 1540 for details.</p></dd><dt><a name="stats.arenas.i.nthreads"/><span class="term"> 1541 <quote><code class="mallctl">stats.arenas.<i>.nthreads</code></quote> 1542 (<span class="type">unsigned</span>) 1543 <code class="literal">r-</code> 1544 </span></dt><dd><p>Number of threads currently assigned to 1545 arena.</p></dd><dt><a name="stats.arenas.i.uptime"/><span class="term"> 1546 <quote><code class="mallctl">stats.arenas.<i>.uptime</code></quote> 1547 (<span class="type">uint64_t</span>) 1548 <code class="literal">r-</code> 1549 </span></dt><dd><p>Time elapsed (in nanoseconds) since the arena was 1550 created. If <i> equals <code class="constant">0</code> or 1551 <code class="constant">MALLCTL_ARENAS_ALL</code>, this is the uptime since malloc 1552 initialization.</p></dd><dt><a name="stats.arenas.i.pactive"/><span class="term"> 1553 <quote><code class="mallctl">stats.arenas.<i>.pactive</code></quote> 1554 (<span class="type">size_t</span>) 1555 <code class="literal">r-</code> 1556 </span></dt><dd><p>Number of pages in active extents.</p></dd><dt><a name="stats.arenas.i.pdirty"/><span class="term"> 1557 <quote><code class="mallctl">stats.arenas.<i>.pdirty</code></quote> 1558 (<span class="type">size_t</span>) 1559 <code class="literal">r-</code> 1560 </span></dt><dd><p>Number of pages within unused extents that are 1561 potentially dirty, and for which <code class="function">madvise()</code> or 1562 similar has not been called. See <a class="link" href="#opt.dirty_decay_ms"><quote><code class="mallctl">opt.dirty_decay_ms</code></quote></a> 1563 for a description of dirty pages.</p></dd><dt><a name="stats.arenas.i.pmuzzy"/><span class="term"> 1564 <quote><code class="mallctl">stats.arenas.<i>.pmuzzy</code></quote> 1565 (<span class="type">size_t</span>) 1566 <code class="literal">r-</code> 1567 </span></dt><dd><p>Number of pages within unused extents that are muzzy. 1568 See <a class="link" href="#opt.muzzy_decay_ms"><quote><code class="mallctl">opt.muzzy_decay_ms</code></quote></a> 1569 for a description of muzzy pages.</p></dd><dt><a name="stats.arenas.i.mapped"/><span class="term"> 1570 <quote><code class="mallctl">stats.arenas.<i>.mapped</code></quote> 1571 (<span class="type">size_t</span>) 1572 <code class="literal">r-</code> 1573 [<code class="option">--enable-stats</code>] 1574 </span></dt><dd><p>Number of mapped bytes.</p></dd><dt><a name="stats.arenas.i.retained"/><span class="term"> 1575 <quote><code class="mallctl">stats.arenas.<i>.retained</code></quote> 1576 (<span class="type">size_t</span>) 1577 <code class="literal">r-</code> 1578 [<code class="option">--enable-stats</code>] 1579 </span></dt><dd><p>Number of retained bytes. See <a class="link" href="#stats.retained"><quote><code class="mallctl">stats.retained</code></quote></a> for 1580 details.</p></dd><dt><a name="stats.arenas.i.extent_avail"/><span class="term"> 1581 <quote><code class="mallctl">stats.arenas.<i>.extent_avail</code></quote> 1582 (<span class="type">size_t</span>) 1583 <code class="literal">r-</code> 1584 [<code class="option">--enable-stats</code>] 1585 </span></dt><dd><p>Number of allocated (but unused) extent structs in this 1586 arena.</p></dd><dt><a name="stats.arenas.i.base"/><span class="term"> 1587 <quote><code class="mallctl">stats.arenas.<i>.base</code></quote> 1588 (<span class="type">size_t</span>) 1589 <code class="literal">r-</code> 1590 [<code class="option">--enable-stats</code>] 1591 </span></dt><dd><p> 1592 Number of bytes dedicated to bootstrap-sensitive allocator metadata 1593 structures.</p></dd><dt><a name="stats.arenas.i.internal"/><span class="term"> 1594 <quote><code class="mallctl">stats.arenas.<i>.internal</code></quote> 1595 (<span class="type">size_t</span>) 1596 <code class="literal">r-</code> 1597 [<code class="option">--enable-stats</code>] 1598 </span></dt><dd><p>Number of bytes dedicated to internal allocations. 1599 Internal allocations differ from application-originated allocations in 1600 that they are for internal use, and that they are omitted from heap 1601 profiles.</p></dd><dt><a name="stats.arenas.i.metadata_thp"/><span class="term"> 1602 <quote><code class="mallctl">stats.arenas.<i>.metadata_thp</code></quote> 1603 (<span class="type">size_t</span>) 1604 <code class="literal">r-</code> 1605 [<code class="option">--enable-stats</code>] 1606 </span></dt><dd><p>Number of transparent huge pages (THP) used for 1607 metadata. See <a class="link" href="#opt.metadata_thp">opt.metadata_thp</a> 1608 for details.</p></dd><dt><a name="stats.arenas.i.resident"/><span class="term"> 1609 <quote><code class="mallctl">stats.arenas.<i>.resident</code></quote> 1610 (<span class="type">size_t</span>) 1611 <code class="literal">r-</code> 1612 [<code class="option">--enable-stats</code>] 1613 </span></dt><dd><p>Maximum number of bytes in physically resident data 1614 pages mapped by the arena, comprising all pages dedicated to allocator 1615 metadata, pages backing active allocations, and unused dirty pages. 1616 This is a maximum rather than precise because pages may not actually be 1617 physically resident if they correspond to demand-zeroed virtual memory 1618 that has not yet been touched. This is a multiple of the page 1619 size.</p></dd><dt><a name="stats.arenas.i.dirty_npurge"/><span class="term"> 1620 <quote><code class="mallctl">stats.arenas.<i>.dirty_npurge</code></quote> 1621 (<span class="type">uint64_t</span>) 1622 <code class="literal">r-</code> 1623 [<code class="option">--enable-stats</code>] 1624 </span></dt><dd><p>Number of dirty page purge sweeps performed. 1625 </p></dd><dt><a name="stats.arenas.i.dirty_nmadvise"/><span class="term"> 1626 <quote><code class="mallctl">stats.arenas.<i>.dirty_nmadvise</code></quote> 1627 (<span class="type">uint64_t</span>) 1628 <code class="literal">r-</code> 1629 [<code class="option">--enable-stats</code>] 1630 </span></dt><dd><p>Number of <code class="function">madvise()</code> or similar 1631 calls made to purge dirty pages.</p></dd><dt><a name="stats.arenas.i.dirty_purged"/><span class="term"> 1632 <quote><code class="mallctl">stats.arenas.<i>.dirty_purged</code></quote> 1633 (<span class="type">uint64_t</span>) 1634 <code class="literal">r-</code> 1635 [<code class="option">--enable-stats</code>] 1636 </span></dt><dd><p>Number of dirty pages purged.</p></dd><dt><a name="stats.arenas.i.muzzy_npurge"/><span class="term"> 1637 <quote><code class="mallctl">stats.arenas.<i>.muzzy_npurge</code></quote> 1638 (<span class="type">uint64_t</span>) 1639 <code class="literal">r-</code> 1640 [<code class="option">--enable-stats</code>] 1641 </span></dt><dd><p>Number of muzzy page purge sweeps performed. 1642 </p></dd><dt><a name="stats.arenas.i.muzzy_nmadvise"/><span class="term"> 1643 <quote><code class="mallctl">stats.arenas.<i>.muzzy_nmadvise</code></quote> 1644 (<span class="type">uint64_t</span>) 1645 <code class="literal">r-</code> 1646 [<code class="option">--enable-stats</code>] 1647 </span></dt><dd><p>Number of <code class="function">madvise()</code> or similar 1648 calls made to purge muzzy pages.</p></dd><dt><a name="stats.arenas.i.muzzy_purged"/><span class="term"> 1649 <quote><code class="mallctl">stats.arenas.<i>.muzzy_purged</code></quote> 1650 (<span class="type">uint64_t</span>) 1651 <code class="literal">r-</code> 1652 [<code class="option">--enable-stats</code>] 1653 </span></dt><dd><p>Number of muzzy pages purged.</p></dd><dt><a name="stats.arenas.i.small.allocated"/><span class="term"> 1654 <quote><code class="mallctl">stats.arenas.<i>.small.allocated</code></quote> 1655 (<span class="type">size_t</span>) 1656 <code class="literal">r-</code> 1657 [<code class="option">--enable-stats</code>] 1658 </span></dt><dd><p>Number of bytes currently allocated by small objects. 1659 </p></dd><dt><a name="stats.arenas.i.small.nmalloc"/><span class="term"> 1660 <quote><code class="mallctl">stats.arenas.<i>.small.nmalloc</code></quote> 1661 (<span class="type">uint64_t</span>) 1662 <code class="literal">r-</code> 1663 [<code class="option">--enable-stats</code>] 1664 </span></dt><dd><p>Cumulative number of times a small allocation was 1665 requested from the arena's bins, whether to fill the relevant tcache if 1666 <a class="link" href="#opt.tcache"><quote><code class="mallctl">opt.tcache</code></quote></a> is 1667 enabled, or to directly satisfy an allocation request 1668 otherwise.</p></dd><dt><a name="stats.arenas.i.small.ndalloc"/><span class="term"> 1669 <quote><code class="mallctl">stats.arenas.<i>.small.ndalloc</code></quote> 1670 (<span class="type">uint64_t</span>) 1671 <code class="literal">r-</code> 1672 [<code class="option">--enable-stats</code>] 1673 </span></dt><dd><p>Cumulative number of times a small allocation was 1674 returned to the arena's bins, whether to flush the relevant tcache if 1675 <a class="link" href="#opt.tcache"><quote><code class="mallctl">opt.tcache</code></quote></a> is 1676 enabled, or to directly deallocate an allocation 1677 otherwise.</p></dd><dt><a name="stats.arenas.i.small.nrequests"/><span class="term"> 1678 <quote><code class="mallctl">stats.arenas.<i>.small.nrequests</code></quote> 1679 (<span class="type">uint64_t</span>) 1680 <code class="literal">r-</code> 1681 [<code class="option">--enable-stats</code>] 1682 </span></dt><dd><p>Cumulative number of allocation requests satisfied by 1683 all bin size classes.</p></dd><dt><a name="stats.arenas.i.small.nfills"/><span class="term"> 1684 <quote><code class="mallctl">stats.arenas.<i>.small.nfills</code></quote> 1685 (<span class="type">uint64_t</span>) 1686 <code class="literal">r-</code> 1687 [<code class="option">--enable-stats</code>] 1688 </span></dt><dd><p>Cumulative number of tcache fills by all small size 1689 classes.</p></dd><dt><a name="stats.arenas.i.small.nflushes"/><span class="term"> 1690 <quote><code class="mallctl">stats.arenas.<i>.small.nflushes</code></quote> 1691 (<span class="type">uint64_t</span>) 1692 <code class="literal">r-</code> 1693 [<code class="option">--enable-stats</code>] 1694 </span></dt><dd><p>Cumulative number of tcache flushes by all small size 1695 classes.</p></dd><dt><a name="stats.arenas.i.large.allocated"/><span class="term"> 1696 <quote><code class="mallctl">stats.arenas.<i>.large.allocated</code></quote> 1697 (<span class="type">size_t</span>) 1698 <code class="literal">r-</code> 1699 [<code class="option">--enable-stats</code>] 1700 </span></dt><dd><p>Number of bytes currently allocated by large objects. 1701 </p></dd><dt><a name="stats.arenas.i.large.nmalloc"/><span class="term"> 1702 <quote><code class="mallctl">stats.arenas.<i>.large.nmalloc</code></quote> 1703 (<span class="type">uint64_t</span>) 1704 <code class="literal">r-</code> 1705 [<code class="option">--enable-stats</code>] 1706 </span></dt><dd><p>Cumulative number of times a large extent was allocated 1707 from the arena, whether to fill the relevant tcache if <a class="link" href="#opt.tcache"><quote><code class="mallctl">opt.tcache</code></quote></a> is enabled and 1708 the size class is within the range being cached, or to directly satisfy 1709 an allocation request otherwise.</p></dd><dt><a name="stats.arenas.i.large.ndalloc"/><span class="term"> 1710 <quote><code class="mallctl">stats.arenas.<i>.large.ndalloc</code></quote> 1711 (<span class="type">uint64_t</span>) 1712 <code class="literal">r-</code> 1713 [<code class="option">--enable-stats</code>] 1714 </span></dt><dd><p>Cumulative number of times a large extent was returned 1715 to the arena, whether to flush the relevant tcache if <a class="link" href="#opt.tcache"><quote><code class="mallctl">opt.tcache</code></quote></a> is enabled and 1716 the size class is within the range being cached, or to directly 1717 deallocate an allocation otherwise.</p></dd><dt><a name="stats.arenas.i.large.nrequests"/><span class="term"> 1718 <quote><code class="mallctl">stats.arenas.<i>.large.nrequests</code></quote> 1719 (<span class="type">uint64_t</span>) 1720 <code class="literal">r-</code> 1721 [<code class="option">--enable-stats</code>] 1722 </span></dt><dd><p>Cumulative number of allocation requests satisfied by 1723 all large size classes.</p></dd><dt><a name="stats.arenas.i.large.nfills"/><span class="term"> 1724 <quote><code class="mallctl">stats.arenas.<i>.large.nfills</code></quote> 1725 (<span class="type">uint64_t</span>) 1726 <code class="literal">r-</code> 1727 [<code class="option">--enable-stats</code>] 1728 </span></dt><dd><p>Cumulative number of tcache fills by all large size 1729 classes.</p></dd><dt><a name="stats.arenas.i.large.nflushes"/><span class="term"> 1730 <quote><code class="mallctl">stats.arenas.<i>.large.nflushes</code></quote> 1731 (<span class="type">uint64_t</span>) 1732 <code class="literal">r-</code> 1733 [<code class="option">--enable-stats</code>] 1734 </span></dt><dd><p>Cumulative number of tcache flushes by all large size 1735 classes.</p></dd><dt><a name="stats.arenas.i.bins.j.nmalloc"/><span class="term"> 1736 <quote><code class="mallctl">stats.arenas.<i>.bins.<j>.nmalloc</code></quote> 1737 (<span class="type">uint64_t</span>) 1738 <code class="literal">r-</code> 1739 [<code class="option">--enable-stats</code>] 1740 </span></dt><dd><p>Cumulative number of times a bin region of the 1741 corresponding size class was allocated from the arena, whether to fill 1742 the relevant tcache if <a class="link" href="#opt.tcache"><quote><code class="mallctl">opt.tcache</code></quote></a> is enabled, or 1743 to directly satisfy an allocation request otherwise.</p></dd><dt><a name="stats.arenas.i.bins.j.ndalloc"/><span class="term"> 1744 <quote><code class="mallctl">stats.arenas.<i>.bins.<j>.ndalloc</code></quote> 1745 (<span class="type">uint64_t</span>) 1746 <code class="literal">r-</code> 1747 [<code class="option">--enable-stats</code>] 1748 </span></dt><dd><p>Cumulative number of times a bin region of the 1749 corresponding size class was returned to the arena, whether to flush the 1750 relevant tcache if <a class="link" href="#opt.tcache"><quote><code class="mallctl">opt.tcache</code></quote></a> is enabled, or 1751 to directly deallocate an allocation otherwise.</p></dd><dt><a name="stats.arenas.i.bins.j.nrequests"/><span class="term"> 1752 <quote><code class="mallctl">stats.arenas.<i>.bins.<j>.nrequests</code></quote> 1753 (<span class="type">uint64_t</span>) 1754 <code class="literal">r-</code> 1755 [<code class="option">--enable-stats</code>] 1756 </span></dt><dd><p>Cumulative number of allocation requests satisfied by 1757 bin regions of the corresponding size class.</p></dd><dt><a name="stats.arenas.i.bins.j.curregs"/><span class="term"> 1758 <quote><code class="mallctl">stats.arenas.<i>.bins.<j>.curregs</code></quote> 1759 (<span class="type">size_t</span>) 1760 <code class="literal">r-</code> 1761 [<code class="option">--enable-stats</code>] 1762 </span></dt><dd><p>Current number of regions for this size 1763 class.</p></dd><dt><a name="stats.arenas.i.bins.j.nfills"/><span class="term"> 1764 <quote><code class="mallctl">stats.arenas.<i>.bins.<j>.nfills</code></quote> 1765 (<span class="type">uint64_t</span>) 1766 <code class="literal">r-</code> 1767 </span></dt><dd><p>Cumulative number of tcache fills.</p></dd><dt><a name="stats.arenas.i.bins.j.nflushes"/><span class="term"> 1768 <quote><code class="mallctl">stats.arenas.<i>.bins.<j>.nflushes</code></quote> 1769 (<span class="type">uint64_t</span>) 1770 <code class="literal">r-</code> 1771 </span></dt><dd><p>Cumulative number of tcache flushes.</p></dd><dt><a name="stats.arenas.i.bins.j.nslabs"/><span class="term"> 1772 <quote><code class="mallctl">stats.arenas.<i>.bins.<j>.nslabs</code></quote> 1773 (<span class="type">uint64_t</span>) 1774 <code class="literal">r-</code> 1775 [<code class="option">--enable-stats</code>] 1776 </span></dt><dd><p>Cumulative number of slabs created.</p></dd><dt><a name="stats.arenas.i.bins.j.nreslabs"/><span class="term"> 1777 <quote><code class="mallctl">stats.arenas.<i>.bins.<j>.nreslabs</code></quote> 1778 (<span class="type">uint64_t</span>) 1779 <code class="literal">r-</code> 1780 [<code class="option">--enable-stats</code>] 1781 </span></dt><dd><p>Cumulative number of times the current slab from which 1782 to allocate changed.</p></dd><dt><a name="stats.arenas.i.bins.j.curslabs"/><span class="term"> 1783 <quote><code class="mallctl">stats.arenas.<i>.bins.<j>.curslabs</code></quote> 1784 (<span class="type">size_t</span>) 1785 <code class="literal">r-</code> 1786 [<code class="option">--enable-stats</code>] 1787 </span></dt><dd><p>Current number of slabs.</p></dd><dt><a name="stats.arenas.i.bins.j.nonfull_slabs"/><span class="term"> 1788 <quote><code class="mallctl">stats.arenas.<i>.bins.<j>.nonfull_slabs</code></quote> 1789 (<span class="type">size_t</span>) 1790 <code class="literal">r-</code> 1791 [<code class="option">--enable-stats</code>] 1792 </span></dt><dd><p>Current number of nonfull slabs.</p></dd><dt><a name="stats.arenas.i.bins.mutex"/><span class="term"> 1793 <quote><code class="mallctl">stats.arenas.<i>.bins.<j>.mutex.{counter}</code></quote> 1794 (<span class="type">counter specific type</span>) <code class="literal">r-</code> 1795 [<code class="option">--enable-stats</code>] 1796 </span></dt><dd><p>Statistics on 1797 <code class="varname">arena.<i>.bins.<j></code> mutex (arena bin 1798 scope; bin operation related). <quote><code class="mallctl">{counter}</code></quote> is one of 1799 the counters in <a class="link" href="#mutex_counters">mutex profiling 1800 counters</a>.</p></dd><dt><a name="stats.arenas.i.extents.n"/><span class="term"> 1801 <quote><code class="mallctl">stats.arenas.<i>.extents.<j>.n{extent_type}</code></quote> 1802 (<span class="type">size_t</span>) 1803 <code class="literal">r-</code> 1804 [<code class="option">--enable-stats</code>] 1805 </span></dt><dd><p> Number of extents of the given type in this arena in 1806 the bucket corresponding to page size index <j>. The extent type 1807 is one of dirty, muzzy, or retained.</p></dd><dt><a name="stats.arenas.i.extents.bytes"/><span class="term"> 1808 <quote><code class="mallctl">stats.arenas.<i>.extents.<j>.{extent_type}_bytes</code></quote> 1809 (<span class="type">size_t</span>) 1810 <code class="literal">r-</code> 1811 [<code class="option">--enable-stats</code>] 1812 </span></dt><dd><p> Sum of the bytes managed by extents of the given type 1813 in this arena in the bucket corresponding to page size index <j>. 1814 The extent type is one of dirty, muzzy, or retained.</p></dd><dt><a name="stats.arenas.i.lextents.j.nmalloc"/><span class="term"> 1815 <quote><code class="mallctl">stats.arenas.<i>.lextents.<j>.nmalloc</code></quote> 1816 (<span class="type">uint64_t</span>) 1817 <code class="literal">r-</code> 1818 [<code class="option">--enable-stats</code>] 1819 </span></dt><dd><p>Cumulative number of times a large extent of the 1820 corresponding size class was allocated from the arena, whether to fill 1821 the relevant tcache if <a class="link" href="#opt.tcache"><quote><code class="mallctl">opt.tcache</code></quote></a> is enabled and 1822 the size class is within the range being cached, or to directly satisfy 1823 an allocation request otherwise.</p></dd><dt><a name="stats.arenas.i.lextents.j.ndalloc"/><span class="term"> 1824 <quote><code class="mallctl">stats.arenas.<i>.lextents.<j>.ndalloc</code></quote> 1825 (<span class="type">uint64_t</span>) 1826 <code class="literal">r-</code> 1827 [<code class="option">--enable-stats</code>] 1828 </span></dt><dd><p>Cumulative number of times a large extent of the 1829 corresponding size class was returned to the arena, whether to flush the 1830 relevant tcache if <a class="link" href="#opt.tcache"><quote><code class="mallctl">opt.tcache</code></quote></a> is enabled and 1831 the size class is within the range being cached, or to directly 1832 deallocate an allocation otherwise.</p></dd><dt><a name="stats.arenas.i.lextents.j.nrequests"/><span class="term"> 1833 <quote><code class="mallctl">stats.arenas.<i>.lextents.<j>.nrequests</code></quote> 1834 (<span class="type">uint64_t</span>) 1835 <code class="literal">r-</code> 1836 [<code class="option">--enable-stats</code>] 1837 </span></dt><dd><p>Cumulative number of allocation requests satisfied by 1838 large extents of the corresponding size class.</p></dd><dt><a name="stats.arenas.i.lextents.j.curlextents"/><span class="term"> 1839 <quote><code class="mallctl">stats.arenas.<i>.lextents.<j>.curlextents</code></quote> 1840 (<span class="type">size_t</span>) 1841 <code class="literal">r-</code> 1842 [<code class="option">--enable-stats</code>] 1843 </span></dt><dd><p>Current number of large allocations for this size class. 1844 </p></dd><dt><a name="stats.arenas.i.mutexes.large"/><span class="term"> 1845 <quote><code class="mallctl">stats.arenas.<i>.mutexes.large.{counter}</code></quote> 1846 (<span class="type">counter specific type</span>) <code class="literal">r-</code> 1847 [<code class="option">--enable-stats</code>] 1848 </span></dt><dd><p>Statistics on <code class="varname">arena.<i>.large</code> 1849 mutex (arena scope; large allocation related). 1850 <quote><code class="mallctl">{counter}</code></quote> is one of the counters in <a class="link" href="#mutex_counters">mutex profiling 1851 counters</a>.</p></dd><dt><a name="stats.arenas.i.mutexes.extent_avail"/><span class="term"> 1852 <quote><code class="mallctl">stats.arenas.<i>.mutexes.extent_avail.{counter}</code></quote> 1853 (<span class="type">counter specific type</span>) <code class="literal">r-</code> 1854 [<code class="option">--enable-stats</code>] 1855 </span></dt><dd><p>Statistics on <code class="varname">arena.<i>.extent_avail 1856 </code> mutex (arena scope; extent avail related). 1857 <quote><code class="mallctl">{counter}</code></quote> is one of the counters in <a class="link" href="#mutex_counters">mutex profiling 1858 counters</a>.</p></dd><dt><a name="stats.arenas.i.mutexes.extents_dirty"/><span class="term"> 1859 <quote><code class="mallctl">stats.arenas.<i>.mutexes.extents_dirty.{counter}</code></quote> 1860 (<span class="type">counter specific type</span>) <code class="literal">r-</code> 1861 [<code class="option">--enable-stats</code>] 1862 </span></dt><dd><p>Statistics on <code class="varname">arena.<i>.extents_dirty 1863 </code> mutex (arena scope; dirty extents related). 1864 <quote><code class="mallctl">{counter}</code></quote> is one of the counters in <a class="link" href="#mutex_counters">mutex profiling 1865 counters</a>.</p></dd><dt><a name="stats.arenas.i.mutexes.extents_muzzy"/><span class="term"> 1866 <quote><code class="mallctl">stats.arenas.<i>.mutexes.extents_muzzy.{counter}</code></quote> 1867 (<span class="type">counter specific type</span>) <code class="literal">r-</code> 1868 [<code class="option">--enable-stats</code>] 1869 </span></dt><dd><p>Statistics on <code class="varname">arena.<i>.extents_muzzy 1870 </code> mutex (arena scope; muzzy extents related). 1871 <quote><code class="mallctl">{counter}</code></quote> is one of the counters in <a class="link" href="#mutex_counters">mutex profiling 1872 counters</a>.</p></dd><dt><a name="stats.arenas.i.mutexes.extents_retained"/><span class="term"> 1873 <quote><code class="mallctl">stats.arenas.<i>.mutexes.extents_retained.{counter}</code></quote> 1874 (<span class="type">counter specific type</span>) <code class="literal">r-</code> 1875 [<code class="option">--enable-stats</code>] 1876 </span></dt><dd><p>Statistics on <code class="varname">arena.<i>.extents_retained 1877 </code> mutex (arena scope; retained extents related). 1878 <quote><code class="mallctl">{counter}</code></quote> is one of the counters in <a class="link" href="#mutex_counters">mutex profiling 1879 counters</a>.</p></dd><dt><a name="stats.arenas.i.mutexes.decay_dirty"/><span class="term"> 1880 <quote><code class="mallctl">stats.arenas.<i>.mutexes.decay_dirty.{counter}</code></quote> 1881 (<span class="type">counter specific type</span>) <code class="literal">r-</code> 1882 [<code class="option">--enable-stats</code>] 1883 </span></dt><dd><p>Statistics on <code class="varname">arena.<i>.decay_dirty 1884 </code> mutex (arena scope; decay for dirty pages related). 1885 <quote><code class="mallctl">{counter}</code></quote> is one of the counters in <a class="link" href="#mutex_counters">mutex profiling 1886 counters</a>.</p></dd><dt><a name="stats.arenas.i.mutexes.decay_muzzy"/><span class="term"> 1887 <quote><code class="mallctl">stats.arenas.<i>.mutexes.decay_muzzy.{counter}</code></quote> 1888 (<span class="type">counter specific type</span>) <code class="literal">r-</code> 1889 [<code class="option">--enable-stats</code>] 1890 </span></dt><dd><p>Statistics on <code class="varname">arena.<i>.decay_muzzy 1891 </code> mutex (arena scope; decay for muzzy pages related). 1892 <quote><code class="mallctl">{counter}</code></quote> is one of the counters in <a class="link" href="#mutex_counters">mutex profiling 1893 counters</a>.</p></dd><dt><a name="stats.arenas.i.mutexes.base"/><span class="term"> 1894 <quote><code class="mallctl">stats.arenas.<i>.mutexes.base.{counter}</code></quote> 1895 (<span class="type">counter specific type</span>) <code class="literal">r-</code> 1896 [<code class="option">--enable-stats</code>] 1897 </span></dt><dd><p>Statistics on <code class="varname">arena.<i>.base</code> 1898 mutex (arena scope; base allocator related). 1899 <quote><code class="mallctl">{counter}</code></quote> is one of the counters in <a class="link" href="#mutex_counters">mutex profiling 1900 counters</a>.</p></dd><dt><a name="stats.arenas.i.mutexes.tcache_list"/><span class="term"> 1901 <quote><code class="mallctl">stats.arenas.<i>.mutexes.tcache_list.{counter}</code></quote> 1902 (<span class="type">counter specific type</span>) <code class="literal">r-</code> 1903 [<code class="option">--enable-stats</code>] 1904 </span></dt><dd><p>Statistics on 1905 <code class="varname">arena.<i>.tcache_list</code> mutex (arena scope; 1906 tcache to arena association related). This mutex is expected to be 1907 accessed less often. <quote><code class="mallctl">{counter}</code></quote> is one of the 1908 counters in <a class="link" href="#mutex_counters">mutex profiling 1909 counters</a>.</p></dd></dl></div></div><div class="refsect1"><a name="heap_profile_format"/><h2>HEAP PROFILE FORMAT</h2><p>Although the heap profiling functionality was originally designed to 1910 be compatible with the 1911 <span class="command"><strong>pprof</strong></span> command that is developed as part of the <a class="ulink" href="http://code.google.com/p/gperftools/" target="_top">gperftools 1912 package</a>, the addition of per thread heap profiling functionality 1913 required a different heap profile format. The <span class="command"><strong>jeprof</strong></span> 1914 command is derived from <span class="command"><strong>pprof</strong></span>, with enhancements to 1915 support the heap profile format described here.</p><p>In the following hypothetical heap profile, <code class="constant">[...]</code> 1916 indicates elision for the sake of compactness. </p><pre class="programlisting"> 1917heap_v2/524288 1918 t*: 28106: 56637512 [0: 0] 1919 [...] 1920 t3: 352: 16777344 [0: 0] 1921 [...] 1922 t99: 17754: 29341640 [0: 0] 1923 [...] 1924@ 0x5f86da8 0x5f5a1dc [...] 0x29e4d4e 0xa200316 0xabb2988 [...] 1925 t*: 13: 6688 [0: 0] 1926 t3: 12: 6496 [0: 0] 1927 t99: 1: 192 [0: 0] 1928[...] 1929 1930MAPPED_LIBRARIES: 1931[...]</pre><p> The following matches the above heap profile, but most 1932tokens are replaced with <code class="constant"><description></code> to indicate 1933descriptions of the corresponding fields. </p><pre class="programlisting"> 1934<heap_profile_format_version>/<mean_sample_interval> 1935 <aggregate>: <curobjs>: <curbytes> [<cumobjs>: <cumbytes>] 1936 [...] 1937 <thread_3_aggregate>: <curobjs>: <curbytes> [<cumobjs>: <cumbytes>] 1938 [...] 1939 <thread_99_aggregate>: <curobjs>: <curbytes> [<cumobjs>: <cumbytes>] 1940 [...] 1941@ <top_frame> <frame> [...] <frame> <frame> <frame> [...] 1942 <backtrace_aggregate>: <curobjs>: <curbytes> [<cumobjs>: <cumbytes>] 1943 <backtrace_thread_3>: <curobjs>: <curbytes> [<cumobjs>: <cumbytes>] 1944 <backtrace_thread_99>: <curobjs>: <curbytes> [<cumobjs>: <cumbytes>] 1945[...] 1946 1947MAPPED_LIBRARIES: 1948</proc/<pid>/maps></pre></div><div class="refsect1"><a name="debugging_malloc_problems"/><h2>DEBUGGING MALLOC PROBLEMS</h2><p>When debugging, it is a good idea to configure/build jemalloc with 1949 the <code class="option">--enable-debug</code> and <code class="option">--enable-fill</code> 1950 options, and recompile the program with suitable options and symbols for 1951 debugger support. When so configured, jemalloc incorporates a wide variety 1952 of run-time assertions that catch application errors such as double-free, 1953 write-after-free, etc.</p><p>Programs often accidentally depend on <span class="quote">“<span class="quote">uninitialized</span>”</span> 1954 memory actually being filled with zero bytes. Junk filling 1955 (see the <a class="link" href="#opt.junk"><quote><code class="mallctl">opt.junk</code></quote></a> 1956 option) tends to expose such bugs in the form of obviously incorrect 1957 results and/or coredumps. Conversely, zero 1958 filling (see the <a class="link" href="#opt.zero"><quote><code class="mallctl">opt.zero</code></quote></a> option) eliminates 1959 the symptoms of such bugs. Between these two options, it is usually 1960 possible to quickly detect, diagnose, and eliminate such bugs.</p><p>This implementation does not provide much detail about the problems 1961 it detects, because the performance impact for storing such information 1962 would be prohibitive.</p></div><div class="refsect1"><a name="diagnostic_messages"/><h2>DIAGNOSTIC MESSAGES</h2><p>If any of the memory allocation/deallocation functions detect an 1963 error or warning condition, a message will be printed to file descriptor 1964 <code class="constant">STDERR_FILENO</code>. Errors will result in the process 1965 dumping core. If the <a class="link" href="#opt.abort"><quote><code class="mallctl">opt.abort</code></quote></a> option is set, most 1966 warnings are treated as errors.</p><p>The <code class="varname">malloc_message</code> variable allows the programmer 1967 to override the function which emits the text strings forming the errors 1968 and warnings if for some reason the <code class="constant">STDERR_FILENO</code> file 1969 descriptor is not suitable for this. 1970 <code class="function">malloc_message()</code> takes the 1971 <em class="parameter"><code>cbopaque</code></em> pointer argument that is 1972 <code class="constant">NULL</code> unless overridden by the arguments in a call to 1973 <code class="function">malloc_stats_print()</code>, followed by a string 1974 pointer. Please note that doing anything which tries to allocate memory in 1975 this function is likely to result in a crash or deadlock.</p><p>All messages are prefixed by 1976 <span class="quote">“<span class="quote"><code class="computeroutput"><jemalloc>: </code></span>”</span>.</p></div><div class="refsect1"><a name="return_values"/><h2>RETURN VALUES</h2><div class="refsect2"><a name="idm46057384902176"/><h3>Standard API</h3><p>The <code class="function">malloc()</code> and 1977 <code class="function">calloc()</code> functions return a pointer to the 1978 allocated memory if successful; otherwise a <code class="constant">NULL</code> 1979 pointer is returned and <code class="varname">errno</code> is set to 1980 <span class="errorname">ENOMEM</span>.</p><p>The <code class="function">posix_memalign()</code> function 1981 returns the value 0 if successful; otherwise it returns an error value. 1982 The <code class="function">posix_memalign()</code> function will fail 1983 if: 1984 </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><span class="errorname">EINVAL</span></span></dt><dd><p>The <em class="parameter"><code>alignment</code></em> parameter is 1985 not a power of 2 at least as large as 1986 <code class="code">sizeof(<span class="type">void *</span>)</code>. 1987 </p></dd><dt><span class="term"><span class="errorname">ENOMEM</span></span></dt><dd><p>Memory allocation error.</p></dd></dl></div><p> 1988 </p><p>The <code class="function">aligned_alloc()</code> function returns 1989 a pointer to the allocated memory if successful; otherwise a 1990 <code class="constant">NULL</code> pointer is returned and 1991 <code class="varname">errno</code> is set. The 1992 <code class="function">aligned_alloc()</code> function will fail if: 1993 </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><span class="errorname">EINVAL</span></span></dt><dd><p>The <em class="parameter"><code>alignment</code></em> parameter is 1994 not a power of 2. 1995 </p></dd><dt><span class="term"><span class="errorname">ENOMEM</span></span></dt><dd><p>Memory allocation error.</p></dd></dl></div><p> 1996 </p><p>The <code class="function">realloc()</code> function returns a 1997 pointer, possibly identical to <em class="parameter"><code>ptr</code></em>, to the 1998 allocated memory if successful; otherwise a <code class="constant">NULL</code> 1999 pointer is returned, and <code class="varname">errno</code> is set to 2000 <span class="errorname">ENOMEM</span> if the error was the result of an 2001 allocation failure. The <code class="function">realloc()</code> 2002 function always leaves the original buffer intact when an error occurs. 2003 </p><p>The <code class="function">free()</code> function returns no 2004 value.</p></div><div class="refsect2"><a name="idm46057384880688"/><h3>Non-standard API</h3><p>The <code class="function">mallocx()</code> and 2005 <code class="function">rallocx()</code> functions return a pointer to 2006 the allocated memory if successful; otherwise a <code class="constant">NULL</code> 2007 pointer is returned to indicate insufficient contiguous memory was 2008 available to service the allocation request. </p><p>The <code class="function">xallocx()</code> function returns the 2009 real size of the resulting resized allocation pointed to by 2010 <em class="parameter"><code>ptr</code></em>, which is a value less than 2011 <em class="parameter"><code>size</code></em> if the allocation could not be adequately 2012 grown in place. </p><p>The <code class="function">sallocx()</code> function returns the 2013 real size of the allocation pointed to by <em class="parameter"><code>ptr</code></em>. 2014 </p><p>The <code class="function">nallocx()</code> returns the real size 2015 that would result from a successful equivalent 2016 <code class="function">mallocx()</code> function call, or zero if 2017 insufficient memory is available to perform the size computation. </p><p>The <code class="function">mallctl()</code>, 2018 <code class="function">mallctlnametomib()</code>, and 2019 <code class="function">mallctlbymib()</code> functions return 0 on 2020 success; otherwise they return an error value. The functions will fail 2021 if: 2022 </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><span class="errorname">EINVAL</span></span></dt><dd><p><em class="parameter"><code>newp</code></em> is not 2023 <code class="constant">NULL</code>, and <em class="parameter"><code>newlen</code></em> is too 2024 large or too small. Alternatively, <em class="parameter"><code>*oldlenp</code></em> 2025 is too large or too small; when it happens, except for a very few 2026 cases explicitly documented otherwise, as much data as possible 2027 are read despite the error, with the amount of data read being 2028 recorded in <em class="parameter"><code>*oldlenp</code></em>.</p></dd><dt><span class="term"><span class="errorname">ENOENT</span></span></dt><dd><p><em class="parameter"><code>name</code></em> or 2029 <em class="parameter"><code>mib</code></em> specifies an unknown/invalid 2030 value.</p></dd><dt><span class="term"><span class="errorname">EPERM</span></span></dt><dd><p>Attempt to read or write void value, or attempt to 2031 write read-only value.</p></dd><dt><span class="term"><span class="errorname">EAGAIN</span></span></dt><dd><p>A memory allocation failure 2032 occurred.</p></dd><dt><span class="term"><span class="errorname">EFAULT</span></span></dt><dd><p>An interface with side effects failed in some way 2033 not directly related to <code class="function">mallctl*()</code> 2034 read/write processing.</p></dd></dl></div><p> 2035 </p><p>The <code class="function">malloc_usable_size()</code> function 2036 returns the usable size of the allocation pointed to by 2037 <em class="parameter"><code>ptr</code></em>. </p></div></div><div class="refsect1"><a name="environment"/><h2>ENVIRONMENT</h2><p>The following environment variable affects the execution of the 2038 allocation functions: 2039 </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="envar">MALLOC_CONF</code></span></dt><dd><p>If the environment variable 2040 <code class="envar">MALLOC_CONF</code> is set, the characters it contains 2041 will be interpreted as options.</p></dd></dl></div><p> 2042 </p></div><div class="refsect1"><a name="examples"/><h2>EXAMPLES</h2><p>To dump core whenever a problem occurs: 2043 </p><pre class="screen">ln -s 'abort:true' /etc/malloc.conf</pre><p> 2044 </p><p>To specify in the source that only one arena should be automatically 2045 created: 2046 </p><pre class="programlisting"> 2047malloc_conf = "narenas:1";</pre></div><div class="refsect1"><a name="see_also"/><h2>SEE ALSO</h2><p><span class="citerefentry"><span class="refentrytitle">madvise</span>(2)</span>, 2048 <span class="citerefentry"><span class="refentrytitle">mmap</span>(2)</span>, 2049 <span class="citerefentry"><span class="refentrytitle">sbrk</span>(2)</span>, 2050 <span class="citerefentry"><span class="refentrytitle">utrace</span>(2)</span>, 2051 <span class="citerefentry"><span class="refentrytitle">alloca</span>(3)</span>, 2052 <span class="citerefentry"><span class="refentrytitle">atexit</span>(3)</span>, 2053 <span class="citerefentry"><span class="refentrytitle">getpagesize</span>(3)</span></p></div><div class="refsect1"><a name="standards"/><h2>STANDARDS</h2><p>The <code class="function">malloc()</code>, 2054 <code class="function">calloc()</code>, 2055 <code class="function">realloc()</code>, and 2056 <code class="function">free()</code> functions conform to ISO/IEC 2057 9899:1990 (<span class="quote">“<span class="quote">ISO C90</span>”</span>).</p><p>The <code class="function">posix_memalign()</code> function conforms 2058 to IEEE Std 1003.1-2001 (<span class="quote">“<span class="quote">POSIX.1</span>”</span>).</p></div></div></body></html>