2
0

jemalloc.html 94 KB

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