1<?xml version='1.0' encoding='UTF-8'?> 2<?xml-stylesheet type="text/xsl" 3 href="http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl"?> 4<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" 5 "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [ 6]> 7 8<refentry> 9 <refentryinfo> 10 <title>User Manual</title> 11 <productname>jemalloc</productname> 12 <releaseinfo role="version">@jemalloc_version@</releaseinfo> 13 <authorgroup> 14 <author> 15 <firstname>Jason</firstname> 16 <surname>Evans</surname> 17 <personblurb>Author</personblurb> 18 </author> 19 </authorgroup> 20 </refentryinfo> 21 <refmeta> 22 <refentrytitle>JEMALLOC</refentrytitle> 23 <manvolnum>3</manvolnum> 24 </refmeta> 25 <refnamediv> 26 <refdescriptor>jemalloc</refdescriptor> 27 <refname>jemalloc</refname> 28 <!-- Each refname causes a man page file to be created. Only if this were 29 the system malloc(3) implementation would these files be appropriate. 30 <refname>malloc</refname> 31 <refname>calloc</refname> 32 <refname>posix_memalign</refname> 33 <refname>aligned_alloc</refname> 34 <refname>realloc</refname> 35 <refname>free</refname> 36 <refname>mallocx</refname> 37 <refname>rallocx</refname> 38 <refname>xallocx</refname> 39 <refname>sallocx</refname> 40 <refname>dallocx</refname> 41 <refname>sdallocx</refname> 42 <refname>nallocx</refname> 43 <refname>mallctl</refname> 44 <refname>mallctlnametomib</refname> 45 <refname>mallctlbymib</refname> 46 <refname>malloc_stats_print</refname> 47 <refname>malloc_usable_size</refname> 48 --> 49 <refpurpose>general purpose memory allocation functions</refpurpose> 50 </refnamediv> 51 <refsect1 id="library"> 52 <title>LIBRARY</title> 53 <para>This manual describes jemalloc @jemalloc_version@. More information 54 can be found at the <ulink 55 url="http://www.canonware.com/jemalloc/">jemalloc website</ulink>.</para> 56 </refsect1> 57 <refsynopsisdiv> 58 <title>SYNOPSIS</title> 59 <funcsynopsis> 60 <funcsynopsisinfo>#include <<filename class="headerfile">jemalloc/jemalloc.h</filename>></funcsynopsisinfo> 61 <refsect2> 62 <title>Standard API</title> 63 <funcprototype> 64 <funcdef>void *<function>malloc</function></funcdef> 65 <paramdef>size_t <parameter>size</parameter></paramdef> 66 </funcprototype> 67 <funcprototype> 68 <funcdef>void *<function>calloc</function></funcdef> 69 <paramdef>size_t <parameter>number</parameter></paramdef> 70 <paramdef>size_t <parameter>size</parameter></paramdef> 71 </funcprototype> 72 <funcprototype> 73 <funcdef>int <function>posix_memalign</function></funcdef> 74 <paramdef>void **<parameter>ptr</parameter></paramdef> 75 <paramdef>size_t <parameter>alignment</parameter></paramdef> 76 <paramdef>size_t <parameter>size</parameter></paramdef> 77 </funcprototype> 78 <funcprototype> 79 <funcdef>void *<function>aligned_alloc</function></funcdef> 80 <paramdef>size_t <parameter>alignment</parameter></paramdef> 81 <paramdef>size_t <parameter>size</parameter></paramdef> 82 </funcprototype> 83 <funcprototype> 84 <funcdef>void *<function>realloc</function></funcdef> 85 <paramdef>void *<parameter>ptr</parameter></paramdef> 86 <paramdef>size_t <parameter>size</parameter></paramdef> 87 </funcprototype> 88 <funcprototype> 89 <funcdef>void <function>free</function></funcdef> 90 <paramdef>void *<parameter>ptr</parameter></paramdef> 91 </funcprototype> 92 </refsect2> 93 <refsect2> 94 <title>Non-standard API</title> 95 <funcprototype> 96 <funcdef>void *<function>mallocx</function></funcdef> 97 <paramdef>size_t <parameter>size</parameter></paramdef> 98 <paramdef>int <parameter>flags</parameter></paramdef> 99 </funcprototype> 100 <funcprototype> 101 <funcdef>void *<function>rallocx</function></funcdef> 102 <paramdef>void *<parameter>ptr</parameter></paramdef> 103 <paramdef>size_t <parameter>size</parameter></paramdef> 104 <paramdef>int <parameter>flags</parameter></paramdef> 105 </funcprototype> 106 <funcprototype> 107 <funcdef>size_t <function>xallocx</function></funcdef> 108 <paramdef>void *<parameter>ptr</parameter></paramdef> 109 <paramdef>size_t <parameter>size</parameter></paramdef> 110 <paramdef>size_t <parameter>extra</parameter></paramdef> 111 <paramdef>int <parameter>flags</parameter></paramdef> 112 </funcprototype> 113 <funcprototype> 114 <funcdef>size_t <function>sallocx</function></funcdef> 115 <paramdef>void *<parameter>ptr</parameter></paramdef> 116 <paramdef>int <parameter>flags</parameter></paramdef> 117 </funcprototype> 118 <funcprototype> 119 <funcdef>void <function>dallocx</function></funcdef> 120 <paramdef>void *<parameter>ptr</parameter></paramdef> 121 <paramdef>int <parameter>flags</parameter></paramdef> 122 </funcprototype> 123 <funcprototype> 124 <funcdef>void <function>sdallocx</function></funcdef> 125 <paramdef>void *<parameter>ptr</parameter></paramdef> 126 <paramdef>size_t <parameter>size</parameter></paramdef> 127 <paramdef>int <parameter>flags</parameter></paramdef> 128 </funcprototype> 129 <funcprototype> 130 <funcdef>size_t <function>nallocx</function></funcdef> 131 <paramdef>size_t <parameter>size</parameter></paramdef> 132 <paramdef>int <parameter>flags</parameter></paramdef> 133 </funcprototype> 134 <funcprototype> 135 <funcdef>int <function>mallctl</function></funcdef> 136 <paramdef>const char *<parameter>name</parameter></paramdef> 137 <paramdef>void *<parameter>oldp</parameter></paramdef> 138 <paramdef>size_t *<parameter>oldlenp</parameter></paramdef> 139 <paramdef>void *<parameter>newp</parameter></paramdef> 140 <paramdef>size_t <parameter>newlen</parameter></paramdef> 141 </funcprototype> 142 <funcprototype> 143 <funcdef>int <function>mallctlnametomib</function></funcdef> 144 <paramdef>const char *<parameter>name</parameter></paramdef> 145 <paramdef>size_t *<parameter>mibp</parameter></paramdef> 146 <paramdef>size_t *<parameter>miblenp</parameter></paramdef> 147 </funcprototype> 148 <funcprototype> 149 <funcdef>int <function>mallctlbymib</function></funcdef> 150 <paramdef>const size_t *<parameter>mib</parameter></paramdef> 151 <paramdef>size_t <parameter>miblen</parameter></paramdef> 152 <paramdef>void *<parameter>oldp</parameter></paramdef> 153 <paramdef>size_t *<parameter>oldlenp</parameter></paramdef> 154 <paramdef>void *<parameter>newp</parameter></paramdef> 155 <paramdef>size_t <parameter>newlen</parameter></paramdef> 156 </funcprototype> 157 <funcprototype> 158 <funcdef>void <function>malloc_stats_print</function></funcdef> 159 <paramdef>void <parameter>(*write_cb)</parameter> 160 <funcparams>void *, const char *</funcparams> 161 </paramdef> 162 <paramdef>void *<parameter>cbopaque</parameter></paramdef> 163 <paramdef>const char *<parameter>opts</parameter></paramdef> 164 </funcprototype> 165 <funcprototype> 166 <funcdef>size_t <function>malloc_usable_size</function></funcdef> 167 <paramdef>const void *<parameter>ptr</parameter></paramdef> 168 </funcprototype> 169 <funcprototype> 170 <funcdef>void <function>(*malloc_message)</function></funcdef> 171 <paramdef>void *<parameter>cbopaque</parameter></paramdef> 172 <paramdef>const char *<parameter>s</parameter></paramdef> 173 </funcprototype> 174 <para><type>const char *</type><varname>malloc_conf</varname>;</para> 175 </refsect2> 176 </funcsynopsis> 177 </refsynopsisdiv> 178 <refsect1 id="description"> 179 <title>DESCRIPTION</title> 180 <refsect2> 181 <title>Standard API</title> 182 183 <para>The <function>malloc<parameter/></function> function allocates 184 <parameter>size</parameter> bytes of uninitialized memory. The allocated 185 space is suitably aligned (after possible pointer coercion) for storage 186 of any type of object.</para> 187 188 <para>The <function>calloc<parameter/></function> function allocates 189 space for <parameter>number</parameter> objects, each 190 <parameter>size</parameter> bytes in length. The result is identical to 191 calling <function>malloc<parameter/></function> with an argument of 192 <parameter>number</parameter> * <parameter>size</parameter>, with the 193 exception that the allocated memory is explicitly initialized to zero 194 bytes.</para> 195 196 <para>The <function>posix_memalign<parameter/></function> function 197 allocates <parameter>size</parameter> bytes of memory such that the 198 allocation's base address is a multiple of 199 <parameter>alignment</parameter>, and returns the allocation in the value 200 pointed to by <parameter>ptr</parameter>. The requested 201 <parameter>alignment</parameter> must be a power of 2 at least as large as 202 <code language="C">sizeof(<type>void *</type>)</code>.</para> 203 204 <para>The <function>aligned_alloc<parameter/></function> function 205 allocates <parameter>size</parameter> bytes of memory such that the 206 allocation's base address is a multiple of 207 <parameter>alignment</parameter>. The requested 208 <parameter>alignment</parameter> must be a power of 2. Behavior is 209 undefined if <parameter>size</parameter> is not an integral multiple of 210 <parameter>alignment</parameter>.</para> 211 212 <para>The <function>realloc<parameter/></function> function changes the 213 size of the previously allocated memory referenced by 214 <parameter>ptr</parameter> to <parameter>size</parameter> bytes. The 215 contents of the memory are unchanged up to the lesser of the new and old 216 sizes. If the new size is larger, the contents of the newly allocated 217 portion of the memory are undefined. Upon success, the memory referenced 218 by <parameter>ptr</parameter> is freed and a pointer to the newly 219 allocated memory is returned. Note that 220 <function>realloc<parameter/></function> may move the memory allocation, 221 resulting in a different return value than <parameter>ptr</parameter>. 222 If <parameter>ptr</parameter> is <constant>NULL</constant>, the 223 <function>realloc<parameter/></function> function behaves identically to 224 <function>malloc<parameter/></function> for the specified size.</para> 225 226 <para>The <function>free<parameter/></function> function causes the 227 allocated memory referenced by <parameter>ptr</parameter> to be made 228 available for future allocations. If <parameter>ptr</parameter> is 229 <constant>NULL</constant>, no action occurs.</para> 230 </refsect2> 231 <refsect2> 232 <title>Non-standard API</title> 233 <para>The <function>mallocx<parameter/></function>, 234 <function>rallocx<parameter/></function>, 235 <function>xallocx<parameter/></function>, 236 <function>sallocx<parameter/></function>, 237 <function>dallocx<parameter/></function>, 238 <function>sdallocx<parameter/></function>, and 239 <function>nallocx<parameter/></function> functions all have a 240 <parameter>flags</parameter> argument that can be used to specify 241 options. The functions only check the options that are contextually 242 relevant. Use bitwise or (<code language="C">|</code>) operations to 243 specify one or more of the following: 244 <variablelist> 245 <varlistentry id="MALLOCX_LG_ALIGN"> 246 <term><constant>MALLOCX_LG_ALIGN(<parameter>la</parameter>) 247 </constant></term> 248 249 <listitem><para>Align the memory allocation to start at an address 250 that is a multiple of <code language="C">(1 << 251 <parameter>la</parameter>)</code>. This macro does not validate 252 that <parameter>la</parameter> is within the valid 253 range.</para></listitem> 254 </varlistentry> 255 <varlistentry id="MALLOCX_ALIGN"> 256 <term><constant>MALLOCX_ALIGN(<parameter>a</parameter>) 257 </constant></term> 258 259 <listitem><para>Align the memory allocation to start at an address 260 that is a multiple of <parameter>a</parameter>, where 261 <parameter>a</parameter> is a power of two. This macro does not 262 validate that <parameter>a</parameter> is a power of 2. 263 </para></listitem> 264 </varlistentry> 265 <varlistentry id="MALLOCX_ZERO"> 266 <term><constant>MALLOCX_ZERO</constant></term> 267 268 <listitem><para>Initialize newly allocated memory to contain zero 269 bytes. In the growing reallocation case, the real size prior to 270 reallocation defines the boundary between untouched bytes and those 271 that are initialized to contain zero bytes. If this macro is 272 absent, newly allocated memory is uninitialized.</para></listitem> 273 </varlistentry> 274 <varlistentry id="MALLOCX_TCACHE"> 275 <term><constant>MALLOCX_TCACHE(<parameter>tc</parameter>) 276 </constant></term> 277 278 <listitem><para>Use the thread-specific cache (tcache) specified by 279 the identifier <parameter>tc</parameter>, which must have been 280 acquired via the <link 281 linkend="tcache.create"><mallctl>tcache.create</mallctl></link> 282 mallctl. This macro does not validate that 283 <parameter>tc</parameter> specifies a valid 284 identifier.</para></listitem> 285 </varlistentry> 286 <varlistentry id="MALLOC_TCACHE_NONE"> 287 <term><constant>MALLOCX_TCACHE_NONE</constant></term> 288 289 <listitem><para>Do not use a thread-specific cache (tcache). Unless 290 <constant>MALLOCX_TCACHE(<parameter>tc</parameter>)</constant> or 291 <constant>MALLOCX_TCACHE_NONE</constant> is specified, an 292 automatically managed tcache will be used under many circumstances. 293 This macro cannot be used in the same <parameter>flags</parameter> 294 argument as 295 <constant>MALLOCX_TCACHE(<parameter>tc</parameter>)</constant>.</para></listitem> 296 </varlistentry> 297 <varlistentry id="MALLOCX_ARENA"> 298 <term><constant>MALLOCX_ARENA(<parameter>a</parameter>) 299 </constant></term> 300 301 <listitem><para>Use the arena specified by the index 302 <parameter>a</parameter>. This macro has no effect for regions that 303 were allocated via an arena other than the one specified. This 304 macro does not validate that <parameter>a</parameter> specifies an 305 arena index in the valid range.</para></listitem> 306 </varlistentry> 307 </variablelist> 308 </para> 309 310 <para>The <function>mallocx<parameter/></function> function allocates at 311 least <parameter>size</parameter> bytes of memory, and returns a pointer 312 to the base address of the allocation. Behavior is undefined if 313 <parameter>size</parameter> is <constant>0</constant>, or if request size 314 overflows due to size class and/or alignment constraints.</para> 315 316 <para>The <function>rallocx<parameter/></function> function resizes the 317 allocation at <parameter>ptr</parameter> to be at least 318 <parameter>size</parameter> bytes, and returns a pointer to the base 319 address of the resulting allocation, which may or may not have moved from 320 its original location. Behavior is undefined if 321 <parameter>size</parameter> is <constant>0</constant>, or if request size 322 overflows due to size class and/or alignment constraints.</para> 323 324 <para>The <function>xallocx<parameter/></function> function resizes the 325 allocation at <parameter>ptr</parameter> in place to be at least 326 <parameter>size</parameter> bytes, and returns the real size of the 327 allocation. If <parameter>extra</parameter> is non-zero, an attempt is 328 made to resize the allocation to be at least <code 329 language="C">(<parameter>size</parameter> + 330 <parameter>extra</parameter>)</code> bytes, though inability to allocate 331 the extra byte(s) will not by itself result in failure to resize. 332 Behavior is undefined if <parameter>size</parameter> is 333 <constant>0</constant>, or if <code 334 language="C">(<parameter>size</parameter> + <parameter>extra</parameter> 335 > <constant>SIZE_T_MAX</constant>)</code>.</para> 336 337 <para>The <function>sallocx<parameter/></function> function returns the 338 real size of the allocation at <parameter>ptr</parameter>.</para> 339 340 <para>The <function>dallocx<parameter/></function> function causes the 341 memory referenced by <parameter>ptr</parameter> to be made available for 342 future allocations.</para> 343 344 <para>The <function>sdallocx<parameter/></function> function is an 345 extension of <function>dallocx<parameter/></function> with a 346 <parameter>size</parameter> parameter to allow the caller to pass in the 347 allocation size as an optimization. The minimum valid input size is the 348 original requested size of the allocation, and the maximum valid input 349 size is the corresponding value returned by 350 <function>nallocx<parameter/></function> or 351 <function>sallocx<parameter/></function>.</para> 352 353 <para>The <function>nallocx<parameter/></function> function allocates no 354 memory, but it performs the same size computation as the 355 <function>mallocx<parameter/></function> function, and returns the real 356 size of the allocation that would result from the equivalent 357 <function>mallocx<parameter/></function> function call. Behavior is 358 undefined if <parameter>size</parameter> is <constant>0</constant>, or if 359 request size overflows due to size class and/or alignment 360 constraints.</para> 361 362 <para>The <function>mallctl<parameter/></function> function provides a 363 general interface for introspecting the memory allocator, as well as 364 setting modifiable parameters and triggering actions. The 365 period-separated <parameter>name</parameter> argument specifies a 366 location in a tree-structured namespace; see the <xref 367 linkend="mallctl_namespace" xrefstyle="template:%t"/> section for 368 documentation on the tree contents. To read a value, pass a pointer via 369 <parameter>oldp</parameter> to adequate space to contain the value, and a 370 pointer to its length via <parameter>oldlenp</parameter>; otherwise pass 371 <constant>NULL</constant> and <constant>NULL</constant>. Similarly, to 372 write a value, pass a pointer to the value via 373 <parameter>newp</parameter>, and its length via 374 <parameter>newlen</parameter>; otherwise pass <constant>NULL</constant> 375 and <constant>0</constant>.</para> 376 377 <para>The <function>mallctlnametomib<parameter/></function> function 378 provides a way to avoid repeated name lookups for applications that 379 repeatedly query the same portion of the namespace, by translating a name 380 to a “Management Information Base” (MIB) that can be passed 381 repeatedly to <function>mallctlbymib<parameter/></function>. Upon 382 successful return from <function>mallctlnametomib<parameter/></function>, 383 <parameter>mibp</parameter> contains an array of 384 <parameter>*miblenp</parameter> integers, where 385 <parameter>*miblenp</parameter> is the lesser of the number of components 386 in <parameter>name</parameter> and the input value of 387 <parameter>*miblenp</parameter>. Thus it is possible to pass a 388 <parameter>*miblenp</parameter> that is smaller than the number of 389 period-separated name components, which results in a partial MIB that can 390 be used as the basis for constructing a complete MIB. For name 391 components that are integers (e.g. the 2 in 392 <link 393 linkend="arenas.bin.i.size"><mallctl>arenas.bin.2.size</mallctl></link>), 394 the corresponding MIB component will always be that integer. Therefore, 395 it is legitimate to construct code like the following: <programlisting 396 language="C"><![CDATA[ 397unsigned nbins, i; 398size_t mib[4]; 399size_t len, miblen; 400 401len = sizeof(nbins); 402mallctl("arenas.nbins", &nbins, &len, NULL, 0); 403 404miblen = 4; 405mallctlnametomib("arenas.bin.0.size", mib, &miblen); 406for (i = 0; i < nbins; i++) { 407 size_t bin_size; 408 409 mib[2] = i; 410 len = sizeof(bin_size); 411 mallctlbymib(mib, miblen, &bin_size, &len, NULL, 0); 412 /* Do something with bin_size... */ 413}]]></programlisting></para> 414 415 <para>The <function>malloc_stats_print<parameter/></function> function 416 writes human-readable summary statistics via the 417 <parameter>write_cb</parameter> callback function pointer and 418 <parameter>cbopaque</parameter> data passed to 419 <parameter>write_cb</parameter>, or 420 <function>malloc_message<parameter/></function> if 421 <parameter>write_cb</parameter> is <constant>NULL</constant>. This 422 function can be called repeatedly. General information that never 423 changes during execution can be omitted by specifying "g" as a character 424 within the <parameter>opts</parameter> string. Note that 425 <function>malloc_message<parameter/></function> uses the 426 <function>mallctl*<parameter/></function> functions internally, so 427 inconsistent statistics can be reported if multiple threads use these 428 functions simultaneously. If <option>--enable-stats</option> is 429 specified during configuration, “m” and “a” can 430 be specified to omit merged arena and per arena statistics, respectively; 431 “b”, “l”, and “h” can be specified to 432 omit per size class statistics for bins, large objects, and huge objects, 433 respectively. Unrecognized characters are silently ignored. Note that 434 thread caching may prevent some statistics from being completely up to 435 date, since extra locking would be required to merge counters that track 436 thread cache operations. 437 </para> 438 439 <para>The <function>malloc_usable_size<parameter/></function> function 440 returns the usable size of the allocation pointed to by 441 <parameter>ptr</parameter>. The return value may be larger than the size 442 that was requested during allocation. The 443 <function>malloc_usable_size<parameter/></function> function is not a 444 mechanism for in-place <function>realloc<parameter/></function>; rather 445 it is provided solely as a tool for introspection purposes. Any 446 discrepancy between the requested allocation size and the size reported 447 by <function>malloc_usable_size<parameter/></function> should not be 448 depended on, since such behavior is entirely implementation-dependent. 449 </para> 450 </refsect2> 451 </refsect1> 452 <refsect1 id="tuning"> 453 <title>TUNING</title> 454 <para>Once, when the first call is made to one of the memory allocation 455 routines, the allocator initializes its internals based in part on various 456 options that can be specified at compile- or run-time.</para> 457 458 <para>The string pointed to by the global variable 459 <varname>malloc_conf</varname>, the “name” of the file 460 referenced by the symbolic link named <filename 461 class="symlink">/etc/malloc.conf</filename>, and the value of the 462 environment variable <envar>MALLOC_CONF</envar>, will be interpreted, in 463 that order, from left to right as options. Note that 464 <varname>malloc_conf</varname> may be read before 465 <function>main<parameter/></function> is entered, so the declaration of 466 <varname>malloc_conf</varname> should specify an initializer that contains 467 the final value to be read by jemalloc. <varname>malloc_conf</varname> is 468 a compile-time setting, whereas <filename 469 class="symlink">/etc/malloc.conf</filename> and <envar>MALLOC_CONF</envar> 470 can be safely set any time prior to program invocation.</para> 471 472 <para>An options string is a comma-separated list of option:value pairs. 473 There is one key corresponding to each <link 474 linkend="opt.abort"><mallctl>opt.*</mallctl></link> mallctl (see the <xref 475 linkend="mallctl_namespace" xrefstyle="template:%t"/> section for options 476 documentation). For example, <literal>abort:true,narenas:1</literal> sets 477 the <link linkend="opt.abort"><mallctl>opt.abort</mallctl></link> and <link 478 linkend="opt.narenas"><mallctl>opt.narenas</mallctl></link> options. Some 479 options have boolean values (true/false), others have integer values (base 480 8, 10, or 16, depending on prefix), and yet others have raw string 481 values.</para> 482 </refsect1> 483 <refsect1 id="implementation_notes"> 484 <title>IMPLEMENTATION NOTES</title> 485 <para>Traditionally, allocators have used 486 <citerefentry><refentrytitle>sbrk</refentrytitle> 487 <manvolnum>2</manvolnum></citerefentry> to obtain memory, which is 488 suboptimal for several reasons, including race conditions, increased 489 fragmentation, and artificial limitations on maximum usable memory. If 490 <citerefentry><refentrytitle>sbrk</refentrytitle> 491 <manvolnum>2</manvolnum></citerefentry> is supported by the operating 492 system, this allocator uses both 493 <citerefentry><refentrytitle>mmap</refentrytitle> 494 <manvolnum>2</manvolnum></citerefentry> and 495 <citerefentry><refentrytitle>sbrk</refentrytitle> 496 <manvolnum>2</manvolnum></citerefentry>, in that order of preference; 497 otherwise only <citerefentry><refentrytitle>mmap</refentrytitle> 498 <manvolnum>2</manvolnum></citerefentry> is used.</para> 499 500 <para>This allocator uses multiple arenas in order to reduce lock 501 contention for threaded programs on multi-processor systems. This works 502 well with regard to threading scalability, but incurs some costs. There is 503 a small fixed per-arena overhead, and additionally, arenas manage memory 504 completely independently of each other, which means a small fixed increase 505 in overall memory fragmentation. These overheads are not generally an 506 issue, given the number of arenas normally used. Note that using 507 substantially more arenas than the default is not likely to improve 508 performance, mainly due to reduced cache performance. However, it may make 509 sense to reduce the number of arenas if an application does not make much 510 use of the allocation functions.</para> 511 512 <para>In addition to multiple arenas, unless 513 <option>--disable-tcache</option> is specified during configuration, this 514 allocator supports thread-specific caching for small and large objects, in 515 order to make it possible to completely avoid synchronization for most 516 allocation requests. Such caching allows very fast allocation in the 517 common case, but it increases memory usage and fragmentation, since a 518 bounded number of objects can remain allocated in each thread cache.</para> 519 520 <para>Memory is conceptually broken into equal-sized chunks, where the 521 chunk size is a power of two that is greater than the page size. Chunks 522 are always aligned to multiples of the chunk size. This alignment makes it 523 possible to find metadata for user objects very quickly.</para> 524 525 <para>User objects are broken into three categories according to size: 526 small, large, and huge. Small and large objects are managed entirely by 527 arenas; huge objects are additionally aggregated in a single data structure 528 that is shared by all threads. Huge objects are typically used by 529 applications infrequently enough that this single data structure is not a 530 scalability issue.</para> 531 532 <para>Each chunk that is managed by an arena tracks its contents as runs of 533 contiguous pages (unused, backing a set of small objects, or backing one 534 large object). The combination of chunk alignment and chunk page maps 535 makes it possible to determine all metadata regarding small and large 536 allocations in constant time.</para> 537 538 <para>Small objects are managed in groups by page runs. Each run maintains 539 a bitmap to track which regions are in use. Allocation requests that are no 540 more than half the quantum (8 or 16, depending on architecture) are rounded 541 up to the nearest power of two that is at least <code 542 language="C">sizeof(<type>double</type>)</code>. All other object size 543 classes are multiples of the quantum, spaced such that there are four size 544 classes for each doubling in size, which limits internal fragmentation to 545 approximately 20% for all but the smallest size classes. Small size classes 546 are smaller than four times the page size, large size classes are smaller 547 than the chunk size (see the <link 548 linkend="opt.lg_chunk"><mallctl>opt.lg_chunk</mallctl></link> option), and 549 huge size classes extend from the chunk size up to one size class less than 550 the full address space size.</para> 551 552 <para>Allocations are packed tightly together, which can be an issue for 553 multi-threaded applications. If you need to assure that allocations do not 554 suffer from cacheline sharing, round your allocation requests up to the 555 nearest multiple of the cacheline size, or specify cacheline alignment when 556 allocating.</para> 557 558 <para>The <function>realloc<parameter/></function>, 559 <function>rallocx<parameter/></function>, and 560 <function>xallocx<parameter/></function> functions may resize allocations 561 without moving them under limited circumstances. Unlike the 562 <function>*allocx<parameter/></function> API, the standard API does not 563 officially round up the usable size of an allocation to the nearest size 564 class, so technically it is necessary to call 565 <function>realloc<parameter/></function> to grow e.g. a 9-byte allocation to 566 16 bytes, or shrink a 16-byte allocation to 9 bytes. Growth and shrinkage 567 trivially succeeds in place as long as the pre-size and post-size both round 568 up to the same size class. No other API guarantees are made regarding 569 in-place resizing, but the current implementation also tries to resize large 570 and huge allocations in place, as long as the pre-size and post-size are 571 both large or both huge. In such cases shrinkage always succeeds, but 572 growth only succeeds if the trailing memory is currently available.</para> 573 574 <para>Assuming 256 KiB chunks, 4 KiB pages, and a 16-byte quantum on a 575 64-bit system, the size classes in each category are as shown in <xref 576 linkend="size_classes" xrefstyle="template:Table %n"/>.</para> 577 578 <table xml:id="size_classes" frame="all"> 579 <title>Size classes</title> 580 <tgroup cols="3" colsep="1" rowsep="1"> 581 <colspec colname="c1" align="left"/> 582 <colspec colname="c2" align="right"/> 583 <colspec colname="c3" align="left"/> 584 <thead> 585 <row> 586 <entry>Category</entry> 587 <entry>Spacing</entry> 588 <entry>Size</entry> 589 </row> 590 </thead> 591 <tbody> 592 <row> 593 <entry morerows="8">Small</entry> 594 <entry>lg</entry> 595 <entry>[8]</entry> 596 </row> 597 <row> 598 <entry>16</entry> 599 <entry>[16, 32, 48, 64, 80, 96, 112, 128]</entry> 600 </row> 601 <row> 602 <entry>32</entry> 603 <entry>[160, 192, 224, 256]</entry> 604 </row> 605 <row> 606 <entry>64</entry> 607 <entry>[320, 384, 448, 512]</entry> 608 </row> 609 <row> 610 <entry>128</entry> 611 <entry>[640, 768, 896, 1024]</entry> 612 </row> 613 <row> 614 <entry>256</entry> 615 <entry>[1280, 1536, 1792, 2048]</entry> 616 </row> 617 <row> 618 <entry>512</entry> 619 <entry>[2560, 3072, 3584, 4096]</entry> 620 </row> 621 <row> 622 <entry>1 KiB</entry> 623 <entry>[5 KiB, 6 KiB, 7 KiB, 8 KiB]</entry> 624 </row> 625 <row> 626 <entry>2 KiB</entry> 627 <entry>[10 KiB, 12 KiB, 14 KiB]</entry> 628 </row> 629 <row> 630 <entry morerows="4">Large</entry> 631 <entry>2 KiB</entry> 632 <entry>[16 KiB]</entry> 633 </row> 634 <row> 635 <entry>4 KiB</entry> 636 <entry>[20 KiB, 24 KiB, 28 KiB, 32 KiB]</entry> 637 </row> 638 <row> 639 <entry>8 KiB</entry> 640 <entry>[40 KiB, 48 KiB, 54 KiB, 64 KiB]</entry> 641 </row> 642 <row> 643 <entry>16 KiB</entry> 644 <entry>[80 KiB, 96 KiB, 112 KiB, 128 KiB]</entry> 645 </row> 646 <row> 647 <entry>32 KiB</entry> 648 <entry>[160 KiB, 192 KiB, 224 KiB]</entry> 649 </row> 650 <row> 651 <entry morerows="9">Huge</entry> 652 <entry>32 KiB</entry> 653 <entry>[256 KiB]</entry> 654 </row> 655 <row> 656 <entry>64 KiB</entry> 657 <entry>[320 KiB, 384 KiB, 448 KiB, 512 KiB]</entry> 658 </row> 659 <row> 660 <entry>128 KiB</entry> 661 <entry>[640 KiB, 768 KiB, 896 KiB, 1 MiB]</entry> 662 </row> 663 <row> 664 <entry>256 KiB</entry> 665 <entry>[1280 KiB, 1536 KiB, 1792 KiB, 2 MiB]</entry> 666 </row> 667 <row> 668 <entry>512 KiB</entry> 669 <entry>[2560 KiB, 3 MiB, 3584 KiB, 4 MiB]</entry> 670 </row> 671 <row> 672 <entry>1 MiB</entry> 673 <entry>[5 MiB, 6 MiB, 7 MiB, 8 MiB]</entry> 674 </row> 675 <row> 676 <entry>2 MiB</entry> 677 <entry>[10 MiB, 12 MiB, 14 MiB, 16 MiB]</entry> 678 </row> 679 <row> 680 <entry>4 MiB</entry> 681 <entry>[20 MiB, 24 MiB, 28 MiB, 32 MiB]</entry> 682 </row> 683 <row> 684 <entry>8 MiB</entry> 685 <entry>[40 MiB, 48 MiB, 56 MiB, 64 MiB]</entry> 686 </row> 687 <row> 688 <entry>...</entry> 689 <entry>...</entry> 690 </row> 691 </tbody> 692 </tgroup> 693 </table> 694 </refsect1> 695 <refsect1 id="mallctl_namespace"> 696 <title>MALLCTL NAMESPACE</title> 697 <para>The following names are defined in the namespace accessible via the 698 <function>mallctl*<parameter/></function> functions. Value types are 699 specified in parentheses, their readable/writable statuses are encoded as 700 <literal>rw</literal>, <literal>r-</literal>, <literal>-w</literal>, or 701 <literal>--</literal>, and required build configuration flags follow, if 702 any. A name element encoded as <literal><i></literal> or 703 <literal><j></literal> indicates an integer component, where the 704 integer varies from 0 to some upper value that must be determined via 705 introspection. In the case of <mallctl>stats.arenas.<i>.*</mallctl>, 706 <literal><i></literal> equal to <link 707 linkend="arenas.narenas"><mallctl>arenas.narenas</mallctl></link> can be 708 used to access the summation of statistics from all arenas. Take special 709 note of the <link linkend="epoch"><mallctl>epoch</mallctl></link> mallctl, 710 which controls refreshing of cached dynamic statistics.</para> 711 712 <variablelist> 713 <varlistentry id="version"> 714 <term> 715 <mallctl>version</mallctl> 716 (<type>const char *</type>) 717 <literal>r-</literal> 718 </term> 719 <listitem><para>Return the jemalloc version string.</para></listitem> 720 </varlistentry> 721 722 <varlistentry id="epoch"> 723 <term> 724 <mallctl>epoch</mallctl> 725 (<type>uint64_t</type>) 726 <literal>rw</literal> 727 </term> 728 <listitem><para>If a value is passed in, refresh the data from which 729 the <function>mallctl*<parameter/></function> functions report values, 730 and increment the epoch. Return the current epoch. This is useful for 731 detecting whether another thread caused a refresh.</para></listitem> 732 </varlistentry> 733 734 <varlistentry id="config.debug"> 735 <term> 736 <mallctl>config.debug</mallctl> 737 (<type>bool</type>) 738 <literal>r-</literal> 739 </term> 740 <listitem><para><option>--enable-debug</option> was specified during 741 build configuration.</para></listitem> 742 </varlistentry> 743 744 <varlistentry id="config.fill"> 745 <term> 746 <mallctl>config.fill</mallctl> 747 (<type>bool</type>) 748 <literal>r-</literal> 749 </term> 750 <listitem><para><option>--enable-fill</option> was specified during 751 build configuration.</para></listitem> 752 </varlistentry> 753 754 <varlistentry id="config.lazy_lock"> 755 <term> 756 <mallctl>config.lazy_lock</mallctl> 757 (<type>bool</type>) 758 <literal>r-</literal> 759 </term> 760 <listitem><para><option>--enable-lazy-lock</option> was specified 761 during build configuration.</para></listitem> 762 </varlistentry> 763 764 <varlistentry id="config.munmap"> 765 <term> 766 <mallctl>config.munmap</mallctl> 767 (<type>bool</type>) 768 <literal>r-</literal> 769 </term> 770 <listitem><para><option>--enable-munmap</option> was specified during 771 build configuration.</para></listitem> 772 </varlistentry> 773 774 <varlistentry id="config.prof"> 775 <term> 776 <mallctl>config.prof</mallctl> 777 (<type>bool</type>) 778 <literal>r-</literal> 779 </term> 780 <listitem><para><option>--enable-prof</option> was specified during 781 build configuration.</para></listitem> 782 </varlistentry> 783 784 <varlistentry id="config.prof_libgcc"> 785 <term> 786 <mallctl>config.prof_libgcc</mallctl> 787 (<type>bool</type>) 788 <literal>r-</literal> 789 </term> 790 <listitem><para><option>--disable-prof-libgcc</option> was not 791 specified during build configuration.</para></listitem> 792 </varlistentry> 793 794 <varlistentry id="config.prof_libunwind"> 795 <term> 796 <mallctl>config.prof_libunwind</mallctl> 797 (<type>bool</type>) 798 <literal>r-</literal> 799 </term> 800 <listitem><para><option>--enable-prof-libunwind</option> was specified 801 during build configuration.</para></listitem> 802 </varlistentry> 803 804 <varlistentry id="config.stats"> 805 <term> 806 <mallctl>config.stats</mallctl> 807 (<type>bool</type>) 808 <literal>r-</literal> 809 </term> 810 <listitem><para><option>--enable-stats</option> was specified during 811 build configuration.</para></listitem> 812 </varlistentry> 813 814 <varlistentry id="config.tcache"> 815 <term> 816 <mallctl>config.tcache</mallctl> 817 (<type>bool</type>) 818 <literal>r-</literal> 819 </term> 820 <listitem><para><option>--disable-tcache</option> was not specified 821 during build configuration.</para></listitem> 822 </varlistentry> 823 824 <varlistentry id="config.tls"> 825 <term> 826 <mallctl>config.tls</mallctl> 827 (<type>bool</type>) 828 <literal>r-</literal> 829 </term> 830 <listitem><para><option>--disable-tls</option> was not specified during 831 build configuration.</para></listitem> 832 </varlistentry> 833 834 <varlistentry id="config.utrace"> 835 <term> 836 <mallctl>config.utrace</mallctl> 837 (<type>bool</type>) 838 <literal>r-</literal> 839 </term> 840 <listitem><para><option>--enable-utrace</option> was specified during 841 build configuration.</para></listitem> 842 </varlistentry> 843 844 <varlistentry id="config.valgrind"> 845 <term> 846 <mallctl>config.valgrind</mallctl> 847 (<type>bool</type>) 848 <literal>r-</literal> 849 </term> 850 <listitem><para><option>--enable-valgrind</option> was specified during 851 build configuration.</para></listitem> 852 </varlistentry> 853 854 <varlistentry id="config.xmalloc"> 855 <term> 856 <mallctl>config.xmalloc</mallctl> 857 (<type>bool</type>) 858 <literal>r-</literal> 859 </term> 860 <listitem><para><option>--enable-xmalloc</option> was specified during 861 build configuration.</para></listitem> 862 </varlistentry> 863 864 <varlistentry id="opt.abort"> 865 <term> 866 <mallctl>opt.abort</mallctl> 867 (<type>bool</type>) 868 <literal>r-</literal> 869 </term> 870 <listitem><para>Abort-on-warning enabled/disabled. If true, most 871 warnings are fatal. The process will call 872 <citerefentry><refentrytitle>abort</refentrytitle> 873 <manvolnum>3</manvolnum></citerefentry> in these cases. This option is 874 disabled by default unless <option>--enable-debug</option> is 875 specified during configuration, in which case it is enabled by default. 876 </para></listitem> 877 </varlistentry> 878 879 <varlistentry id="opt.dss"> 880 <term> 881 <mallctl>opt.dss</mallctl> 882 (<type>const char *</type>) 883 <literal>r-</literal> 884 </term> 885 <listitem><para>dss (<citerefentry><refentrytitle>sbrk</refentrytitle> 886 <manvolnum>2</manvolnum></citerefentry>) allocation precedence as 887 related to <citerefentry><refentrytitle>mmap</refentrytitle> 888 <manvolnum>2</manvolnum></citerefentry> allocation. The following 889 settings are supported if 890 <citerefentry><refentrytitle>sbrk</refentrytitle> 891 <manvolnum>2</manvolnum></citerefentry> is supported by the operating 892 system: “disabled”, “primary”, and 893 “secondary”; otherwise only “disabled” is 894 supported. The default is “secondary” if 895 <citerefentry><refentrytitle>sbrk</refentrytitle> 896 <manvolnum>2</manvolnum></citerefentry> is supported by the operating 897 system; “disabled” otherwise. 898 </para></listitem> 899 </varlistentry> 900 901 <varlistentry id="opt.lg_chunk"> 902 <term> 903 <mallctl>opt.lg_chunk</mallctl> 904 (<type>size_t</type>) 905 <literal>r-</literal> 906 </term> 907 <listitem><para>Virtual memory chunk size (log base 2). If a chunk 908 size outside the supported size range is specified, the size is 909 silently clipped to the minimum/maximum supported size. The default 910 chunk size is 256 KiB (2^18). 911 </para></listitem> 912 </varlistentry> 913 914 <varlistentry id="opt.narenas"> 915 <term> 916 <mallctl>opt.narenas</mallctl> 917 (<type>size_t</type>) 918 <literal>r-</literal> 919 </term> 920 <listitem><para>Maximum number of arenas to use for automatic 921 multiplexing of threads and arenas. The default is four times the 922 number of CPUs, or one if there is a single CPU.</para></listitem> 923 </varlistentry> 924 925 <varlistentry id="opt.lg_dirty_mult"> 926 <term> 927 <mallctl>opt.lg_dirty_mult</mallctl> 928 (<type>ssize_t</type>) 929 <literal>r-</literal> 930 </term> 931 <listitem><para>Per-arena minimum ratio (log base 2) of active to dirty 932 pages. Some dirty unused pages may be allowed to accumulate, within 933 the limit set by the ratio (or one chunk worth of dirty pages, 934 whichever is greater), before informing the kernel about some of those 935 pages via <citerefentry><refentrytitle>madvise</refentrytitle> 936 <manvolnum>2</manvolnum></citerefentry> or a similar system call. This 937 provides the kernel with sufficient information to recycle dirty pages 938 if physical memory becomes scarce and the pages remain unused. The 939 default minimum ratio is 8:1 (2^3:1); an option value of -1 will 940 disable dirty page purging. See <link 941 linkend="arenas.lg_dirty_mult"><mallctl>arenas.lg_dirty_mult</mallctl></link> 942 and <link 943 linkend="arena.i.lg_dirty_mult"><mallctl>arena.<i>.lg_dirty_mult</mallctl></link> 944 for related dynamic control options.</para></listitem> 945 </varlistentry> 946 947 <varlistentry id="opt.stats_print"> 948 <term> 949 <mallctl>opt.stats_print</mallctl> 950 (<type>bool</type>) 951 <literal>r-</literal> 952 </term> 953 <listitem><para>Enable/disable statistics printing at exit. If 954 enabled, the <function>malloc_stats_print<parameter/></function> 955 function is called at program exit via an 956 <citerefentry><refentrytitle>atexit</refentrytitle> 957 <manvolnum>3</manvolnum></citerefentry> function. If 958 <option>--enable-stats</option> is specified during configuration, this 959 has the potential to cause deadlock for a multi-threaded process that 960 exits while one or more threads are executing in the memory allocation 961 functions. Furthermore, <function>atexit<parameter/></function> may 962 allocate memory during application initialization and then deadlock 963 internally when jemalloc in turn calls 964 <function>atexit<parameter/></function>, so this option is not 965 univerally usable (though the application can register its own 966 <function>atexit<parameter/></function> function with equivalent 967 functionality). Therefore, this option should only be used with care; 968 it is primarily intended as a performance tuning aid during application 969 development. This option is disabled by default.</para></listitem> 970 </varlistentry> 971 972 <varlistentry id="opt.junk"> 973 <term> 974 <mallctl>opt.junk</mallctl> 975 (<type>const char *</type>) 976 <literal>r-</literal> 977 [<option>--enable-fill</option>] 978 </term> 979 <listitem><para>Junk filling. If set to "alloc", each byte of 980 uninitialized allocated memory will be initialized to 981 <literal>0xa5</literal>. If set to "free", all deallocated memory will 982 be initialized to <literal>0x5a</literal>. If set to "true", both 983 allocated and deallocated memory will be initialized, and if set to 984 "false", junk filling be disabled entirely. This is intended for 985 debugging and will impact performance negatively. This option is 986 "false" by default unless <option>--enable-debug</option> is specified 987 during configuration, in which case it is "true" by default unless 988 running inside <ulink 989 url="http://valgrind.org/">Valgrind</ulink>.</para></listitem> 990 </varlistentry> 991 992 <varlistentry id="opt.quarantine"> 993 <term> 994 <mallctl>opt.quarantine</mallctl> 995 (<type>size_t</type>) 996 <literal>r-</literal> 997 [<option>--enable-fill</option>] 998 </term> 999 <listitem><para>Per thread quarantine size in bytes. If non-zero, each 1000 thread maintains a FIFO object quarantine that stores up to the 1001 specified number of bytes of memory. The quarantined memory is not 1002 freed until it is released from quarantine, though it is immediately 1003 junk-filled if the <link 1004 linkend="opt.junk"><mallctl>opt.junk</mallctl></link> option is 1005 enabled. This feature is of particular use in combination with <ulink 1006 url="http://valgrind.org/">Valgrind</ulink>, which can detect attempts 1007 to access quarantined objects. This is intended for debugging and will 1008 impact performance negatively. The default quarantine size is 0 unless 1009 running inside Valgrind, in which case the default is 16 1010 MiB.</para></listitem> 1011 </varlistentry> 1012 1013 <varlistentry id="opt.redzone"> 1014 <term> 1015 <mallctl>opt.redzone</mallctl> 1016 (<type>bool</type>) 1017 <literal>r-</literal> 1018 [<option>--enable-fill</option>] 1019 </term> 1020 <listitem><para>Redzones enabled/disabled. If enabled, small 1021 allocations have redzones before and after them. Furthermore, if the 1022 <link linkend="opt.junk"><mallctl>opt.junk</mallctl></link> option is 1023 enabled, the redzones are checked for corruption during deallocation. 1024 However, the primary intended purpose of this feature is to be used in 1025 combination with <ulink url="http://valgrind.org/">Valgrind</ulink>, 1026 which needs redzones in order to do effective buffer overflow/underflow 1027 detection. This option is intended for debugging and will impact 1028 performance negatively. This option is disabled by 1029 default unless running inside Valgrind.</para></listitem> 1030 </varlistentry> 1031 1032 <varlistentry id="opt.zero"> 1033 <term> 1034 <mallctl>opt.zero</mallctl> 1035 (<type>bool</type>) 1036 <literal>r-</literal> 1037 [<option>--enable-fill</option>] 1038 </term> 1039 <listitem><para>Zero filling enabled/disabled. If enabled, each byte 1040 of uninitialized allocated memory will be initialized to 0. Note that 1041 this initialization only happens once for each byte, so 1042 <function>realloc<parameter/></function> and 1043 <function>rallocx<parameter/></function> calls do not zero memory that 1044 was previously allocated. This is intended for debugging and will 1045 impact performance negatively. This option is disabled by default. 1046 </para></listitem> 1047 </varlistentry> 1048 1049 <varlistentry id="opt.utrace"> 1050 <term> 1051 <mallctl>opt.utrace</mallctl> 1052 (<type>bool</type>) 1053 <literal>r-</literal> 1054 [<option>--enable-utrace</option>] 1055 </term> 1056 <listitem><para>Allocation tracing based on 1057 <citerefentry><refentrytitle>utrace</refentrytitle> 1058 <manvolnum>2</manvolnum></citerefentry> enabled/disabled. This option 1059 is disabled by default.</para></listitem> 1060 </varlistentry> 1061 1062 <varlistentry id="opt.xmalloc"> 1063 <term> 1064 <mallctl>opt.xmalloc</mallctl> 1065 (<type>bool</type>) 1066 <literal>r-</literal> 1067 [<option>--enable-xmalloc</option>] 1068 </term> 1069 <listitem><para>Abort-on-out-of-memory enabled/disabled. If enabled, 1070 rather than returning failure for any allocation function, display a 1071 diagnostic message on <constant>STDERR_FILENO</constant> and cause the 1072 program to drop core (using 1073 <citerefentry><refentrytitle>abort</refentrytitle> 1074 <manvolnum>3</manvolnum></citerefentry>). If an application is 1075 designed to depend on this behavior, set the option at compile time by 1076 including the following in the source code: 1077 <programlisting language="C"><![CDATA[ 1078malloc_conf = "xmalloc:true";]]></programlisting> 1079 This option is disabled by default.</para></listitem> 1080 </varlistentry> 1081 1082 <varlistentry id="opt.tcache"> 1083 <term> 1084 <mallctl>opt.tcache</mallctl> 1085 (<type>bool</type>) 1086 <literal>r-</literal> 1087 [<option>--enable-tcache</option>] 1088 </term> 1089 <listitem><para>Thread-specific caching (tcache) enabled/disabled. When 1090 there are multiple threads, each thread uses a tcache for objects up to 1091 a certain size. Thread-specific caching allows many allocations to be 1092 satisfied without performing any thread synchronization, at the cost of 1093 increased memory use. See the <link 1094 linkend="opt.lg_tcache_max"><mallctl>opt.lg_tcache_max</mallctl></link> 1095 option for related tuning information. This option is enabled by 1096 default unless running inside <ulink 1097 url="http://valgrind.org/">Valgrind</ulink>, in which case it is 1098 forcefully disabled.</para></listitem> 1099 </varlistentry> 1100 1101 <varlistentry id="opt.lg_tcache_max"> 1102 <term> 1103 <mallctl>opt.lg_tcache_max</mallctl> 1104 (<type>size_t</type>) 1105 <literal>r-</literal> 1106 [<option>--enable-tcache</option>] 1107 </term> 1108 <listitem><para>Maximum size class (log base 2) to cache in the 1109 thread-specific cache (tcache). At a minimum, all small size classes 1110 are cached, and at a maximum all large size classes are cached. The 1111 default maximum is 32 KiB (2^15).</para></listitem> 1112 </varlistentry> 1113 1114 <varlistentry id="opt.prof"> 1115 <term> 1116 <mallctl>opt.prof</mallctl> 1117 (<type>bool</type>) 1118 <literal>r-</literal> 1119 [<option>--enable-prof</option>] 1120 </term> 1121 <listitem><para>Memory profiling enabled/disabled. If enabled, profile 1122 memory allocation activity. See the <link 1123 linkend="opt.prof_active"><mallctl>opt.prof_active</mallctl></link> 1124 option for on-the-fly activation/deactivation. See the <link 1125 linkend="opt.lg_prof_sample"><mallctl>opt.lg_prof_sample</mallctl></link> 1126 option for probabilistic sampling control. See the <link 1127 linkend="opt.prof_accum"><mallctl>opt.prof_accum</mallctl></link> 1128 option for control of cumulative sample reporting. See the <link 1129 linkend="opt.lg_prof_interval"><mallctl>opt.lg_prof_interval</mallctl></link> 1130 option for information on interval-triggered profile dumping, the <link 1131 linkend="opt.prof_gdump"><mallctl>opt.prof_gdump</mallctl></link> 1132 option for information on high-water-triggered profile dumping, and the 1133 <link linkend="opt.prof_final"><mallctl>opt.prof_final</mallctl></link> 1134 option for final profile dumping. Profile output is compatible with 1135 the <command>jeprof</command> command, which is based on the 1136 <command>pprof</command> that is developed as part of the <ulink 1137 url="http://code.google.com/p/gperftools/">gperftools 1138 package</ulink>.</para></listitem> 1139 </varlistentry> 1140 1141 <varlistentry id="opt.prof_prefix"> 1142 <term> 1143 <mallctl>opt.prof_prefix</mallctl> 1144 (<type>const char *</type>) 1145 <literal>r-</literal> 1146 [<option>--enable-prof</option>] 1147 </term> 1148 <listitem><para>Filename prefix for profile dumps. If the prefix is 1149 set to the empty string, no automatic dumps will occur; this is 1150 primarily useful for disabling the automatic final heap dump (which 1151 also disables leak reporting, if enabled). The default prefix is 1152 <filename>jeprof</filename>.</para></listitem> 1153 </varlistentry> 1154 1155 <varlistentry id="opt.prof_active"> 1156 <term> 1157 <mallctl>opt.prof_active</mallctl> 1158 (<type>bool</type>) 1159 <literal>r-</literal> 1160 [<option>--enable-prof</option>] 1161 </term> 1162 <listitem><para>Profiling activated/deactivated. This is a secondary 1163 control mechanism that makes it possible to start the application with 1164 profiling enabled (see the <link 1165 linkend="opt.prof"><mallctl>opt.prof</mallctl></link> option) but 1166 inactive, then toggle profiling at any time during program execution 1167 with the <link 1168 linkend="prof.active"><mallctl>prof.active</mallctl></link> mallctl. 1169 This option is enabled by default.</para></listitem> 1170 </varlistentry> 1171 1172 <varlistentry id="opt.prof_thread_active_init"> 1173 <term> 1174 <mallctl>opt.prof_thread_active_init</mallctl> 1175 (<type>bool</type>) 1176 <literal>r-</literal> 1177 [<option>--enable-prof</option>] 1178 </term> 1179 <listitem><para>Initial setting for <link 1180 linkend="thread.prof.active"><mallctl>thread.prof.active</mallctl></link> 1181 in newly created threads. The initial setting for newly created threads 1182 can also be changed during execution via the <link 1183 linkend="prof.thread_active_init"><mallctl>prof.thread_active_init</mallctl></link> 1184 mallctl. This option is enabled by default.</para></listitem> 1185 </varlistentry> 1186 1187 <varlistentry id="opt.lg_prof_sample"> 1188 <term> 1189 <mallctl>opt.lg_prof_sample</mallctl> 1190 (<type>size_t</type>) 1191 <literal>r-</literal> 1192 [<option>--enable-prof</option>] 1193 </term> 1194 <listitem><para>Average interval (log base 2) between allocation 1195 samples, as measured in bytes of allocation activity. Increasing the 1196 sampling interval decreases profile fidelity, but also decreases the 1197 computational overhead. The default sample interval is 512 KiB (2^19 1198 B).</para></listitem> 1199 </varlistentry> 1200 1201 <varlistentry id="opt.prof_accum"> 1202 <term> 1203 <mallctl>opt.prof_accum</mallctl> 1204 (<type>bool</type>) 1205 <literal>r-</literal> 1206 [<option>--enable-prof</option>] 1207 </term> 1208 <listitem><para>Reporting of cumulative object/byte counts in profile 1209 dumps enabled/disabled. If this option is enabled, every unique 1210 backtrace must be stored for the duration of execution. Depending on 1211 the application, this can impose a large memory overhead, and the 1212 cumulative counts are not always of interest. This option is disabled 1213 by default.</para></listitem> 1214 </varlistentry> 1215 1216 <varlistentry id="opt.lg_prof_interval"> 1217 <term> 1218 <mallctl>opt.lg_prof_interval</mallctl> 1219 (<type>ssize_t</type>) 1220 <literal>r-</literal> 1221 [<option>--enable-prof</option>] 1222 </term> 1223 <listitem><para>Average interval (log base 2) between memory profile 1224 dumps, as measured in bytes of allocation activity. The actual 1225 interval between dumps may be sporadic because decentralized allocation 1226 counters are used to avoid synchronization bottlenecks. Profiles are 1227 dumped to files named according to the pattern 1228 <filename><prefix>.<pid>.<seq>.i<iseq>.heap</filename>, 1229 where <literal><prefix></literal> is controlled by the 1230 <link 1231 linkend="opt.prof_prefix"><mallctl>opt.prof_prefix</mallctl></link> 1232 option. By default, interval-triggered profile dumping is disabled 1233 (encoded as -1). 1234 </para></listitem> 1235 </varlistentry> 1236 1237 <varlistentry id="opt.prof_gdump"> 1238 <term> 1239 <mallctl>opt.prof_gdump</mallctl> 1240 (<type>bool</type>) 1241 <literal>r-</literal> 1242 [<option>--enable-prof</option>] 1243 </term> 1244 <listitem><para>Set the initial state of <link 1245 linkend="prof.gdump"><mallctl>prof.gdump</mallctl></link>, which when 1246 enabled triggers a memory profile dump every time the total virtual 1247 memory exceeds the previous maximum. This option is disabled by 1248 default.</para></listitem> 1249 </varlistentry> 1250 1251 <varlistentry id="opt.prof_final"> 1252 <term> 1253 <mallctl>opt.prof_final</mallctl> 1254 (<type>bool</type>) 1255 <literal>r-</literal> 1256 [<option>--enable-prof</option>] 1257 </term> 1258 <listitem><para>Use an 1259 <citerefentry><refentrytitle>atexit</refentrytitle> 1260 <manvolnum>3</manvolnum></citerefentry> function to dump final memory 1261 usage to a file named according to the pattern 1262 <filename><prefix>.<pid>.<seq>.f.heap</filename>, 1263 where <literal><prefix></literal> is controlled by the <link 1264 linkend="opt.prof_prefix"><mallctl>opt.prof_prefix</mallctl></link> 1265 option. Note that <function>atexit<parameter/></function> may allocate 1266 memory during application initialization and then deadlock internally 1267 when jemalloc in turn calls <function>atexit<parameter/></function>, so 1268 this option is not univerally usable (though the application can 1269 register its own <function>atexit<parameter/></function> function with 1270 equivalent functionality). This option is disabled by 1271 default.</para></listitem> 1272 </varlistentry> 1273 1274 <varlistentry id="opt.prof_leak"> 1275 <term> 1276 <mallctl>opt.prof_leak</mallctl> 1277 (<type>bool</type>) 1278 <literal>r-</literal> 1279 [<option>--enable-prof</option>] 1280 </term> 1281 <listitem><para>Leak reporting enabled/disabled. If enabled, use an 1282 <citerefentry><refentrytitle>atexit</refentrytitle> 1283 <manvolnum>3</manvolnum></citerefentry> function to report memory leaks 1284 detected by allocation sampling. See the 1285 <link linkend="opt.prof"><mallctl>opt.prof</mallctl></link> option for 1286 information on analyzing heap profile output. This option is disabled 1287 by default.</para></listitem> 1288 </varlistentry> 1289 1290 <varlistentry id="thread.arena"> 1291 <term> 1292 <mallctl>thread.arena</mallctl> 1293 (<type>unsigned</type>) 1294 <literal>rw</literal> 1295 </term> 1296 <listitem><para>Get or set the arena associated with the calling 1297 thread. If the specified arena was not initialized beforehand (see the 1298 <link 1299 linkend="arenas.initialized"><mallctl>arenas.initialized</mallctl></link> 1300 mallctl), it will be automatically initialized as a side effect of 1301 calling this interface.</para></listitem> 1302 </varlistentry> 1303 1304 <varlistentry id="thread.allocated"> 1305 <term> 1306 <mallctl>thread.allocated</mallctl> 1307 (<type>uint64_t</type>) 1308 <literal>r-</literal> 1309 [<option>--enable-stats</option>] 1310 </term> 1311 <listitem><para>Get the total number of bytes ever allocated by the 1312 calling thread. This counter has the potential to wrap around; it is 1313 up to the application to appropriately interpret the counter in such 1314 cases.</para></listitem> 1315 </varlistentry> 1316 1317 <varlistentry id="thread.allocatedp"> 1318 <term> 1319 <mallctl>thread.allocatedp</mallctl> 1320 (<type>uint64_t *</type>) 1321 <literal>r-</literal> 1322 [<option>--enable-stats</option>] 1323 </term> 1324 <listitem><para>Get a pointer to the the value that is returned by the 1325 <link 1326 linkend="thread.allocated"><mallctl>thread.allocated</mallctl></link> 1327 mallctl. This is useful for avoiding the overhead of repeated 1328 <function>mallctl*<parameter/></function> calls.</para></listitem> 1329 </varlistentry> 1330 1331 <varlistentry id="thread.deallocated"> 1332 <term> 1333 <mallctl>thread.deallocated</mallctl> 1334 (<type>uint64_t</type>) 1335 <literal>r-</literal> 1336 [<option>--enable-stats</option>] 1337 </term> 1338 <listitem><para>Get the total number of bytes ever deallocated by the 1339 calling thread. This counter has the potential to wrap around; it is 1340 up to the application to appropriately interpret the counter in such 1341 cases.</para></listitem> 1342 </varlistentry> 1343 1344 <varlistentry id="thread.deallocatedp"> 1345 <term> 1346 <mallctl>thread.deallocatedp</mallctl> 1347 (<type>uint64_t *</type>) 1348 <literal>r-</literal> 1349 [<option>--enable-stats</option>] 1350 </term> 1351 <listitem><para>Get a pointer to the the value that is returned by the 1352 <link 1353 linkend="thread.deallocated"><mallctl>thread.deallocated</mallctl></link> 1354 mallctl. This is useful for avoiding the overhead of repeated 1355 <function>mallctl*<parameter/></function> calls.</para></listitem> 1356 </varlistentry> 1357 1358 <varlistentry id="thread.tcache.enabled"> 1359 <term> 1360 <mallctl>thread.tcache.enabled</mallctl> 1361 (<type>bool</type>) 1362 <literal>rw</literal> 1363 [<option>--enable-tcache</option>] 1364 </term> 1365 <listitem><para>Enable/disable calling thread's tcache. The tcache is 1366 implicitly flushed as a side effect of becoming 1367 disabled (see <link 1368 linkend="thread.tcache.flush"><mallctl>thread.tcache.flush</mallctl></link>). 1369 </para></listitem> 1370 </varlistentry> 1371 1372 <varlistentry id="thread.tcache.flush"> 1373 <term> 1374 <mallctl>thread.tcache.flush</mallctl> 1375 (<type>void</type>) 1376 <literal>--</literal> 1377 [<option>--enable-tcache</option>] 1378 </term> 1379 <listitem><para>Flush calling thread's thread-specific cache (tcache). 1380 This interface releases all cached objects and internal data structures 1381 associated with the calling thread's tcache. Ordinarily, this interface 1382 need not be called, since automatic periodic incremental garbage 1383 collection occurs, and the thread cache is automatically discarded when 1384 a thread exits. However, garbage collection is triggered by allocation 1385 activity, so it is possible for a thread that stops 1386 allocating/deallocating to retain its cache indefinitely, in which case 1387 the developer may find manual flushing useful.</para></listitem> 1388 </varlistentry> 1389 1390 <varlistentry id="thread.prof.name"> 1391 <term> 1392 <mallctl>thread.prof.name</mallctl> 1393 (<type>const char *</type>) 1394 <literal>r-</literal> or 1395 <literal>-w</literal> 1396 [<option>--enable-prof</option>] 1397 </term> 1398 <listitem><para>Get/set the descriptive name associated with the calling 1399 thread in memory profile dumps. An internal copy of the name string is 1400 created, so the input string need not be maintained after this interface 1401 completes execution. The output string of this interface should be 1402 copied for non-ephemeral uses, because multiple implementation details 1403 can cause asynchronous string deallocation. Furthermore, each 1404 invocation of this interface can only read or write; simultaneous 1405 read/write is not supported due to string lifetime limitations. The 1406 name string must nil-terminated and comprised only of characters in the 1407 sets recognized 1408 by <citerefentry><refentrytitle>isgraph</refentrytitle> 1409 <manvolnum>3</manvolnum></citerefentry> and 1410 <citerefentry><refentrytitle>isblank</refentrytitle> 1411 <manvolnum>3</manvolnum></citerefentry>.</para></listitem> 1412 </varlistentry> 1413 1414 <varlistentry id="thread.prof.active"> 1415 <term> 1416 <mallctl>thread.prof.active</mallctl> 1417 (<type>bool</type>) 1418 <literal>rw</literal> 1419 [<option>--enable-prof</option>] 1420 </term> 1421 <listitem><para>Control whether sampling is currently active for the 1422 calling thread. This is an activation mechanism in addition to <link 1423 linkend="prof.active"><mallctl>prof.active</mallctl></link>; both must 1424 be active for the calling thread to sample. This flag is enabled by 1425 default.</para></listitem> 1426 </varlistentry> 1427 1428 <varlistentry id="tcache.create"> 1429 <term> 1430 <mallctl>tcache.create</mallctl> 1431 (<type>unsigned</type>) 1432 <literal>r-</literal> 1433 [<option>--enable-tcache</option>] 1434 </term> 1435 <listitem><para>Create an explicit thread-specific cache (tcache) and 1436 return an identifier that can be passed to the <link 1437 linkend="MALLOCX_TCACHE"><constant>MALLOCX_TCACHE(<parameter>tc</parameter>)</constant></link> 1438 macro to explicitly use the specified cache rather than the 1439 automatically managed one that is used by default. Each explicit cache 1440 can be used by only one thread at a time; the application must assure 1441 that this constraint holds. 1442 </para></listitem> 1443 </varlistentry> 1444 1445 <varlistentry id="tcache.flush"> 1446 <term> 1447 <mallctl>tcache.flush</mallctl> 1448 (<type>unsigned</type>) 1449 <literal>-w</literal> 1450 [<option>--enable-tcache</option>] 1451 </term> 1452 <listitem><para>Flush the specified thread-specific cache (tcache). The 1453 same considerations apply to this interface as to <link 1454 linkend="thread.tcache.flush"><mallctl>thread.tcache.flush</mallctl></link>, 1455 except that the tcache will never be automatically be discarded. 1456 </para></listitem> 1457 </varlistentry> 1458 1459 <varlistentry id="tcache.destroy"> 1460 <term> 1461 <mallctl>tcache.destroy</mallctl> 1462 (<type>unsigned</type>) 1463 <literal>-w</literal> 1464 [<option>--enable-tcache</option>] 1465 </term> 1466 <listitem><para>Flush the specified thread-specific cache (tcache) and 1467 make the identifier available for use during a future tcache creation. 1468 </para></listitem> 1469 </varlistentry> 1470 1471 <varlistentry id="arena.i.purge"> 1472 <term> 1473 <mallctl>arena.<i>.purge</mallctl> 1474 (<type>void</type>) 1475 <literal>--</literal> 1476 </term> 1477 <listitem><para>Purge unused dirty pages for arena <i>, or for 1478 all arenas if <i> equals <link 1479 linkend="arenas.narenas"><mallctl>arenas.narenas</mallctl></link>. 1480 </para></listitem> 1481 </varlistentry> 1482 1483 <varlistentry id="arena.i.dss"> 1484 <term> 1485 <mallctl>arena.<i>.dss</mallctl> 1486 (<type>const char *</type>) 1487 <literal>rw</literal> 1488 </term> 1489 <listitem><para>Set the precedence of dss allocation as related to mmap 1490 allocation for arena <i>, or for all arenas if <i> equals 1491 <link 1492 linkend="arenas.narenas"><mallctl>arenas.narenas</mallctl></link>. See 1493 <link linkend="opt.dss"><mallctl>opt.dss</mallctl></link> for supported 1494 settings.</para></listitem> 1495 </varlistentry> 1496 1497 <varlistentry id="arena.i.lg_dirty_mult"> 1498 <term> 1499 <mallctl>arena.<i>.lg_dirty_mult</mallctl> 1500 (<type>ssize_t</type>) 1501 <literal>rw</literal> 1502 </term> 1503 <listitem><para>Current per-arena minimum ratio (log base 2) of active 1504 to dirty pages for arena <i>. Each time this interface is set and 1505 the ratio is increased, pages are synchronously purged as necessary to 1506 impose the new ratio. See <link 1507 linkend="opt.lg_dirty_mult"><mallctl>opt.lg_dirty_mult</mallctl></link> 1508 for additional information.</para></listitem> 1509 </varlistentry> 1510 1511 <varlistentry id="arena.i.chunk.alloc"> 1512 <term> 1513 <mallctl>arena.<i>.chunk.alloc</mallctl> 1514 (<type>chunk_alloc_t *</type>) 1515 <literal>rw</literal> 1516 </term> 1517 <listitem><para>Get or set the chunk allocation function for arena 1518 <i>. If setting, the chunk deallocation function should 1519 also be set via <link linkend="arena.i.chunk.dalloc"> 1520 <mallctl>arena.<i>.chunk.dalloc</mallctl></link> to a companion 1521 function that knows how to deallocate the chunks. 1522 <funcsynopsis><funcprototype> 1523 <funcdef>typedef void *<function>(chunk_alloc_t)</function></funcdef> 1524 <paramdef>void *<parameter>chunk</parameter></paramdef> 1525 <paramdef>size_t <parameter>size</parameter></paramdef> 1526 <paramdef>size_t <parameter>alignment</parameter></paramdef> 1527 <paramdef>bool *<parameter>zero</parameter></paramdef> 1528 <paramdef>unsigned <parameter>arena_ind</parameter></paramdef> 1529 </funcprototype></funcsynopsis> 1530 A chunk allocation function conforms to the <type>chunk_alloc_t</type> 1531 type and upon success returns a pointer to <parameter>size</parameter> 1532 bytes of memory on behalf of arena <parameter>arena_ind</parameter> such 1533 that the chunk's base address is a multiple of 1534 <parameter>alignment</parameter>, as well as setting 1535 <parameter>*zero</parameter> to indicate whether the chunk is zeroed. 1536 Upon error the function returns <constant>NULL</constant> and leaves 1537 <parameter>*zero</parameter> unmodified. The 1538 <parameter>size</parameter> parameter is always a multiple of the chunk 1539 size. The <parameter>alignment</parameter> parameter is always a power 1540 of two at least as large as the chunk size. Zeroing is mandatory if 1541 <parameter>*zero</parameter> is true upon function entry. If 1542 <parameter>chunk</parameter> is not <constant>NULL</constant>, the 1543 returned pointer must be <parameter>chunk</parameter> or 1544 <constant>NULL</constant> if it could not be allocated.</para> 1545 1546 <para>Note that replacing the default chunk allocation function makes 1547 the arena's <link 1548 linkend="arena.i.dss"><mallctl>arena.<i>.dss</mallctl></link> 1549 setting irrelevant.</para></listitem> 1550 </varlistentry> 1551 1552 <varlistentry id="arena.i.chunk.dalloc"> 1553 <term> 1554 <mallctl>arena.<i>.chunk.dalloc</mallctl> 1555 (<type>chunk_dalloc_t *</type>) 1556 <literal>rw</literal> 1557 </term> 1558 <listitem><para>Get or set the chunk deallocation function for arena 1559 <i>. If setting, the chunk deallocation function must 1560 be capable of deallocating all extant chunks associated with arena 1561 <i>, usually by passing unknown chunks to the deallocation 1562 function that was replaced. In practice, it is feasible to control 1563 allocation for arenas created via <link 1564 linkend="arenas.extend"><mallctl>arenas.extend</mallctl></link> such 1565 that all chunks originate from an application-supplied chunk allocator 1566 (by setting custom chunk allocation/deallocation/purge functions just 1567 after arena creation), but the automatically created arenas may have 1568 already created chunks prior to the application having an opportunity to 1569 take over chunk allocation. 1570 <funcsynopsis><funcprototype> 1571 <funcdef>typedef bool <function>(chunk_dalloc_t)</function></funcdef> 1572 <paramdef>void *<parameter>chunk</parameter></paramdef> 1573 <paramdef>size_t <parameter>size</parameter></paramdef> 1574 <paramdef>unsigned <parameter>arena_ind</parameter></paramdef> 1575 </funcprototype></funcsynopsis> 1576 A chunk deallocation function conforms to the 1577 <type>chunk_dalloc_t</type> type and deallocates a 1578 <parameter>chunk</parameter> of given <parameter>size</parameter> on 1579 behalf of arena <parameter>arena_ind</parameter>, returning false upon 1580 success.</para></listitem> 1581 </varlistentry> 1582 1583 <varlistentry id="arena.i.chunk.purge"> 1584 <term> 1585 <mallctl>arena.<i>.chunk.purge</mallctl> 1586 (<type>chunk_purge_t *</type>) 1587 <literal>rw</literal> 1588 </term> 1589 <listitem><para>Get or set the chunk purge function for arena <i>. 1590 A chunk purge function optionally discards physical pages associated 1591 with pages in the chunk's virtual memory range but leaves the virtual 1592 memory mapping intact, and indicates via its return value whether pages 1593 in the virtual memory range will be zero-filled the next time they are 1594 accessed. If setting, the chunk purge function must be capable of 1595 purging all extant chunks associated with arena <i>, usually by 1596 passing unknown chunks to the purge function that was replaced. In 1597 practice, it is feasible to control allocation for arenas created via 1598 <link linkend="arenas.extend"><mallctl>arenas.extend</mallctl></link> 1599 such that all chunks originate from an application-supplied chunk 1600 allocator (by setting custom chunk allocation/deallocation/purge 1601 functions just after arena creation), but the automatically created 1602 arenas may have already created chunks prior to the application having 1603 an opportunity to take over chunk allocation. 1604 <funcsynopsis><funcprototype> 1605 <funcdef>typedef bool <function>(chunk_purge_t)</function></funcdef> 1606 <paramdef>void *<parameter>chunk</parameter></paramdef> 1607 <paramdef>size_t <parameter>offset</parameter></paramdef> 1608 <paramdef>size_t <parameter>length</parameter></paramdef> 1609 <paramdef>unsigned <parameter>arena_ind</parameter></paramdef> 1610 </funcprototype></funcsynopsis> 1611 A chunk purge function conforms to the <type>chunk_purge_t</type> type 1612 and purges pages within <parameter>chunk</parameter> at 1613 <parameter>offset</parameter> bytes, extending for 1614 <parameter>length</parameter> on behalf of arena 1615 <parameter>arena_ind</parameter>, returning false if pages within the 1616 purged virtual memory range will be zero-filled the next time they are 1617 accessed. Note that the memory range being purged may span multiple 1618 contiguous chunks, e.g. when purging memory that backed a huge 1619 allocation.</para></listitem> 1620 </varlistentry> 1621 1622 <varlistentry id="arenas.narenas"> 1623 <term> 1624 <mallctl>arenas.narenas</mallctl> 1625 (<type>unsigned</type>) 1626 <literal>r-</literal> 1627 </term> 1628 <listitem><para>Current limit on number of arenas.</para></listitem> 1629 </varlistentry> 1630 1631 <varlistentry id="arenas.initialized"> 1632 <term> 1633 <mallctl>arenas.initialized</mallctl> 1634 (<type>bool *</type>) 1635 <literal>r-</literal> 1636 </term> 1637 <listitem><para>An array of <link 1638 linkend="arenas.narenas"><mallctl>arenas.narenas</mallctl></link> 1639 booleans. Each boolean indicates whether the corresponding arena is 1640 initialized.</para></listitem> 1641 </varlistentry> 1642 1643 <varlistentry id="arenas.lg_dirty_mult"> 1644 <term> 1645 <mallctl>arenas.lg_dirty_mult</mallctl> 1646 (<type>ssize_t</type>) 1647 <literal>rw</literal> 1648 </term> 1649 <listitem><para>Current default per-arena minimum ratio (log base 2) of 1650 active to dirty pages, used to initialize <link 1651 linkend="arena.i.lg_dirty_mult"><mallctl>arena.<i>.lg_dirty_mult</mallctl></link> 1652 during arena creation. See <link 1653 linkend="opt.lg_dirty_mult"><mallctl>opt.lg_dirty_mult</mallctl></link> 1654 for additional information.</para></listitem> 1655 </varlistentry> 1656 1657 <varlistentry id="arenas.quantum"> 1658 <term> 1659 <mallctl>arenas.quantum</mallctl> 1660 (<type>size_t</type>) 1661 <literal>r-</literal> 1662 </term> 1663 <listitem><para>Quantum size.</para></listitem> 1664 </varlistentry> 1665 1666 <varlistentry id="arenas.page"> 1667 <term> 1668 <mallctl>arenas.page</mallctl> 1669 (<type>size_t</type>) 1670 <literal>r-</literal> 1671 </term> 1672 <listitem><para>Page size.</para></listitem> 1673 </varlistentry> 1674 1675 <varlistentry id="arenas.tcache_max"> 1676 <term> 1677 <mallctl>arenas.tcache_max</mallctl> 1678 (<type>size_t</type>) 1679 <literal>r-</literal> 1680 [<option>--enable-tcache</option>] 1681 </term> 1682 <listitem><para>Maximum thread-cached size class.</para></listitem> 1683 </varlistentry> 1684 1685 <varlistentry id="arenas.nbins"> 1686 <term> 1687 <mallctl>arenas.nbins</mallctl> 1688 (<type>unsigned</type>) 1689 <literal>r-</literal> 1690 </term> 1691 <listitem><para>Number of bin size classes.</para></listitem> 1692 </varlistentry> 1693 1694 <varlistentry id="arenas.nhbins"> 1695 <term> 1696 <mallctl>arenas.nhbins</mallctl> 1697 (<type>unsigned</type>) 1698 <literal>r-</literal> 1699 [<option>--enable-tcache</option>] 1700 </term> 1701 <listitem><para>Total number of thread cache bin size 1702 classes.</para></listitem> 1703 </varlistentry> 1704 1705 <varlistentry id="arenas.bin.i.size"> 1706 <term> 1707 <mallctl>arenas.bin.<i>.size</mallctl> 1708 (<type>size_t</type>) 1709 <literal>r-</literal> 1710 </term> 1711 <listitem><para>Maximum size supported by size class.</para></listitem> 1712 </varlistentry> 1713 1714 <varlistentry id="arenas.bin.i.nregs"> 1715 <term> 1716 <mallctl>arenas.bin.<i>.nregs</mallctl> 1717 (<type>uint32_t</type>) 1718 <literal>r-</literal> 1719 </term> 1720 <listitem><para>Number of regions per page run.</para></listitem> 1721 </varlistentry> 1722 1723 <varlistentry id="arenas.bin.i.run_size"> 1724 <term> 1725 <mallctl>arenas.bin.<i>.run_size</mallctl> 1726 (<type>size_t</type>) 1727 <literal>r-</literal> 1728 </term> 1729 <listitem><para>Number of bytes per page run.</para></listitem> 1730 </varlistentry> 1731 1732 <varlistentry id="arenas.nlruns"> 1733 <term> 1734 <mallctl>arenas.nlruns</mallctl> 1735 (<type>unsigned</type>) 1736 <literal>r-</literal> 1737 </term> 1738 <listitem><para>Total number of large size classes.</para></listitem> 1739 </varlistentry> 1740 1741 <varlistentry id="arenas.lrun.i.size"> 1742 <term> 1743 <mallctl>arenas.lrun.<i>.size</mallctl> 1744 (<type>size_t</type>) 1745 <literal>r-</literal> 1746 </term> 1747 <listitem><para>Maximum size supported by this large size 1748 class.</para></listitem> 1749 </varlistentry> 1750 1751 <varlistentry id="arenas.nhchunks"> 1752 <term> 1753 <mallctl>arenas.nhchunks</mallctl> 1754 (<type>unsigned</type>) 1755 <literal>r-</literal> 1756 </term> 1757 <listitem><para>Total number of huge size classes.</para></listitem> 1758 </varlistentry> 1759 1760 <varlistentry id="arenas.hchunk.i.size"> 1761 <term> 1762 <mallctl>arenas.hchunk.<i>.size</mallctl> 1763 (<type>size_t</type>) 1764 <literal>r-</literal> 1765 </term> 1766 <listitem><para>Maximum size supported by this huge size 1767 class.</para></listitem> 1768 </varlistentry> 1769 1770 <varlistentry id="arenas.extend"> 1771 <term> 1772 <mallctl>arenas.extend</mallctl> 1773 (<type>unsigned</type>) 1774 <literal>r-</literal> 1775 </term> 1776 <listitem><para>Extend the array of arenas by appending a new arena, 1777 and returning the new arena index.</para></listitem> 1778 </varlistentry> 1779 1780 <varlistentry id="prof.thread_active_init"> 1781 <term> 1782 <mallctl>prof.thread_active_init</mallctl> 1783 (<type>bool</type>) 1784 <literal>rw</literal> 1785 [<option>--enable-prof</option>] 1786 </term> 1787 <listitem><para>Control the initial setting for <link 1788 linkend="thread.prof.active"><mallctl>thread.prof.active</mallctl></link> 1789 in newly created threads. See the <link 1790 linkend="opt.prof_thread_active_init"><mallctl>opt.prof_thread_active_init</mallctl></link> 1791 option for additional information.</para></listitem> 1792 </varlistentry> 1793 1794 <varlistentry id="prof.active"> 1795 <term> 1796 <mallctl>prof.active</mallctl> 1797 (<type>bool</type>) 1798 <literal>rw</literal> 1799 [<option>--enable-prof</option>] 1800 </term> 1801 <listitem><para>Control whether sampling is currently active. See the 1802 <link 1803 linkend="opt.prof_active"><mallctl>opt.prof_active</mallctl></link> 1804 option for additional information, as well as the interrelated <link 1805 linkend="thread.prof.active"><mallctl>thread.prof.active</mallctl></link> 1806 mallctl.</para></listitem> 1807 </varlistentry> 1808 1809 <varlistentry id="prof.dump"> 1810 <term> 1811 <mallctl>prof.dump</mallctl> 1812 (<type>const char *</type>) 1813 <literal>-w</literal> 1814 [<option>--enable-prof</option>] 1815 </term> 1816 <listitem><para>Dump a memory profile to the specified file, or if NULL 1817 is specified, to a file according to the pattern 1818 <filename><prefix>.<pid>.<seq>.m<mseq>.heap</filename>, 1819 where <literal><prefix></literal> is controlled by the 1820 <link 1821 linkend="opt.prof_prefix"><mallctl>opt.prof_prefix</mallctl></link> 1822 option.</para></listitem> 1823 </varlistentry> 1824 1825 <varlistentry id="prof.gdump"> 1826 <term> 1827 <mallctl>prof.gdump</mallctl> 1828 (<type>bool</type>) 1829 <literal>rw</literal> 1830 [<option>--enable-prof</option>] 1831 </term> 1832 <listitem><para>When enabled, trigger a memory profile dump every time 1833 the total virtual memory exceeds the previous maximum. Profiles are 1834 dumped to files named according to the pattern 1835 <filename><prefix>.<pid>.<seq>.u<useq>.heap</filename>, 1836 where <literal><prefix></literal> is controlled by the <link 1837 linkend="opt.prof_prefix"><mallctl>opt.prof_prefix</mallctl></link> 1838 option.</para></listitem> 1839 </varlistentry> 1840 1841 <varlistentry id="prof.reset"> 1842 <term> 1843 <mallctl>prof.reset</mallctl> 1844 (<type>size_t</type>) 1845 <literal>-w</literal> 1846 [<option>--enable-prof</option>] 1847 </term> 1848 <listitem><para>Reset all memory profile statistics, and optionally 1849 update the sample rate (see <link 1850 linkend="opt.lg_prof_sample"><mallctl>opt.lg_prof_sample</mallctl></link> 1851 and <link 1852 linkend="prof.lg_sample"><mallctl>prof.lg_sample</mallctl></link>). 1853 </para></listitem> 1854 </varlistentry> 1855 1856 <varlistentry id="prof.lg_sample"> 1857 <term> 1858 <mallctl>prof.lg_sample</mallctl> 1859 (<type>size_t</type>) 1860 <literal>r-</literal> 1861 [<option>--enable-prof</option>] 1862 </term> 1863 <listitem><para>Get the current sample rate (see <link 1864 linkend="opt.lg_prof_sample"><mallctl>opt.lg_prof_sample</mallctl></link>). 1865 </para></listitem> 1866 </varlistentry> 1867 1868 <varlistentry id="prof.interval"> 1869 <term> 1870 <mallctl>prof.interval</mallctl> 1871 (<type>uint64_t</type>) 1872 <literal>r-</literal> 1873 [<option>--enable-prof</option>] 1874 </term> 1875 <listitem><para>Average number of bytes allocated between 1876 inverval-based profile dumps. See the 1877 <link 1878 linkend="opt.lg_prof_interval"><mallctl>opt.lg_prof_interval</mallctl></link> 1879 option for additional information.</para></listitem> 1880 </varlistentry> 1881 1882 <varlistentry id="stats.cactive"> 1883 <term> 1884 <mallctl>stats.cactive</mallctl> 1885 (<type>size_t *</type>) 1886 <literal>r-</literal> 1887 [<option>--enable-stats</option>] 1888 </term> 1889 <listitem><para>Pointer to a counter that contains an approximate count 1890 of the current number of bytes in active pages. The estimate may be 1891 high, but never low, because each arena rounds up when computing its 1892 contribution to the counter. Note that the <link 1893 linkend="epoch"><mallctl>epoch</mallctl></link> mallctl has no bearing 1894 on this counter. Furthermore, counter consistency is maintained via 1895 atomic operations, so it is necessary to use an atomic operation in 1896 order to guarantee a consistent read when dereferencing the pointer. 1897 </para></listitem> 1898 </varlistentry> 1899 1900 <varlistentry id="stats.allocated"> 1901 <term> 1902 <mallctl>stats.allocated</mallctl> 1903 (<type>size_t</type>) 1904 <literal>r-</literal> 1905 [<option>--enable-stats</option>] 1906 </term> 1907 <listitem><para>Total number of bytes allocated by the 1908 application.</para></listitem> 1909 </varlistentry> 1910 1911 <varlistentry id="stats.active"> 1912 <term> 1913 <mallctl>stats.active</mallctl> 1914 (<type>size_t</type>) 1915 <literal>r-</literal> 1916 [<option>--enable-stats</option>] 1917 </term> 1918 <listitem><para>Total number of bytes in active pages allocated by the 1919 application. This is a multiple of the page size, and greater than or 1920 equal to <link 1921 linkend="stats.allocated"><mallctl>stats.allocated</mallctl></link>. 1922 This does not include <link linkend="stats.arenas.i.pdirty"> 1923 <mallctl>stats.arenas.<i>.pdirty</mallctl></link>, nor pages 1924 entirely devoted to allocator metadata.</para></listitem> 1925 </varlistentry> 1926 1927 <varlistentry id="stats.metadata"> 1928 <term> 1929 <mallctl>stats.metadata</mallctl> 1930 (<type>size_t</type>) 1931 <literal>r-</literal> 1932 [<option>--enable-stats</option>] 1933 </term> 1934 <listitem><para>Total number of bytes dedicated to metadata, which 1935 comprise base allocations used for bootstrap-sensitive internal 1936 allocator data structures, arena chunk headers (see <link 1937 linkend="stats.arenas.i.metadata.mapped"><mallctl>stats.arenas.<i>.metadata.mapped</mallctl></link>), 1938 and internal allocations (see <link 1939 linkend="stats.arenas.i.metadata.allocated"><mallctl>stats.arenas.<i>.metadata.allocated</mallctl></link>).</para></listitem> 1940 </varlistentry> 1941 1942 <varlistentry id="stats.resident"> 1943 <term> 1944 <mallctl>stats.resident</mallctl> 1945 (<type>size_t</type>) 1946 <literal>r-</literal> 1947 [<option>--enable-stats</option>] 1948 </term> 1949 <listitem><para>Maximum number of bytes in physically resident data 1950 pages mapped by the allocator, comprising all pages dedicated to 1951 allocator metadata, pages backing active allocations, and unused dirty 1952 pages. This is a maximum rather than precise because pages may not 1953 actually be physically resident if they correspond to demand-zeroed 1954 virtual memory that has not yet been touched. This is a multiple of the 1955 page size, and is larger than <link 1956 linkend="stats.active"><mallctl>stats.active</mallctl></link>.</para></listitem> 1957 </varlistentry> 1958 1959 <varlistentry id="stats.mapped"> 1960 <term> 1961 <mallctl>stats.mapped</mallctl> 1962 (<type>size_t</type>) 1963 <literal>r-</literal> 1964 [<option>--enable-stats</option>] 1965 </term> 1966 <listitem><para>Total number of bytes in active chunks mapped by the 1967 allocator. This is a multiple of the chunk size, and is at least as 1968 large as <link 1969 linkend="stats.resident"><mallctl>stats.resident</mallctl></link>. This 1970 does not include inactive chunks.</para></listitem> 1971 </varlistentry> 1972 1973 <varlistentry id="stats.arenas.i.dss"> 1974 <term> 1975 <mallctl>stats.arenas.<i>.dss</mallctl> 1976 (<type>const char *</type>) 1977 <literal>r-</literal> 1978 </term> 1979 <listitem><para>dss (<citerefentry><refentrytitle>sbrk</refentrytitle> 1980 <manvolnum>2</manvolnum></citerefentry>) allocation precedence as 1981 related to <citerefentry><refentrytitle>mmap</refentrytitle> 1982 <manvolnum>2</manvolnum></citerefentry> allocation. See <link 1983 linkend="opt.dss"><mallctl>opt.dss</mallctl></link> for details. 1984 </para></listitem> 1985 </varlistentry> 1986 1987 <varlistentry id="stats.arenas.i.lg_dirty_mult"> 1988 <term> 1989 <mallctl>stats.arenas.<i>.lg_dirty_mult</mallctl> 1990 (<type>ssize_t</type>) 1991 <literal>r-</literal> 1992 </term> 1993 <listitem><para>Minimum ratio (log base 2) of active to dirty pages. 1994 See <link 1995 linkend="opt.lg_dirty_mult"><mallctl>opt.lg_dirty_mult</mallctl></link> 1996 for details.</para></listitem> 1997 </varlistentry> 1998 1999 <varlistentry id="stats.arenas.i.nthreads"> 2000 <term> 2001 <mallctl>stats.arenas.<i>.nthreads</mallctl> 2002 (<type>unsigned</type>) 2003 <literal>r-</literal> 2004 </term> 2005 <listitem><para>Number of threads currently assigned to 2006 arena.</para></listitem> 2007 </varlistentry> 2008 2009 <varlistentry id="stats.arenas.i.pactive"> 2010 <term> 2011 <mallctl>stats.arenas.<i>.pactive</mallctl> 2012 (<type>size_t</type>) 2013 <literal>r-</literal> 2014 </term> 2015 <listitem><para>Number of pages in active runs.</para></listitem> 2016 </varlistentry> 2017 2018 <varlistentry id="stats.arenas.i.pdirty"> 2019 <term> 2020 <mallctl>stats.arenas.<i>.pdirty</mallctl> 2021 (<type>size_t</type>) 2022 <literal>r-</literal> 2023 </term> 2024 <listitem><para>Number of pages within unused runs that are potentially 2025 dirty, and for which <function>madvise<parameter>...</parameter> 2026 <parameter><constant>MADV_DONTNEED</constant></parameter></function> or 2027 similar has not been called.</para></listitem> 2028 </varlistentry> 2029 2030 <varlistentry id="stats.arenas.i.mapped"> 2031 <term> 2032 <mallctl>stats.arenas.<i>.mapped</mallctl> 2033 (<type>size_t</type>) 2034 <literal>r-</literal> 2035 [<option>--enable-stats</option>] 2036 </term> 2037 <listitem><para>Number of mapped bytes.</para></listitem> 2038 </varlistentry> 2039 2040 <varlistentry id="stats.arenas.i.metadata.mapped"> 2041 <term> 2042 <mallctl>stats.arenas.<i>.metadata.mapped</mallctl> 2043 (<type>size_t</type>) 2044 <literal>r-</literal> 2045 [<option>--enable-stats</option>] 2046 </term> 2047 <listitem><para>Number of mapped bytes in arena chunk headers, which 2048 track the states of the non-metadata pages.</para></listitem> 2049 </varlistentry> 2050 2051 <varlistentry id="stats.arenas.i.metadata.allocated"> 2052 <term> 2053 <mallctl>stats.arenas.<i>.metadata.allocated</mallctl> 2054 (<type>size_t</type>) 2055 <literal>r-</literal> 2056 [<option>--enable-stats</option>] 2057 </term> 2058 <listitem><para>Number of bytes dedicated to internal allocations. 2059 Internal allocations differ from application-originated allocations in 2060 that they are for internal use, and that they are omitted from heap 2061 profiles. This statistic is reported separately from <link 2062 linkend="stats.metadata"><mallctl>stats.metadata</mallctl></link> and 2063 <link 2064 linkend="stats.arenas.i.metadata.mapped"><mallctl>stats.arenas.<i>.metadata.mapped</mallctl></link> 2065 because it overlaps with e.g. the <link 2066 linkend="stats.allocated"><mallctl>stats.allocated</mallctl></link> and 2067 <link linkend="stats.active"><mallctl>stats.active</mallctl></link> 2068 statistics, whereas the other metadata statistics do 2069 not.</para></listitem> 2070 </varlistentry> 2071 2072 <varlistentry id="stats.arenas.i.npurge"> 2073 <term> 2074 <mallctl>stats.arenas.<i>.npurge</mallctl> 2075 (<type>uint64_t</type>) 2076 <literal>r-</literal> 2077 [<option>--enable-stats</option>] 2078 </term> 2079 <listitem><para>Number of dirty page purge sweeps performed. 2080 </para></listitem> 2081 </varlistentry> 2082 2083 <varlistentry id="stats.arenas.i.nmadvise"> 2084 <term> 2085 <mallctl>stats.arenas.<i>.nmadvise</mallctl> 2086 (<type>uint64_t</type>) 2087 <literal>r-</literal> 2088 [<option>--enable-stats</option>] 2089 </term> 2090 <listitem><para>Number of <function>madvise<parameter>...</parameter> 2091 <parameter><constant>MADV_DONTNEED</constant></parameter></function> or 2092 similar calls made to purge dirty pages.</para></listitem> 2093 </varlistentry> 2094 2095 <varlistentry id="stats.arenas.i.purged"> 2096 <term> 2097 <mallctl>stats.arenas.<i>.purged</mallctl> 2098 (<type>uint64_t</type>) 2099 <literal>r-</literal> 2100 [<option>--enable-stats</option>] 2101 </term> 2102 <listitem><para>Number of pages purged.</para></listitem> 2103 </varlistentry> 2104 2105 <varlistentry id="stats.arenas.i.small.allocated"> 2106 <term> 2107 <mallctl>stats.arenas.<i>.small.allocated</mallctl> 2108 (<type>size_t</type>) 2109 <literal>r-</literal> 2110 [<option>--enable-stats</option>] 2111 </term> 2112 <listitem><para>Number of bytes currently allocated by small objects. 2113 </para></listitem> 2114 </varlistentry> 2115 2116 <varlistentry id="stats.arenas.i.small.nmalloc"> 2117 <term> 2118 <mallctl>stats.arenas.<i>.small.nmalloc</mallctl> 2119 (<type>uint64_t</type>) 2120 <literal>r-</literal> 2121 [<option>--enable-stats</option>] 2122 </term> 2123 <listitem><para>Cumulative number of allocation requests served by 2124 small bins.</para></listitem> 2125 </varlistentry> 2126 2127 <varlistentry id="stats.arenas.i.small.ndalloc"> 2128 <term> 2129 <mallctl>stats.arenas.<i>.small.ndalloc</mallctl> 2130 (<type>uint64_t</type>) 2131 <literal>r-</literal> 2132 [<option>--enable-stats</option>] 2133 </term> 2134 <listitem><para>Cumulative number of small objects returned to bins. 2135 </para></listitem> 2136 </varlistentry> 2137 2138 <varlistentry id="stats.arenas.i.small.nrequests"> 2139 <term> 2140 <mallctl>stats.arenas.<i>.small.nrequests</mallctl> 2141 (<type>uint64_t</type>) 2142 <literal>r-</literal> 2143 [<option>--enable-stats</option>] 2144 </term> 2145 <listitem><para>Cumulative number of small allocation requests. 2146 </para></listitem> 2147 </varlistentry> 2148 2149 <varlistentry id="stats.arenas.i.large.allocated"> 2150 <term> 2151 <mallctl>stats.arenas.<i>.large.allocated</mallctl> 2152 (<type>size_t</type>) 2153 <literal>r-</literal> 2154 [<option>--enable-stats</option>] 2155 </term> 2156 <listitem><para>Number of bytes currently allocated by large objects. 2157 </para></listitem> 2158 </varlistentry> 2159 2160 <varlistentry id="stats.arenas.i.large.nmalloc"> 2161 <term> 2162 <mallctl>stats.arenas.<i>.large.nmalloc</mallctl> 2163 (<type>uint64_t</type>) 2164 <literal>r-</literal> 2165 [<option>--enable-stats</option>] 2166 </term> 2167 <listitem><para>Cumulative number of large allocation requests served 2168 directly by the arena.</para></listitem> 2169 </varlistentry> 2170 2171 <varlistentry id="stats.arenas.i.large.ndalloc"> 2172 <term> 2173 <mallctl>stats.arenas.<i>.large.ndalloc</mallctl> 2174 (<type>uint64_t</type>) 2175 <literal>r-</literal> 2176 [<option>--enable-stats</option>] 2177 </term> 2178 <listitem><para>Cumulative number of large deallocation requests served 2179 directly by the arena.</para></listitem> 2180 </varlistentry> 2181 2182 <varlistentry id="stats.arenas.i.large.nrequests"> 2183 <term> 2184 <mallctl>stats.arenas.<i>.large.nrequests</mallctl> 2185 (<type>uint64_t</type>) 2186 <literal>r-</literal> 2187 [<option>--enable-stats</option>] 2188 </term> 2189 <listitem><para>Cumulative number of large allocation requests. 2190 </para></listitem> 2191 </varlistentry> 2192 2193 <varlistentry id="stats.arenas.i.huge.allocated"> 2194 <term> 2195 <mallctl>stats.arenas.<i>.huge.allocated</mallctl> 2196 (<type>size_t</type>) 2197 <literal>r-</literal> 2198 [<option>--enable-stats</option>] 2199 </term> 2200 <listitem><para>Number of bytes currently allocated by huge objects. 2201 </para></listitem> 2202 </varlistentry> 2203 2204 <varlistentry id="stats.arenas.i.huge.nmalloc"> 2205 <term> 2206 <mallctl>stats.arenas.<i>.huge.nmalloc</mallctl> 2207 (<type>uint64_t</type>) 2208 <literal>r-</literal> 2209 [<option>--enable-stats</option>] 2210 </term> 2211 <listitem><para>Cumulative number of huge allocation requests served 2212 directly by the arena.</para></listitem> 2213 </varlistentry> 2214 2215 <varlistentry id="stats.arenas.i.huge.ndalloc"> 2216 <term> 2217 <mallctl>stats.arenas.<i>.huge.ndalloc</mallctl> 2218 (<type>uint64_t</type>) 2219 <literal>r-</literal> 2220 [<option>--enable-stats</option>] 2221 </term> 2222 <listitem><para>Cumulative number of huge deallocation requests served 2223 directly by the arena.</para></listitem> 2224 </varlistentry> 2225 2226 <varlistentry id="stats.arenas.i.huge.nrequests"> 2227 <term> 2228 <mallctl>stats.arenas.<i>.huge.nrequests</mallctl> 2229 (<type>uint64_t</type>) 2230 <literal>r-</literal> 2231 [<option>--enable-stats</option>] 2232 </term> 2233 <listitem><para>Cumulative number of huge allocation requests. 2234 </para></listitem> 2235 </varlistentry> 2236 2237 <varlistentry id="stats.arenas.i.bins.j.nmalloc"> 2238 <term> 2239 <mallctl>stats.arenas.<i>.bins.<j>.nmalloc</mallctl> 2240 (<type>uint64_t</type>) 2241 <literal>r-</literal> 2242 [<option>--enable-stats</option>] 2243 </term> 2244 <listitem><para>Cumulative number of allocations served by bin. 2245 </para></listitem> 2246 </varlistentry> 2247 2248 <varlistentry id="stats.arenas.i.bins.j.ndalloc"> 2249 <term> 2250 <mallctl>stats.arenas.<i>.bins.<j>.ndalloc</mallctl> 2251 (<type>uint64_t</type>) 2252 <literal>r-</literal> 2253 [<option>--enable-stats</option>] 2254 </term> 2255 <listitem><para>Cumulative number of allocations returned to bin. 2256 </para></listitem> 2257 </varlistentry> 2258 2259 <varlistentry id="stats.arenas.i.bins.j.nrequests"> 2260 <term> 2261 <mallctl>stats.arenas.<i>.bins.<j>.nrequests</mallctl> 2262 (<type>uint64_t</type>) 2263 <literal>r-</literal> 2264 [<option>--enable-stats</option>] 2265 </term> 2266 <listitem><para>Cumulative number of allocation 2267 requests.</para></listitem> 2268 </varlistentry> 2269 2270 <varlistentry id="stats.arenas.i.bins.j.curregs"> 2271 <term> 2272 <mallctl>stats.arenas.<i>.bins.<j>.curregs</mallctl> 2273 (<type>size_t</type>) 2274 <literal>r-</literal> 2275 [<option>--enable-stats</option>] 2276 </term> 2277 <listitem><para>Current number of regions for this size 2278 class.</para></listitem> 2279 </varlistentry> 2280 2281 <varlistentry id="stats.arenas.i.bins.j.nfills"> 2282 <term> 2283 <mallctl>stats.arenas.<i>.bins.<j>.nfills</mallctl> 2284 (<type>uint64_t</type>) 2285 <literal>r-</literal> 2286 [<option>--enable-stats</option> <option>--enable-tcache</option>] 2287 </term> 2288 <listitem><para>Cumulative number of tcache fills.</para></listitem> 2289 </varlistentry> 2290 2291 <varlistentry id="stats.arenas.i.bins.j.nflushes"> 2292 <term> 2293 <mallctl>stats.arenas.<i>.bins.<j>.nflushes</mallctl> 2294 (<type>uint64_t</type>) 2295 <literal>r-</literal> 2296 [<option>--enable-stats</option> <option>--enable-tcache</option>] 2297 </term> 2298 <listitem><para>Cumulative number of tcache flushes.</para></listitem> 2299 </varlistentry> 2300 2301 <varlistentry id="stats.arenas.i.bins.j.nruns"> 2302 <term> 2303 <mallctl>stats.arenas.<i>.bins.<j>.nruns</mallctl> 2304 (<type>uint64_t</type>) 2305 <literal>r-</literal> 2306 [<option>--enable-stats</option>] 2307 </term> 2308 <listitem><para>Cumulative number of runs created.</para></listitem> 2309 </varlistentry> 2310 2311 <varlistentry id="stats.arenas.i.bins.j.nreruns"> 2312 <term> 2313 <mallctl>stats.arenas.<i>.bins.<j>.nreruns</mallctl> 2314 (<type>uint64_t</type>) 2315 <literal>r-</literal> 2316 [<option>--enable-stats</option>] 2317 </term> 2318 <listitem><para>Cumulative number of times the current run from which 2319 to allocate changed.</para></listitem> 2320 </varlistentry> 2321 2322 <varlistentry id="stats.arenas.i.bins.j.curruns"> 2323 <term> 2324 <mallctl>stats.arenas.<i>.bins.<j>.curruns</mallctl> 2325 (<type>size_t</type>) 2326 <literal>r-</literal> 2327 [<option>--enable-stats</option>] 2328 </term> 2329 <listitem><para>Current number of runs.</para></listitem> 2330 </varlistentry> 2331 2332 <varlistentry id="stats.arenas.i.lruns.j.nmalloc"> 2333 <term> 2334 <mallctl>stats.arenas.<i>.lruns.<j>.nmalloc</mallctl> 2335 (<type>uint64_t</type>) 2336 <literal>r-</literal> 2337 [<option>--enable-stats</option>] 2338 </term> 2339 <listitem><para>Cumulative number of allocation requests for this size 2340 class served directly by the arena.</para></listitem> 2341 </varlistentry> 2342 2343 <varlistentry id="stats.arenas.i.lruns.j.ndalloc"> 2344 <term> 2345 <mallctl>stats.arenas.<i>.lruns.<j>.ndalloc</mallctl> 2346 (<type>uint64_t</type>) 2347 <literal>r-</literal> 2348 [<option>--enable-stats</option>] 2349 </term> 2350 <listitem><para>Cumulative number of deallocation requests for this 2351 size class served directly by the arena.</para></listitem> 2352 </varlistentry> 2353 2354 <varlistentry id="stats.arenas.i.lruns.j.nrequests"> 2355 <term> 2356 <mallctl>stats.arenas.<i>.lruns.<j>.nrequests</mallctl> 2357 (<type>uint64_t</type>) 2358 <literal>r-</literal> 2359 [<option>--enable-stats</option>] 2360 </term> 2361 <listitem><para>Cumulative number of allocation requests for this size 2362 class.</para></listitem> 2363 </varlistentry> 2364 2365 <varlistentry id="stats.arenas.i.lruns.j.curruns"> 2366 <term> 2367 <mallctl>stats.arenas.<i>.lruns.<j>.curruns</mallctl> 2368 (<type>size_t</type>) 2369 <literal>r-</literal> 2370 [<option>--enable-stats</option>] 2371 </term> 2372 <listitem><para>Current number of runs for this size class. 2373 </para></listitem> 2374 </varlistentry> 2375 2376 <varlistentry id="stats.arenas.i.hchunks.j.nmalloc"> 2377 <term> 2378 <mallctl>stats.arenas.<i>.hchunks.<j>.nmalloc</mallctl> 2379 (<type>uint64_t</type>) 2380 <literal>r-</literal> 2381 [<option>--enable-stats</option>] 2382 </term> 2383 <listitem><para>Cumulative number of allocation requests for this size 2384 class served directly by the arena.</para></listitem> 2385 </varlistentry> 2386 2387 <varlistentry id="stats.arenas.i.hchunks.j.ndalloc"> 2388 <term> 2389 <mallctl>stats.arenas.<i>.hchunks.<j>.ndalloc</mallctl> 2390 (<type>uint64_t</type>) 2391 <literal>r-</literal> 2392 [<option>--enable-stats</option>] 2393 </term> 2394 <listitem><para>Cumulative number of deallocation requests for this 2395 size class served directly by the arena.</para></listitem> 2396 </varlistentry> 2397 2398 <varlistentry id="stats.arenas.i.hchunks.j.nrequests"> 2399 <term> 2400 <mallctl>stats.arenas.<i>.hchunks.<j>.nrequests</mallctl> 2401 (<type>uint64_t</type>) 2402 <literal>r-</literal> 2403 [<option>--enable-stats</option>] 2404 </term> 2405 <listitem><para>Cumulative number of allocation requests for this size 2406 class.</para></listitem> 2407 </varlistentry> 2408 2409 <varlistentry id="stats.arenas.i.hchunks.j.curhchunks"> 2410 <term> 2411 <mallctl>stats.arenas.<i>.hchunks.<j>.curhchunks</mallctl> 2412 (<type>size_t</type>) 2413 <literal>r-</literal> 2414 [<option>--enable-stats</option>] 2415 </term> 2416 <listitem><para>Current number of huge allocations for this size class. 2417 </para></listitem> 2418 </varlistentry> 2419 </variablelist> 2420 </refsect1> 2421 <refsect1 id="debugging_malloc_problems"> 2422 <title>DEBUGGING MALLOC PROBLEMS</title> 2423 <para>When debugging, it is a good idea to configure/build jemalloc with 2424 the <option>--enable-debug</option> and <option>--enable-fill</option> 2425 options, and recompile the program with suitable options and symbols for 2426 debugger support. When so configured, jemalloc incorporates a wide variety 2427 of run-time assertions that catch application errors such as double-free, 2428 write-after-free, etc.</para> 2429 2430 <para>Programs often accidentally depend on “uninitialized” 2431 memory actually being filled with zero bytes. Junk filling 2432 (see the <link linkend="opt.junk"><mallctl>opt.junk</mallctl></link> 2433 option) tends to expose such bugs in the form of obviously incorrect 2434 results and/or coredumps. Conversely, zero 2435 filling (see the <link 2436 linkend="opt.zero"><mallctl>opt.zero</mallctl></link> option) eliminates 2437 the symptoms of such bugs. Between these two options, it is usually 2438 possible to quickly detect, diagnose, and eliminate such bugs.</para> 2439 2440 <para>This implementation does not provide much detail about the problems 2441 it detects, because the performance impact for storing such information 2442 would be prohibitive. However, jemalloc does integrate with the most 2443 excellent <ulink url="http://valgrind.org/">Valgrind</ulink> tool if the 2444 <option>--enable-valgrind</option> configuration option is enabled.</para> 2445 </refsect1> 2446 <refsect1 id="diagnostic_messages"> 2447 <title>DIAGNOSTIC MESSAGES</title> 2448 <para>If any of the memory allocation/deallocation functions detect an 2449 error or warning condition, a message will be printed to file descriptor 2450 <constant>STDERR_FILENO</constant>. Errors will result in the process 2451 dumping core. If the <link 2452 linkend="opt.abort"><mallctl>opt.abort</mallctl></link> option is set, most 2453 warnings are treated as errors.</para> 2454 2455 <para>The <varname>malloc_message</varname> variable allows the programmer 2456 to override the function which emits the text strings forming the errors 2457 and warnings if for some reason the <constant>STDERR_FILENO</constant> file 2458 descriptor is not suitable for this. 2459 <function>malloc_message<parameter/></function> takes the 2460 <parameter>cbopaque</parameter> pointer argument that is 2461 <constant>NULL</constant> unless overridden by the arguments in a call to 2462 <function>malloc_stats_print<parameter/></function>, followed by a string 2463 pointer. Please note that doing anything which tries to allocate memory in 2464 this function is likely to result in a crash or deadlock.</para> 2465 2466 <para>All messages are prefixed by 2467 “<computeroutput><jemalloc>: </computeroutput>”.</para> 2468 </refsect1> 2469 <refsect1 id="return_values"> 2470 <title>RETURN VALUES</title> 2471 <refsect2> 2472 <title>Standard API</title> 2473 <para>The <function>malloc<parameter/></function> and 2474 <function>calloc<parameter/></function> functions return a pointer to the 2475 allocated memory if successful; otherwise a <constant>NULL</constant> 2476 pointer is returned and <varname>errno</varname> is set to 2477 <errorname>ENOMEM</errorname>.</para> 2478 2479 <para>The <function>posix_memalign<parameter/></function> function 2480 returns the value 0 if successful; otherwise it returns an error value. 2481 The <function>posix_memalign<parameter/></function> function will fail 2482 if: 2483 <variablelist> 2484 <varlistentry> 2485 <term><errorname>EINVAL</errorname></term> 2486 2487 <listitem><para>The <parameter>alignment</parameter> parameter is 2488 not a power of 2 at least as large as 2489 <code language="C">sizeof(<type>void *</type>)</code>. 2490 </para></listitem> 2491 </varlistentry> 2492 <varlistentry> 2493 <term><errorname>ENOMEM</errorname></term> 2494 2495 <listitem><para>Memory allocation error.</para></listitem> 2496 </varlistentry> 2497 </variablelist> 2498 </para> 2499 2500 <para>The <function>aligned_alloc<parameter/></function> function returns 2501 a pointer to the allocated memory if successful; otherwise a 2502 <constant>NULL</constant> pointer is returned and 2503 <varname>errno</varname> is set. The 2504 <function>aligned_alloc<parameter/></function> function will fail if: 2505 <variablelist> 2506 <varlistentry> 2507 <term><errorname>EINVAL</errorname></term> 2508 2509 <listitem><para>The <parameter>alignment</parameter> parameter is 2510 not a power of 2. 2511 </para></listitem> 2512 </varlistentry> 2513 <varlistentry> 2514 <term><errorname>ENOMEM</errorname></term> 2515 2516 <listitem><para>Memory allocation error.</para></listitem> 2517 </varlistentry> 2518 </variablelist> 2519 </para> 2520 2521 <para>The <function>realloc<parameter/></function> function returns a 2522 pointer, possibly identical to <parameter>ptr</parameter>, to the 2523 allocated memory if successful; otherwise a <constant>NULL</constant> 2524 pointer is returned, and <varname>errno</varname> is set to 2525 <errorname>ENOMEM</errorname> if the error was the result of an 2526 allocation failure. The <function>realloc<parameter/></function> 2527 function always leaves the original buffer intact when an error occurs. 2528 </para> 2529 2530 <para>The <function>free<parameter/></function> function returns no 2531 value.</para> 2532 </refsect2> 2533 <refsect2> 2534 <title>Non-standard API</title> 2535 <para>The <function>mallocx<parameter/></function> and 2536 <function>rallocx<parameter/></function> functions return a pointer to 2537 the allocated memory if successful; otherwise a <constant>NULL</constant> 2538 pointer is returned to indicate insufficient contiguous memory was 2539 available to service the allocation request. </para> 2540 2541 <para>The <function>xallocx<parameter/></function> function returns the 2542 real size of the resulting resized allocation pointed to by 2543 <parameter>ptr</parameter>, which is a value less than 2544 <parameter>size</parameter> if the allocation could not be adequately 2545 grown in place. </para> 2546 2547 <para>The <function>sallocx<parameter/></function> function returns the 2548 real size of the allocation pointed to by <parameter>ptr</parameter>. 2549 </para> 2550 2551 <para>The <function>nallocx<parameter/></function> returns the real size 2552 that would result from a successful equivalent 2553 <function>mallocx<parameter/></function> function call, or zero if 2554 insufficient memory is available to perform the size computation. </para> 2555 2556 <para>The <function>mallctl<parameter/></function>, 2557 <function>mallctlnametomib<parameter/></function>, and 2558 <function>mallctlbymib<parameter/></function> functions return 0 on 2559 success; otherwise they return an error value. The functions will fail 2560 if: 2561 <variablelist> 2562 <varlistentry> 2563 <term><errorname>EINVAL</errorname></term> 2564 2565 <listitem><para><parameter>newp</parameter> is not 2566 <constant>NULL</constant>, and <parameter>newlen</parameter> is too 2567 large or too small. Alternatively, <parameter>*oldlenp</parameter> 2568 is too large or too small; in this case as much data as possible 2569 are read despite the error.</para></listitem> 2570 </varlistentry> 2571 <varlistentry> 2572 <term><errorname>ENOENT</errorname></term> 2573 2574 <listitem><para><parameter>name</parameter> or 2575 <parameter>mib</parameter> specifies an unknown/invalid 2576 value.</para></listitem> 2577 </varlistentry> 2578 <varlistentry> 2579 <term><errorname>EPERM</errorname></term> 2580 2581 <listitem><para>Attempt to read or write void value, or attempt to 2582 write read-only value.</para></listitem> 2583 </varlistentry> 2584 <varlistentry> 2585 <term><errorname>EAGAIN</errorname></term> 2586 2587 <listitem><para>A memory allocation failure 2588 occurred.</para></listitem> 2589 </varlistentry> 2590 <varlistentry> 2591 <term><errorname>EFAULT</errorname></term> 2592 2593 <listitem><para>An interface with side effects failed in some way 2594 not directly related to <function>mallctl*<parameter/></function> 2595 read/write processing.</para></listitem> 2596 </varlistentry> 2597 </variablelist> 2598 </para> 2599 2600 <para>The <function>malloc_usable_size<parameter/></function> function 2601 returns the usable size of the allocation pointed to by 2602 <parameter>ptr</parameter>. </para> 2603 </refsect2> 2604 </refsect1> 2605 <refsect1 id="environment"> 2606 <title>ENVIRONMENT</title> 2607 <para>The following environment variable affects the execution of the 2608 allocation functions: 2609 <variablelist> 2610 <varlistentry> 2611 <term><envar>MALLOC_CONF</envar></term> 2612 2613 <listitem><para>If the environment variable 2614 <envar>MALLOC_CONF</envar> is set, the characters it contains 2615 will be interpreted as options.</para></listitem> 2616 </varlistentry> 2617 </variablelist> 2618 </para> 2619 </refsect1> 2620 <refsect1 id="examples"> 2621 <title>EXAMPLES</title> 2622 <para>To dump core whenever a problem occurs: 2623 <screen>ln -s 'abort:true' /etc/malloc.conf</screen> 2624 </para> 2625 <para>To specify in the source a chunk size that is 16 MiB: 2626 <programlisting language="C"><![CDATA[ 2627malloc_conf = "lg_chunk:24";]]></programlisting></para> 2628 </refsect1> 2629 <refsect1 id="see_also"> 2630 <title>SEE ALSO</title> 2631 <para><citerefentry><refentrytitle>madvise</refentrytitle> 2632 <manvolnum>2</manvolnum></citerefentry>, 2633 <citerefentry><refentrytitle>mmap</refentrytitle> 2634 <manvolnum>2</manvolnum></citerefentry>, 2635 <citerefentry><refentrytitle>sbrk</refentrytitle> 2636 <manvolnum>2</manvolnum></citerefentry>, 2637 <citerefentry><refentrytitle>utrace</refentrytitle> 2638 <manvolnum>2</manvolnum></citerefentry>, 2639 <citerefentry><refentrytitle>alloca</refentrytitle> 2640 <manvolnum>3</manvolnum></citerefentry>, 2641 <citerefentry><refentrytitle>atexit</refentrytitle> 2642 <manvolnum>3</manvolnum></citerefentry>, 2643 <citerefentry><refentrytitle>getpagesize</refentrytitle> 2644 <manvolnum>3</manvolnum></citerefentry></para> 2645 </refsect1> 2646 <refsect1 id="standards"> 2647 <title>STANDARDS</title> 2648 <para>The <function>malloc<parameter/></function>, 2649 <function>calloc<parameter/></function>, 2650 <function>realloc<parameter/></function>, and 2651 <function>free<parameter/></function> functions conform to ISO/IEC 2652 9899:1990 (“ISO C90”).</para> 2653 2654 <para>The <function>posix_memalign<parameter/></function> function conforms 2655 to IEEE Std 1003.1-2001 (“POSIX.1”).</para> 2656 </refsect1> 2657</refentry> 2658