3 .\" Author: Jason Evans
4 .\" Generator: DocBook XSL Stylesheets v1.76.1 <http://docbook.sf.net/>
6 .\" Manual: User Manual
7 .\" Source: jemalloc 4.0.4-0-g91010a9e2ebfc84b1ac1ed7fdde3bfed4f65f180
10 .TH "JEMALLOC" "3" "10/24/2015" "jemalloc 4.0.4-0-g91010a9e2ebf" "User Manual"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 jemalloc \- general purpose memory allocation functions
34 This manual describes jemalloc 4\&.0\&.4\-0\-g91010a9e2ebfc84b1ac1ed7fdde3bfed4f65f180\&. More information can be found at the
35 \m[blue]\fBjemalloc website\fR\m[]\&\s-2\u[1]\d\s+2\&.
37 The following configuration options are enabled in libc\*(Aqs built\-in jemalloc:
38 \fB\-\-enable\-fill\fR,
39 \fB\-\-enable\-lazy\-lock\fR,
40 \fB\-\-enable\-munmap\fR,
41 \fB\-\-enable\-stats\fR,
42 \fB\-\-enable\-tcache\fR,
43 \fB\-\-enable\-tls\fR,
44 \fB\-\-enable\-utrace\fR, and
45 \fB\-\-enable\-xmalloc\fR\&. Additionally,
46 \fB\-\-enable\-debug\fR
47 is enabled in development versions of FreeBSD (controlled by the
48 \fBMALLOC_PRODUCTION\fR
55 #include <malloc_np\&.h>
59 .HP \w'void\ *malloc('u
60 .BI "void *malloc(size_t\ " "size" ");"
61 .HP \w'void\ *calloc('u
62 .BI "void *calloc(size_t\ " "number" ", size_t\ " "size" ");"
63 .HP \w'int\ posix_memalign('u
64 .BI "int posix_memalign(void\ **" "ptr" ", size_t\ " "alignment" ", size_t\ " "size" ");"
65 .HP \w'void\ *aligned_alloc('u
66 .BI "void *aligned_alloc(size_t\ " "alignment" ", size_t\ " "size" ");"
67 .HP \w'void\ *realloc('u
68 .BI "void *realloc(void\ *" "ptr" ", size_t\ " "size" ");"
70 .BI "void free(void\ *" "ptr" ");"
71 .SS "Non\-standard API"
72 .HP \w'void\ *mallocx('u
73 .BI "void *mallocx(size_t\ " "size" ", int\ " "flags" ");"
74 .HP \w'void\ *rallocx('u
75 .BI "void *rallocx(void\ *" "ptr" ", size_t\ " "size" ", int\ " "flags" ");"
76 .HP \w'size_t\ xallocx('u
77 .BI "size_t xallocx(void\ *" "ptr" ", size_t\ " "size" ", size_t\ " "extra" ", int\ " "flags" ");"
78 .HP \w'size_t\ sallocx('u
79 .BI "size_t sallocx(void\ *" "ptr" ", int\ " "flags" ");"
80 .HP \w'void\ dallocx('u
81 .BI "void dallocx(void\ *" "ptr" ", int\ " "flags" ");"
82 .HP \w'void\ sdallocx('u
83 .BI "void sdallocx(void\ *" "ptr" ", size_t\ " "size" ", int\ " "flags" ");"
84 .HP \w'size_t\ nallocx('u
85 .BI "size_t nallocx(size_t\ " "size" ", int\ " "flags" ");"
86 .HP \w'int\ mallctl('u
87 .BI "int mallctl(const\ char\ *" "name" ", void\ *" "oldp" ", size_t\ *" "oldlenp" ", void\ *" "newp" ", size_t\ " "newlen" ");"
88 .HP \w'int\ mallctlnametomib('u
89 .BI "int mallctlnametomib(const\ char\ *" "name" ", size_t\ *" "mibp" ", size_t\ *" "miblenp" ");"
90 .HP \w'int\ mallctlbymib('u
91 .BI "int mallctlbymib(const\ size_t\ *" "mib" ", size_t\ " "miblen" ", void\ *" "oldp" ", size_t\ *" "oldlenp" ", void\ *" "newp" ", size_t\ " "newlen" ");"
92 .HP \w'void\ malloc_stats_print('u
93 .BI "void malloc_stats_print(void\ " "(*write_cb)" "\ (void\ *,\ const\ char\ *), void\ *" "cbopaque" ", const\ char\ *" "opts" ");"
94 .HP \w'size_t\ malloc_usable_size('u
95 .BI "size_t malloc_usable_size(const\ void\ *" "ptr" ");"
96 .HP \w'void\ (*malloc_message)('u
97 .BI "void (*malloc_message)(void\ *" "cbopaque" ", const\ char\ *" "s" ");"
99 const char *\fImalloc_conf\fR;
107 bytes of uninitialized memory\&. The allocated space is suitably aligned (after possible pointer coercion) for storage of any type of object\&.
111 function allocates space for
115 bytes in length\&. The result is identical to calling
120 \fIsize\fR, with the exception that the allocated memory is explicitly initialized to zero bytes\&.
123 \fBposix_memalign\fR\fB\fR
126 bytes of memory such that the allocation\*(Aqs base address is a multiple of
127 \fIalignment\fR, and returns the allocation in the value pointed to by
128 \fIptr\fR\&. The requested
130 must be a power of 2 at least as large as
131 sizeof(\fBvoid *\fR)\&.
134 \fBaligned_alloc\fR\fB\fR
137 bytes of memory such that the allocation\*(Aqs base address is a multiple of
138 \fIalignment\fR\&. The requested
140 must be a power of 2\&. Behavior is undefined if
142 is not an integral multiple of
147 function changes the size of the previously allocated memory referenced by
151 bytes\&. The contents of the memory are unchanged up to the lesser of the new and old sizes\&. If the new size is larger, the contents of the newly allocated portion of the memory are undefined\&. Upon success, the memory referenced by
153 is freed and a pointer to the newly allocated memory is returned\&. Note that
155 may move the memory allocation, resulting in a different return value than
161 function behaves identically to
163 for the specified size\&.
167 function causes the allocated memory referenced by
169 to be made available for future allocations\&. If
172 \fBNULL\fR, no action occurs\&.
173 .SS "Non\-standard API"
181 \fBsdallocx\fR\fB\fR, and
185 argument that can be used to specify options\&. The functions only check the options that are contextually relevant\&. Use bitwise or (|) operations to specify one or more of the following:
187 \fBMALLOCX_LG_ALIGN(\fR\fB\fIla\fR\fR\fB) \fR
189 Align the memory allocation to start at an address that is a multiple of
190 (1 << \fIla\fR)\&. This macro does not validate that
192 is within the valid range\&.
195 \fBMALLOCX_ALIGN(\fR\fB\fIa\fR\fR\fB) \fR
197 Align the memory allocation to start at an address that is a multiple of
200 is a power of two\&. This macro does not validate that
207 Initialize newly allocated memory to contain zero bytes\&. In the growing reallocation case, the real size prior to reallocation defines the boundary between untouched bytes and those that are initialized to contain zero bytes\&. If this macro is absent, newly allocated memory is uninitialized\&.
210 \fBMALLOCX_TCACHE(\fR\fB\fItc\fR\fR\fB) \fR
212 Use the thread\-specific cache (tcache) specified by the identifier
213 \fItc\fR, which must have been acquired via the
215 mallctl\&. This macro does not validate that
217 specifies a valid identifier\&.
220 \fBMALLOCX_TCACHE_NONE\fR
222 Do not use a thread\-specific cache (tcache)\&. Unless
223 \fBMALLOCX_TCACHE(\fR\fB\fItc\fR\fR\fB)\fR
225 \fBMALLOCX_TCACHE_NONE\fR
226 is specified, an automatically managed tcache will be used under many circumstances\&. This macro cannot be used in the same
229 \fBMALLOCX_TCACHE(\fR\fB\fItc\fR\fR\fB)\fR\&.
232 \fBMALLOCX_ARENA(\fR\fB\fIa\fR\fR\fB) \fR
234 Use the arena specified by the index
235 \fIa\fR\&. This macro has no effect for regions that were allocated via an arena other than the one specified\&. This macro does not validate that
237 specifies an arena index in the valid range\&.
242 function allocates at least
244 bytes of memory, and returns a pointer to the base address of the allocation\&. Behavior is undefined if
247 \fB0\fR, or if request size overflows due to size class and/or alignment constraints\&.
251 function resizes the allocation at
255 bytes, and returns a pointer to the base address of the resulting allocation, which may or may not have moved from its original location\&. Behavior is undefined if
258 \fB0\fR, or if request size overflows due to size class and/or alignment constraints\&.
262 function resizes the allocation at
264 in place to be at least
266 bytes, and returns the real size of the allocation\&. If
268 is non\-zero, an attempt is made to resize the allocation to be at least
269 (\fIsize\fR + \fIextra\fR)
270 bytes, though inability to allocate the extra byte(s) will not by itself result in failure to resize\&. Behavior is undefined if
274 (\fIsize\fR + \fIextra\fR > \fBSIZE_T_MAX\fR)\&.
278 function returns the real size of the allocation at
283 function causes the memory referenced by
285 to be made available for future allocations\&.
289 function is an extension of
293 parameter to allow the caller to pass in the allocation size as an optimization\&. The minimum valid input size is the original requested size of the allocation, and the maximum valid input size is the corresponding value returned by
296 \fBsallocx\fR\fB\fR\&.
300 function allocates no memory, but it performs the same size computation as the
302 function, and returns the real size of the allocation that would result from the equivalent
304 function call\&. Behavior is undefined if
307 \fB0\fR, or if request size overflows due to size class and/or alignment constraints\&.
311 function provides a general interface for introspecting the memory allocator, as well as setting modifiable parameters and triggering actions\&. The period\-separated
313 argument specifies a location in a tree\-structured namespace; see the
315 section for documentation on the tree contents\&. To read a value, pass a pointer via
317 to adequate space to contain the value, and a pointer to its length via
318 \fIoldlenp\fR; otherwise pass
321 \fBNULL\fR\&. Similarly, to write a value, pass a pointer to the value via
322 \fInewp\fR, and its length via
323 \fInewlen\fR; otherwise pass
329 \fBmallctlnametomib\fR\fB\fR
330 function provides a way to avoid repeated name lookups for applications that repeatedly query the same portion of the namespace, by translating a name to a \(lqManagement Information Base\(rq (MIB) that can be passed repeatedly to
331 \fBmallctlbymib\fR\fB\fR\&. Upon successful return from
332 \fBmallctlnametomib\fR\fB\fR,
338 is the lesser of the number of components in
340 and the input value of
341 \fI*miblenp\fR\&. Thus it is possible to pass a
343 that is smaller than the number of period\-separated name components, which results in a partial MIB that can be used as the basis for constructing a complete MIB\&. For name components that are integers (e\&.g\&. the 2 in
344 "arenas\&.bin\&.2\&.size"), the corresponding MIB component will always be that integer\&. Therefore, it is legitimate to construct code like the following:
355 mallctl("arenas\&.nbins", &nbins, &len, NULL, 0);
358 mallctlnametomib("arenas\&.bin\&.0\&.size", mib, &miblen);
359 for (i = 0; i < nbins; i++) {
363 len = sizeof(bin_size);
364 mallctlbymib(mib, miblen, &bin_size, &len, NULL, 0);
365 /* Do something with bin_size\&.\&.\&. */
373 \fBmalloc_stats_print\fR\fB\fR
374 function writes human\-readable summary statistics via the
376 callback function pointer and
380 \fBmalloc_message\fR\fB\fR
384 \fBNULL\fR\&. This function can be called repeatedly\&. General information that never changes during execution can be omitted by specifying "g" as a character within the
387 \fBmalloc_message\fR\fB\fR
390 functions internally, so inconsistent statistics can be reported if multiple threads use these functions simultaneously\&. If
391 \fB\-\-enable\-stats\fR
392 is specified during configuration, \(lqm\(rq and \(lqa\(rq can be specified to omit merged arena and per arena statistics, respectively; \(lqb\(rq, \(lql\(rq, and \(lqh\(rq can be specified to omit per size class statistics for bins, large objects, and huge objects, respectively\&. Unrecognized characters are silently ignored\&. Note that thread caching may prevent some statistics from being completely up to date, since extra locking would be required to merge counters that track thread cache operations\&.
395 \fBmalloc_usable_size\fR\fB\fR
396 function returns the usable size of the allocation pointed to by
397 \fIptr\fR\&. The return value may be larger than the size that was requested during allocation\&. The
398 \fBmalloc_usable_size\fR\fB\fR
399 function is not a mechanism for in\-place
400 \fBrealloc\fR\fB\fR; rather it is provided solely as a tool for introspection purposes\&. Any discrepancy between the requested allocation size and the size reported by
401 \fBmalloc_usable_size\fR\fB\fR
402 should not be depended on, since such behavior is entirely implementation\-dependent\&.
405 Once, when the first call is made to one of the memory allocation routines, the allocator initializes its internals based in part on various options that can be specified at compile\- or run\-time\&.
407 The string pointed to by the global variable
408 \fImalloc_conf\fR, the \(lqname\(rq of the file referenced by the symbolic link named
409 /etc/malloc\&.conf, and the value of the environment variable
410 \fBMALLOC_CONF\fR, will be interpreted, in that order, from left to right as options\&. Note that
414 is entered, so the declaration of
416 should specify an initializer that contains the final value to be read by jemalloc\&.
418 is a compile\-time setting, whereas
422 can be safely set any time prior to program invocation\&.
424 An options string is a comma\-separated list of option:value pairs\&. There is one key corresponding to each
428 section for options documentation)\&. For example,
434 options\&. Some options have boolean values (true/false), others have integer values (base 8, 10, or 16, depending on prefix), and yet others have raw string values\&.
435 .SH "IMPLEMENTATION NOTES"
437 Traditionally, allocators have used
439 to obtain memory, which is suboptimal for several reasons, including race conditions, increased fragmentation, and artificial limitations on maximum usable memory\&. If
441 is supported by the operating system, this allocator uses both
444 \fBsbrk\fR(2), in that order of preference; otherwise only
448 This allocator uses multiple arenas in order to reduce lock contention for threaded programs on multi\-processor systems\&. This works well with regard to threading scalability, but incurs some costs\&. There is a small fixed per\-arena overhead, and additionally, arenas manage memory completely independently of each other, which means a small fixed increase in overall memory fragmentation\&. These overheads are not generally an issue, given the number of arenas normally used\&. Note that using substantially more arenas than the default is not likely to improve performance, mainly due to reduced cache performance\&. However, it may make sense to reduce the number of arenas if an application does not make much use of the allocation functions\&.
450 In addition to multiple arenas, unless
451 \fB\-\-disable\-tcache\fR
452 is specified during configuration, this allocator supports thread\-specific caching for small and large objects, in order to make it possible to completely avoid synchronization for most allocation requests\&. Such caching allows very fast allocation in the common case, but it increases memory usage and fragmentation, since a bounded number of objects can remain allocated in each thread cache\&.
454 Memory is conceptually broken into equal\-sized chunks, where the chunk size is a power of two that is greater than the page size\&. Chunks are always aligned to multiples of the chunk size\&. This alignment makes it possible to find metadata for user objects very quickly\&.
456 User objects are broken into three categories according to size: small, large, and huge\&. Small and large objects are managed entirely by arenas; huge objects are additionally aggregated in a single data structure that is shared by all threads\&. Huge objects are typically used by applications infrequently enough that this single data structure is not a scalability issue\&.
458 Each chunk that is managed by an arena tracks its contents as runs of contiguous pages (unused, backing a set of small objects, or backing one large object)\&. The combination of chunk alignment and chunk page maps makes it possible to determine all metadata regarding small and large allocations in constant time\&.
460 Small objects are managed in groups by page runs\&. Each run maintains a bitmap to track which regions are in use\&. Allocation requests that are no more than half the quantum (8 or 16, depending on architecture) are rounded up to the nearest power of two that is at least
461 sizeof(\fBdouble\fR)\&. All other object size classes are multiples of the quantum, spaced such that there are four size classes for each doubling in size, which limits internal fragmentation to approximately 20% for all but the smallest size classes\&. Small size classes are smaller than four times the page size, large size classes are smaller than the chunk size (see the
463 option), and huge size classes extend from the chunk size up to one size class less than the full address space size\&.
465 Allocations are packed tightly together, which can be an issue for multi\-threaded applications\&. If you need to assure that allocations do not suffer from cacheline sharing, round your allocation requests up to the nearest multiple of the cacheline size, or specify cacheline alignment when allocating\&.
469 \fBrallocx\fR\fB\fR, and
471 functions may resize allocations without moving them under limited circumstances\&. Unlike the
473 API, the standard API does not officially round up the usable size of an allocation to the nearest size class, so technically it is necessary to call
475 to grow e\&.g\&. a 9\-byte allocation to 16 bytes, or shrink a 16\-byte allocation to 9 bytes\&. Growth and shrinkage trivially succeeds in place as long as the pre\-size and post\-size both round up to the same size class\&. No other API guarantees are made regarding in\-place resizing, but the current implementation also tries to resize large and huge allocations in place, as long as the pre\-size and post\-size are both large or both huge\&. In such cases shrinkage always succeeds for large size classes, but for huge size classes the chunk allocator must support splitting (see
476 "arena\&.<i>\&.chunk_hooks")\&. Growth only succeeds if the trailing memory is currently available, and additionally for huge size classes the chunk allocator must support merging\&.
478 Assuming 2 MiB chunks, 4 KiB pages, and a 16\-byte quantum on a 64\-bit system, the size classes in each category are as shown in
482 .nr an-no-space-flag 1
485 .B Table\ \&1.\ \&Size classes
531 [16, 32, 48, 64, 80, 96, 112, 128]
546 [640, 768, 896, 1024]
551 [1280, 1536, 1792, 2048]
556 [2560, 3072, 3584, 4096]
561 [5 KiB, 6 KiB, 7 KiB, 8 KiB]
566 [10 KiB, 12 KiB, 14 KiB]
578 [20 KiB, 24 KiB, 28 KiB, 32 KiB]
583 [40 KiB, 48 KiB, 54 KiB, 64 KiB]
588 [80 KiB, 96 KiB, 112 KiB, 128 KiB]
593 [160 KiB, 192 KiB, 224 KiB, 256 KiB]
598 [320 KiB, 384 KiB, 448 KiB, 512 KiB]
603 [640 KiB, 768 KiB, 896 KiB, 1 MiB]
608 [1280 KiB, 1536 KiB, 1792 KiB]
620 [2560 KiB, 3 MiB, 3584 KiB, 4 MiB]
625 [5 MiB, 6 MiB, 7 MiB, 8 MiB]
630 [10 MiB, 12 MiB, 14 MiB, 16 MiB]
635 [20 MiB, 24 MiB, 28 MiB, 32 MiB]
640 [40 MiB, 48 MiB, 56 MiB, 64 MiB]
649 .SH "MALLCTL NAMESPACE"
651 The following names are defined in the namespace accessible via the
653 functions\&. Value types are specified in parentheses, their readable/writable statuses are encoded as
657 \-\-, and required build configuration flags follow, if any\&. A name element encoded as
661 indicates an integer component, where the integer varies from 0 to some upper value that must be determined via introspection\&. In the case of
662 "stats\&.arenas\&.<i>\&.*",
666 can be used to access the summation of statistics from all arenas\&. Take special note of the
668 mallctl, which controls refreshing of cached dynamic statistics\&.
670 "version" (\fBconst char *\fR) r\-
672 Return the jemalloc version string\&.
675 "epoch" (\fBuint64_t\fR) rw
677 If a value is passed in, refresh the data from which the
679 functions report values, and increment the epoch\&. Return the current epoch\&. This is useful for detecting whether another thread caused a refresh\&.
682 "config\&.cache_oblivious" (\fBbool\fR) r\-
684 \fB\-\-enable\-cache\-oblivious\fR
685 was specified during build configuration\&.
688 "config\&.debug" (\fBbool\fR) r\-
690 \fB\-\-enable\-debug\fR
691 was specified during build configuration\&.
694 "config\&.fill" (\fBbool\fR) r\-
696 \fB\-\-enable\-fill\fR
697 was specified during build configuration\&.
700 "config\&.lazy_lock" (\fBbool\fR) r\-
702 \fB\-\-enable\-lazy\-lock\fR
703 was specified during build configuration\&.
706 "config\&.munmap" (\fBbool\fR) r\-
708 \fB\-\-enable\-munmap\fR
709 was specified during build configuration\&.
712 "config\&.prof" (\fBbool\fR) r\-
714 \fB\-\-enable\-prof\fR
715 was specified during build configuration\&.
718 "config\&.prof_libgcc" (\fBbool\fR) r\-
720 \fB\-\-disable\-prof\-libgcc\fR
721 was not specified during build configuration\&.
724 "config\&.prof_libunwind" (\fBbool\fR) r\-
726 \fB\-\-enable\-prof\-libunwind\fR
727 was specified during build configuration\&.
730 "config\&.stats" (\fBbool\fR) r\-
732 \fB\-\-enable\-stats\fR
733 was specified during build configuration\&.
736 "config\&.tcache" (\fBbool\fR) r\-
738 \fB\-\-disable\-tcache\fR
739 was not specified during build configuration\&.
742 "config\&.tls" (\fBbool\fR) r\-
744 \fB\-\-disable\-tls\fR
745 was not specified during build configuration\&.
748 "config\&.utrace" (\fBbool\fR) r\-
750 \fB\-\-enable\-utrace\fR
751 was specified during build configuration\&.
754 "config\&.valgrind" (\fBbool\fR) r\-
756 \fB\-\-enable\-valgrind\fR
757 was specified during build configuration\&.
760 "config\&.xmalloc" (\fBbool\fR) r\-
762 \fB\-\-enable\-xmalloc\fR
763 was specified during build configuration\&.
766 "opt\&.abort" (\fBbool\fR) r\-
768 Abort\-on\-warning enabled/disabled\&. If true, most warnings are fatal\&. The process will call
770 in these cases\&. This option is disabled by default unless
771 \fB\-\-enable\-debug\fR
772 is specified during configuration, in which case it is enabled by default\&.
775 "opt\&.dss" (\fBconst char *\fR) r\-
777 dss (\fBsbrk\fR(2)) allocation precedence as related to
779 allocation\&. The following settings are supported if
781 is supported by the operating system: \(lqdisabled\(rq, \(lqprimary\(rq, and \(lqsecondary\(rq; otherwise only \(lqdisabled\(rq is supported\&. The default is \(lqsecondary\(rq if
783 is supported by the operating system; \(lqdisabled\(rq otherwise\&.
786 "opt\&.lg_chunk" (\fBsize_t\fR) r\-
788 Virtual memory chunk size (log base 2)\&. If a chunk size outside the supported size range is specified, the size is silently clipped to the minimum/maximum supported size\&. The default chunk size is 2 MiB (2^21)\&.
791 "opt\&.narenas" (\fBsize_t\fR) r\-
793 Maximum number of arenas to use for automatic multiplexing of threads and arenas\&. The default is four times the number of CPUs, or one if there is a single CPU\&.
796 "opt\&.lg_dirty_mult" (\fBssize_t\fR) r\-
798 Per\-arena minimum ratio (log base 2) of active to dirty pages\&. Some dirty unused pages may be allowed to accumulate, within the limit set by the ratio (or one chunk worth of dirty pages, whichever is greater), before informing the kernel about some of those pages via
800 or a similar system call\&. This provides the kernel with sufficient information to recycle dirty pages if physical memory becomes scarce and the pages remain unused\&. The default minimum ratio is 8:1 (2^3:1); an option value of \-1 will disable dirty page purging\&. See
801 "arenas\&.lg_dirty_mult"
803 "arena\&.<i>\&.lg_dirty_mult"
804 for related dynamic control options\&.
807 "opt\&.stats_print" (\fBbool\fR) r\-
809 Enable/disable statistics printing at exit\&. If enabled, the
810 \fBmalloc_stats_print\fR\fB\fR
811 function is called at program exit via an
814 \fB\-\-enable\-stats\fR
815 is specified during configuration, this has the potential to cause deadlock for a multi\-threaded process that exits while one or more threads are executing in the memory allocation functions\&. Furthermore,
817 may allocate memory during application initialization and then deadlock internally when jemalloc in turn calls
818 \fBatexit\fR\fB\fR, so this option is not univerally usable (though the application can register its own
820 function with equivalent functionality)\&. Therefore, this option should only be used with care; it is primarily intended as a performance tuning aid during application development\&. This option is disabled by default\&.
823 "opt\&.junk" (\fBconst char *\fR) r\- [\fB\-\-enable\-fill\fR]
825 Junk filling\&. If set to "alloc", each byte of uninitialized allocated memory will be initialized to
826 0xa5\&. If set to "free", all deallocated memory will be initialized to
827 0x5a\&. If set to "true", both allocated and deallocated memory will be initialized, and if set to "false", junk filling be disabled entirely\&. This is intended for debugging and will impact performance negatively\&. This option is "false" by default unless
828 \fB\-\-enable\-debug\fR
829 is specified during configuration, in which case it is "true" by default unless running inside
830 \m[blue]\fBValgrind\fR\m[]\&\s-2\u[2]\d\s+2\&.
833 "opt\&.quarantine" (\fBsize_t\fR) r\- [\fB\-\-enable\-fill\fR]
835 Per thread quarantine size in bytes\&. If non\-zero, each thread maintains a FIFO object quarantine that stores up to the specified number of bytes of memory\&. The quarantined memory is not freed until it is released from quarantine, though it is immediately junk\-filled if the
837 option is enabled\&. This feature is of particular use in combination with
838 \m[blue]\fBValgrind\fR\m[]\&\s-2\u[2]\d\s+2, which can detect attempts to access quarantined objects\&. This is intended for debugging and will impact performance negatively\&. The default quarantine size is 0 unless running inside Valgrind, in which case the default is 16 MiB\&.
841 "opt\&.redzone" (\fBbool\fR) r\- [\fB\-\-enable\-fill\fR]
843 Redzones enabled/disabled\&. If enabled, small allocations have redzones before and after them\&. Furthermore, if the
845 option is enabled, the redzones are checked for corruption during deallocation\&. However, the primary intended purpose of this feature is to be used in combination with
846 \m[blue]\fBValgrind\fR\m[]\&\s-2\u[2]\d\s+2, which needs redzones in order to do effective buffer overflow/underflow detection\&. This option is intended for debugging and will impact performance negatively\&. This option is disabled by default unless running inside Valgrind\&.
849 "opt\&.zero" (\fBbool\fR) r\- [\fB\-\-enable\-fill\fR]
851 Zero filling enabled/disabled\&. If enabled, each byte of uninitialized allocated memory will be initialized to 0\&. Note that this initialization only happens once for each byte, so
855 calls do not zero memory that was previously allocated\&. This is intended for debugging and will impact performance negatively\&. This option is disabled by default\&.
858 "opt\&.utrace" (\fBbool\fR) r\- [\fB\-\-enable\-utrace\fR]
860 Allocation tracing based on
862 enabled/disabled\&. This option is disabled by default\&.
865 "opt\&.xmalloc" (\fBbool\fR) r\- [\fB\-\-enable\-xmalloc\fR]
867 Abort\-on\-out\-of\-memory enabled/disabled\&. If enabled, rather than returning failure for any allocation function, display a diagnostic message on
869 and cause the program to drop core (using
870 \fBabort\fR(3))\&. If an application is designed to depend on this behavior, set the option at compile time by including the following in the source code:
876 malloc_conf = "xmalloc:true";
882 This option is disabled by default\&.
885 "opt\&.tcache" (\fBbool\fR) r\- [\fB\-\-enable\-tcache\fR]
887 Thread\-specific caching (tcache) enabled/disabled\&. When there are multiple threads, each thread uses a tcache for objects up to a certain size\&. Thread\-specific caching allows many allocations to be satisfied without performing any thread synchronization, at the cost of increased memory use\&. See the
888 "opt\&.lg_tcache_max"
889 option for related tuning information\&. This option is enabled by default unless running inside
890 \m[blue]\fBValgrind\fR\m[]\&\s-2\u[2]\d\s+2, in which case it is forcefully disabled\&.
893 "opt\&.lg_tcache_max" (\fBsize_t\fR) r\- [\fB\-\-enable\-tcache\fR]
895 Maximum size class (log base 2) to cache in the thread\-specific cache (tcache)\&. At a minimum, all small size classes are cached, and at a maximum all large size classes are cached\&. The default maximum is 32 KiB (2^15)\&.
898 "opt\&.prof" (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
900 Memory profiling enabled/disabled\&. If enabled, profile memory allocation activity\&. See the
902 option for on\-the\-fly activation/deactivation\&. See the
903 "opt\&.lg_prof_sample"
904 option for probabilistic sampling control\&. See the
906 option for control of cumulative sample reporting\&. See the
907 "opt\&.lg_prof_interval"
908 option for information on interval\-triggered profile dumping, the
910 option for information on high\-water\-triggered profile dumping, and the
912 option for final profile dumping\&. Profile output is compatible with the
914 command, which is based on the
916 that is developed as part of the
917 \m[blue]\fBgperftools package\fR\m[]\&\s-2\u[3]\d\s+2\&.
920 "opt\&.prof_prefix" (\fBconst char *\fR) r\- [\fB\-\-enable\-prof\fR]
922 Filename prefix for profile dumps\&. If the prefix is set to the empty string, no automatic dumps will occur; this is primarily useful for disabling the automatic final heap dump (which also disables leak reporting, if enabled)\&. The default prefix is
926 "opt\&.prof_active" (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
928 Profiling activated/deactivated\&. This is a secondary control mechanism that makes it possible to start the application with profiling enabled (see the
930 option) but inactive, then toggle profiling at any time during program execution with the
932 mallctl\&. This option is enabled by default\&.
935 "opt\&.prof_thread_active_init" (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
938 "thread\&.prof\&.active"
939 in newly created threads\&. The initial setting for newly created threads can also be changed during execution via the
940 "prof\&.thread_active_init"
941 mallctl\&. This option is enabled by default\&.
944 "opt\&.lg_prof_sample" (\fBsize_t\fR) r\- [\fB\-\-enable\-prof\fR]
946 Average interval (log base 2) between allocation samples, as measured in bytes of allocation activity\&. Increasing the sampling interval decreases profile fidelity, but also decreases the computational overhead\&. The default sample interval is 512 KiB (2^19 B)\&.
949 "opt\&.prof_accum" (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
951 Reporting of cumulative object/byte counts in profile dumps enabled/disabled\&. If this option is enabled, every unique backtrace must be stored for the duration of execution\&. Depending on the application, this can impose a large memory overhead, and the cumulative counts are not always of interest\&. This option is disabled by default\&.
954 "opt\&.lg_prof_interval" (\fBssize_t\fR) r\- [\fB\-\-enable\-prof\fR]
956 Average interval (log base 2) between memory profile dumps, as measured in bytes of allocation activity\&. The actual interval between dumps may be sporadic because decentralized allocation counters are used to avoid synchronization bottlenecks\&. Profiles are dumped to files named according to the pattern
957 <prefix>\&.<pid>\&.<seq>\&.i<iseq>\&.heap, where
961 option\&. By default, interval\-triggered profile dumping is disabled (encoded as \-1)\&.
964 "opt\&.prof_gdump" (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
966 Set the initial state of
967 "prof\&.gdump", which when enabled triggers a memory profile dump every time the total virtual memory exceeds the previous maximum\&. This option is disabled by default\&.
970 "opt\&.prof_final" (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
974 function to dump final memory usage to a file named according to the pattern
975 <prefix>\&.<pid>\&.<seq>\&.f\&.heap, where
981 may allocate memory during application initialization and then deadlock internally when jemalloc in turn calls
982 \fBatexit\fR\fB\fR, so this option is not univerally usable (though the application can register its own
984 function with equivalent functionality)\&. This option is disabled by default\&.
987 "opt\&.prof_leak" (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
989 Leak reporting enabled/disabled\&. If enabled, use an
991 function to report memory leaks detected by allocation sampling\&. See the
993 option for information on analyzing heap profile output\&. This option is disabled by default\&.
996 "thread\&.arena" (\fBunsigned\fR) rw
998 Get or set the arena associated with the calling thread\&. If the specified arena was not initialized beforehand (see the
999 "arenas\&.initialized"
1000 mallctl), it will be automatically initialized as a side effect of calling this interface\&.
1003 "thread\&.allocated" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1005 Get the total number of bytes ever allocated by the calling thread\&. This counter has the potential to wrap around; it is up to the application to appropriately interpret the counter in such cases\&.
1008 "thread\&.allocatedp" (\fBuint64_t *\fR) r\- [\fB\-\-enable\-stats\fR]
1010 Get a pointer to the the value that is returned by the
1011 "thread\&.allocated"
1012 mallctl\&. This is useful for avoiding the overhead of repeated
1013 \fBmallctl*\fR\fB\fR
1017 "thread\&.deallocated" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1019 Get the total number of bytes ever deallocated by the calling thread\&. This counter has the potential to wrap around; it is up to the application to appropriately interpret the counter in such cases\&.
1022 "thread\&.deallocatedp" (\fBuint64_t *\fR) r\- [\fB\-\-enable\-stats\fR]
1024 Get a pointer to the the value that is returned by the
1025 "thread\&.deallocated"
1026 mallctl\&. This is useful for avoiding the overhead of repeated
1027 \fBmallctl*\fR\fB\fR
1031 "thread\&.tcache\&.enabled" (\fBbool\fR) rw [\fB\-\-enable\-tcache\fR]
1033 Enable/disable calling thread\*(Aqs tcache\&. The tcache is implicitly flushed as a side effect of becoming disabled (see
1034 "thread\&.tcache\&.flush")\&.
1037 "thread\&.tcache\&.flush" (\fBvoid\fR) \-\- [\fB\-\-enable\-tcache\fR]
1039 Flush calling thread\*(Aqs thread\-specific cache (tcache)\&. This interface releases all cached objects and internal data structures associated with the calling thread\*(Aqs tcache\&. Ordinarily, this interface need not be called, since automatic periodic incremental garbage collection occurs, and the thread cache is automatically discarded when a thread exits\&. However, garbage collection is triggered by allocation activity, so it is possible for a thread that stops allocating/deallocating to retain its cache indefinitely, in which case the developer may find manual flushing useful\&.
1042 "thread\&.prof\&.name" (\fBconst char *\fR) r\- or \-w [\fB\-\-enable\-prof\fR]
1044 Get/set the descriptive name associated with the calling thread in memory profile dumps\&. An internal copy of the name string is created, so the input string need not be maintained after this interface completes execution\&. The output string of this interface should be copied for non\-ephemeral uses, because multiple implementation details can cause asynchronous string deallocation\&. Furthermore, each invocation of this interface can only read or write; simultaneous read/write is not supported due to string lifetime limitations\&. The name string must be nil\-terminated and comprised only of characters in the sets recognized by
1050 "thread\&.prof\&.active" (\fBbool\fR) rw [\fB\-\-enable\-prof\fR]
1052 Control whether sampling is currently active for the calling thread\&. This is an activation mechanism in addition to
1053 "prof\&.active"; both must be active for the calling thread to sample\&. This flag is enabled by default\&.
1056 "tcache\&.create" (\fBunsigned\fR) r\- [\fB\-\-enable\-tcache\fR]
1058 Create an explicit thread\-specific cache (tcache) and return an identifier that can be passed to the
1059 \fBMALLOCX_TCACHE(\fR\fB\fItc\fR\fR\fB)\fR
1060 macro to explicitly use the specified cache rather than the automatically managed one that is used by default\&. Each explicit cache can be used by only one thread at a time; the application must assure that this constraint holds\&.
1063 "tcache\&.flush" (\fBunsigned\fR) \-w [\fB\-\-enable\-tcache\fR]
1065 Flush the specified thread\-specific cache (tcache)\&. The same considerations apply to this interface as to
1066 "thread\&.tcache\&.flush", except that the tcache will never be automatically be discarded\&.
1069 "tcache\&.destroy" (\fBunsigned\fR) \-w [\fB\-\-enable\-tcache\fR]
1071 Flush the specified thread\-specific cache (tcache) and make the identifier available for use during a future tcache creation\&.
1074 "arena\&.<i>\&.purge" (\fBvoid\fR) \-\-
1076 Purge unused dirty pages for arena <i>, or for all arenas if <i> equals
1077 "arenas\&.narenas"\&.
1080 "arena\&.<i>\&.dss" (\fBconst char *\fR) rw
1082 Set the precedence of dss allocation as related to mmap allocation for arena <i>, or for all arenas if <i> equals
1083 "arenas\&.narenas"\&. See
1085 for supported settings\&.
1088 "arena\&.<i>\&.lg_dirty_mult" (\fBssize_t\fR) rw
1090 Current per\-arena minimum ratio (log base 2) of active to dirty pages for arena <i>\&. Each time this interface is set and the ratio is increased, pages are synchronously purged as necessary to impose the new ratio\&. See
1091 "opt\&.lg_dirty_mult"
1092 for additional information\&.
1095 "arena\&.<i>\&.chunk_hooks" (\fBchunk_hooks_t\fR) rw
1097 Get or set the chunk management hook functions for arena <i>\&. The functions must be capable of operating on all extant chunks associated with arena <i>, usually by passing unknown chunks to the replaced functions\&. In practice, it is feasible to control allocation for arenas created via
1099 such that all chunks originate from an application\-supplied chunk allocator (by setting custom chunk hook functions just after arena creation), but the automatically created arenas may have already created chunks prior to the application having an opportunity to take over chunk allocation\&.
1106 chunk_alloc_t *alloc;
1107 chunk_dalloc_t *dalloc;
1108 chunk_commit_t *commit;
1109 chunk_decommit_t *decommit;
1110 chunk_purge_t *purge;
1111 chunk_split_t *split;
1112 chunk_merge_t *merge;
1121 structure comprises function pointers which are described individually below\&. jemalloc uses these functions to manage chunk lifetime, which starts off with allocation of mapped committed memory, in the simplest case followed by deallocation\&. However, there are performance and platform reasons to retain chunks for later reuse\&. Cleanup attempts cascade from deallocation to decommit to purging, which gives the chunk management functions opportunities to reject the most permanent cleanup operations in favor of less permanent (and often less costly) operations\&. The chunk splitting and merging operations can also be opted out of, but this is mainly intended to support platforms on which virtual memory mappings provided by the operating system kernel do not automatically coalesce and split, e\&.g\&. Windows\&.
1122 .HP \w'typedef\ void\ *(chunk_alloc_t)('u
1123 .BI "typedef void *(chunk_alloc_t)(void\ *" "chunk" ", size_t\ " "size" ", size_t\ " "alignment" ", bool\ *" "zero" ", bool\ *" "commit" ", unsigned\ " "arena_ind" ");"
1134 A chunk allocation function conforms to the
1136 type and upon success returns a pointer to
1138 bytes of mapped memory on behalf of arena
1140 such that the chunk\*(Aqs base address is a multiple of
1141 \fIalignment\fR, as well as setting
1143 to indicate whether the chunk is zeroed and
1145 to indicate whether the chunk is committed\&. Upon error the function returns
1153 parameter is always a multiple of the chunk size\&. The
1155 parameter is always a power of two at least as large as the chunk size\&. Zeroing is mandatory if
1157 is true upon function entry\&. Committing is mandatory if
1159 is true upon function entry\&. If
1162 \fBNULL\fR, the returned pointer must be
1166 on error\&. Committed memory may be committed in absolute terms as on a system that does not overcommit, or in implicit terms as on a system that overcommits and satisfies physical memory needs on demand via soft page faults\&. Note that replacing the default chunk allocation function makes the arena\*(Aqs
1168 setting irrelevant\&.
1169 .HP \w'typedef\ bool\ (chunk_dalloc_t)('u
1170 .BI "typedef bool (chunk_dalloc_t)(void\ *" "chunk" ", size_t\ " "size" ", bool\ " "committed" ", unsigned\ " "arena_ind" ");"
1181 A chunk deallocation function conforms to the
1182 \fBchunk_dalloc_t\fR
1183 type and deallocates a
1188 \fIcommitted\fR/decommited memory as indicated, on behalf of arena
1189 \fIarena_ind\fR, returning false upon success\&. If the function returns true, this indicates opt\-out from deallocation; the virtual memory mapping associated with the chunk remains mapped, in the same commit state, and available for future use, in which case it will be automatically retained for later reuse\&.
1190 .HP \w'typedef\ bool\ (chunk_commit_t)('u
1191 .BI "typedef bool (chunk_commit_t)(void\ *" "chunk" ", size_t\ " "size" ", size_t\ " "offset" ", size_t\ " "length" ", unsigned\ " "arena_ind" ");"
1202 A chunk commit function conforms to the
1203 \fBchunk_commit_t\fR
1204 type and commits zeroed physical memory to back pages within a
1210 bytes, extending for
1213 \fIarena_ind\fR, returning false upon success\&. Committed memory may be committed in absolute terms as on a system that does not overcommit, or in implicit terms as on a system that overcommits and satisfies physical memory needs on demand via soft page faults\&. If the function returns true, this indicates insufficient physical memory to satisfy the request\&.
1214 .HP \w'typedef\ bool\ (chunk_decommit_t)('u
1215 .BI "typedef bool (chunk_decommit_t)(void\ *" "chunk" ", size_t\ " "size" ", size_t\ " "offset" ", size_t\ " "length" ", unsigned\ " "arena_ind" ");"
1226 A chunk decommit function conforms to the
1227 \fBchunk_decommit_t\fR
1228 type and decommits any physical memory that is backing pages within a
1234 bytes, extending for
1237 \fIarena_ind\fR, returning false upon success, in which case the pages will be committed via the chunk commit function before being reused\&. If the function returns true, this indicates opt\-out from decommit; the memory remains committed and available for future use, in which case it will be automatically retained for later reuse\&.
1238 .HP \w'typedef\ bool\ (chunk_purge_t)('u
1239 .BI "typedef bool (chunk_purge_t)(void\ *" "chunk" ", size_t" "size" ", size_t\ " "offset" ", size_t\ " "length" ", unsigned\ " "arena_ind" ");"
1250 A chunk purge function conforms to the
1252 type and optionally discards physical pages within the virtual memory mapping associated with
1258 bytes, extending for
1261 \fIarena_ind\fR, returning false if pages within the purged virtual memory range will be zero\-filled the next time they are accessed\&.
1262 .HP \w'typedef\ bool\ (chunk_split_t)('u
1263 .BI "typedef bool (chunk_split_t)(void\ *" "chunk" ", size_t\ " "size" ", size_t\ " "size_a" ", size_t\ " "size_b" ", bool\ " "committed" ", unsigned\ " "arena_ind" ");"
1274 A chunk split function conforms to the
1276 type and optionally splits
1280 into two adjacent chunks, the first of
1282 bytes, and the second of
1285 \fIcommitted\fR/decommitted memory as indicated, on behalf of arena
1286 \fIarena_ind\fR, returning false upon success\&. If the function returns true, this indicates that the chunk remains unsplit and therefore should continue to be operated on as a whole\&.
1287 .HP \w'typedef\ bool\ (chunk_merge_t)('u
1288 .BI "typedef bool (chunk_merge_t)(void\ *" "chunk_a" ", size_t\ " "size_a" ", void\ *" "chunk_b" ", size_t\ " "size_b" ", bool\ " "committed" ", unsigned\ " "arena_ind" ");"
1299 A chunk merge function conforms to the
1301 type and optionally merges adjacent chunks,
1309 into one contiguous chunk, operating on
1310 \fIcommitted\fR/decommitted memory as indicated, on behalf of arena
1311 \fIarena_ind\fR, returning false upon success\&. If the function returns true, this indicates that the chunks remain distinct mappings and therefore should continue to be operated on independently\&.
1314 "arenas\&.narenas" (\fBunsigned\fR) r\-
1316 Current limit on number of arenas\&.
1319 "arenas\&.initialized" (\fBbool *\fR) r\-
1323 booleans\&. Each boolean indicates whether the corresponding arena is initialized\&.
1326 "arenas\&.lg_dirty_mult" (\fBssize_t\fR) rw
1328 Current default per\-arena minimum ratio (log base 2) of active to dirty pages, used to initialize
1329 "arena\&.<i>\&.lg_dirty_mult"
1330 during arena creation\&. See
1331 "opt\&.lg_dirty_mult"
1332 for additional information\&.
1335 "arenas\&.quantum" (\fBsize_t\fR) r\-
1340 "arenas\&.page" (\fBsize_t\fR) r\-
1345 "arenas\&.tcache_max" (\fBsize_t\fR) r\- [\fB\-\-enable\-tcache\fR]
1347 Maximum thread\-cached size class\&.
1350 "arenas\&.nbins" (\fBunsigned\fR) r\-
1352 Number of bin size classes\&.
1355 "arenas\&.nhbins" (\fBunsigned\fR) r\- [\fB\-\-enable\-tcache\fR]
1357 Total number of thread cache bin size classes\&.
1360 "arenas\&.bin\&.<i>\&.size" (\fBsize_t\fR) r\-
1362 Maximum size supported by size class\&.
1365 "arenas\&.bin\&.<i>\&.nregs" (\fBuint32_t\fR) r\-
1367 Number of regions per page run\&.
1370 "arenas\&.bin\&.<i>\&.run_size" (\fBsize_t\fR) r\-
1372 Number of bytes per page run\&.
1375 "arenas\&.nlruns" (\fBunsigned\fR) r\-
1377 Total number of large size classes\&.
1380 "arenas\&.lrun\&.<i>\&.size" (\fBsize_t\fR) r\-
1382 Maximum size supported by this large size class\&.
1385 "arenas\&.nhchunks" (\fBunsigned\fR) r\-
1387 Total number of huge size classes\&.
1390 "arenas\&.hchunk\&.<i>\&.size" (\fBsize_t\fR) r\-
1392 Maximum size supported by this huge size class\&.
1395 "arenas\&.extend" (\fBunsigned\fR) r\-
1397 Extend the array of arenas by appending a new arena, and returning the new arena index\&.
1400 "prof\&.thread_active_init" (\fBbool\fR) rw [\fB\-\-enable\-prof\fR]
1402 Control the initial setting for
1403 "thread\&.prof\&.active"
1404 in newly created threads\&. See the
1405 "opt\&.prof_thread_active_init"
1406 option for additional information\&.
1409 "prof\&.active" (\fBbool\fR) rw [\fB\-\-enable\-prof\fR]
1411 Control whether sampling is currently active\&. See the
1413 option for additional information, as well as the interrelated
1414 "thread\&.prof\&.active"
1418 "prof\&.dump" (\fBconst char *\fR) \-w [\fB\-\-enable\-prof\fR]
1420 Dump a memory profile to the specified file, or if NULL is specified, to a file according to the pattern
1421 <prefix>\&.<pid>\&.<seq>\&.m<mseq>\&.heap, where
1423 is controlled by the
1428 "prof\&.gdump" (\fBbool\fR) rw [\fB\-\-enable\-prof\fR]
1430 When enabled, trigger a memory profile dump every time the total virtual memory exceeds the previous maximum\&. Profiles are dumped to files named according to the pattern
1431 <prefix>\&.<pid>\&.<seq>\&.u<useq>\&.heap, where
1433 is controlled by the
1438 "prof\&.reset" (\fBsize_t\fR) \-w [\fB\-\-enable\-prof\fR]
1440 Reset all memory profile statistics, and optionally update the sample rate (see
1441 "opt\&.lg_prof_sample"
1443 "prof\&.lg_sample")\&.
1446 "prof\&.lg_sample" (\fBsize_t\fR) r\- [\fB\-\-enable\-prof\fR]
1448 Get the current sample rate (see
1449 "opt\&.lg_prof_sample")\&.
1452 "prof\&.interval" (\fBuint64_t\fR) r\- [\fB\-\-enable\-prof\fR]
1454 Average number of bytes allocated between inverval\-based profile dumps\&. See the
1455 "opt\&.lg_prof_interval"
1456 option for additional information\&.
1459 "stats\&.cactive" (\fBsize_t *\fR) r\- [\fB\-\-enable\-stats\fR]
1461 Pointer to a counter that contains an approximate count of the current number of bytes in active pages\&. The estimate may be high, but never low, because each arena rounds up when computing its contribution to the counter\&. Note that the
1463 mallctl has no bearing on this counter\&. Furthermore, counter consistency is maintained via atomic operations, so it is necessary to use an atomic operation in order to guarantee a consistent read when dereferencing the pointer\&.
1466 "stats\&.allocated" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1468 Total number of bytes allocated by the application\&.
1471 "stats\&.active" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1473 Total number of bytes in active pages allocated by the application\&. This is a multiple of the page size, and greater than or equal to
1474 "stats\&.allocated"\&. This does not include
1475 "stats\&.arenas\&.<i>\&.pdirty", nor pages entirely devoted to allocator metadata\&.
1478 "stats\&.metadata" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1480 Total number of bytes dedicated to metadata, which comprise base allocations used for bootstrap\-sensitive internal allocator data structures, arena chunk headers (see
1481 "stats\&.arenas\&.<i>\&.metadata\&.mapped"), and internal allocations (see
1482 "stats\&.arenas\&.<i>\&.metadata\&.allocated")\&.
1485 "stats\&.resident" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1487 Maximum number of bytes in physically resident data pages mapped by the allocator, comprising all pages dedicated to allocator metadata, pages backing active allocations, and unused dirty pages\&. This is a maximum rather than precise because pages may not actually be physically resident if they correspond to demand\-zeroed virtual memory that has not yet been touched\&. This is a multiple of the page size, and is larger than
1491 "stats\&.mapped" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1493 Total number of bytes in active chunks mapped by the allocator\&. This is a multiple of the chunk size, and is larger than
1494 "stats\&.active"\&. This does not include inactive chunks, even those that contain unused dirty pages, which means that there is no strict ordering between this and
1495 "stats\&.resident"\&.
1498 "stats\&.arenas\&.<i>\&.dss" (\fBconst char *\fR) r\-
1500 dss (\fBsbrk\fR(2)) allocation precedence as related to
1507 "stats\&.arenas\&.<i>\&.lg_dirty_mult" (\fBssize_t\fR) r\-
1509 Minimum ratio (log base 2) of active to dirty pages\&. See
1510 "opt\&.lg_dirty_mult"
1514 "stats\&.arenas\&.<i>\&.nthreads" (\fBunsigned\fR) r\-
1516 Number of threads currently assigned to arena\&.
1519 "stats\&.arenas\&.<i>\&.pactive" (\fBsize_t\fR) r\-
1521 Number of pages in active runs\&.
1524 "stats\&.arenas\&.<i>\&.pdirty" (\fBsize_t\fR) r\-
1526 Number of pages within unused runs that are potentially dirty, and for which
1527 \fBmadvise\fR\fB\fI\&.\&.\&.\fR\fR\fB \fR\fB\fI\fBMADV_DONTNEED\fR\fR\fR
1528 or similar has not been called\&.
1531 "stats\&.arenas\&.<i>\&.mapped" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1533 Number of mapped bytes\&.
1536 "stats\&.arenas\&.<i>\&.metadata\&.mapped" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1538 Number of mapped bytes in arena chunk headers, which track the states of the non\-metadata pages\&.
1541 "stats\&.arenas\&.<i>\&.metadata\&.allocated" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1543 Number of bytes dedicated to internal allocations\&. Internal allocations differ from application\-originated allocations in that they are for internal use, and that they are omitted from heap profiles\&. This statistic is reported separately from
1546 "stats\&.arenas\&.<i>\&.metadata\&.mapped"
1547 because it overlaps with e\&.g\&. the
1551 statistics, whereas the other metadata statistics do not\&.
1554 "stats\&.arenas\&.<i>\&.npurge" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1556 Number of dirty page purge sweeps performed\&.
1559 "stats\&.arenas\&.<i>\&.nmadvise" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1562 \fBmadvise\fR\fB\fI\&.\&.\&.\fR\fR\fB \fR\fB\fI\fBMADV_DONTNEED\fR\fR\fR
1563 or similar calls made to purge dirty pages\&.
1566 "stats\&.arenas\&.<i>\&.purged" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1568 Number of pages purged\&.
1571 "stats\&.arenas\&.<i>\&.small\&.allocated" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1573 Number of bytes currently allocated by small objects\&.
1576 "stats\&.arenas\&.<i>\&.small\&.nmalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1578 Cumulative number of allocation requests served by small bins\&.
1581 "stats\&.arenas\&.<i>\&.small\&.ndalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1583 Cumulative number of small objects returned to bins\&.
1586 "stats\&.arenas\&.<i>\&.small\&.nrequests" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1588 Cumulative number of small allocation requests\&.
1591 "stats\&.arenas\&.<i>\&.large\&.allocated" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1593 Number of bytes currently allocated by large objects\&.
1596 "stats\&.arenas\&.<i>\&.large\&.nmalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1598 Cumulative number of large allocation requests served directly by the arena\&.
1601 "stats\&.arenas\&.<i>\&.large\&.ndalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1603 Cumulative number of large deallocation requests served directly by the arena\&.
1606 "stats\&.arenas\&.<i>\&.large\&.nrequests" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1608 Cumulative number of large allocation requests\&.
1611 "stats\&.arenas\&.<i>\&.huge\&.allocated" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1613 Number of bytes currently allocated by huge objects\&.
1616 "stats\&.arenas\&.<i>\&.huge\&.nmalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1618 Cumulative number of huge allocation requests served directly by the arena\&.
1621 "stats\&.arenas\&.<i>\&.huge\&.ndalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1623 Cumulative number of huge deallocation requests served directly by the arena\&.
1626 "stats\&.arenas\&.<i>\&.huge\&.nrequests" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1628 Cumulative number of huge allocation requests\&.
1631 "stats\&.arenas\&.<i>\&.bins\&.<j>\&.nmalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1633 Cumulative number of allocations served by bin\&.
1636 "stats\&.arenas\&.<i>\&.bins\&.<j>\&.ndalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1638 Cumulative number of allocations returned to bin\&.
1641 "stats\&.arenas\&.<i>\&.bins\&.<j>\&.nrequests" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1643 Cumulative number of allocation requests\&.
1646 "stats\&.arenas\&.<i>\&.bins\&.<j>\&.curregs" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1648 Current number of regions for this size class\&.
1651 "stats\&.arenas\&.<i>\&.bins\&.<j>\&.nfills" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR \fB\-\-enable\-tcache\fR]
1653 Cumulative number of tcache fills\&.
1656 "stats\&.arenas\&.<i>\&.bins\&.<j>\&.nflushes" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR \fB\-\-enable\-tcache\fR]
1658 Cumulative number of tcache flushes\&.
1661 "stats\&.arenas\&.<i>\&.bins\&.<j>\&.nruns" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1663 Cumulative number of runs created\&.
1666 "stats\&.arenas\&.<i>\&.bins\&.<j>\&.nreruns" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1668 Cumulative number of times the current run from which to allocate changed\&.
1671 "stats\&.arenas\&.<i>\&.bins\&.<j>\&.curruns" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1673 Current number of runs\&.
1676 "stats\&.arenas\&.<i>\&.lruns\&.<j>\&.nmalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1678 Cumulative number of allocation requests for this size class served directly by the arena\&.
1681 "stats\&.arenas\&.<i>\&.lruns\&.<j>\&.ndalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1683 Cumulative number of deallocation requests for this size class served directly by the arena\&.
1686 "stats\&.arenas\&.<i>\&.lruns\&.<j>\&.nrequests" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1688 Cumulative number of allocation requests for this size class\&.
1691 "stats\&.arenas\&.<i>\&.lruns\&.<j>\&.curruns" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1693 Current number of runs for this size class\&.
1696 "stats\&.arenas\&.<i>\&.hchunks\&.<j>\&.nmalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1698 Cumulative number of allocation requests for this size class served directly by the arena\&.
1701 "stats\&.arenas\&.<i>\&.hchunks\&.<j>\&.ndalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1703 Cumulative number of deallocation requests for this size class served directly by the arena\&.
1706 "stats\&.arenas\&.<i>\&.hchunks\&.<j>\&.nrequests" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1708 Cumulative number of allocation requests for this size class\&.
1711 "stats\&.arenas\&.<i>\&.hchunks\&.<j>\&.curhchunks" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1713 Current number of huge allocations for this size class\&.
1715 .SH "DEBUGGING MALLOC PROBLEMS"
1717 When debugging, it is a good idea to configure/build jemalloc with the
1718 \fB\-\-enable\-debug\fR
1720 \fB\-\-enable\-fill\fR
1721 options, and recompile the program with suitable options and symbols for debugger support\&. When so configured, jemalloc incorporates a wide variety of run\-time assertions that catch application errors such as double\-free, write\-after\-free, etc\&.
1723 Programs often accidentally depend on \(lquninitialized\(rq memory actually being filled with zero bytes\&. Junk filling (see the
1725 option) tends to expose such bugs in the form of obviously incorrect results and/or coredumps\&. Conversely, zero filling (see the
1727 option) eliminates the symptoms of such bugs\&. Between these two options, it is usually possible to quickly detect, diagnose, and eliminate such bugs\&.
1729 This implementation does not provide much detail about the problems it detects, because the performance impact for storing such information would be prohibitive\&. However, jemalloc does integrate with the most excellent
1730 \m[blue]\fBValgrind\fR\m[]\&\s-2\u[2]\d\s+2
1732 \fB\-\-enable\-valgrind\fR
1733 configuration option is enabled\&.
1734 .SH "DIAGNOSTIC MESSAGES"
1736 If any of the memory allocation/deallocation functions detect an error or warning condition, a message will be printed to file descriptor
1737 \fBSTDERR_FILENO\fR\&. Errors will result in the process dumping core\&. If the
1739 option is set, most warnings are treated as errors\&.
1742 \fImalloc_message\fR
1743 variable allows the programmer to override the function which emits the text strings forming the errors and warnings if for some reason the
1745 file descriptor is not suitable for this\&.
1746 \fBmalloc_message\fR\fB\fR
1749 pointer argument that is
1751 unless overridden by the arguments in a call to
1752 \fBmalloc_stats_print\fR\fB\fR, followed by a string pointer\&. Please note that doing anything which tries to allocate memory in this function is likely to result in a crash or deadlock\&.
1754 All messages are prefixed by \(lq<jemalloc>:\(rq\&.
1762 functions return a pointer to the allocated memory if successful; otherwise a
1764 pointer is returned and
1770 \fBposix_memalign\fR\fB\fR
1771 function returns the value 0 if successful; otherwise it returns an error value\&. The
1772 \fBposix_memalign\fR\fB\fR
1773 function will fail if:
1779 parameter is not a power of 2 at least as large as
1780 sizeof(\fBvoid *\fR)\&.
1785 Memory allocation error\&.
1789 \fBaligned_alloc\fR\fB\fR
1790 function returns a pointer to the allocated memory if successful; otherwise a
1792 pointer is returned and
1795 \fBaligned_alloc\fR\fB\fR
1796 function will fail if:
1802 parameter is not a power of 2\&.
1807 Memory allocation error\&.
1812 function returns a pointer, possibly identical to
1813 \fIptr\fR, to the allocated memory if successful; otherwise a
1815 pointer is returned, and
1819 if the error was the result of an allocation failure\&. The
1821 function always leaves the original buffer intact when an error occurs\&.
1825 function returns no value\&.
1826 .SS "Non\-standard API"
1832 functions return a pointer to the allocated memory if successful; otherwise a
1834 pointer is returned to indicate insufficient contiguous memory was available to service the allocation request\&.
1838 function returns the real size of the resulting resized allocation pointed to by
1839 \fIptr\fR, which is a value less than
1841 if the allocation could not be adequately grown in place\&.
1845 function returns the real size of the allocation pointed to by
1850 returns the real size that would result from a successful equivalent
1852 function call, or zero if insufficient memory is available to perform the size computation\&.
1855 \fBmallctl\fR\fB\fR,
1856 \fBmallctlnametomib\fR\fB\fR, and
1857 \fBmallctlbymib\fR\fB\fR
1858 functions return 0 on success; otherwise they return an error value\&. The functions will fail if:
1866 is too large or too small\&. Alternatively,
1868 is too large or too small; in this case as much data as possible are read despite the error\&.
1876 specifies an unknown/invalid value\&.
1881 Attempt to read or write void value, or attempt to write read\-only value\&.
1886 A memory allocation failure occurred\&.
1891 An interface with side effects failed in some way not directly related to
1892 \fBmallctl*\fR\fB\fR
1893 read/write processing\&.
1897 \fBmalloc_usable_size\fR\fB\fR
1898 function returns the usable size of the allocation pointed to by
1902 The following environment variable affects the execution of the allocation functions:
1906 If the environment variable
1908 is set, the characters it contains will be interpreted as options\&.
1912 To dump core whenever a problem occurs:
1918 ln \-s \*(Aqabort:true\*(Aq /etc/malloc\&.conf
1924 To specify in the source a chunk size that is 16 MiB:
1930 malloc_conf = "lg_chunk:24";
1943 \fBgetpagesize\fR(3)
1949 \fBrealloc\fR\fB\fR, and
1951 functions conform to ISO/IEC 9899:1990 (\(lqISO C90\(rq)\&.
1954 \fBposix_memalign\fR\fB\fR
1955 function conforms to IEEE Std 1003\&.1\-2001 (\(lqPOSIX\&.1\(rq)\&.
1959 \fBmalloc_usable_size\fR\fB\fR
1961 \fBposix_memalign\fR\fB\fR
1962 functions first appeared in FreeBSD 7\&.0\&.
1965 \fBaligned_alloc\fR\fB\fR,
1966 \fBmalloc_stats_print\fR\fB\fR, and
1967 \fBmallctl*\fR\fB\fR
1968 functions first appeared in FreeBSD 10\&.0\&.
1972 functions first appeared in FreeBSD 11\&.0\&.
1982 \%http://www.canonware.com/jemalloc/
1987 \%http://valgrind.org/
1992 \%http://code.google.com/p/gperftools/