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