]> git.saurik.com Git - redis.git/blame - deps/jemalloc/doc/jemalloc.3
Sentinel: SENTINEL FAILOVER command implemented.
[redis.git] / deps / jemalloc / doc / jemalloc.3
CommitLineData
a78e148b 1'\" t
2.\" Title: JEMALLOC
3.\" Author: Jason Evans
ad4c0b41 4.\" Generator: DocBook XSL Stylesheets v1.76.1 <http://docbook.sf.net/>
5.\" Date: 05/11/2012
a78e148b 6.\" Manual: User Manual
ad4c0b41 7.\" Source: jemalloc 3.0.0-0-gfc9b1dbf69f59d7ecfc4ac68da9847e017e1d046
a78e148b 8.\" Language: English
9.\"
ad4c0b41 10.TH "JEMALLOC" "3" "05/11/2012" "jemalloc 3.0.0-0-gfc9b1dbf69f5" "User Manual"
a78e148b 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.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18.ie \n(.g .ds Aq \(aq
19.el .ds Aq '
20.\" -----------------------------------------------------------------
21.\" * set default formatting
22.\" -----------------------------------------------------------------
23.\" disable hyphenation
24.nh
25.\" disable justification (adjust text to left margin only)
26.ad l
27.\" -----------------------------------------------------------------
28.\" * MAIN CONTENT STARTS HERE *
29.\" -----------------------------------------------------------------
30.SH "NAME"
31jemalloc \- general purpose memory allocation functions
32.SH "LIBRARY"
33.PP
ad4c0b41 34This manual describes jemalloc 3\&.0\&.0\-0\-gfc9b1dbf69f59d7ecfc4ac68da9847e017e1d046\&. More information can be found at the
a78e148b 35\m[blue]\fBjemalloc website\fR\m[]\&\s-2\u[1]\d\s+2\&.
36.SH "SYNOPSIS"
37.sp
38.ft B
39.nf
40#include <stdlib\&.h>
41#include <jemalloc/jemalloc\&.h>
42.fi
43.ft
44.SS "Standard API"
45.HP \w'void\ *malloc('u
46.BI "void *malloc(size_t\ " "size" ");"
47.HP \w'void\ *calloc('u
48.BI "void *calloc(size_t\ " "number" ", size_t\ " "size" ");"
49.HP \w'int\ posix_memalign('u
50.BI "int posix_memalign(void\ **" "ptr" ", size_t\ " "alignment" ", size_t\ " "size" ");"
ad4c0b41 51.HP \w'void\ *aligned_alloc('u
52.BI "void *aligned_alloc(size_t\ " "alignment" ", size_t\ " "size" ");"
a78e148b 53.HP \w'void\ *realloc('u
54.BI "void *realloc(void\ *" "ptr" ", size_t\ " "size" ");"
55.HP \w'void\ free('u
56.BI "void free(void\ *" "ptr" ");"
57.SS "Non\-standard API"
58.HP \w'size_t\ malloc_usable_size('u
59.BI "size_t malloc_usable_size(const\ void\ *" "ptr" ");"
60.HP \w'void\ malloc_stats_print('u
61.BI "void malloc_stats_print(void\ " "(*write_cb)" "\ (void\ *,\ const\ char\ *), void\ *" "cbopaque" ", const\ char\ *" "opts" ");"
62.HP \w'int\ mallctl('u
63.BI "int mallctl(const\ char\ *" "name" ", void\ *" "oldp" ", size_t\ *" "oldlenp" ", void\ *" "newp" ", size_t\ " "newlen" ");"
64.HP \w'int\ mallctlnametomib('u
65.BI "int mallctlnametomib(const\ char\ *" "name" ", size_t\ *" "mibp" ", size_t\ *" "miblenp" ");"
66.HP \w'int\ mallctlbymib('u
67.BI "int mallctlbymib(const\ size_t\ *" "mib" ", size_t\ " "miblen" ", void\ *" "oldp" ", size_t\ *" "oldlenp" ", void\ *" "newp" ", size_t\ " "newlen" ");"
68.HP \w'void\ (*malloc_message)('u
69.BI "void (*malloc_message)(void\ *" "cbopaque" ", const\ char\ *" "s" ");"
70.PP
71const char *\fImalloc_conf\fR;
72.SS "Experimental API"
73.HP \w'int\ allocm('u
74.BI "int allocm(void\ **" "ptr" ", size_t\ *" "rsize" ", size_t\ " "size" ", int\ " "flags" ");"
75.HP \w'int\ rallocm('u
76.BI "int rallocm(void\ **" "ptr" ", size_t\ *" "rsize" ", size_t\ " "size" ", size_t\ " "extra" ", int\ " "flags" ");"
77.HP \w'int\ sallocm('u
78.BI "int sallocm(const\ void\ *" "ptr" ", size_t\ *" "rsize" ", int\ " "flags" ");"
79.HP \w'int\ dallocm('u
80.BI "int dallocm(void\ *" "ptr" ", int\ " "flags" ");"
ad4c0b41 81.HP \w'int\ nallocm('u
82.BI "int nallocm(size_t\ *" "rsize" ", size_t\ " "size" ", int\ " "flags" ");"
a78e148b 83.SH "DESCRIPTION"
84.SS "Standard API"
85.PP
86The
87\fBmalloc\fR\fB\fR
88function allocates
89\fIsize\fR
90bytes of uninitialized memory\&. The allocated space is suitably aligned (after possible pointer coercion) for storage of any type of object\&.
91.PP
92The
93\fBcalloc\fR\fB\fR
94function allocates space for
95\fInumber\fR
96objects, each
97\fIsize\fR
98bytes in length\&. The result is identical to calling
99\fBmalloc\fR\fB\fR
100with an argument of
101\fInumber\fR
102*
103\fIsize\fR, with the exception that the allocated memory is explicitly initialized to zero bytes\&.
104.PP
105The
106\fBposix_memalign\fR\fB\fR
107function allocates
108\fIsize\fR
109bytes of memory such that the allocation\*(Aqs base address is an even multiple of
110\fIalignment\fR, and returns the allocation in the value pointed to by
111\fIptr\fR\&. The requested
112\fIalignment\fR
113must be a power of 2 at least as large as
114sizeof(\fBvoid *\fR)\&.
115.PP
116The
ad4c0b41 117\fBaligned_alloc\fR\fB\fR
118function allocates
119\fIsize\fR
120bytes of memory such that the allocation\*(Aqs base address is an even multiple of
121\fIalignment\fR\&. The requested
122\fIalignment\fR
123must be a power of 2\&. Behavior is undefined if
124\fIsize\fR
125is not an integral multiple of
126\fIalignment\fR\&.
127.PP
128The
a78e148b 129\fBrealloc\fR\fB\fR
130function changes the size of the previously allocated memory referenced by
131\fIptr\fR
132to
133\fIsize\fR
134bytes\&. 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
135\fIptr\fR
136is freed and a pointer to the newly allocated memory is returned\&. Note that
137\fBrealloc\fR\fB\fR
138may move the memory allocation, resulting in a different return value than
139\fIptr\fR\&. If
140\fIptr\fR
141is
142\fBNULL\fR, the
143\fBrealloc\fR\fB\fR
144function behaves identically to
145\fBmalloc\fR\fB\fR
146for the specified size\&.
147.PP
148The
149\fBfree\fR\fB\fR
150function causes the allocated memory referenced by
151\fIptr\fR
152to be made available for future allocations\&. If
153\fIptr\fR
154is
155\fBNULL\fR, no action occurs\&.
156.SS "Non\-standard API"
157.PP
158The
159\fBmalloc_usable_size\fR\fB\fR
160function returns the usable size of the allocation pointed to by
161\fIptr\fR\&. The return value may be larger than the size that was requested during allocation\&. The
162\fBmalloc_usable_size\fR\fB\fR
163function is not a mechanism for in\-place
164\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
165\fBmalloc_usable_size\fR\fB\fR
166should not be depended on, since such behavior is entirely implementation\-dependent\&.
167.PP
168The
169\fBmalloc_stats_print\fR\fB\fR
170function writes human\-readable summary statistics via the
171\fIwrite_cb\fR
172callback function pointer and
173\fIcbopaque\fR
174data passed to
175\fIwrite_cb\fR, or
176\fBmalloc_message\fR\fB\fR
177if
178\fIwrite_cb\fR
179is
180\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
181\fIopts\fR
182string\&. Note that
183\fBmalloc_message\fR\fB\fR
184uses the
185\fBmallctl*\fR\fB\fR
186functions internally, so inconsistent statistics can be reported if multiple threads use these functions simultaneously\&. If
187\fB\-\-enable\-stats\fR
188is specified during configuration, \(lqm\(rq and \(lqa\(rq can be specified to omit merged arena and per arena statistics, respectively; \(lqb\(rq and \(lql\(rq can be specified to omit per size class statistics for bins and large 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\&.
189.PP
190The
191\fBmallctl\fR\fB\fR
192function provides a general interface for introspecting the memory allocator, as well as setting modifiable parameters and triggering actions\&. The period\-separated
193\fIname\fR
194argument specifies a location in a tree\-structured namespace; see the
195MALLCTL NAMESPACE
196section for documentation on the tree contents\&. To read a value, pass a pointer via
197\fIoldp\fR
198to adequate space to contain the value, and a pointer to its length via
199\fIoldlenp\fR; otherwise pass
200\fBNULL\fR
201and
202\fBNULL\fR\&. Similarly, to write a value, pass a pointer to the value via
203\fInewp\fR, and its length via
204\fInewlen\fR; otherwise pass
205\fBNULL\fR
206and
207\fB0\fR\&.
208.PP
209The
210\fBmallctlnametomib\fR\fB\fR
211function 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
212\fBmallctlbymib\fR\fB\fR\&. Upon successful return from
213\fBmallctlnametomib\fR\fB\fR,
214\fImibp\fR
215contains an array of
216\fI*miblenp\fR
217integers, where
218\fI*miblenp\fR
219is the lesser of the number of components in
220\fIname\fR
221and the input value of
222\fI*miblenp\fR\&. Thus it is possible to pass a
223\fI*miblenp\fR
224that 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
225"arenas\&.bin\&.2\&.size"), the corresponding MIB component will always be that integer\&. Therefore, it is legitimate to construct code like the following:
226.sp
227.if n \{\
228.RS 4
229.\}
230.nf
231unsigned nbins, i;
232
233int mib[4];
234size_t len, miblen;
235
236len = sizeof(nbins);
237mallctl("arenas\&.nbins", &nbins, &len, NULL, 0);
238
239miblen = 4;
240mallnametomib("arenas\&.bin\&.0\&.size", mib, &miblen);
241for (i = 0; i < nbins; i++) {
242 size_t bin_size;
243
244 mib[2] = i;
245 len = sizeof(bin_size);
246 mallctlbymib(mib, miblen, &bin_size, &len, NULL, 0);
247 /* Do something with bin_size\&.\&.\&. */
248}
249.fi
250.if n \{\
251.RE
252.\}
253.SS "Experimental API"
254.PP
ad4c0b41 255The experimental API is subject to change or removal without regard for backward compatibility\&. If
256\fB\-\-disable\-experimental\fR
257is specified during configuration, the experimental API is omitted\&.
a78e148b 258.PP
259The
260\fBallocm\fR\fB\fR,
261\fBrallocm\fR\fB\fR,
ad4c0b41 262\fBsallocm\fR\fB\fR,
263\fBdallocm\fR\fB\fR, and
264\fBnallocm\fR\fB\fR
a78e148b 265functions all have a
266\fIflags\fR
267argument 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:
268.PP
269\fBALLOCM_LG_ALIGN(\fR\fB\fIla\fR\fR\fB) \fR
270.RS 4
271Align the memory allocation to start at an address that is a multiple of
272(1 << \fIla\fR)\&. This macro does not validate that
273\fIla\fR
274is within the valid range\&.
275.RE
276.PP
277\fBALLOCM_ALIGN(\fR\fB\fIa\fR\fR\fB) \fR
278.RS 4
279Align the memory allocation to start at an address that is a multiple of
280\fIa\fR, where
281\fIa\fR
282is a power of two\&. This macro does not validate that
283\fIa\fR
284is a power of 2\&.
285.RE
286.PP
287\fBALLOCM_ZERO\fR
288.RS 4
289Initialize 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 option is absent, newly allocated memory is uninitialized\&.
290.RE
291.PP
292\fBALLOCM_NO_MOVE\fR
293.RS 4
294For reallocation, fail rather than moving the object\&. This constraint can apply to both growth and shrinkage\&.
295.RE
296.PP
297The
298\fBallocm\fR\fB\fR
299function allocates at least
300\fIsize\fR
301bytes of memory, sets
302\fI*ptr\fR
303to the base address of the allocation, and sets
304\fI*rsize\fR
305to the real size of the allocation if
306\fIrsize\fR
307is not
ad4c0b41 308\fBNULL\fR\&. Behavior is undefined if
309\fIsize\fR
310is
311\fB0\fR\&.
a78e148b 312.PP
313The
314\fBrallocm\fR\fB\fR
315function resizes the allocation at
316\fI*ptr\fR
317to be at least
318\fIsize\fR
319bytes, sets
320\fI*ptr\fR
321to the base address of the allocation if it moved, and sets
322\fI*rsize\fR
323to the real size of the allocation if
324\fIrsize\fR
325is not
326\fBNULL\fR\&. If
327\fIextra\fR
328is non\-zero, an attempt is made to resize the allocation to be at least
329\fIsize\fR + \fIextra\fR)
330bytes, though inability to allocate the extra byte(s) will not by itself result in failure\&. Behavior is undefined if
ad4c0b41 331\fIsize\fR
332is
333\fB0\fR, or if
a78e148b 334(\fIsize\fR + \fIextra\fR > \fBSIZE_T_MAX\fR)\&.
335.PP
336The
337\fBsallocm\fR\fB\fR
338function sets
339\fI*rsize\fR
340to the real size of the allocation\&.
341.PP
342The
343\fBdallocm\fR\fB\fR
344function causes the memory referenced by
345\fIptr\fR
346to be made available for future allocations\&.
ad4c0b41 347.PP
348The
349\fBnallocm\fR\fB\fR
350function allocates no memory, but it performs the same size computation as the
351\fBallocm\fR\fB\fR
352function, and if
353\fIrsize\fR
354is not
355\fBNULL\fR
356it sets
357\fI*rsize\fR
358to the real size of the allocation that would result from the equivalent
359\fBallocm\fR\fB\fR
360function call\&. Behavior is undefined if
361\fIsize\fR
362is
363\fB0\fR\&.
a78e148b 364.SH "TUNING"
365.PP
366Once, 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\&.
367.PP
368The string pointed to by the global variable
369\fImalloc_conf\fR, the \(lqname\(rq of the file referenced by the symbolic link named
370/etc/malloc\&.conf, and the value of the environment variable
371\fBMALLOC_CONF\fR, will be interpreted, in that order, from left to right as options\&.
372.PP
373An options string is a comma\-separated list of option:value pairs\&. There is one key corresponding to each
374"opt\&.*"
375mallctl (see the
376MALLCTL NAMESPACE
377section for options documentation)\&. For example,
378abort:true,narenas:1
379sets the
380"opt\&.abort"
381and
382"opt\&.narenas"
383options\&. 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\&.
384.SH "IMPLEMENTATION NOTES"
385.PP
386Traditionally, allocators have used
387\fBsbrk\fR(2)
388to obtain memory, which is suboptimal for several reasons, including race conditions, increased fragmentation, and artificial limitations on maximum usable memory\&. If
389\fB\-\-enable\-dss\fR
390is specified during configuration, this allocator uses both
ad4c0b41 391\fBmmap\fR(2)
a78e148b 392and
ad4c0b41 393\fBsbrk\fR(2), in that order of preference; otherwise only
a78e148b 394\fBmmap\fR(2)
395is used\&.
396.PP
397This 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\&.
398.PP
399In addition to multiple arenas, unless
400\fB\-\-disable\-tcache\fR
401is 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\&.
402.PP
403Memory 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\&.
404.PP
405User objects are broken into three categories according to size: small, large, and huge\&. Small objects are smaller than one page\&. Large objects are smaller than the chunk size\&. Huge objects are a multiple of the chunk size\&. Small and large objects are managed by arenas; huge objects are managed separately in a single data structure that is shared by all threads\&. Huge objects are used by applications infrequently enough that this single data structure is not a scalability issue\&.
406.PP
407Each 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\&.
408.PP
ad4c0b41 409Small objects are managed in groups by page runs\&. Each run maintains a frontier and free list 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
410sizeof(\fBdouble\fR)\&. All other small object size classes are multiples of the quantum, spaced such that internal fragmentation is limited to approximately 25% for all but the smallest size classes\&. Allocation requests that are larger than the maximum small size class, but small enough to fit in an arena\-managed chunk (see the
a78e148b 411"opt\&.lg_chunk"
412option), are rounded up to the nearest run size\&. Allocation requests that are too large to fit in an arena\-managed chunk are rounded up to the nearest multiple of the chunk size\&.
413.PP
414Allocations 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\&.
415.PP
416Assuming 4 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
417Table 1\&.
418.sp
419.it 1 an-trap
420.nr an-no-space-flag 1
421.nr an-break-flag 1
422.br
423.B Table\ \&1.\ \&Size classes
424.TS
425allbox tab(:);
ad4c0b41 426lB rB lB.
a78e148b 427T{
428Category
429T}:T{
ad4c0b41 430Spacing
a78e148b 431T}:T{
432Size
433T}
434.T&
ad4c0b41 435l r l
436^ r l
437^ r l
438^ r l
439^ r l
440^ r l
441^ r l
442l r l
443l r l.
a78e148b 444T{
445Small
446T}:T{
ad4c0b41 447lg
a78e148b 448T}:T{
449[8]
450T}
451:T{
ad4c0b41 45216
a78e148b 453T}:T{
454[16, 32, 48, \&.\&.\&., 128]
455T}
456:T{
ad4c0b41 45732
458T}:T{
459[160, 192, 224, 256]
460T}
461:T{
46264
463T}:T{
464[320, 384, 448, 512]
465T}
466:T{
467128
468T}:T{
469[640, 768, 896, 1024]
470T}
471:T{
472256
a78e148b 473T}:T{
ad4c0b41 474[1280, 1536, 1792, 2048]
a78e148b 475T}
476:T{
ad4c0b41 477512
a78e148b 478T}:T{
ad4c0b41 479[2560, 3072, 3584]
a78e148b 480T}
481T{
482Large
483T}:T{
ad4c0b41 4844 KiB
485T}:T{
a78e148b 486[4 KiB, 8 KiB, 12 KiB, \&.\&.\&., 4072 KiB]
487T}
488T{
489Huge
490T}:T{
ad4c0b41 4914 MiB
492T}:T{
a78e148b 493[4 MiB, 8 MiB, 12 MiB, \&.\&.\&.]
494T}
495.TE
496.sp 1
497.SH "MALLCTL NAMESPACE"
498.PP
499The following names are defined in the namespace accessible via the
500\fBmallctl*\fR\fB\fR
501functions\&. Value types are specified in parentheses, their readable/writable statuses are encoded as
502rw,
503r\-,
504\-w, or
505\-\-, and required build configuration flags follow, if any\&. A name element encoded as
506<i>
507or
508<j>
509indicates an integer component, where the integer varies from 0 to some upper value that must be determined via introspection\&. In the case of
510"stats\&.arenas\&.<i>\&.*",
511<i>
512equal to
513"arenas\&.narenas"
514can be used to access the summation of statistics from all arenas\&. Take special note of the
515"epoch"
516mallctl, which controls refreshing of cached dynamic statistics\&.
517.PP
518"version" (\fBconst char *\fR) r\-
519.RS 4
520Return the jemalloc version string\&.
521.RE
522.PP
523"epoch" (\fBuint64_t\fR) rw
524.RS 4
525If a value is passed in, refresh the data from which the
526\fBmallctl*\fR\fB\fR
527functions report values, and increment the epoch\&. Return the current epoch\&. This is useful for detecting whether another thread caused a refresh\&.
528.RE
529.PP
530"config\&.debug" (\fBbool\fR) r\-
531.RS 4
532\fB\-\-enable\-debug\fR
533was specified during build configuration\&.
534.RE
535.PP
536"config\&.dss" (\fBbool\fR) r\-
537.RS 4
538\fB\-\-enable\-dss\fR
539was specified during build configuration\&.
540.RE
541.PP
a78e148b 542"config\&.fill" (\fBbool\fR) r\-
543.RS 4
544\fB\-\-enable\-fill\fR
545was specified during build configuration\&.
546.RE
547.PP
548"config\&.lazy_lock" (\fBbool\fR) r\-
549.RS 4
550\fB\-\-enable\-lazy\-lock\fR
551was specified during build configuration\&.
552.RE
553.PP
ad4c0b41 554"config\&.mremap" (\fBbool\fR) r\-
555.RS 4
556\fB\-\-enable\-mremap\fR
557was specified during build configuration\&.
558.RE
559.PP
560"config\&.munmap" (\fBbool\fR) r\-
561.RS 4
562\fB\-\-enable\-munmap\fR
563was specified during build configuration\&.
564.RE
565.PP
a78e148b 566"config\&.prof" (\fBbool\fR) r\-
567.RS 4
568\fB\-\-enable\-prof\fR
569was specified during build configuration\&.
570.RE
571.PP
572"config\&.prof_libgcc" (\fBbool\fR) r\-
573.RS 4
574\fB\-\-disable\-prof\-libgcc\fR
575was not specified during build configuration\&.
576.RE
577.PP
578"config\&.prof_libunwind" (\fBbool\fR) r\-
579.RS 4
580\fB\-\-enable\-prof\-libunwind\fR
581was specified during build configuration\&.
582.RE
583.PP
584"config\&.stats" (\fBbool\fR) r\-
585.RS 4
586\fB\-\-enable\-stats\fR
587was specified during build configuration\&.
588.RE
589.PP
a78e148b 590"config\&.tcache" (\fBbool\fR) r\-
591.RS 4
592\fB\-\-disable\-tcache\fR
593was not specified during build configuration\&.
594.RE
595.PP
ad4c0b41 596"config\&.tls" (\fBbool\fR) r\-
a78e148b 597.RS 4
ad4c0b41 598\fB\-\-disable\-tls\fR
a78e148b 599was not specified during build configuration\&.
600.RE
601.PP
ad4c0b41 602"config\&.utrace" (\fBbool\fR) r\-
a78e148b 603.RS 4
ad4c0b41 604\fB\-\-enable\-utrace\fR
605was specified during build configuration\&.
606.RE
607.PP
608"config\&.valgrind" (\fBbool\fR) r\-
609.RS 4
610\fB\-\-enable\-valgrind\fR
611was specified during build configuration\&.
a78e148b 612.RE
613.PP
614"config\&.xmalloc" (\fBbool\fR) r\-
615.RS 4
616\fB\-\-enable\-xmalloc\fR
617was specified during build configuration\&.
618.RE
619.PP
620"opt\&.abort" (\fBbool\fR) r\-
621.RS 4
622Abort\-on\-warning enabled/disabled\&. If true, most warnings are fatal\&. The process will call
623\fBabort\fR(3)
624in these cases\&. This option is disabled by default unless
625\fB\-\-enable\-debug\fR
626is specified during configuration, in which case it is enabled by default\&.
627.RE
628.PP
a78e148b 629"opt\&.lg_chunk" (\fBsize_t\fR) r\-
630.RS 4
631Virtual memory chunk size (log base 2)\&. The default chunk size is 4 MiB (2^22)\&.
632.RE
633.PP
634"opt\&.narenas" (\fBsize_t\fR) r\-
635.RS 4
636Maximum number of arenas to use\&. The default maximum number of arenas is four times the number of CPUs, or one if there is a single CPU\&.
637.RE
638.PP
639"opt\&.lg_dirty_mult" (\fBssize_t\fR) r\-
640.RS 4
641Per\-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
642\fBmadvise\fR(2)
643or 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 32:1 (2^5:1); an option value of \-1 will disable dirty page purging\&.
644.RE
645.PP
646"opt\&.stats_print" (\fBbool\fR) r\-
647.RS 4
648Enable/disable statistics printing at exit\&. If enabled, the
649\fBmalloc_stats_print\fR\fB\fR
650function is called at program exit via an
651\fBatexit\fR(3)
652function\&. If
653\fB\-\-enable\-stats\fR
654is 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\&. 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\&.
655.RE
656.PP
657"opt\&.junk" (\fBbool\fR) r\- [\fB\-\-enable\-fill\fR]
658.RS 4
659Junk filling enabled/disabled\&. If enabled, each byte of uninitialized allocated memory will be initialized to
6600xa5\&. All deallocated memory will be initialized to
6610x5a\&. This is intended for debugging and will impact performance negatively\&. This option is disabled by default unless
662\fB\-\-enable\-debug\fR
663is specified during configuration, in which case it is enabled by default\&.
664.RE
665.PP
ad4c0b41 666"opt\&.quarantine" (\fBsize_t\fR) r\- [\fB\-\-enable\-fill\fR]
667.RS 4
668Per 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
669"opt\&.junk"
670option is enabled\&. This feature is of particular use in combination with
671\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\&.
672.RE
673.PP
674"opt\&.redzone" (\fBbool\fR) r\- [\fB\-\-enable\-fill\fR]
675.RS 4
676Redzones enabled/disabled\&. If enabled, small allocations have redzones before and after them\&. Furthermore, if the
677"opt\&.junk"
678option 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
679\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\&.
680.RE
681.PP
a78e148b 682"opt\&.zero" (\fBbool\fR) r\- [\fB\-\-enable\-fill\fR]
683.RS 4
684Zero 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
685\fBrealloc\fR\fB\fR
686and
687\fBrallocm\fR\fB\fR
688calls do not zero memory that was previously allocated\&. This is intended for debugging and will impact performance negatively\&. This option is disabled by default\&.
689.RE
690.PP
ad4c0b41 691"opt\&.utrace" (\fBbool\fR) r\- [\fB\-\-enable\-utrace\fR]
a78e148b 692.RS 4
ad4c0b41 693Allocation tracing based on
694\fButrace\fR(2)
695enabled/disabled\&. This option is disabled by default\&.
696.RE
697.PP
698"opt\&.valgrind" (\fBbool\fR) r\- [\fB\-\-enable\-valgrind\fR]
699.RS 4
700\m[blue]\fBValgrind\fR\m[]\&\s-2\u[2]\d\s+2
701support enabled/disabled\&. If enabled, several other options are automatically modified during options processing to work well with Valgrind:
702"opt\&.junk"
703and
704"opt\&.zero"
705are set to false,
706"opt\&.quarantine"
707is set to 16 MiB, and
708"opt\&.redzone"
709is set to true\&. This option is disabled by default\&.
a78e148b 710.RE
711.PP
712"opt\&.xmalloc" (\fBbool\fR) r\- [\fB\-\-enable\-xmalloc\fR]
713.RS 4
714Abort\-on\-out\-of\-memory enabled/disabled\&. If enabled, rather than returning failure for any allocation function, display a diagnostic message on
715\fBSTDERR_FILENO\fR
716and cause the program to drop core (using
717\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:
718.sp
719.if n \{\
720.RS 4
721.\}
722.nf
723malloc_conf = "xmalloc:true";
724.fi
725.if n \{\
726.RE
727.\}
728.sp
729This option is disabled by default\&.
730.RE
731.PP
732"opt\&.tcache" (\fBbool\fR) r\- [\fB\-\-enable\-tcache\fR]
733.RS 4
734Thread\-specific caching enabled/disabled\&. When there are multiple threads, each thread uses a thread\-specific cache 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
a78e148b 735"opt\&.lg_tcache_max"
ad4c0b41 736option for related tuning information\&. This option is enabled by default\&.
a78e148b 737.RE
738.PP
739"opt\&.lg_tcache_max" (\fBsize_t\fR) r\- [\fB\-\-enable\-tcache\fR]
740.RS 4
741Maximum size class (log base 2) to cache in the thread\-specific cache\&. 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)\&.
742.RE
743.PP
744"opt\&.prof" (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
745.RS 4
ad4c0b41 746Memory profiling enabled/disabled\&. If enabled, profile memory allocation activity\&. See the
a78e148b 747"opt\&.prof_active"
748option for on\-the\-fly activation/deactivation\&. See the
749"opt\&.lg_prof_sample"
750option for probabilistic sampling control\&. See the
751"opt\&.prof_accum"
752option for control of cumulative sample reporting\&. See the
a78e148b 753"opt\&.lg_prof_interval"
ad4c0b41 754option for information on interval\-triggered profile dumping, the
a78e148b 755"opt\&.prof_gdump"
ad4c0b41 756option for information on high\-water\-triggered profile dumping, and the
757"opt\&.prof_final"
758option for final profile dumping\&. Profile output is compatible with the included
a78e148b 759\fBpprof\fR
760Perl script, which originates from the
ad4c0b41 761\m[blue]\fBgperftools package\fR\m[]\&\s-2\u[3]\d\s+2\&.
a78e148b 762.RE
763.PP
764"opt\&.prof_prefix" (\fBconst char *\fR) r\- [\fB\-\-enable\-prof\fR]
765.RS 4
766Filename 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
767jeprof\&.
768.RE
769.PP
a78e148b 770"opt\&.prof_active" (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
771.RS 4
772Profiling activated/deactivated\&. This is a secondary control mechanism that makes it possible to start the application with profiling enabled (see the
773"opt\&.prof"
774option) but inactive, then toggle profiling at any time during program execution with the
775"prof\&.active"
776mallctl\&. This option is enabled by default\&.
777.RE
778.PP
779"opt\&.lg_prof_sample" (\fBssize_t\fR) r\- [\fB\-\-enable\-prof\fR]
780.RS 4
ad4c0b41 781Average 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)\&.
a78e148b 782.RE
783.PP
784"opt\&.prof_accum" (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
785.RS 4
ad4c0b41 786Reporting 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\&.
a78e148b 787.RE
788.PP
789"opt\&.lg_prof_interval" (\fBssize_t\fR) r\- [\fB\-\-enable\-prof\fR]
790.RS 4
791Average 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
792<prefix>\&.<pid>\&.<seq>\&.i<iseq>\&.heap, where
793<prefix>
794is controlled by the
795"opt\&.prof_prefix"
796option\&. By default, interval\-triggered profile dumping is disabled (encoded as \-1)\&.
797.RE
798.PP
799"opt\&.prof_gdump" (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
800.RS 4
801Trigger a memory profile dump every time the total virtual memory exceeds the previous maximum\&. Profiles are dumped to files named according to the pattern
802<prefix>\&.<pid>\&.<seq>\&.u<useq>\&.heap, where
803<prefix>
804is controlled by the
805"opt\&.prof_prefix"
806option\&. This option is disabled by default\&.
807.RE
808.PP
ad4c0b41 809"opt\&.prof_final" (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
810.RS 4
811Use an
812\fBatexit\fR(3)
813function to dump final memory usage to a file named according to the pattern
814<prefix>\&.<pid>\&.<seq>\&.f\&.heap, where
815<prefix>
816is controlled by the
817"opt\&.prof_prefix"
818option\&. This option is enabled by default\&.
819.RE
820.PP
a78e148b 821"opt\&.prof_leak" (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
822.RS 4
823Leak reporting enabled/disabled\&. If enabled, use an
824\fBatexit\fR(3)
825function to report memory leaks detected by allocation sampling\&. See the
a78e148b 826"opt\&.prof"
827option for information on analyzing heap profile output\&. This option is disabled by default\&.
828.RE
829.PP
a78e148b 830"thread\&.arena" (\fBunsigned\fR) rw
831.RS 4
832Get or set the arena associated with the calling thread\&. The arena index must be less than the maximum number of arenas (see the
833"arenas\&.narenas"
834mallctl)\&. If the specified arena was not initialized beforehand (see the
835"arenas\&.initialized"
836mallctl), it will be automatically initialized as a side effect of calling this interface\&.
837.RE
838.PP
839"thread\&.allocated" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
840.RS 4
841Get 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\&.
842.RE
843.PP
844"thread\&.allocatedp" (\fBuint64_t *\fR) r\- [\fB\-\-enable\-stats\fR]
845.RS 4
846Get a pointer to the the value that is returned by the
847"thread\&.allocated"
848mallctl\&. This is useful for avoiding the overhead of repeated
849\fBmallctl*\fR\fB\fR
850calls\&.
851.RE
852.PP
853"thread\&.deallocated" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
854.RS 4
855Get 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\&.
856.RE
857.PP
858"thread\&.deallocatedp" (\fBuint64_t *\fR) r\- [\fB\-\-enable\-stats\fR]
859.RS 4
860Get a pointer to the the value that is returned by the
861"thread\&.deallocated"
862mallctl\&. This is useful for avoiding the overhead of repeated
863\fBmallctl*\fR\fB\fR
864calls\&.
865.RE
866.PP
ad4c0b41 867"thread\&.tcache\&.enabled" (\fBbool\fR) rw [\fB\-\-enable\-tcache\fR]
868.RS 4
869Enable/disable calling thread\*(Aqs tcache\&. The tcache is implicitly flushed as a side effect of becoming disabled (see
870"thread\&.tcache\&.flush")\&.
871.RE
872.PP
873"thread\&.tcache\&.flush" (\fBvoid\fR) \-\- [\fB\-\-enable\-tcache\fR]
874.RS 4
875Flush calling thread\*(Aqs tcache\&. This interface releases all cached objects and internal data structures associated with the calling thread\*(Aqs thread\-specific cache\&. 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\&.
876.RE
877.PP
a78e148b 878"arenas\&.narenas" (\fBunsigned\fR) r\-
879.RS 4
880Maximum number of arenas\&.
881.RE
882.PP
883"arenas\&.initialized" (\fBbool *\fR) r\-
884.RS 4
885An array of
886"arenas\&.narenas"
887booleans\&. Each boolean indicates whether the corresponding arena is initialized\&.
888.RE
889.PP
890"arenas\&.quantum" (\fBsize_t\fR) r\-
891.RS 4
892Quantum size\&.
893.RE
894.PP
ad4c0b41 895"arenas\&.page" (\fBsize_t\fR) r\-
a78e148b 896.RS 4
897Page size\&.
898.RE
899.PP
a78e148b 900"arenas\&.tcache_max" (\fBsize_t\fR) r\- [\fB\-\-enable\-tcache\fR]
901.RS 4
902Maximum thread\-cached size class\&.
903.RE
904.PP
a78e148b 905"arenas\&.nbins" (\fBunsigned\fR) r\-
906.RS 4
ad4c0b41 907Number of bin size classes\&.
a78e148b 908.RE
909.PP
910"arenas\&.nhbins" (\fBunsigned\fR) r\- [\fB\-\-enable\-tcache\fR]
911.RS 4
912Total number of thread cache bin size classes\&.
913.RE
914.PP
915"arenas\&.bin\&.<i>\&.size" (\fBsize_t\fR) r\-
916.RS 4
917Maximum size supported by size class\&.
918.RE
919.PP
920"arenas\&.bin\&.<i>\&.nregs" (\fBuint32_t\fR) r\-
921.RS 4
922Number of regions per page run\&.
923.RE
924.PP
925"arenas\&.bin\&.<i>\&.run_size" (\fBsize_t\fR) r\-
926.RS 4
927Number of bytes per page run\&.
928.RE
929.PP
930"arenas\&.nlruns" (\fBsize_t\fR) r\-
931.RS 4
932Total number of large size classes\&.
933.RE
934.PP
935"arenas\&.lrun\&.<i>\&.size" (\fBsize_t\fR) r\-
936.RS 4
937Maximum size supported by this large size class\&.
938.RE
939.PP
940"arenas\&.purge" (\fBunsigned\fR) \-w
941.RS 4
942Purge unused dirty pages for the specified arena, or for all arenas if none is specified\&.
943.RE
944.PP
945"prof\&.active" (\fBbool\fR) rw [\fB\-\-enable\-prof\fR]
946.RS 4
947Control whether sampling is currently active\&. See the
948"opt\&.prof_active"
949option for additional information\&.
950.RE
951.PP
952"prof\&.dump" (\fBconst char *\fR) \-w [\fB\-\-enable\-prof\fR]
953.RS 4
954Dump a memory profile to the specified file, or if NULL is specified, to a file according to the pattern
955<prefix>\&.<pid>\&.<seq>\&.m<mseq>\&.heap, where
956<prefix>
957is controlled by the
958"opt\&.prof_prefix"
959option\&.
960.RE
961.PP
962"prof\&.interval" (\fBuint64_t\fR) r\- [\fB\-\-enable\-prof\fR]
963.RS 4
964Average number of bytes allocated between inverval\-based profile dumps\&. See the
965"opt\&.lg_prof_interval"
966option for additional information\&.
967.RE
968.PP
969"stats\&.cactive" (\fBsize_t *\fR) r\- [\fB\-\-enable\-stats\fR]
970.RS 4
971Pointer 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 to the nearest multiple of the chunk size when computing its contribution to the counter\&. Note that the
972"epoch"
973mallctl 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\&.
974.RE
975.PP
976"stats\&.allocated" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
977.RS 4
978Total number of bytes allocated by the application\&.
979.RE
980.PP
981"stats\&.active" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
982.RS 4
983Total number of bytes in active pages allocated by the application\&. This is a multiple of the page size, and greater than or equal to
984"stats\&.allocated"\&.
985.RE
986.PP
987"stats\&.mapped" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
988.RS 4
989Total number of bytes in chunks mapped on behalf of the application\&. This is a multiple of the chunk size, and is at least as large as
ad4c0b41 990"stats\&.active"\&. This does not include inactive chunks\&.
a78e148b 991.RE
992.PP
993"stats\&.chunks\&.current" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
994.RS 4
ad4c0b41 995Total number of chunks actively mapped on behalf of the application\&. This does not include inactive chunks\&.
a78e148b 996.RE
997.PP
998"stats\&.chunks\&.total" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
999.RS 4
1000Cumulative number of chunks allocated\&.
1001.RE
1002.PP
1003"stats\&.chunks\&.high" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1004.RS 4
1005Maximum number of active chunks at any time thus far\&.
1006.RE
1007.PP
1008"stats\&.huge\&.allocated" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1009.RS 4
1010Number of bytes currently allocated by huge objects\&.
1011.RE
1012.PP
1013"stats\&.huge\&.nmalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1014.RS 4
1015Cumulative number of huge allocation requests\&.
1016.RE
1017.PP
1018"stats\&.huge\&.ndalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1019.RS 4
1020Cumulative number of huge deallocation requests\&.
1021.RE
1022.PP
1023"stats\&.arenas\&.<i>\&.nthreads" (\fBunsigned\fR) r\-
1024.RS 4
1025Number of threads currently assigned to arena\&.
1026.RE
1027.PP
1028"stats\&.arenas\&.<i>\&.pactive" (\fBsize_t\fR) r\-
1029.RS 4
1030Number of pages in active runs\&.
1031.RE
1032.PP
1033"stats\&.arenas\&.<i>\&.pdirty" (\fBsize_t\fR) r\-
1034.RS 4
1035Number of pages within unused runs that are potentially dirty, and for which
1036\fBmadvise\fR\fB\fI\&.\&.\&.\fR\fR\fB \fR\fB\fI\fBMADV_DONTNEED\fR\fR\fR
1037or similar has not been called\&.
1038.RE
1039.PP
1040"stats\&.arenas\&.<i>\&.mapped" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1041.RS 4
1042Number of mapped bytes\&.
1043.RE
1044.PP
1045"stats\&.arenas\&.<i>\&.npurge" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1046.RS 4
1047Number of dirty page purge sweeps performed\&.
1048.RE
1049.PP
1050"stats\&.arenas\&.<i>\&.nmadvise" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1051.RS 4
1052Number of
1053\fBmadvise\fR\fB\fI\&.\&.\&.\fR\fR\fB \fR\fB\fI\fBMADV_DONTNEED\fR\fR\fR
1054or similar calls made to purge dirty pages\&.
1055.RE
1056.PP
1057"stats\&.arenas\&.<i>\&.npurged" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1058.RS 4
1059Number of pages purged\&.
1060.RE
1061.PP
1062"stats\&.arenas\&.<i>\&.small\&.allocated" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1063.RS 4
1064Number of bytes currently allocated by small objects\&.
1065.RE
1066.PP
1067"stats\&.arenas\&.<i>\&.small\&.nmalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1068.RS 4
1069Cumulative number of allocation requests served by small bins\&.
1070.RE
1071.PP
1072"stats\&.arenas\&.<i>\&.small\&.ndalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1073.RS 4
1074Cumulative number of small objects returned to bins\&.
1075.RE
1076.PP
1077"stats\&.arenas\&.<i>\&.small\&.nrequests" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1078.RS 4
1079Cumulative number of small allocation requests\&.
1080.RE
1081.PP
1082"stats\&.arenas\&.<i>\&.large\&.allocated" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1083.RS 4
1084Number of bytes currently allocated by large objects\&.
1085.RE
1086.PP
1087"stats\&.arenas\&.<i>\&.large\&.nmalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1088.RS 4
1089Cumulative number of large allocation requests served directly by the arena\&.
1090.RE
1091.PP
1092"stats\&.arenas\&.<i>\&.large\&.ndalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1093.RS 4
1094Cumulative number of large deallocation requests served directly by the arena\&.
1095.RE
1096.PP
1097"stats\&.arenas\&.<i>\&.large\&.nrequests" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1098.RS 4
1099Cumulative number of large allocation requests\&.
1100.RE
1101.PP
1102"stats\&.arenas\&.<i>\&.bins\&.<j>\&.allocated" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1103.RS 4
1104Current number of bytes allocated by bin\&.
1105.RE
1106.PP
1107"stats\&.arenas\&.<i>\&.bins\&.<j>\&.nmalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1108.RS 4
1109Cumulative number of allocations served by bin\&.
1110.RE
1111.PP
1112"stats\&.arenas\&.<i>\&.bins\&.<j>\&.ndalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1113.RS 4
1114Cumulative number of allocations returned to bin\&.
1115.RE
1116.PP
1117"stats\&.arenas\&.<i>\&.bins\&.<j>\&.nrequests" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1118.RS 4
1119Cumulative number of allocation requests\&.
1120.RE
1121.PP
1122"stats\&.arenas\&.<i>\&.bins\&.<j>\&.nfills" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR \fB\-\-enable\-tcache\fR]
1123.RS 4
1124Cumulative number of tcache fills\&.
1125.RE
1126.PP
1127"stats\&.arenas\&.<i>\&.bins\&.<j>\&.nflushes" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR \fB\-\-enable\-tcache\fR]
1128.RS 4
1129Cumulative number of tcache flushes\&.
1130.RE
1131.PP
1132"stats\&.arenas\&.<i>\&.bins\&.<j>\&.nruns" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1133.RS 4
1134Cumulative number of runs created\&.
1135.RE
1136.PP
1137"stats\&.arenas\&.<i>\&.bins\&.<j>\&.nreruns" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1138.RS 4
1139Cumulative number of times the current run from which to allocate changed\&.
1140.RE
1141.PP
a78e148b 1142"stats\&.arenas\&.<i>\&.bins\&.<j>\&.curruns" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1143.RS 4
1144Current number of runs\&.
1145.RE
1146.PP
1147"stats\&.arenas\&.<i>\&.lruns\&.<j>\&.nmalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1148.RS 4
1149Cumulative number of allocation requests for this size class served directly by the arena\&.
1150.RE
1151.PP
1152"stats\&.arenas\&.<i>\&.lruns\&.<j>\&.ndalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1153.RS 4
1154Cumulative number of deallocation requests for this size class served directly by the arena\&.
1155.RE
1156.PP
1157"stats\&.arenas\&.<i>\&.lruns\&.<j>\&.nrequests" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1158.RS 4
1159Cumulative number of allocation requests for this size class\&.
1160.RE
1161.PP
a78e148b 1162"stats\&.arenas\&.<i>\&.lruns\&.<j>\&.curruns" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1163.RS 4
1164Current number of runs for this size class\&.
1165.RE
a78e148b 1166.SH "DEBUGGING MALLOC PROBLEMS"
1167.PP
1168When debugging, it is a good idea to configure/build jemalloc with the
1169\fB\-\-enable\-debug\fR
1170and
1171\fB\-\-enable\-fill\fR
1172options, 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\&.
1173.PP
1174Programs often accidentally depend on \(lquninitialized\(rq memory actually being filled with zero bytes\&. Junk filling (see the
1175"opt\&.junk"
1176option) tends to expose such bugs in the form of obviously incorrect results and/or coredumps\&. Conversely, zero filling (see the
1177"opt\&.zero"
1178option) eliminates the symptoms of such bugs\&. Between these two options, it is usually possible to quickly detect, diagnose, and eliminate such bugs\&.
1179.PP
ad4c0b41 1180This 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
1181\m[blue]\fBValgrind\fR\m[]\&\s-2\u[2]\d\s+2
1182tool if the
1183\fB\-\-enable\-valgrind\fR
1184configuration option is enabled and the
1185"opt\&.valgrind"
1186option is enabled\&.
a78e148b 1187.SH "DIAGNOSTIC MESSAGES"
1188.PP
1189If any of the memory allocation/deallocation functions detect an error or warning condition, a message will be printed to file descriptor
1190\fBSTDERR_FILENO\fR\&. Errors will result in the process dumping core\&. If the
1191"opt\&.abort"
1192option is set, most warnings are treated as errors\&.
1193.PP
1194The
1195\fImalloc_message\fR
1196variable allows the programmer to override the function which emits the text strings forming the errors and warnings if for some reason the
1197\fBSTDERR_FILENO\fR
1198file descriptor is not suitable for this\&.
1199\fBmalloc_message\fR\fB\fR
1200takes the
1201\fIcbopaque\fR
1202pointer argument that is
1203\fBNULL\fR
1204unless overridden by the arguments in a call to
1205\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\&.
1206.PP
1207All messages are prefixed by \(lq<jemalloc>:\(rq\&.
1208.SH "RETURN VALUES"
1209.SS "Standard API"
1210.PP
1211The
1212\fBmalloc\fR\fB\fR
1213and
1214\fBcalloc\fR\fB\fR
1215functions return a pointer to the allocated memory if successful; otherwise a
1216\fBNULL\fR
1217pointer is returned and
1218\fIerrno\fR
1219is set to
1220ENOMEM\&.
1221.PP
1222The
1223\fBposix_memalign\fR\fB\fR
1224function returns the value 0 if successful; otherwise it returns an error value\&. The
1225\fBposix_memalign\fR\fB\fR
1226function will fail if:
1227.PP
1228EINVAL
1229.RS 4
1230The
1231\fIalignment\fR
1232parameter is not a power of 2 at least as large as
1233sizeof(\fBvoid *\fR)\&.
1234.RE
1235.PP
1236ENOMEM
1237.RS 4
1238Memory allocation error\&.
1239.RE
1240.PP
1241The
ad4c0b41 1242\fBaligned_alloc\fR\fB\fR
1243function returns a pointer to the allocated memory if successful; otherwise a
1244\fBNULL\fR
1245pointer is returned and
1246\fIerrno\fR
1247is set\&. The
1248\fBaligned_alloc\fR\fB\fR
1249function will fail if:
1250.PP
1251EINVAL
1252.RS 4
1253The
1254\fIalignment\fR
1255parameter is not a power of 2\&.
1256.RE
1257.PP
1258ENOMEM
1259.RS 4
1260Memory allocation error\&.
1261.RE
1262.PP
1263The
a78e148b 1264\fBrealloc\fR\fB\fR
1265function returns a pointer, possibly identical to
1266\fIptr\fR, to the allocated memory if successful; otherwise a
1267\fBNULL\fR
1268pointer is returned, and
1269\fIerrno\fR
1270is set to
1271ENOMEM
1272if the error was the result of an allocation failure\&. The
1273\fBrealloc\fR\fB\fR
1274function always leaves the original buffer intact when an error occurs\&.
1275.PP
1276The
1277\fBfree\fR\fB\fR
1278function returns no value\&.
1279.SS "Non\-standard API"
1280.PP
1281The
1282\fBmalloc_usable_size\fR\fB\fR
1283function returns the usable size of the allocation pointed to by
1284\fIptr\fR\&.
1285.PP
1286The
1287\fBmallctl\fR\fB\fR,
1288\fBmallctlnametomib\fR\fB\fR, and
1289\fBmallctlbymib\fR\fB\fR
1290functions return 0 on success; otherwise they return an error value\&. The functions will fail if:
1291.PP
1292EINVAL
1293.RS 4
1294\fInewp\fR
1295is not
1296\fBNULL\fR, and
1297\fInewlen\fR
1298is too large or too small\&. Alternatively,
1299\fI*oldlenp\fR
1300is too large or too small; in this case as much data as possible are read despite the error\&.
1301.RE
1302.PP
1303ENOMEM
1304.RS 4
1305\fI*oldlenp\fR
1306is too short to hold the requested value\&.
1307.RE
1308.PP
1309ENOENT
1310.RS 4
1311\fIname\fR
1312or
1313\fImib\fR
1314specifies an unknown/invalid value\&.
1315.RE
1316.PP
1317EPERM
1318.RS 4
1319Attempt to read or write void value, or attempt to write read\-only value\&.
1320.RE
1321.PP
1322EAGAIN
1323.RS 4
1324A memory allocation failure occurred\&.
1325.RE
1326.PP
1327EFAULT
1328.RS 4
1329An interface with side effects failed in some way not directly related to
1330\fBmallctl*\fR\fB\fR
1331read/write processing\&.
1332.RE
1333.SS "Experimental API"
1334.PP
1335The
1336\fBallocm\fR\fB\fR,
1337\fBrallocm\fR\fB\fR,
ad4c0b41 1338\fBsallocm\fR\fB\fR,
1339\fBdallocm\fR\fB\fR, and
1340\fBnallocm\fR\fB\fR
a78e148b 1341functions return
1342\fBALLOCM_SUCCESS\fR
1343on success; otherwise they return an error value\&. The
ad4c0b41 1344\fBallocm\fR\fB\fR,
1345\fBrallocm\fR\fB\fR, and
1346\fBnallocm\fR\fB\fR
a78e148b 1347functions will fail if:
1348.PP
1349ALLOCM_ERR_OOM
1350.RS 4
1351Out of memory\&. Insufficient contiguous memory was available to service the allocation request\&. The
1352\fBallocm\fR\fB\fR
1353function additionally sets
1354\fI*ptr\fR
1355to
1356\fBNULL\fR, whereas the
1357\fBrallocm\fR\fB\fR
1358function leaves
1359\fB*ptr\fR
1360unmodified\&.
1361.RE
1362The
1363\fBrallocm\fR\fB\fR
1364function will also fail if:
1365.PP
1366ALLOCM_ERR_NOT_MOVED
1367.RS 4
1368\fBALLOCM_NO_MOVE\fR
1369was specified, but the reallocation request could not be serviced without moving the object\&.
1370.RE
1371.SH "ENVIRONMENT"
1372.PP
1373The following environment variable affects the execution of the allocation functions:
1374.PP
1375\fBMALLOC_CONF\fR
1376.RS 4
1377If the environment variable
1378\fBMALLOC_CONF\fR
1379is set, the characters it contains will be interpreted as options\&.
1380.RE
1381.SH "EXAMPLES"
1382.PP
1383To dump core whenever a problem occurs:
1384.sp
1385.if n \{\
1386.RS 4
1387.\}
1388.nf
1389ln \-s \*(Aqabort:true\*(Aq /etc/malloc\&.conf
1390.fi
1391.if n \{\
1392.RE
1393.\}
1394.PP
1395To specify in the source a chunk size that is 16 MiB:
1396.sp
1397.if n \{\
1398.RS 4
1399.\}
1400.nf
1401malloc_conf = "lg_chunk:24";
1402.fi
1403.if n \{\
1404.RE
1405.\}
1406.SH "SEE ALSO"
1407.PP
1408\fBmadvise\fR(2),
1409\fBmmap\fR(2),
1410\fBsbrk\fR(2),
ad4c0b41 1411\fButrace\fR(2),
a78e148b 1412\fBalloca\fR(3),
1413\fBatexit\fR(3),
1414\fBgetpagesize\fR(3)
1415.SH "STANDARDS"
1416.PP
1417The
1418\fBmalloc\fR\fB\fR,
1419\fBcalloc\fR\fB\fR,
1420\fBrealloc\fR\fB\fR, and
1421\fBfree\fR\fB\fR
1422functions conform to ISO/IEC 9899:1990 (\(lqISO C90\(rq)\&.
1423.PP
1424The
1425\fBposix_memalign\fR\fB\fR
1426function conforms to IEEE Std 1003\&.1\-2001 (\(lqPOSIX\&.1\(rq)\&.
1427.SH "AUTHOR"
1428.PP
1429\fBJason Evans\fR
1430.RS 4
1431.RE
1432.SH "NOTES"
1433.IP " 1." 4
1434jemalloc website
1435.RS 4
1436\%http://www.canonware.com/jemalloc/
1437.RE
1438.IP " 2." 4
ad4c0b41 1439Valgrind
1440.RS 4
1441\%http://valgrind.org/
1442.RE
1443.IP " 3." 4
1444gperftools package
a78e148b 1445.RS 4
ad4c0b41 1446\%http://code.google.com/p/gperftools/
a78e148b 1447.RE