2
0

jemalloc.html 107 KB

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