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