]> git.saurik.com Git - redis.git/blame - deps/jemalloc/doc/jemalloc.3
Query the archive to provide a complete KEYS list.
[redis.git] / deps / jemalloc / doc / jemalloc.3
CommitLineData
a78e148b 1'\" t
2.\" Title: JEMALLOC
3.\" Author: Jason Evans
4934f93d 4.\" Generator: DocBook XSL Stylesheets v1.76.1 <http://docbook.sf.net/>
21b26915 5.\" Date: 11/09/2012
a78e148b 6.\" Manual: User Manual
21b26915 7.\" Source: jemalloc 3.2.0-0-g87499f6748ebe4817571e817e9f680ccb5bf54a9
a78e148b 8.\" Language: English
9.\"
21b26915 10.TH "JEMALLOC" "3" "11/09/2012" "jemalloc 3.2.0-0-g87499f6748eb" "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
21b26915 34This manual describes jemalloc 3\&.2\&.0\-0\-g87499f6748ebe4817571e817e9f680ccb5bf54a9\&. 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" ");"
4934f93d 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" ");"
4934f93d 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
4934f93d 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
4934f93d 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,
4934f93d 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
21b26915 297\fBALLOCM_ARENA(\fR\fB\fIa\fR\fR\fB) \fR
298.RS 4
299Use the arena specified by the index
300\fIa\fR\&. This macro does not validate that
301\fIa\fR
302specifies an arena in the valid range\&.
303.RE
304.PP
a78e148b 305The
306\fBallocm\fR\fB\fR
307function allocates at least
308\fIsize\fR
309bytes of memory, sets
310\fI*ptr\fR
311to the base address of the allocation, and sets
312\fI*rsize\fR
313to the real size of the allocation if
314\fIrsize\fR
315is not
4934f93d 316\fBNULL\fR\&. Behavior is undefined if
317\fIsize\fR
318is
319\fB0\fR\&.
a78e148b 320.PP
321The
322\fBrallocm\fR\fB\fR
323function resizes the allocation at
324\fI*ptr\fR
325to be at least
326\fIsize\fR
327bytes, sets
328\fI*ptr\fR
329to the base address of the allocation if it moved, and sets
330\fI*rsize\fR
331to the real size of the allocation if
332\fIrsize\fR
333is not
334\fBNULL\fR\&. If
335\fIextra\fR
336is non\-zero, an attempt is made to resize the allocation to be at least
337\fIsize\fR + \fIextra\fR)
338bytes, though inability to allocate the extra byte(s) will not by itself result in failure\&. Behavior is undefined if
4934f93d 339\fIsize\fR
340is
341\fB0\fR, or if
a78e148b 342(\fIsize\fR + \fIextra\fR > \fBSIZE_T_MAX\fR)\&.
343.PP
344The
345\fBsallocm\fR\fB\fR
346function sets
347\fI*rsize\fR
348to the real size of the allocation\&.
349.PP
350The
351\fBdallocm\fR\fB\fR
352function causes the memory referenced by
353\fIptr\fR
354to be made available for future allocations\&.
4934f93d 355.PP
356The
357\fBnallocm\fR\fB\fR
358function allocates no memory, but it performs the same size computation as the
359\fBallocm\fR\fB\fR
360function, and if
361\fIrsize\fR
362is not
363\fBNULL\fR
364it sets
365\fI*rsize\fR
366to the real size of the allocation that would result from the equivalent
367\fBallocm\fR\fB\fR
368function call\&. Behavior is undefined if
369\fIsize\fR
370is
371\fB0\fR\&.
a78e148b 372.SH "TUNING"
373.PP
374Once, 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\&.
375.PP
376The string pointed to by the global variable
377\fImalloc_conf\fR, the \(lqname\(rq of the file referenced by the symbolic link named
378/etc/malloc\&.conf, and the value of the environment variable
379\fBMALLOC_CONF\fR, will be interpreted, in that order, from left to right as options\&.
380.PP
381An options string is a comma\-separated list of option:value pairs\&. There is one key corresponding to each
382"opt\&.*"
383mallctl (see the
384MALLCTL NAMESPACE
385section for options documentation)\&. For example,
386abort:true,narenas:1
387sets the
388"opt\&.abort"
389and
390"opt\&.narenas"
391options\&. 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\&.
392.SH "IMPLEMENTATION NOTES"
393.PP
394Traditionally, allocators have used
395\fBsbrk\fR(2)
396to obtain memory, which is suboptimal for several reasons, including race conditions, increased fragmentation, and artificial limitations on maximum usable memory\&. If
397\fB\-\-enable\-dss\fR
398is specified during configuration, this allocator uses both
4934f93d 399\fBmmap\fR(2)
a78e148b 400and
4934f93d 401\fBsbrk\fR(2), in that order of preference; otherwise only
a78e148b 402\fBmmap\fR(2)
403is used\&.
404.PP
405This 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\&.
406.PP
407In addition to multiple arenas, unless
408\fB\-\-disable\-tcache\fR
409is 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\&.
410.PP
411Memory 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\&.
412.PP
413User 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\&.
414.PP
415Each 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\&.
416.PP
4934f93d 417Small 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
418sizeof(\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 419"opt\&.lg_chunk"
420option), 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\&.
421.PP
422Allocations 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\&.
423.PP
424Assuming 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
425Table 1\&.
426.sp
427.it 1 an-trap
428.nr an-no-space-flag 1
429.nr an-break-flag 1
430.br
431.B Table\ \&1.\ \&Size classes
432.TS
433allbox tab(:);
4934f93d 434lB rB lB.
a78e148b 435T{
436Category
437T}:T{
4934f93d 438Spacing
a78e148b 439T}:T{
440Size
441T}
442.T&
4934f93d 443l r l
444^ r l
445^ r l
446^ r l
447^ r l
448^ r l
449^ r l
450l r l
451l r l.
a78e148b 452T{
453Small
454T}:T{
4934f93d 455lg
a78e148b 456T}:T{
457[8]
458T}
459:T{
4934f93d 46016
a78e148b 461T}:T{
462[16, 32, 48, \&.\&.\&., 128]
463T}
464:T{
4934f93d 46532
466T}:T{
467[160, 192, 224, 256]
468T}
469:T{
47064
471T}:T{
472[320, 384, 448, 512]
473T}
474:T{
475128
476T}:T{
477[640, 768, 896, 1024]
478T}
479:T{
480256
a78e148b 481T}:T{
4934f93d 482[1280, 1536, 1792, 2048]
a78e148b 483T}
484:T{
4934f93d 485512
a78e148b 486T}:T{
4934f93d 487[2560, 3072, 3584]
a78e148b 488T}
489T{
490Large
491T}:T{
4934f93d 4924 KiB
493T}:T{
a78e148b 494[4 KiB, 8 KiB, 12 KiB, \&.\&.\&., 4072 KiB]
495T}
496T{
497Huge
498T}:T{
4934f93d 4994 MiB
500T}:T{
a78e148b 501[4 MiB, 8 MiB, 12 MiB, \&.\&.\&.]
502T}
503.TE
504.sp 1
505.SH "MALLCTL NAMESPACE"
506.PP
507The following names are defined in the namespace accessible via the
508\fBmallctl*\fR\fB\fR
509functions\&. Value types are specified in parentheses, their readable/writable statuses are encoded as
510rw,
511r\-,
512\-w, or
513\-\-, and required build configuration flags follow, if any\&. A name element encoded as
514<i>
515or
516<j>
517indicates an integer component, where the integer varies from 0 to some upper value that must be determined via introspection\&. In the case of
518"stats\&.arenas\&.<i>\&.*",
519<i>
520equal to
521"arenas\&.narenas"
522can be used to access the summation of statistics from all arenas\&. Take special note of the
523"epoch"
524mallctl, which controls refreshing of cached dynamic statistics\&.
525.PP
526"version" (\fBconst char *\fR) r\-
527.RS 4
528Return the jemalloc version string\&.
529.RE
530.PP
531"epoch" (\fBuint64_t\fR) rw
532.RS 4
533If a value is passed in, refresh the data from which the
534\fBmallctl*\fR\fB\fR
535functions report values, and increment the epoch\&. Return the current epoch\&. This is useful for detecting whether another thread caused a refresh\&.
536.RE
537.PP
538"config\&.debug" (\fBbool\fR) r\-
539.RS 4
540\fB\-\-enable\-debug\fR
541was specified during build configuration\&.
542.RE
543.PP
544"config\&.dss" (\fBbool\fR) r\-
545.RS 4
546\fB\-\-enable\-dss\fR
547was specified during build configuration\&.
548.RE
549.PP
a78e148b 550"config\&.fill" (\fBbool\fR) r\-
551.RS 4
552\fB\-\-enable\-fill\fR
553was specified during build configuration\&.
554.RE
555.PP
556"config\&.lazy_lock" (\fBbool\fR) r\-
557.RS 4
558\fB\-\-enable\-lazy\-lock\fR
559was specified during build configuration\&.
560.RE
561.PP
4934f93d 562"config\&.mremap" (\fBbool\fR) r\-
563.RS 4
564\fB\-\-enable\-mremap\fR
565was specified during build configuration\&.
566.RE
567.PP
568"config\&.munmap" (\fBbool\fR) r\-
569.RS 4
570\fB\-\-enable\-munmap\fR
571was specified during build configuration\&.
572.RE
573.PP
a78e148b 574"config\&.prof" (\fBbool\fR) r\-
575.RS 4
576\fB\-\-enable\-prof\fR
577was specified during build configuration\&.
578.RE
579.PP
580"config\&.prof_libgcc" (\fBbool\fR) r\-
581.RS 4
582\fB\-\-disable\-prof\-libgcc\fR
583was not specified during build configuration\&.
584.RE
585.PP
586"config\&.prof_libunwind" (\fBbool\fR) r\-
587.RS 4
588\fB\-\-enable\-prof\-libunwind\fR
589was specified during build configuration\&.
590.RE
591.PP
592"config\&.stats" (\fBbool\fR) r\-
593.RS 4
594\fB\-\-enable\-stats\fR
595was specified during build configuration\&.
596.RE
597.PP
a78e148b 598"config\&.tcache" (\fBbool\fR) r\-
599.RS 4
600\fB\-\-disable\-tcache\fR
601was not specified during build configuration\&.
602.RE
603.PP
4934f93d 604"config\&.tls" (\fBbool\fR) r\-
a78e148b 605.RS 4
4934f93d 606\fB\-\-disable\-tls\fR
a78e148b 607was not specified during build configuration\&.
608.RE
609.PP
4934f93d 610"config\&.utrace" (\fBbool\fR) r\-
a78e148b 611.RS 4
4934f93d 612\fB\-\-enable\-utrace\fR
613was specified during build configuration\&.
614.RE
615.PP
616"config\&.valgrind" (\fBbool\fR) r\-
617.RS 4
618\fB\-\-enable\-valgrind\fR
619was specified during build configuration\&.
a78e148b 620.RE
621.PP
622"config\&.xmalloc" (\fBbool\fR) r\-
623.RS 4
624\fB\-\-enable\-xmalloc\fR
625was specified during build configuration\&.
626.RE
627.PP
628"opt\&.abort" (\fBbool\fR) r\-
629.RS 4
630Abort\-on\-warning enabled/disabled\&. If true, most warnings are fatal\&. The process will call
631\fBabort\fR(3)
632in these cases\&. This option is disabled by default unless
633\fB\-\-enable\-debug\fR
634is specified during configuration, in which case it is enabled by default\&.
635.RE
636.PP
a78e148b 637"opt\&.lg_chunk" (\fBsize_t\fR) r\-
638.RS 4
639Virtual memory chunk size (log base 2)\&. The default chunk size is 4 MiB (2^22)\&.
640.RE
641.PP
21b26915 642"opt\&.dss" (\fBconst char *\fR) r\-
643.RS 4
644dss (\fBsbrk\fR(2)) allocation precedence as related to
645\fBmmap\fR(2)
646allocation\&. The following settings are supported: \(lqdisabled\(rq, \(lqprimary\(rq, and \(lqsecondary\(rq (default)\&.
647.RE
648.PP
a78e148b 649"opt\&.narenas" (\fBsize_t\fR) r\-
650.RS 4
21b26915 651Maximum 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\&.
a78e148b 652.RE
653.PP
654"opt\&.lg_dirty_mult" (\fBssize_t\fR) r\-
655.RS 4
656Per\-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
657\fBmadvise\fR(2)
21b26915 658or 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\&.
a78e148b 659.RE
660.PP
661"opt\&.stats_print" (\fBbool\fR) r\-
662.RS 4
663Enable/disable statistics printing at exit\&. If enabled, the
664\fBmalloc_stats_print\fR\fB\fR
665function is called at program exit via an
666\fBatexit\fR(3)
667function\&. If
668\fB\-\-enable\-stats\fR
669is 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\&.
670.RE
671.PP
672"opt\&.junk" (\fBbool\fR) r\- [\fB\-\-enable\-fill\fR]
673.RS 4
674Junk filling enabled/disabled\&. If enabled, each byte of uninitialized allocated memory will be initialized to
6750xa5\&. All deallocated memory will be initialized to
6760x5a\&. This is intended for debugging and will impact performance negatively\&. This option is disabled by default unless
677\fB\-\-enable\-debug\fR
21b26915 678is specified during configuration, in which case it is enabled by default unless running inside
679\m[blue]\fBValgrind\fR\m[]\&\s-2\u[2]\d\s+2\&.
a78e148b 680.RE
681.PP
4934f93d 682"opt\&.quarantine" (\fBsize_t\fR) r\- [\fB\-\-enable\-fill\fR]
683.RS 4
684Per 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
685"opt\&.junk"
686option is enabled\&. This feature is of particular use in combination with
21b26915 687\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\&.
4934f93d 688.RE
689.PP
690"opt\&.redzone" (\fBbool\fR) r\- [\fB\-\-enable\-fill\fR]
691.RS 4
692Redzones enabled/disabled\&. If enabled, small allocations have redzones before and after them\&. Furthermore, if the
693"opt\&.junk"
694option 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
21b26915 695\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\&.
4934f93d 696.RE
697.PP
a78e148b 698"opt\&.zero" (\fBbool\fR) r\- [\fB\-\-enable\-fill\fR]
699.RS 4
700Zero 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
701\fBrealloc\fR\fB\fR
702and
703\fBrallocm\fR\fB\fR
704calls do not zero memory that was previously allocated\&. This is intended for debugging and will impact performance negatively\&. This option is disabled by default\&.
705.RE
706.PP
4934f93d 707"opt\&.utrace" (\fBbool\fR) r\- [\fB\-\-enable\-utrace\fR]
a78e148b 708.RS 4
4934f93d 709Allocation tracing based on
710\fButrace\fR(2)
711enabled/disabled\&. This option is disabled by default\&.
712.RE
713.PP
714"opt\&.valgrind" (\fBbool\fR) r\- [\fB\-\-enable\-valgrind\fR]
715.RS 4
716\m[blue]\fBValgrind\fR\m[]\&\s-2\u[2]\d\s+2
21b26915 717support enabled/disabled\&. This option is vestigal because jemalloc auto\-detects whether it is running inside Valgrind\&. This option is disabled by default, unless running inside Valgrind\&.
a78e148b 718.RE
719.PP
720"opt\&.xmalloc" (\fBbool\fR) r\- [\fB\-\-enable\-xmalloc\fR]
721.RS 4
722Abort\-on\-out\-of\-memory enabled/disabled\&. If enabled, rather than returning failure for any allocation function, display a diagnostic message on
723\fBSTDERR_FILENO\fR
724and cause the program to drop core (using
725\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:
726.sp
727.if n \{\
728.RS 4
729.\}
730.nf
731malloc_conf = "xmalloc:true";
732.fi
733.if n \{\
734.RE
735.\}
736.sp
737This option is disabled by default\&.
738.RE
739.PP
740"opt\&.tcache" (\fBbool\fR) r\- [\fB\-\-enable\-tcache\fR]
741.RS 4
742Thread\-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 743"opt\&.lg_tcache_max"
21b26915 744option for related tuning information\&. This option is enabled by default unless running inside
745\m[blue]\fBValgrind\fR\m[]\&\s-2\u[2]\d\s+2\&.
a78e148b 746.RE
747.PP
748"opt\&.lg_tcache_max" (\fBsize_t\fR) r\- [\fB\-\-enable\-tcache\fR]
749.RS 4
750Maximum 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)\&.
751.RE
752.PP
753"opt\&.prof" (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
754.RS 4
4934f93d 755Memory profiling enabled/disabled\&. If enabled, profile memory allocation activity\&. See the
a78e148b 756"opt\&.prof_active"
757option for on\-the\-fly activation/deactivation\&. See the
758"opt\&.lg_prof_sample"
759option for probabilistic sampling control\&. See the
760"opt\&.prof_accum"
761option for control of cumulative sample reporting\&. See the
a78e148b 762"opt\&.lg_prof_interval"
4934f93d 763option for information on interval\-triggered profile dumping, the
a78e148b 764"opt\&.prof_gdump"
4934f93d 765option for information on high\-water\-triggered profile dumping, and the
766"opt\&.prof_final"
767option for final profile dumping\&. Profile output is compatible with the included
a78e148b 768\fBpprof\fR
769Perl script, which originates from the
4934f93d 770\m[blue]\fBgperftools package\fR\m[]\&\s-2\u[3]\d\s+2\&.
a78e148b 771.RE
772.PP
773"opt\&.prof_prefix" (\fBconst char *\fR) r\- [\fB\-\-enable\-prof\fR]
774.RS 4
775Filename 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
776jeprof\&.
777.RE
778.PP
a78e148b 779"opt\&.prof_active" (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
780.RS 4
781Profiling activated/deactivated\&. This is a secondary control mechanism that makes it possible to start the application with profiling enabled (see the
782"opt\&.prof"
783option) but inactive, then toggle profiling at any time during program execution with the
784"prof\&.active"
785mallctl\&. This option is enabled by default\&.
786.RE
787.PP
788"opt\&.lg_prof_sample" (\fBssize_t\fR) r\- [\fB\-\-enable\-prof\fR]
789.RS 4
4934f93d 790Average 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 791.RE
792.PP
793"opt\&.prof_accum" (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
794.RS 4
4934f93d 795Reporting 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 796.RE
797.PP
798"opt\&.lg_prof_interval" (\fBssize_t\fR) r\- [\fB\-\-enable\-prof\fR]
799.RS 4
800Average 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
801<prefix>\&.<pid>\&.<seq>\&.i<iseq>\&.heap, where
802<prefix>
803is controlled by the
804"opt\&.prof_prefix"
805option\&. By default, interval\-triggered profile dumping is disabled (encoded as \-1)\&.
806.RE
807.PP
808"opt\&.prof_gdump" (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
809.RS 4
810Trigger a memory profile dump every time the total virtual memory exceeds the previous maximum\&. Profiles are dumped to files named according to the pattern
811<prefix>\&.<pid>\&.<seq>\&.u<useq>\&.heap, where
812<prefix>
813is controlled by the
814"opt\&.prof_prefix"
815option\&. This option is disabled by default\&.
816.RE
817.PP
4934f93d 818"opt\&.prof_final" (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
819.RS 4
820Use an
821\fBatexit\fR(3)
822function to dump final memory usage to a file named according to the pattern
823<prefix>\&.<pid>\&.<seq>\&.f\&.heap, where
824<prefix>
825is controlled by the
826"opt\&.prof_prefix"
827option\&. This option is enabled by default\&.
828.RE
829.PP
a78e148b 830"opt\&.prof_leak" (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
831.RS 4
832Leak reporting enabled/disabled\&. If enabled, use an
833\fBatexit\fR(3)
834function to report memory leaks detected by allocation sampling\&. See the
a78e148b 835"opt\&.prof"
836option for information on analyzing heap profile output\&. This option is disabled by default\&.
837.RE
838.PP
a78e148b 839"thread\&.arena" (\fBunsigned\fR) rw
840.RS 4
21b26915 841Get or set the arena associated with the calling thread\&. If the specified arena was not initialized beforehand (see the
a78e148b 842"arenas\&.initialized"
843mallctl), it will be automatically initialized as a side effect of calling this interface\&.
844.RE
845.PP
846"thread\&.allocated" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
847.RS 4
848Get 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\&.
849.RE
850.PP
851"thread\&.allocatedp" (\fBuint64_t *\fR) r\- [\fB\-\-enable\-stats\fR]
852.RS 4
853Get a pointer to the the value that is returned by the
854"thread\&.allocated"
855mallctl\&. This is useful for avoiding the overhead of repeated
856\fBmallctl*\fR\fB\fR
857calls\&.
858.RE
859.PP
860"thread\&.deallocated" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
861.RS 4
862Get 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\&.
863.RE
864.PP
865"thread\&.deallocatedp" (\fBuint64_t *\fR) r\- [\fB\-\-enable\-stats\fR]
866.RS 4
867Get a pointer to the the value that is returned by the
868"thread\&.deallocated"
869mallctl\&. This is useful for avoiding the overhead of repeated
870\fBmallctl*\fR\fB\fR
871calls\&.
872.RE
873.PP
4934f93d 874"thread\&.tcache\&.enabled" (\fBbool\fR) rw [\fB\-\-enable\-tcache\fR]
875.RS 4
876Enable/disable calling thread\*(Aqs tcache\&. The tcache is implicitly flushed as a side effect of becoming disabled (see
877"thread\&.tcache\&.flush")\&.
878.RE
879.PP
880"thread\&.tcache\&.flush" (\fBvoid\fR) \-\- [\fB\-\-enable\-tcache\fR]
881.RS 4
882Flush 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\&.
883.RE
884.PP
21b26915 885"arena\&.<i>\&.purge" (\fBunsigned\fR) \-\-
886.RS 4
887Purge unused dirty pages for arena <i>, or for all arenas if <i> equals
888"arenas\&.narenas"\&.
889.RE
890.PP
891"arena\&.<i>\&.dss" (\fBconst char *\fR) rw
892.RS 4
893Set the precedence of dss allocation as related to mmap allocation for arena <i>, or for all arenas if <i> equals
894"arenas\&.narenas"\&. See
895"opt\&.dss"
896for supported settings\&.
897.RE
898.PP
a78e148b 899"arenas\&.narenas" (\fBunsigned\fR) r\-
900.RS 4
21b26915 901Current limit on number of arenas\&.
a78e148b 902.RE
903.PP
904"arenas\&.initialized" (\fBbool *\fR) r\-
905.RS 4
906An array of
907"arenas\&.narenas"
908booleans\&. Each boolean indicates whether the corresponding arena is initialized\&.
909.RE
910.PP
911"arenas\&.quantum" (\fBsize_t\fR) r\-
912.RS 4
913Quantum size\&.
914.RE
915.PP
4934f93d 916"arenas\&.page" (\fBsize_t\fR) r\-
a78e148b 917.RS 4
918Page size\&.
919.RE
920.PP
a78e148b 921"arenas\&.tcache_max" (\fBsize_t\fR) r\- [\fB\-\-enable\-tcache\fR]
922.RS 4
923Maximum thread\-cached size class\&.
924.RE
925.PP
a78e148b 926"arenas\&.nbins" (\fBunsigned\fR) r\-
927.RS 4
4934f93d 928Number of bin size classes\&.
a78e148b 929.RE
930.PP
931"arenas\&.nhbins" (\fBunsigned\fR) r\- [\fB\-\-enable\-tcache\fR]
932.RS 4
933Total number of thread cache bin size classes\&.
934.RE
935.PP
936"arenas\&.bin\&.<i>\&.size" (\fBsize_t\fR) r\-
937.RS 4
938Maximum size supported by size class\&.
939.RE
940.PP
941"arenas\&.bin\&.<i>\&.nregs" (\fBuint32_t\fR) r\-
942.RS 4
943Number of regions per page run\&.
944.RE
945.PP
946"arenas\&.bin\&.<i>\&.run_size" (\fBsize_t\fR) r\-
947.RS 4
948Number of bytes per page run\&.
949.RE
950.PP
951"arenas\&.nlruns" (\fBsize_t\fR) r\-
952.RS 4
953Total number of large size classes\&.
954.RE
955.PP
956"arenas\&.lrun\&.<i>\&.size" (\fBsize_t\fR) r\-
957.RS 4
958Maximum size supported by this large size class\&.
959.RE
960.PP
961"arenas\&.purge" (\fBunsigned\fR) \-w
962.RS 4
963Purge unused dirty pages for the specified arena, or for all arenas if none is specified\&.
964.RE
965.PP
21b26915 966"arenas\&.extend" (\fBunsigned\fR) r\-
967.RS 4
968Extend the array of arenas by appending a new arena, and returning the new arena index\&.
969.RE
970.PP
a78e148b 971"prof\&.active" (\fBbool\fR) rw [\fB\-\-enable\-prof\fR]
972.RS 4
973Control whether sampling is currently active\&. See the
974"opt\&.prof_active"
975option for additional information\&.
976.RE
977.PP
978"prof\&.dump" (\fBconst char *\fR) \-w [\fB\-\-enable\-prof\fR]
979.RS 4
980Dump a memory profile to the specified file, or if NULL is specified, to a file according to the pattern
981<prefix>\&.<pid>\&.<seq>\&.m<mseq>\&.heap, where
982<prefix>
983is controlled by the
984"opt\&.prof_prefix"
985option\&.
986.RE
987.PP
988"prof\&.interval" (\fBuint64_t\fR) r\- [\fB\-\-enable\-prof\fR]
989.RS 4
990Average number of bytes allocated between inverval\-based profile dumps\&. See the
991"opt\&.lg_prof_interval"
992option for additional information\&.
993.RE
994.PP
995"stats\&.cactive" (\fBsize_t *\fR) r\- [\fB\-\-enable\-stats\fR]
996.RS 4
997Pointer 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
998"epoch"
999mallctl 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\&.
1000.RE
1001.PP
1002"stats\&.allocated" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1003.RS 4
1004Total number of bytes allocated by the application\&.
1005.RE
1006.PP
1007"stats\&.active" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1008.RS 4
1009Total number of bytes in active pages allocated by the application\&. This is a multiple of the page size, and greater than or equal to
21b26915 1010"stats\&.allocated"\&. This does not include
1011"stats\&.arenas\&.<i>\&.pdirty"
1012and pages entirely devoted to allocator metadata\&.
a78e148b 1013.RE
1014.PP
1015"stats\&.mapped" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1016.RS 4
1017Total 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
4934f93d 1018"stats\&.active"\&. This does not include inactive chunks\&.
a78e148b 1019.RE
1020.PP
1021"stats\&.chunks\&.current" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1022.RS 4
4934f93d 1023Total number of chunks actively mapped on behalf of the application\&. This does not include inactive chunks\&.
a78e148b 1024.RE
1025.PP
1026"stats\&.chunks\&.total" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1027.RS 4
1028Cumulative number of chunks allocated\&.
1029.RE
1030.PP
1031"stats\&.chunks\&.high" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1032.RS 4
1033Maximum number of active chunks at any time thus far\&.
1034.RE
1035.PP
1036"stats\&.huge\&.allocated" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1037.RS 4
1038Number of bytes currently allocated by huge objects\&.
1039.RE
1040.PP
1041"stats\&.huge\&.nmalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1042.RS 4
1043Cumulative number of huge allocation requests\&.
1044.RE
1045.PP
1046"stats\&.huge\&.ndalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1047.RS 4
1048Cumulative number of huge deallocation requests\&.
1049.RE
1050.PP
21b26915 1051"stats\&.arenas\&.<i>\&.dss" (\fBconst char *\fR) r\-
1052.RS 4
1053dss (\fBsbrk\fR(2)) allocation precedence as related to
1054\fBmmap\fR(2)
1055allocation\&. See
1056"opt\&.dss"
1057for details\&.
1058.RE
1059.PP
a78e148b 1060"stats\&.arenas\&.<i>\&.nthreads" (\fBunsigned\fR) r\-
1061.RS 4
1062Number of threads currently assigned to arena\&.
1063.RE
1064.PP
1065"stats\&.arenas\&.<i>\&.pactive" (\fBsize_t\fR) r\-
1066.RS 4
1067Number of pages in active runs\&.
1068.RE
1069.PP
1070"stats\&.arenas\&.<i>\&.pdirty" (\fBsize_t\fR) r\-
1071.RS 4
1072Number of pages within unused runs that are potentially dirty, and for which
1073\fBmadvise\fR\fB\fI\&.\&.\&.\fR\fR\fB \fR\fB\fI\fBMADV_DONTNEED\fR\fR\fR
1074or similar has not been called\&.
1075.RE
1076.PP
1077"stats\&.arenas\&.<i>\&.mapped" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1078.RS 4
1079Number of mapped bytes\&.
1080.RE
1081.PP
1082"stats\&.arenas\&.<i>\&.npurge" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1083.RS 4
1084Number of dirty page purge sweeps performed\&.
1085.RE
1086.PP
1087"stats\&.arenas\&.<i>\&.nmadvise" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1088.RS 4
1089Number of
1090\fBmadvise\fR\fB\fI\&.\&.\&.\fR\fR\fB \fR\fB\fI\fBMADV_DONTNEED\fR\fR\fR
1091or similar calls made to purge dirty pages\&.
1092.RE
1093.PP
1094"stats\&.arenas\&.<i>\&.npurged" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1095.RS 4
1096Number of pages purged\&.
1097.RE
1098.PP
1099"stats\&.arenas\&.<i>\&.small\&.allocated" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1100.RS 4
1101Number of bytes currently allocated by small objects\&.
1102.RE
1103.PP
1104"stats\&.arenas\&.<i>\&.small\&.nmalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1105.RS 4
1106Cumulative number of allocation requests served by small bins\&.
1107.RE
1108.PP
1109"stats\&.arenas\&.<i>\&.small\&.ndalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1110.RS 4
1111Cumulative number of small objects returned to bins\&.
1112.RE
1113.PP
1114"stats\&.arenas\&.<i>\&.small\&.nrequests" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1115.RS 4
1116Cumulative number of small allocation requests\&.
1117.RE
1118.PP
1119"stats\&.arenas\&.<i>\&.large\&.allocated" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1120.RS 4
1121Number of bytes currently allocated by large objects\&.
1122.RE
1123.PP
1124"stats\&.arenas\&.<i>\&.large\&.nmalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1125.RS 4
1126Cumulative number of large allocation requests served directly by the arena\&.
1127.RE
1128.PP
1129"stats\&.arenas\&.<i>\&.large\&.ndalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1130.RS 4
1131Cumulative number of large deallocation requests served directly by the arena\&.
1132.RE
1133.PP
1134"stats\&.arenas\&.<i>\&.large\&.nrequests" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1135.RS 4
1136Cumulative number of large allocation requests\&.
1137.RE
1138.PP
1139"stats\&.arenas\&.<i>\&.bins\&.<j>\&.allocated" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1140.RS 4
1141Current number of bytes allocated by bin\&.
1142.RE
1143.PP
1144"stats\&.arenas\&.<i>\&.bins\&.<j>\&.nmalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1145.RS 4
1146Cumulative number of allocations served by bin\&.
1147.RE
1148.PP
1149"stats\&.arenas\&.<i>\&.bins\&.<j>\&.ndalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1150.RS 4
1151Cumulative number of allocations returned to bin\&.
1152.RE
1153.PP
1154"stats\&.arenas\&.<i>\&.bins\&.<j>\&.nrequests" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1155.RS 4
1156Cumulative number of allocation requests\&.
1157.RE
1158.PP
1159"stats\&.arenas\&.<i>\&.bins\&.<j>\&.nfills" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR \fB\-\-enable\-tcache\fR]
1160.RS 4
1161Cumulative number of tcache fills\&.
1162.RE
1163.PP
1164"stats\&.arenas\&.<i>\&.bins\&.<j>\&.nflushes" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR \fB\-\-enable\-tcache\fR]
1165.RS 4
1166Cumulative number of tcache flushes\&.
1167.RE
1168.PP
1169"stats\&.arenas\&.<i>\&.bins\&.<j>\&.nruns" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1170.RS 4
1171Cumulative number of runs created\&.
1172.RE
1173.PP
1174"stats\&.arenas\&.<i>\&.bins\&.<j>\&.nreruns" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1175.RS 4
1176Cumulative number of times the current run from which to allocate changed\&.
1177.RE
1178.PP
a78e148b 1179"stats\&.arenas\&.<i>\&.bins\&.<j>\&.curruns" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1180.RS 4
1181Current number of runs\&.
1182.RE
1183.PP
1184"stats\&.arenas\&.<i>\&.lruns\&.<j>\&.nmalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1185.RS 4
1186Cumulative number of allocation requests for this size class served directly by the arena\&.
1187.RE
1188.PP
1189"stats\&.arenas\&.<i>\&.lruns\&.<j>\&.ndalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1190.RS 4
1191Cumulative number of deallocation requests for this size class served directly by the arena\&.
1192.RE
1193.PP
1194"stats\&.arenas\&.<i>\&.lruns\&.<j>\&.nrequests" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1195.RS 4
1196Cumulative number of allocation requests for this size class\&.
1197.RE
1198.PP
a78e148b 1199"stats\&.arenas\&.<i>\&.lruns\&.<j>\&.curruns" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1200.RS 4
1201Current number of runs for this size class\&.
1202.RE
a78e148b 1203.SH "DEBUGGING MALLOC PROBLEMS"
1204.PP
1205When debugging, it is a good idea to configure/build jemalloc with the
1206\fB\-\-enable\-debug\fR
1207and
1208\fB\-\-enable\-fill\fR
1209options, 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\&.
1210.PP
1211Programs often accidentally depend on \(lquninitialized\(rq memory actually being filled with zero bytes\&. Junk filling (see the
1212"opt\&.junk"
1213option) tends to expose such bugs in the form of obviously incorrect results and/or coredumps\&. Conversely, zero filling (see the
1214"opt\&.zero"
1215option) eliminates the symptoms of such bugs\&. Between these two options, it is usually possible to quickly detect, diagnose, and eliminate such bugs\&.
1216.PP
4934f93d 1217This 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
1218\m[blue]\fBValgrind\fR\m[]\&\s-2\u[2]\d\s+2
1219tool if the
1220\fB\-\-enable\-valgrind\fR
21b26915 1221configuration option is enabled\&.
a78e148b 1222.SH "DIAGNOSTIC MESSAGES"
1223.PP
1224If any of the memory allocation/deallocation functions detect an error or warning condition, a message will be printed to file descriptor
1225\fBSTDERR_FILENO\fR\&. Errors will result in the process dumping core\&. If the
1226"opt\&.abort"
1227option is set, most warnings are treated as errors\&.
1228.PP
1229The
1230\fImalloc_message\fR
1231variable allows the programmer to override the function which emits the text strings forming the errors and warnings if for some reason the
1232\fBSTDERR_FILENO\fR
1233file descriptor is not suitable for this\&.
1234\fBmalloc_message\fR\fB\fR
1235takes the
1236\fIcbopaque\fR
1237pointer argument that is
1238\fBNULL\fR
1239unless overridden by the arguments in a call to
1240\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\&.
1241.PP
1242All messages are prefixed by \(lq<jemalloc>:\(rq\&.
1243.SH "RETURN VALUES"
1244.SS "Standard API"
1245.PP
1246The
1247\fBmalloc\fR\fB\fR
1248and
1249\fBcalloc\fR\fB\fR
1250functions return a pointer to the allocated memory if successful; otherwise a
1251\fBNULL\fR
1252pointer is returned and
1253\fIerrno\fR
1254is set to
1255ENOMEM\&.
1256.PP
1257The
1258\fBposix_memalign\fR\fB\fR
1259function returns the value 0 if successful; otherwise it returns an error value\&. The
1260\fBposix_memalign\fR\fB\fR
1261function will fail if:
1262.PP
1263EINVAL
1264.RS 4
1265The
1266\fIalignment\fR
1267parameter is not a power of 2 at least as large as
1268sizeof(\fBvoid *\fR)\&.
1269.RE
1270.PP
1271ENOMEM
1272.RS 4
1273Memory allocation error\&.
1274.RE
1275.PP
1276The
4934f93d 1277\fBaligned_alloc\fR\fB\fR
1278function returns a pointer to the allocated memory if successful; otherwise a
1279\fBNULL\fR
1280pointer is returned and
1281\fIerrno\fR
1282is set\&. The
1283\fBaligned_alloc\fR\fB\fR
1284function will fail if:
1285.PP
1286EINVAL
1287.RS 4
1288The
1289\fIalignment\fR
1290parameter is not a power of 2\&.
1291.RE
1292.PP
1293ENOMEM
1294.RS 4
1295Memory allocation error\&.
1296.RE
1297.PP
1298The
a78e148b 1299\fBrealloc\fR\fB\fR
1300function returns a pointer, possibly identical to
1301\fIptr\fR, to the allocated memory if successful; otherwise a
1302\fBNULL\fR
1303pointer is returned, and
1304\fIerrno\fR
1305is set to
1306ENOMEM
1307if the error was the result of an allocation failure\&. The
1308\fBrealloc\fR\fB\fR
1309function always leaves the original buffer intact when an error occurs\&.
1310.PP
1311The
1312\fBfree\fR\fB\fR
1313function returns no value\&.
1314.SS "Non\-standard API"
1315.PP
1316The
1317\fBmalloc_usable_size\fR\fB\fR
1318function returns the usable size of the allocation pointed to by
1319\fIptr\fR\&.
1320.PP
1321The
1322\fBmallctl\fR\fB\fR,
1323\fBmallctlnametomib\fR\fB\fR, and
1324\fBmallctlbymib\fR\fB\fR
1325functions return 0 on success; otherwise they return an error value\&. The functions will fail if:
1326.PP
1327EINVAL
1328.RS 4
1329\fInewp\fR
1330is not
1331\fBNULL\fR, and
1332\fInewlen\fR
1333is too large or too small\&. Alternatively,
1334\fI*oldlenp\fR
1335is too large or too small; in this case as much data as possible are read despite the error\&.
1336.RE
1337.PP
1338ENOMEM
1339.RS 4
1340\fI*oldlenp\fR
1341is too short to hold the requested value\&.
1342.RE
1343.PP
1344ENOENT
1345.RS 4
1346\fIname\fR
1347or
1348\fImib\fR
1349specifies an unknown/invalid value\&.
1350.RE
1351.PP
1352EPERM
1353.RS 4
1354Attempt to read or write void value, or attempt to write read\-only value\&.
1355.RE
1356.PP
1357EAGAIN
1358.RS 4
1359A memory allocation failure occurred\&.
1360.RE
1361.PP
1362EFAULT
1363.RS 4
1364An interface with side effects failed in some way not directly related to
1365\fBmallctl*\fR\fB\fR
1366read/write processing\&.
1367.RE
1368.SS "Experimental API"
1369.PP
1370The
1371\fBallocm\fR\fB\fR,
1372\fBrallocm\fR\fB\fR,
4934f93d 1373\fBsallocm\fR\fB\fR,
1374\fBdallocm\fR\fB\fR, and
1375\fBnallocm\fR\fB\fR
a78e148b 1376functions return
1377\fBALLOCM_SUCCESS\fR
1378on success; otherwise they return an error value\&. The
4934f93d 1379\fBallocm\fR\fB\fR,
1380\fBrallocm\fR\fB\fR, and
1381\fBnallocm\fR\fB\fR
a78e148b 1382functions will fail if:
1383.PP
1384ALLOCM_ERR_OOM
1385.RS 4
1386Out of memory\&. Insufficient contiguous memory was available to service the allocation request\&. The
1387\fBallocm\fR\fB\fR
1388function additionally sets
1389\fI*ptr\fR
1390to
1391\fBNULL\fR, whereas the
1392\fBrallocm\fR\fB\fR
1393function leaves
1394\fB*ptr\fR
1395unmodified\&.
1396.RE
1397The
1398\fBrallocm\fR\fB\fR
1399function will also fail if:
1400.PP
1401ALLOCM_ERR_NOT_MOVED
1402.RS 4
1403\fBALLOCM_NO_MOVE\fR
1404was specified, but the reallocation request could not be serviced without moving the object\&.
1405.RE
1406.SH "ENVIRONMENT"
1407.PP
1408The following environment variable affects the execution of the allocation functions:
1409.PP
1410\fBMALLOC_CONF\fR
1411.RS 4
1412If the environment variable
1413\fBMALLOC_CONF\fR
1414is set, the characters it contains will be interpreted as options\&.
1415.RE
1416.SH "EXAMPLES"
1417.PP
1418To dump core whenever a problem occurs:
1419.sp
1420.if n \{\
1421.RS 4
1422.\}
1423.nf
1424ln \-s \*(Aqabort:true\*(Aq /etc/malloc\&.conf
1425.fi
1426.if n \{\
1427.RE
1428.\}
1429.PP
1430To specify in the source a chunk size that is 16 MiB:
1431.sp
1432.if n \{\
1433.RS 4
1434.\}
1435.nf
1436malloc_conf = "lg_chunk:24";
1437.fi
1438.if n \{\
1439.RE
1440.\}
1441.SH "SEE ALSO"
1442.PP
1443\fBmadvise\fR(2),
1444\fBmmap\fR(2),
1445\fBsbrk\fR(2),
4934f93d 1446\fButrace\fR(2),
a78e148b 1447\fBalloca\fR(3),
1448\fBatexit\fR(3),
1449\fBgetpagesize\fR(3)
1450.SH "STANDARDS"
1451.PP
1452The
1453\fBmalloc\fR\fB\fR,
1454\fBcalloc\fR\fB\fR,
1455\fBrealloc\fR\fB\fR, and
1456\fBfree\fR\fB\fR
1457functions conform to ISO/IEC 9899:1990 (\(lqISO C90\(rq)\&.
1458.PP
1459The
1460\fBposix_memalign\fR\fB\fR
1461function conforms to IEEE Std 1003\&.1\-2001 (\(lqPOSIX\&.1\(rq)\&.
1462.SH "AUTHOR"
1463.PP
1464\fBJason Evans\fR
1465.RS 4
1466.RE
1467.SH "NOTES"
1468.IP " 1." 4
1469jemalloc website
1470.RS 4
1471\%http://www.canonware.com/jemalloc/
1472.RE
1473.IP " 2." 4
4934f93d 1474Valgrind
1475.RS 4
1476\%http://valgrind.org/
1477.RE
1478.IP " 3." 4
1479gperftools package
a78e148b 1480.RS 4
4934f93d 1481\%http://code.google.com/p/gperftools/
a78e148b 1482.RE