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