Deleted Added
sdiff udiff text old ( 286911 ) new ( 288090 )
full compact
1'\" t
2.\" Title: JEMALLOC
3.\" Author: Jason Evans
4.\" Generator: DocBook XSL Stylesheets v1.76.1 <http://docbook.sf.net/>
5.\" Date: 08/18/2015
6.\" Manual: User Manual
7.\" Source: jemalloc 4.0.0-0-g6e98caf8f064482b9ab292ef3638dea67420bbc2
8.\" Language: English
9.\"
10.TH "JEMALLOC" "3" "08/18/2015" "jemalloc 4.0.0-0-g6e98caf8f064" "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
34This manual describes jemalloc 4\&.0\&.0\-0\-g6e98caf8f064482b9ab292ef3638dea67420bbc2\&. 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\-fill\fR,
39\fB\-\-enable\-lazy\-lock\fR,
40\fB\-\-enable\-munmap\fR,
41\fB\-\-enable\-stats\fR,
42\fB\-\-enable\-tcache\fR,
43\fB\-\-enable\-tls\fR,
44\fB\-\-enable\-utrace\fR, and
45\fB\-\-enable\-xmalloc\fR\&. Additionally,
46\fB\-\-enable\-debug\fR
47is enabled in development versions of FreeBSD (controlled by the
48\fBMALLOC_PRODUCTION\fR
49make variable)\&.
50.SH "SYNOPSIS"
51.sp
52.ft B
53.nf
54#include <stdlib\&.h>
55#include <malloc_np\&.h>
56.fi
57.ft
58.SS "Standard API"
59.HP \w'void\ *malloc('u
60.BI "void *malloc(size_t\ " "size" ");"
61.HP \w'void\ *calloc('u
62.BI "void *calloc(size_t\ " "number" ", size_t\ " "size" ");"
63.HP \w'int\ posix_memalign('u
64.BI "int posix_memalign(void\ **" "ptr" ", size_t\ " "alignment" ", size_t\ " "size" ");"
65.HP \w'void\ *aligned_alloc('u
66.BI "void *aligned_alloc(size_t\ " "alignment" ", size_t\ " "size" ");"
67.HP \w'void\ *realloc('u
68.BI "void *realloc(void\ *" "ptr" ", size_t\ " "size" ");"
69.HP \w'void\ free('u
70.BI "void free(void\ *" "ptr" ");"
71.SS "Non\-standard API"
72.HP \w'void\ *mallocx('u
73.BI "void *mallocx(size_t\ " "size" ", int\ " "flags" ");"
74.HP \w'void\ *rallocx('u
75.BI "void *rallocx(void\ *" "ptr" ", size_t\ " "size" ", int\ " "flags" ");"
76.HP \w'size_t\ xallocx('u
77.BI "size_t xallocx(void\ *" "ptr" ", size_t\ " "size" ", size_t\ " "extra" ", int\ " "flags" ");"
78.HP \w'size_t\ sallocx('u
79.BI "size_t sallocx(void\ *" "ptr" ", int\ " "flags" ");"
80.HP \w'void\ dallocx('u
81.BI "void dallocx(void\ *" "ptr" ", int\ " "flags" ");"
82.HP \w'void\ sdallocx('u
83.BI "void sdallocx(void\ *" "ptr" ", size_t\ " "size" ", int\ " "flags" ");"
84.HP \w'size_t\ nallocx('u
85.BI "size_t nallocx(size_t\ " "size" ", int\ " "flags" ");"
86.HP \w'int\ mallctl('u
87.BI "int mallctl(const\ char\ *" "name" ", void\ *" "oldp" ", size_t\ *" "oldlenp" ", void\ *" "newp" ", size_t\ " "newlen" ");"
88.HP \w'int\ mallctlnametomib('u
89.BI "int mallctlnametomib(const\ char\ *" "name" ", size_t\ *" "mibp" ", size_t\ *" "miblenp" ");"
90.HP \w'int\ mallctlbymib('u
91.BI "int mallctlbymib(const\ size_t\ *" "mib" ", size_t\ " "miblen" ", void\ *" "oldp" ", size_t\ *" "oldlenp" ", void\ *" "newp" ", size_t\ " "newlen" ");"
92.HP \w'void\ malloc_stats_print('u
93.BI "void malloc_stats_print(void\ " "(*write_cb)" "\ (void\ *,\ const\ char\ *), void\ *" "cbopaque" ", const\ char\ *" "opts" ");"
94.HP \w'size_t\ malloc_usable_size('u
95.BI "size_t malloc_usable_size(const\ void\ *" "ptr" ");"
96.HP \w'void\ (*malloc_message)('u
97.BI "void (*malloc_message)(void\ *" "cbopaque" ", const\ char\ *" "s" ");"
98.PP
99const char *\fImalloc_conf\fR;
100.SH "DESCRIPTION"
101.SS "Standard API"
102.PP
103The
104\fBmalloc\fR\fB\fR
105function allocates
106\fIsize\fR
107bytes of uninitialized memory\&. The allocated space is suitably aligned (after possible pointer coercion) for storage of any type of object\&.
108.PP
109The
110\fBcalloc\fR\fB\fR
111function allocates space for
112\fInumber\fR
113objects, each
114\fIsize\fR
115bytes in length\&. The result is identical to calling
116\fBmalloc\fR\fB\fR
117with an argument of
118\fInumber\fR
119*
120\fIsize\fR, with the exception that the allocated memory is explicitly initialized to zero bytes\&.
121.PP
122The
123\fBposix_memalign\fR\fB\fR
124function allocates
125\fIsize\fR
126bytes of memory such that the allocation\*(Aqs base address is a multiple of
127\fIalignment\fR, and returns the allocation in the value pointed to by
128\fIptr\fR\&. The requested
129\fIalignment\fR
130must be a power of 2 at least as large as
131sizeof(\fBvoid *\fR)\&.
132.PP
133The
134\fBaligned_alloc\fR\fB\fR
135function allocates
136\fIsize\fR
137bytes of memory such that the allocation\*(Aqs base address is a multiple of
138\fIalignment\fR\&. The requested
139\fIalignment\fR
140must be a power of 2\&. Behavior is undefined if
141\fIsize\fR
142is not an integral multiple of
143\fIalignment\fR\&.
144.PP
145The
146\fBrealloc\fR\fB\fR
147function changes the size of the previously allocated memory referenced by
148\fIptr\fR
149to
150\fIsize\fR
151bytes\&. 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
152\fIptr\fR
153is freed and a pointer to the newly allocated memory is returned\&. Note that
154\fBrealloc\fR\fB\fR
155may move the memory allocation, resulting in a different return value than
156\fIptr\fR\&. If
157\fIptr\fR
158is
159\fBNULL\fR, the
160\fBrealloc\fR\fB\fR
161function behaves identically to
162\fBmalloc\fR\fB\fR
163for the specified size\&.
164.PP
165The
166\fBfree\fR\fB\fR
167function causes the allocated memory referenced by
168\fIptr\fR
169to be made available for future allocations\&. If
170\fIptr\fR
171is
172\fBNULL\fR, no action occurs\&.
173.SS "Non\-standard API"
174.PP
175The
176\fBmallocx\fR\fB\fR,
177\fBrallocx\fR\fB\fR,
178\fBxallocx\fR\fB\fR,
179\fBsallocx\fR\fB\fR,
180\fBdallocx\fR\fB\fR,
181\fBsdallocx\fR\fB\fR, and
182\fBnallocx\fR\fB\fR
183functions all have a
184\fIflags\fR
185argument 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:
186.PP
187\fBMALLOCX_LG_ALIGN(\fR\fB\fIla\fR\fR\fB) \fR
188.RS 4
189Align the memory allocation to start at an address that is a multiple of
190(1 << \fIla\fR)\&. This macro does not validate that
191\fIla\fR
192is within the valid range\&.
193.RE
194.PP
195\fBMALLOCX_ALIGN(\fR\fB\fIa\fR\fR\fB) \fR
196.RS 4
197Align the memory allocation to start at an address that is a multiple of
198\fIa\fR, where
199\fIa\fR
200is a power of two\&. This macro does not validate that
201\fIa\fR
202is a power of 2\&.
203.RE
204.PP
205\fBMALLOCX_ZERO\fR
206.RS 4
207Initialize 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\&.
208.RE
209.PP
210\fBMALLOCX_TCACHE(\fR\fB\fItc\fR\fR\fB) \fR
211.RS 4
212Use the thread\-specific cache (tcache) specified by the identifier
213\fItc\fR, which must have been acquired via the
214"tcache\&.create"
215mallctl\&. This macro does not validate that
216\fItc\fR
217specifies a valid identifier\&.
218.RE
219.PP
220\fBMALLOCX_TCACHE_NONE\fR
221.RS 4
222Do not use a thread\-specific cache (tcache)\&. Unless
223\fBMALLOCX_TCACHE(\fR\fB\fItc\fR\fR\fB)\fR
224or
225\fBMALLOCX_TCACHE_NONE\fR
226is specified, an automatically managed tcache will be used under many circumstances\&. This macro cannot be used in the same
227\fIflags\fR
228argument as
229\fBMALLOCX_TCACHE(\fR\fB\fItc\fR\fR\fB)\fR\&.
230.RE
231.PP
232\fBMALLOCX_ARENA(\fR\fB\fIa\fR\fR\fB) \fR
233.RS 4
234Use the arena specified by the index
235\fIa\fR\&. This macro has no effect for regions that were allocated via an arena other than the one specified\&. This macro does not validate that
236\fIa\fR
237specifies an arena index in the valid range\&.
238.RE
239.PP
240The
241\fBmallocx\fR\fB\fR
242function allocates at least
243\fIsize\fR
244bytes of memory, and returns a pointer to the base address of the allocation\&. 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\fBrallocx\fR\fB\fR
251function resizes the allocation at
252\fIptr\fR
253to be at least
254\fIsize\fR
255bytes, 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
256\fIsize\fR
257is
258\fB0\fR, or if request size overflows due to size class and/or alignment constraints\&.
259.PP
260The
261\fBxallocx\fR\fB\fR
262function resizes the allocation at
263\fIptr\fR
264in place to be at least
265\fIsize\fR
266bytes, and returns the real size of the allocation\&. If
267\fIextra\fR
268is non\-zero, an attempt is made to resize the allocation to be at least
269(\fIsize\fR + \fIextra\fR)
270bytes, though inability to allocate the extra byte(s) will not by itself result in failure to resize\&. Behavior is undefined if
271\fIsize\fR
272is
273\fB0\fR, or if
274(\fIsize\fR + \fIextra\fR > \fBSIZE_T_MAX\fR)\&.
275.PP
276The
277\fBsallocx\fR\fB\fR
278function returns the real size of the allocation at
279\fIptr\fR\&.
280.PP
281The
282\fBdallocx\fR\fB\fR
283function causes the memory referenced by
284\fIptr\fR
285to be made available for future allocations\&.
286.PP
287The
288\fBsdallocx\fR\fB\fR
289function is an extension of
290\fBdallocx\fR\fB\fR
291with a
292\fIsize\fR
293parameter to allow the caller to pass in the allocation size as an optimization\&. The minimum valid input size is the original requested size of the allocation, and the maximum valid input size is the corresponding value returned by
294\fBnallocx\fR\fB\fR
295or
296\fBsallocx\fR\fB\fR\&.
297.PP
298The
299\fBnallocx\fR\fB\fR
300function allocates no memory, but it performs the same size computation as the
301\fBmallocx\fR\fB\fR
302function, and returns the real size of the allocation that would result from the equivalent
303\fBmallocx\fR\fB\fR
304function call\&. Behavior is undefined if
305\fIsize\fR
306is
307\fB0\fR, or if request size overflows due to size class and/or alignment constraints\&.
308.PP
309The
310\fBmallctl\fR\fB\fR
311function provides a general interface for introspecting the memory allocator, as well as setting modifiable parameters and triggering actions\&. The period\-separated
312\fIname\fR
313argument specifies a location in a tree\-structured namespace; see the
314MALLCTL NAMESPACE
315section for documentation on the tree contents\&. To read a value, pass a pointer via
316\fIoldp\fR
317to adequate space to contain the value, and a pointer to its length via
318\fIoldlenp\fR; otherwise pass
319\fBNULL\fR
320and
321\fBNULL\fR\&. Similarly, to write a value, pass a pointer to the value via
322\fInewp\fR, and its length via
323\fInewlen\fR; otherwise pass
324\fBNULL\fR
325and
326\fB0\fR\&.
327.PP
328The
329\fBmallctlnametomib\fR\fB\fR
330function provides a way to avoid repeated name lookups for applications that repeatedly query the same portion of the namespace, by translating a name to a \(lqManagement Information Base\(rq (MIB) that can be passed repeatedly to
331\fBmallctlbymib\fR\fB\fR\&. Upon successful return from
332\fBmallctlnametomib\fR\fB\fR,
333\fImibp\fR
334contains an array of
335\fI*miblenp\fR
336integers, where
337\fI*miblenp\fR
338is the lesser of the number of components in
339\fIname\fR
340and the input value of
341\fI*miblenp\fR\&. Thus it is possible to pass a
342\fI*miblenp\fR
343that is smaller than the number of period\-separated name components, which results in a partial MIB that can be used as the basis for constructing a complete MIB\&. For name components that are integers (e\&.g\&. the 2 in
344"arenas\&.bin\&.2\&.size"), the corresponding MIB component will always be that integer\&. Therefore, it is legitimate to construct code like the following:
345.sp
346.if n \{\
347.RS 4
348.\}
349.nf
350unsigned nbins, i;
351size_t mib[4];
352size_t len, miblen;
353
354len = sizeof(nbins);
355mallctl("arenas\&.nbins", &nbins, &len, NULL, 0);
356
357miblen = 4;
358mallctlnametomib("arenas\&.bin\&.0\&.size", mib, &miblen);
359for (i = 0; i < nbins; i++) {
360 size_t bin_size;
361
362 mib[2] = i;
363 len = sizeof(bin_size);
364 mallctlbymib(mib, miblen, &bin_size, &len, NULL, 0);
365 /* Do something with bin_size\&.\&.\&. */
366}
367.fi
368.if n \{\
369.RE
370.\}
371.PP
372The
373\fBmalloc_stats_print\fR\fB\fR
374function writes human\-readable summary statistics via the
375\fIwrite_cb\fR
376callback function pointer and
377\fIcbopaque\fR
378data passed to
379\fIwrite_cb\fR, or
380\fBmalloc_message\fR\fB\fR
381if
382\fIwrite_cb\fR
383is
384\fBNULL\fR\&. This function can be called repeatedly\&. General information that never changes during execution can be omitted by specifying "g" as a character within the
385\fIopts\fR
386string\&. Note that
387\fBmalloc_message\fR\fB\fR
388uses the
389\fBmallctl*\fR\fB\fR
390functions internally, so inconsistent statistics can be reported if multiple threads use these functions simultaneously\&. If
391\fB\-\-enable\-stats\fR
392is specified during configuration, \(lqm\(rq and \(lqa\(rq can be specified to omit merged arena and per arena statistics, respectively; \(lqb\(rq, \(lql\(rq, and \(lqh\(rq can be specified to omit per size class statistics for bins, large objects, and huge objects, respectively\&. Unrecognized characters are silently ignored\&. Note that thread caching may prevent some statistics from being completely up to date, since extra locking would be required to merge counters that track thread cache operations\&.
393.PP
394The
395\fBmalloc_usable_size\fR\fB\fR
396function returns the usable size of the allocation pointed to by
397\fIptr\fR\&. The return value may be larger than the size that was requested during allocation\&. The
398\fBmalloc_usable_size\fR\fB\fR
399function is not a mechanism for in\-place
400\fBrealloc\fR\fB\fR; rather it is provided solely as a tool for introspection purposes\&. Any discrepancy between the requested allocation size and the size reported by
401\fBmalloc_usable_size\fR\fB\fR
402should not be depended on, since such behavior is entirely implementation\-dependent\&.
403.SH "TUNING"
404.PP
405Once, 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\&.
406.PP
407The string pointed to by the global variable
408\fImalloc_conf\fR, the \(lqname\(rq of the file referenced by the symbolic link named
409/etc/malloc\&.conf, and the value of the environment variable
410\fBMALLOC_CONF\fR, will be interpreted, in that order, from left to right as options\&. Note that
411\fImalloc_conf\fR
412may be read before
413\fBmain\fR\fB\fR
414is entered, so the declaration of
415\fImalloc_conf\fR
416should specify an initializer that contains the final value to be read by jemalloc\&.
417\fImalloc_conf\fR
418is a compile\-time setting, whereas
419/etc/malloc\&.conf
420and
421\fBMALLOC_CONF\fR
422can be safely set any time prior to program invocation\&.
423.PP
424An options string is a comma\-separated list of option:value pairs\&. There is one key corresponding to each
425"opt\&.*"
426mallctl (see the
427MALLCTL NAMESPACE
428section for options documentation)\&. For example,
429abort:true,narenas:1
430sets the
431"opt\&.abort"
432and
433"opt\&.narenas"
434options\&. Some options have boolean values (true/false), others have integer values (base 8, 10, or 16, depending on prefix), and yet others have raw string values\&.
435.SH "IMPLEMENTATION NOTES"
436.PP
437Traditionally, allocators have used
438\fBsbrk\fR(2)
439to obtain memory, which is suboptimal for several reasons, including race conditions, increased fragmentation, and artificial limitations on maximum usable memory\&. If
440\fBsbrk\fR(2)
441is supported by the operating system, this allocator uses both
442\fBmmap\fR(2)
443and
444\fBsbrk\fR(2), in that order of preference; otherwise only
445\fBmmap\fR(2)
446is used\&.
447.PP
448This 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\&.
449.PP
450In addition to multiple arenas, unless
451\fB\-\-disable\-tcache\fR
452is 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\&.
453.PP
454Memory 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\&.
455.PP
456User objects are broken into three categories according to size: small, large, and huge\&. Small and large objects are managed entirely by arenas; huge objects are additionally aggregated in a single data structure that is shared by all threads\&. Huge objects are typically used by applications infrequently enough that this single data structure is not a scalability issue\&.
457.PP
458Each 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\&.
459.PP
460Small objects are managed in groups by page runs\&. Each run maintains a bitmap to track which regions are in use\&. Allocation requests that are no more than half the quantum (8 or 16, depending on architecture) are rounded up to the nearest power of two that is at least
461sizeof(\fBdouble\fR)\&. All other object size classes are multiples of the quantum, spaced such that there are four size classes for each doubling in size, which limits internal fragmentation to approximately 20% for all but the smallest size classes\&. Small size classes are smaller than four times the page size, large size classes are smaller than the chunk size (see the
462"opt\&.lg_chunk"
463option), and huge size classes extend from the chunk size up to one size class less than the full address space size\&.
464.PP
465Allocations 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\&.
466.PP
467The
468\fBrealloc\fR\fB\fR,
469\fBrallocx\fR\fB\fR, and
470\fBxallocx\fR\fB\fR
471functions may resize allocations without moving them under limited circumstances\&. Unlike the
472\fB*allocx\fR\fB\fR
473API, the standard API does not officially round up the usable size of an allocation to the nearest size class, so technically it is necessary to call
474\fBrealloc\fR\fB\fR
475to grow e\&.g\&. a 9\-byte allocation to 16 bytes, or shrink a 16\-byte allocation to 9 bytes\&. Growth and shrinkage trivially succeeds in place as long as the pre\-size and post\-size both round up to the same size class\&. No other API guarantees are made regarding in\-place resizing, but the current implementation also tries to resize large and huge allocations in place, as long as the pre\-size and post\-size are both large or both huge\&. In such cases shrinkage always succeeds for large size classes, but for huge size classes the chunk allocator must support splitting (see
476"arena\&.<i>\&.chunk_hooks")\&. Growth only succeeds if the trailing memory is currently available, and additionally for huge size classes the chunk allocator must support merging\&.
477.PP
478Assuming 2 MiB chunks, 4 KiB pages, and a 16\-byte quantum on a 64\-bit system, the size classes in each category are as shown in
479Table 1\&.
480.sp
481.it 1 an-trap
482.nr an-no-space-flag 1
483.nr an-break-flag 1
484.br
485.B Table\ \&1.\ \&Size classes
486.TS
487allbox tab(:);
488lB rB lB.
489T{
490Category
491T}:T{
492Spacing
493T}:T{
494Size
495T}
496.T&
497l r l
498^ r l
499^ r l
500^ r l
501^ r l
502^ r l
503^ r l
504^ r l
505^ r l
506l r l
507^ r l
508^ r l
509^ r l
510^ r l
511^ r l
512^ r l
513^ r l
514l r l
515^ r l
516^ r l
517^ r l
518^ r l
519^ r l
520^ r l.
521T{
522Small
523T}:T{
524lg
525T}:T{
526[8]
527T}
528:T{
52916
530T}:T{
531[16, 32, 48, 64, 80, 96, 112, 128]
532T}
533:T{
53432
535T}:T{
536[160, 192, 224, 256]
537T}
538:T{
53964
540T}:T{
541[320, 384, 448, 512]
542T}
543:T{
544128
545T}:T{
546[640, 768, 896, 1024]
547T}
548:T{
549256
550T}:T{
551[1280, 1536, 1792, 2048]
552T}
553:T{
554512
555T}:T{
556[2560, 3072, 3584, 4096]
557T}
558:T{
5591 KiB
560T}:T{
561[5 KiB, 6 KiB, 7 KiB, 8 KiB]
562T}
563:T{
5642 KiB
565T}:T{
566[10 KiB, 12 KiB, 14 KiB]
567T}
568T{
569Large
570T}:T{
5712 KiB
572T}:T{
573[16 KiB]
574T}
575:T{
5764 KiB
577T}:T{
578[20 KiB, 24 KiB, 28 KiB, 32 KiB]
579T}
580:T{
5818 KiB
582T}:T{
583[40 KiB, 48 KiB, 54 KiB, 64 KiB]
584T}
585:T{
58616 KiB
587T}:T{
588[80 KiB, 96 KiB, 112 KiB, 128 KiB]
589T}
590:T{
59132 KiB
592T}:T{
593[160 KiB, 192 KiB, 224 KiB, 256 KiB]
594T}
595:T{
59664 KiB
597T}:T{
598[320 KiB, 384 KiB, 448 KiB, 512 KiB]
599T}
600:T{
601128 KiB
602T}:T{
603[640 KiB, 768 KiB, 896 KiB, 1 MiB]
604T}
605:T{
606256 KiB
607T}:T{
608[1280 KiB, 1536 KiB, 1792 KiB]
609T}
610T{
611Huge
612T}:T{
613256 KiB
614T}:T{
615[2 MiB]
616T}
617:T{
618512 KiB
619T}:T{
620[2560 KiB, 3 MiB, 3584 KiB, 4 MiB]
621T}
622:T{
6231 MiB
624T}:T{
625[5 MiB, 6 MiB, 7 MiB, 8 MiB]
626T}
627:T{
6282 MiB
629T}:T{
630[10 MiB, 12 MiB, 14 MiB, 16 MiB]
631T}
632:T{
6334 MiB
634T}:T{
635[20 MiB, 24 MiB, 28 MiB, 32 MiB]
636T}
637:T{
6388 MiB
639T}:T{
640[40 MiB, 48 MiB, 56 MiB, 64 MiB]
641T}
642:T{
643\&.\&.\&.
644T}:T{
645\&.\&.\&.
646T}
647.TE
648.sp 1
649.SH "MALLCTL NAMESPACE"
650.PP
651The following names are defined in the namespace accessible via the
652\fBmallctl*\fR\fB\fR
653functions\&. Value types are specified in parentheses, their readable/writable statuses are encoded as
654rw,
655r\-,
656\-w, or
657\-\-, and required build configuration flags follow, if any\&. A name element encoded as
658<i>
659or
660<j>
661indicates an integer component, where the integer varies from 0 to some upper value that must be determined via introspection\&. In the case of
662"stats\&.arenas\&.<i>\&.*",
663<i>
664equal to
665"arenas\&.narenas"
666can be used to access the summation of statistics from all arenas\&. Take special note of the
667"epoch"
668mallctl, which controls refreshing of cached dynamic statistics\&.
669.PP
670"version" (\fBconst char *\fR) r\-
671.RS 4
672Return the jemalloc version string\&.
673.RE
674.PP
675"epoch" (\fBuint64_t\fR) rw
676.RS 4
677If a value is passed in, refresh the data from which the
678\fBmallctl*\fR\fB\fR
679functions report values, and increment the epoch\&. Return the current epoch\&. This is useful for detecting whether another thread caused a refresh\&.
680.RE
681.PP
682"config\&.cache_oblivious" (\fBbool\fR) r\-
683.RS 4
684\fB\-\-enable\-cache\-oblivious\fR
685was specified during build configuration\&.
686.RE
687.PP
688"config\&.debug" (\fBbool\fR) r\-
689.RS 4
690\fB\-\-enable\-debug\fR
691was specified during build configuration\&.
692.RE
693.PP
694"config\&.fill" (\fBbool\fR) r\-
695.RS 4
696\fB\-\-enable\-fill\fR
697was specified during build configuration\&.
698.RE
699.PP
700"config\&.lazy_lock" (\fBbool\fR) r\-
701.RS 4
702\fB\-\-enable\-lazy\-lock\fR
703was specified during build configuration\&.
704.RE
705.PP
706"config\&.munmap" (\fBbool\fR) r\-
707.RS 4
708\fB\-\-enable\-munmap\fR
709was specified during build configuration\&.
710.RE
711.PP
712"config\&.prof" (\fBbool\fR) r\-
713.RS 4
714\fB\-\-enable\-prof\fR
715was specified during build configuration\&.
716.RE
717.PP
718"config\&.prof_libgcc" (\fBbool\fR) r\-
719.RS 4
720\fB\-\-disable\-prof\-libgcc\fR
721was not specified during build configuration\&.
722.RE
723.PP
724"config\&.prof_libunwind" (\fBbool\fR) r\-
725.RS 4
726\fB\-\-enable\-prof\-libunwind\fR
727was specified during build configuration\&.
728.RE
729.PP
730"config\&.stats" (\fBbool\fR) r\-
731.RS 4
732\fB\-\-enable\-stats\fR
733was specified during build configuration\&.
734.RE
735.PP
736"config\&.tcache" (\fBbool\fR) r\-
737.RS 4
738\fB\-\-disable\-tcache\fR
739was not specified during build configuration\&.
740.RE
741.PP
742"config\&.tls" (\fBbool\fR) r\-
743.RS 4
744\fB\-\-disable\-tls\fR
745was not specified during build configuration\&.
746.RE
747.PP
748"config\&.utrace" (\fBbool\fR) r\-
749.RS 4
750\fB\-\-enable\-utrace\fR
751was specified during build configuration\&.
752.RE
753.PP
754"config\&.valgrind" (\fBbool\fR) r\-
755.RS 4
756\fB\-\-enable\-valgrind\fR
757was specified during build configuration\&.
758.RE
759.PP
760"config\&.xmalloc" (\fBbool\fR) r\-
761.RS 4
762\fB\-\-enable\-xmalloc\fR
763was specified during build configuration\&.
764.RE
765.PP
766"opt\&.abort" (\fBbool\fR) r\-
767.RS 4
768Abort\-on\-warning enabled/disabled\&. If true, most warnings are fatal\&. The process will call
769\fBabort\fR(3)
770in these cases\&. This option is disabled by default unless
771\fB\-\-enable\-debug\fR
772is specified during configuration, in which case it is enabled by default\&.
773.RE
774.PP
775"opt\&.dss" (\fBconst char *\fR) r\-
776.RS 4
777dss (\fBsbrk\fR(2)) allocation precedence as related to
778\fBmmap\fR(2)
779allocation\&. The following settings are supported if
780\fBsbrk\fR(2)
781is supported by the operating system: \(lqdisabled\(rq, \(lqprimary\(rq, and \(lqsecondary\(rq; otherwise only \(lqdisabled\(rq is supported\&. The default is \(lqsecondary\(rq if
782\fBsbrk\fR(2)
783is supported by the operating system; \(lqdisabled\(rq otherwise\&.
784.RE
785.PP
786"opt\&.lg_chunk" (\fBsize_t\fR) r\-
787.RS 4
788Virtual memory chunk size (log base 2)\&. If a chunk size outside the supported size range is specified, the size is silently clipped to the minimum/maximum supported size\&. The default chunk size is 2 MiB (2^21)\&.
789.RE
790.PP
791"opt\&.narenas" (\fBsize_t\fR) r\-
792.RS 4
793Maximum 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\&.
794.RE
795.PP
796"opt\&.lg_dirty_mult" (\fBssize_t\fR) r\-
797.RS 4
798Per\-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
799\fBmadvise\fR(2)
800or a similar system call\&. This provides the kernel with sufficient information to recycle dirty pages if physical memory becomes scarce and the pages remain unused\&. The default minimum ratio is 8:1 (2^3:1); an option value of \-1 will disable dirty page purging\&. See
801"arenas\&.lg_dirty_mult"
802and
803"arena\&.<i>\&.lg_dirty_mult"
804for related dynamic control options\&.
805.RE
806.PP
807"opt\&.stats_print" (\fBbool\fR) r\-
808.RS 4
809Enable/disable statistics printing at exit\&. If enabled, the
810\fBmalloc_stats_print\fR\fB\fR
811function is called at program exit via an
812\fBatexit\fR(3)
813function\&. If
814\fB\-\-enable\-stats\fR
815is specified during configuration, this has the potential to cause deadlock for a multi\-threaded process that exits while one or more threads are executing in the memory allocation functions\&. Furthermore,
816\fBatexit\fR\fB\fR
817may allocate memory during application initialization and then deadlock internally when jemalloc in turn calls
818\fBatexit\fR\fB\fR, so this option is not univerally usable (though the application can register its own
819\fBatexit\fR\fB\fR
820function with equivalent functionality)\&. Therefore, this option should only be used with care; it is primarily intended as a performance tuning aid during application development\&. This option is disabled by default\&.
821.RE
822.PP
823"opt\&.junk" (\fBconst char *\fR) r\- [\fB\-\-enable\-fill\fR]
824.RS 4
825Junk filling\&. If set to "alloc", each byte of uninitialized allocated memory will be initialized to
8260xa5\&. If set to "free", all deallocated memory will be initialized to
8270x5a\&. If set to "true", both allocated and deallocated memory will be initialized, and if set to "false", junk filling be disabled entirely\&. This is intended for debugging and will impact performance negatively\&. This option is "false" by default unless
828\fB\-\-enable\-debug\fR
829is specified during configuration, in which case it is "true" by default unless running inside
830\m[blue]\fBValgrind\fR\m[]\&\s-2\u[2]\d\s+2\&.
831.RE
832.PP
833"opt\&.quarantine" (\fBsize_t\fR) r\- [\fB\-\-enable\-fill\fR]
834.RS 4
835Per 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
836"opt\&.junk"
837option is enabled\&. This feature is of particular use in combination with
838\m[blue]\fBValgrind\fR\m[]\&\s-2\u[2]\d\s+2, which can detect attempts to access quarantined objects\&. This is intended for debugging and will impact performance negatively\&. The default quarantine size is 0 unless running inside Valgrind, in which case the default is 16 MiB\&.
839.RE
840.PP
841"opt\&.redzone" (\fBbool\fR) r\- [\fB\-\-enable\-fill\fR]
842.RS 4
843Redzones enabled/disabled\&. If enabled, small allocations have redzones before and after them\&. Furthermore, if the
844"opt\&.junk"
845option is enabled, the redzones are checked for corruption during deallocation\&. However, the primary intended purpose of this feature is to be used in combination with
846\m[blue]\fBValgrind\fR\m[]\&\s-2\u[2]\d\s+2, which needs redzones in order to do effective buffer overflow/underflow detection\&. This option is intended for debugging and will impact performance negatively\&. This option is disabled by default unless running inside Valgrind\&.
847.RE
848.PP
849"opt\&.zero" (\fBbool\fR) r\- [\fB\-\-enable\-fill\fR]
850.RS 4
851Zero 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
852\fBrealloc\fR\fB\fR
853and
854\fBrallocx\fR\fB\fR
855calls do not zero memory that was previously allocated\&. This is intended for debugging and will impact performance negatively\&. This option is disabled by default\&.
856.RE
857.PP
858"opt\&.utrace" (\fBbool\fR) r\- [\fB\-\-enable\-utrace\fR]
859.RS 4
860Allocation tracing based on
861\fButrace\fR(2)
862enabled/disabled\&. This option is disabled by default\&.
863.RE
864.PP
865"opt\&.xmalloc" (\fBbool\fR) r\- [\fB\-\-enable\-xmalloc\fR]
866.RS 4
867Abort\-on\-out\-of\-memory enabled/disabled\&. If enabled, rather than returning failure for any allocation function, display a diagnostic message on
868\fBSTDERR_FILENO\fR
869and cause the program to drop core (using
870\fBabort\fR(3))\&. If an application is designed to depend on this behavior, set the option at compile time by including the following in the source code:
871.sp
872.if n \{\
873.RS 4
874.\}
875.nf
876malloc_conf = "xmalloc:true";
877.fi
878.if n \{\
879.RE
880.\}
881.sp
882This option is disabled by default\&.
883.RE
884.PP
885"opt\&.tcache" (\fBbool\fR) r\- [\fB\-\-enable\-tcache\fR]
886.RS 4
887Thread\-specific caching (tcache) enabled/disabled\&. When there are multiple threads, each thread uses a tcache for objects up to a certain size\&. Thread\-specific caching allows many allocations to be satisfied without performing any thread synchronization, at the cost of increased memory use\&. See the
888"opt\&.lg_tcache_max"
889option for related tuning information\&. This option is enabled by default unless running inside
890\m[blue]\fBValgrind\fR\m[]\&\s-2\u[2]\d\s+2, in which case it is forcefully disabled\&.
891.RE
892.PP
893"opt\&.lg_tcache_max" (\fBsize_t\fR) r\- [\fB\-\-enable\-tcache\fR]
894.RS 4
895Maximum size class (log base 2) to cache in the thread\-specific cache (tcache)\&. At a minimum, all small size classes are cached, and at a maximum all large size classes are cached\&. The default maximum is 32 KiB (2^15)\&.
896.RE
897.PP
898"opt\&.prof" (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
899.RS 4
900Memory profiling enabled/disabled\&. If enabled, profile memory allocation activity\&. See the
901"opt\&.prof_active"
902option for on\-the\-fly activation/deactivation\&. See the
903"opt\&.lg_prof_sample"
904option for probabilistic sampling control\&. See the
905"opt\&.prof_accum"
906option for control of cumulative sample reporting\&. See the
907"opt\&.lg_prof_interval"
908option for information on interval\-triggered profile dumping, the
909"opt\&.prof_gdump"
910option for information on high\-water\-triggered profile dumping, and the
911"opt\&.prof_final"
912option for final profile dumping\&. Profile output is compatible with the
913\fBjeprof\fR
914command, which is based on the
915\fBpprof\fR
916that is developed as part of the
917\m[blue]\fBgperftools package\fR\m[]\&\s-2\u[3]\d\s+2\&.
918.RE
919.PP
920"opt\&.prof_prefix" (\fBconst char *\fR) r\- [\fB\-\-enable\-prof\fR]
921.RS 4
922Filename 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
923jeprof\&.
924.RE
925.PP
926"opt\&.prof_active" (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
927.RS 4
928Profiling activated/deactivated\&. This is a secondary control mechanism that makes it possible to start the application with profiling enabled (see the
929"opt\&.prof"
930option) but inactive, then toggle profiling at any time during program execution with the
931"prof\&.active"
932mallctl\&. This option is enabled by default\&.
933.RE
934.PP
935"opt\&.prof_thread_active_init" (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
936.RS 4
937Initial setting for
938"thread\&.prof\&.active"
939in newly created threads\&. The initial setting for newly created threads can also be changed during execution via the
940"prof\&.thread_active_init"
941mallctl\&. This option is enabled by default\&.
942.RE
943.PP
944"opt\&.lg_prof_sample" (\fBsize_t\fR) r\- [\fB\-\-enable\-prof\fR]
945.RS 4
946Average 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)\&.
947.RE
948.PP
949"opt\&.prof_accum" (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
950.RS 4
951Reporting 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\&.
952.RE
953.PP
954"opt\&.lg_prof_interval" (\fBssize_t\fR) r\- [\fB\-\-enable\-prof\fR]
955.RS 4
956Average interval (log base 2) between memory profile dumps, as measured in bytes of allocation activity\&. The actual interval between dumps may be sporadic because decentralized allocation counters are used to avoid synchronization bottlenecks\&. Profiles are dumped to files named according to the pattern
957<prefix>\&.<pid>\&.<seq>\&.i<iseq>\&.heap, where
958<prefix>
959is controlled by the
960"opt\&.prof_prefix"
961option\&. By default, interval\-triggered profile dumping is disabled (encoded as \-1)\&.
962.RE
963.PP
964"opt\&.prof_gdump" (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
965.RS 4
966Set the initial state of
967"prof\&.gdump", which when enabled triggers a memory profile dump every time the total virtual memory exceeds the previous maximum\&. This option is disabled by default\&.
968.RE
969.PP
970"opt\&.prof_final" (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
971.RS 4
972Use an
973\fBatexit\fR(3)
974function to dump final memory usage to a file named according to the pattern
975<prefix>\&.<pid>\&.<seq>\&.f\&.heap, where
976<prefix>
977is controlled by the
978"opt\&.prof_prefix"
979option\&. Note that
980\fBatexit\fR\fB\fR
981may allocate memory during application initialization and then deadlock internally when jemalloc in turn calls
982\fBatexit\fR\fB\fR, so this option is not univerally usable (though the application can register its own
983\fBatexit\fR\fB\fR
984function with equivalent functionality)\&. This option is disabled by default\&.
985.RE
986.PP
987"opt\&.prof_leak" (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
988.RS 4
989Leak reporting enabled/disabled\&. If enabled, use an
990\fBatexit\fR(3)
991function to report memory leaks detected by allocation sampling\&. See the
992"opt\&.prof"
993option for information on analyzing heap profile output\&. This option is disabled by default\&.
994.RE
995.PP
996"thread\&.arena" (\fBunsigned\fR) rw
997.RS 4
998Get or set the arena associated with the calling thread\&. If the specified arena was not initialized beforehand (see the
999"arenas\&.initialized"
1000mallctl), it will be automatically initialized as a side effect of calling this interface\&.
1001.RE
1002.PP
1003"thread\&.allocated" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1004.RS 4
1005Get 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\&.
1006.RE
1007.PP
1008"thread\&.allocatedp" (\fBuint64_t *\fR) r\- [\fB\-\-enable\-stats\fR]
1009.RS 4
1010Get a pointer to the the value that is returned by the
1011"thread\&.allocated"
1012mallctl\&. This is useful for avoiding the overhead of repeated
1013\fBmallctl*\fR\fB\fR
1014calls\&.
1015.RE
1016.PP
1017"thread\&.deallocated" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1018.RS 4
1019Get 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\&.
1020.RE
1021.PP
1022"thread\&.deallocatedp" (\fBuint64_t *\fR) r\- [\fB\-\-enable\-stats\fR]
1023.RS 4
1024Get a pointer to the the value that is returned by the
1025"thread\&.deallocated"
1026mallctl\&. This is useful for avoiding the overhead of repeated
1027\fBmallctl*\fR\fB\fR
1028calls\&.
1029.RE
1030.PP
1031"thread\&.tcache\&.enabled" (\fBbool\fR) rw [\fB\-\-enable\-tcache\fR]
1032.RS 4
1033Enable/disable calling thread\*(Aqs tcache\&. The tcache is implicitly flushed as a side effect of becoming disabled (see
1034"thread\&.tcache\&.flush")\&.
1035.RE
1036.PP
1037"thread\&.tcache\&.flush" (\fBvoid\fR) \-\- [\fB\-\-enable\-tcache\fR]
1038.RS 4
1039Flush calling thread\*(Aqs thread\-specific cache (tcache)\&. This interface releases all cached objects and internal data structures associated with the calling thread\*(Aqs tcache\&. Ordinarily, this interface need not be called, since automatic periodic incremental garbage collection occurs, and the thread cache is automatically discarded when a thread exits\&. However, garbage collection is triggered by allocation activity, so it is possible for a thread that stops allocating/deallocating to retain its cache indefinitely, in which case the developer may find manual flushing useful\&.
1040.RE
1041.PP
1042"thread\&.prof\&.name" (\fBconst char *\fR) r\- or \-w [\fB\-\-enable\-prof\fR]
1043.RS 4
1044Get/set the descriptive name associated with the calling thread in memory profile dumps\&. An internal copy of the name string is created, so the input string need not be maintained after this interface completes execution\&. The output string of this interface should be copied for non\-ephemeral uses, because multiple implementation details can cause asynchronous string deallocation\&. Furthermore, each invocation of this interface can only read or write; simultaneous read/write is not supported due to string lifetime limitations\&. The name string must nil\-terminated and comprised only of characters in the sets recognized by
1045\fBisgraph\fR(3)
1046and
1047\fBisblank\fR(3)\&.
1048.RE
1049.PP
1050"thread\&.prof\&.active" (\fBbool\fR) rw [\fB\-\-enable\-prof\fR]
1051.RS 4
1052Control whether sampling is currently active for the calling thread\&. This is an activation mechanism in addition to
1053"prof\&.active"; both must be active for the calling thread to sample\&. This flag is enabled by default\&.
1054.RE
1055.PP
1056"tcache\&.create" (\fBunsigned\fR) r\- [\fB\-\-enable\-tcache\fR]
1057.RS 4
1058Create an explicit thread\-specific cache (tcache) and return an identifier that can be passed to the
1059\fBMALLOCX_TCACHE(\fR\fB\fItc\fR\fR\fB)\fR
1060macro to explicitly use the specified cache rather than the automatically managed one that is used by default\&. Each explicit cache can be used by only one thread at a time; the application must assure that this constraint holds\&.
1061.RE
1062.PP
1063"tcache\&.flush" (\fBunsigned\fR) \-w [\fB\-\-enable\-tcache\fR]
1064.RS 4
1065Flush the specified thread\-specific cache (tcache)\&. The same considerations apply to this interface as to
1066"thread\&.tcache\&.flush", except that the tcache will never be automatically be discarded\&.
1067.RE
1068.PP
1069"tcache\&.destroy" (\fBunsigned\fR) \-w [\fB\-\-enable\-tcache\fR]
1070.RS 4
1071Flush the specified thread\-specific cache (tcache) and make the identifier available for use during a future tcache creation\&.
1072.RE
1073.PP
1074"arena\&.<i>\&.purge" (\fBvoid\fR) \-\-
1075.RS 4
1076Purge unused dirty pages for arena <i>, or for all arenas if <i> equals
1077"arenas\&.narenas"\&.
1078.RE
1079.PP
1080"arena\&.<i>\&.dss" (\fBconst char *\fR) rw
1081.RS 4
1082Set the precedence of dss allocation as related to mmap allocation for arena <i>, or for all arenas if <i> equals
1083"arenas\&.narenas"\&. See
1084"opt\&.dss"
1085for supported settings\&.
1086.RE
1087.PP
1088"arena\&.<i>\&.lg_dirty_mult" (\fBssize_t\fR) rw
1089.RS 4
1090Current per\-arena minimum ratio (log base 2) of active to dirty pages for arena <i>\&. Each time this interface is set and the ratio is increased, pages are synchronously purged as necessary to impose the new ratio\&. See
1091"opt\&.lg_dirty_mult"
1092for additional information\&.
1093.RE
1094.PP
1095"arena\&.<i>\&.chunk_hooks" (\fBchunk_hooks_t\fR) rw
1096.RS 4
1097Get or set the chunk management hook functions for arena <i>\&. The functions must be capable of operating on all extant chunks associated with arena <i>, usually by passing unknown chunks to the replaced functions\&. In practice, it is feasible to control allocation for arenas created via
1098"arenas\&.extend"
1099such that all chunks originate from an application\-supplied chunk allocator (by setting custom chunk hook functions just after arena creation), but the automatically created arenas may have already created chunks prior to the application having an opportunity to take over chunk allocation\&.
1100.sp
1101.if n \{\
1102.RS 4
1103.\}
1104.nf
1105typedef struct {
1106 chunk_alloc_t *alloc;
1107 chunk_dalloc_t *dalloc;
1108 chunk_commit_t *commit;
1109 chunk_decommit_t *decommit;
1110 chunk_purge_t *purge;
1111 chunk_split_t *split;
1112 chunk_merge_t *merge;
1113} chunk_hooks_t;
1114.fi
1115.if n \{\
1116.RE
1117.\}
1118.sp
1119The
1120\fBchunk_hooks_t\fR
1121structure comprises function pointers which are described individually below\&. jemalloc uses these functions to manage chunk lifetime, which starts off with allocation of mapped committed memory, in the simplest case followed by deallocation\&. However, there are performance and platform reasons to retain chunks for later reuse\&. Cleanup attempts cascade from deallocation to decommit to purging, which gives the chunk management functions opportunities to reject the most permanent cleanup operations in favor of less permanent (and often less costly) operations\&. The chunk splitting and merging operations can also be opted out of, but this is mainly intended to support platforms on which virtual memory mappings provided by the operating system kernel do not automatically coalesce and split, e\&.g\&. Windows\&.
1122.HP \w'typedef\ void\ *(chunk_alloc_t)('u
1123.BI "typedef void *(chunk_alloc_t)(void\ *" "chunk" ", size_t\ " "size" ", size_t\ " "alignment" ", bool\ *" "zero" ", bool\ *" "commit" ", unsigned\ " "arena_ind" ");"
1124.sp
1125.if n \{\
1126.RS 4
1127.\}
1128.nf
1129.fi
1130.if n \{\
1131.RE
1132.\}
1133.sp
1134A chunk allocation function conforms to the
1135\fBchunk_alloc_t\fR
1136type and upon success returns a pointer to
1137\fIsize\fR
1138bytes of mapped memory on behalf of arena
1139\fIarena_ind\fR
1140such that the chunk\*(Aqs base address is a multiple of
1141\fIalignment\fR, as well as setting
1142\fI*zero\fR
1143to indicate whether the chunk is zeroed and
1144\fI*commit\fR
1145to indicate whether the chunk is committed\&. Upon error the function returns
1146\fBNULL\fR
1147and leaves
1148\fI*zero\fR
1149and
1150\fI*commit\fR
1151unmodified\&. The
1152\fIsize\fR
1153parameter is always a multiple of the chunk size\&. The
1154\fIalignment\fR
1155parameter is always a power of two at least as large as the chunk size\&. Zeroing is mandatory if
1156\fI*zero\fR
1157is true upon function entry\&. Committing is mandatory if
1158\fI*commit\fR
1159is true upon function entry\&. If
1160\fIchunk\fR
1161is not
1162\fBNULL\fR, the returned pointer must be
1163\fIchunk\fR
1164on success or
1165\fBNULL\fR
1166on error\&. Committed memory may be committed in absolute terms as on a system that does not overcommit, or in implicit terms as on a system that overcommits and satisfies physical memory needs on demand via soft page faults\&. Note that replacing the default chunk allocation function makes the arena\*(Aqs
1167"arena\&.<i>\&.dss"
1168setting irrelevant\&.
1169.HP \w'typedef\ bool\ (chunk_dalloc_t)('u
1170.BI "typedef bool (chunk_dalloc_t)(void\ *" "chunk" ", size_t\ " "size" ", bool\ " "committed" ", unsigned\ " "arena_ind" ");"
1171.sp
1172.if n \{\
1173.RS 4
1174.\}
1175.nf
1176.fi
1177.if n \{\
1178.RE
1179.\}
1180.sp
1181A chunk deallocation function conforms to the
1182\fBchunk_dalloc_t\fR
1183type and deallocates a
1184\fIchunk\fR
1185of given
1186\fIsize\fR
1187with
1188\fIcommitted\fR/decommited memory as indicated, on behalf of arena
1189\fIarena_ind\fR, returning false upon success\&. If the function returns true, this indicates opt\-out from deallocation; the virtual memory mapping associated with the chunk remains mapped, in the same commit state, and available for future use, in which case it will be automatically retained for later reuse\&.
1190.HP \w'typedef\ bool\ (chunk_commit_t)('u
1191.BI "typedef bool (chunk_commit_t)(void\ *" "chunk" ", size_t\ " "size" ", size_t\ " "offset" ", size_t\ " "length" ", unsigned\ " "arena_ind" ");"
1192.sp
1193.if n \{\
1194.RS 4
1195.\}
1196.nf
1197.fi
1198.if n \{\
1199.RE
1200.\}
1201.sp
1202A chunk commit function conforms to the
1203\fBchunk_commit_t\fR
1204type and commits zeroed physical memory to back pages within a
1205\fIchunk\fR
1206of given
1207\fIsize\fR
1208at
1209\fIoffset\fR
1210bytes, extending for
1211\fIlength\fR
1212on behalf of arena
1213\fIarena_ind\fR, returning false upon success\&. Committed memory may be committed in absolute terms as on a system that does not overcommit, or in implicit terms as on a system that overcommits and satisfies physical memory needs on demand via soft page faults\&. If the function returns true, this indicates insufficient physical memory to satisfy the request\&.
1214.HP \w'typedef\ bool\ (chunk_decommit_t)('u
1215.BI "typedef bool (chunk_decommit_t)(void\ *" "chunk" ", size_t\ " "size" ", size_t\ " "offset" ", size_t\ " "length" ", unsigned\ " "arena_ind" ");"
1216.sp
1217.if n \{\
1218.RS 4
1219.\}
1220.nf
1221.fi
1222.if n \{\
1223.RE
1224.\}
1225.sp
1226A chunk decommit function conforms to the
1227\fBchunk_decommit_t\fR
1228type and decommits any physical memory that is backing pages within a
1229\fIchunk\fR
1230of given
1231\fIsize\fR
1232at
1233\fIoffset\fR
1234bytes, extending for
1235\fIlength\fR
1236on behalf of arena
1237\fIarena_ind\fR, returning false upon success, in which case the pages will be committed via the chunk commit function before being reused\&. If the function returns true, this indicates opt\-out from decommit; the memory remains committed and available for future use, in which case it will be automatically retained for later reuse\&.
1238.HP \w'typedef\ bool\ (chunk_purge_t)('u
1239.BI "typedef bool (chunk_purge_t)(void\ *" "chunk" ", size_t" "size" ", size_t\ " "offset" ", size_t\ " "length" ", unsigned\ " "arena_ind" ");"
1240.sp
1241.if n \{\
1242.RS 4
1243.\}
1244.nf
1245.fi
1246.if n \{\
1247.RE
1248.\}
1249.sp
1250A chunk purge function conforms to the
1251\fBchunk_purge_t\fR
1252type and optionally discards physical pages within the virtual memory mapping associated with
1253\fIchunk\fR
1254of given
1255\fIsize\fR
1256at
1257\fIoffset\fR
1258bytes, extending for
1259\fIlength\fR
1260on behalf of arena
1261\fIarena_ind\fR, returning false if pages within the purged virtual memory range will be zero\-filled the next time they are accessed\&.
1262.HP \w'typedef\ bool\ (chunk_split_t)('u
1263.BI "typedef bool (chunk_split_t)(void\ *" "chunk" ", size_t\ " "size" ", size_t\ " "size_a" ", size_t\ " "size_b" ", bool\ " "committed" ", unsigned\ " "arena_ind" ");"
1264.sp
1265.if n \{\
1266.RS 4
1267.\}
1268.nf
1269.fi
1270.if n \{\
1271.RE
1272.\}
1273.sp
1274A chunk split function conforms to the
1275\fBchunk_split_t\fR
1276type and optionally splits
1277\fIchunk\fR
1278of given
1279\fIsize\fR
1280into two adjacent chunks, the first of
1281\fIsize_a\fR
1282bytes, and the second of
1283\fIsize_b\fR
1284bytes, operating on
1285\fIcommitted\fR/decommitted memory as indicated, on behalf of arena
1286\fIarena_ind\fR, returning false upon success\&. If the function returns true, this indicates that the chunk remains unsplit and therefore should continue to be operated on as a whole\&.
1287.HP \w'typedef\ bool\ (chunk_merge_t)('u
1288.BI "typedef bool (chunk_merge_t)(void\ *" "chunk_a" ", size_t\ " "size_a" ", void\ *" "chunk_b" ", size_t\ " "size_b" ", bool\ " "committed" ", unsigned\ " "arena_ind" ");"
1289.sp
1290.if n \{\
1291.RS 4
1292.\}
1293.nf
1294.fi
1295.if n \{\
1296.RE
1297.\}
1298.sp
1299A chunk merge function conforms to the
1300\fBchunk_merge_t\fR
1301type and optionally merges adjacent chunks,
1302\fIchunk_a\fR
1303of given
1304\fIsize_a\fR
1305and
1306\fIchunk_b\fR
1307of given
1308\fIsize_b\fR
1309into one contiguous chunk, operating on
1310\fIcommitted\fR/decommitted memory as indicated, on behalf of arena
1311\fIarena_ind\fR, returning false upon success\&. If the function returns true, this indicates that the chunks remain distinct mappings and therefore should continue to be operated on independently\&.
1312.RE
1313.PP
1314"arenas\&.narenas" (\fBunsigned\fR) r\-
1315.RS 4
1316Current limit on number of arenas\&.
1317.RE
1318.PP
1319"arenas\&.initialized" (\fBbool *\fR) r\-
1320.RS 4
1321An array of
1322"arenas\&.narenas"
1323booleans\&. Each boolean indicates whether the corresponding arena is initialized\&.
1324.RE
1325.PP
1326"arenas\&.lg_dirty_mult" (\fBssize_t\fR) rw
1327.RS 4
1328Current default per\-arena minimum ratio (log base 2) of active to dirty pages, used to initialize
1329"arena\&.<i>\&.lg_dirty_mult"
1330during arena creation\&. See
1331"opt\&.lg_dirty_mult"
1332for additional information\&.
1333.RE
1334.PP
1335"arenas\&.quantum" (\fBsize_t\fR) r\-
1336.RS 4
1337Quantum size\&.
1338.RE
1339.PP
1340"arenas\&.page" (\fBsize_t\fR) r\-
1341.RS 4
1342Page size\&.
1343.RE
1344.PP
1345"arenas\&.tcache_max" (\fBsize_t\fR) r\- [\fB\-\-enable\-tcache\fR]
1346.RS 4
1347Maximum thread\-cached size class\&.
1348.RE
1349.PP
1350"arenas\&.nbins" (\fBunsigned\fR) r\-
1351.RS 4
1352Number of bin size classes\&.
1353.RE
1354.PP
1355"arenas\&.nhbins" (\fBunsigned\fR) r\- [\fB\-\-enable\-tcache\fR]
1356.RS 4
1357Total number of thread cache bin size classes\&.
1358.RE
1359.PP
1360"arenas\&.bin\&.<i>\&.size" (\fBsize_t\fR) r\-
1361.RS 4
1362Maximum size supported by size class\&.
1363.RE
1364.PP
1365"arenas\&.bin\&.<i>\&.nregs" (\fBuint32_t\fR) r\-
1366.RS 4
1367Number of regions per page run\&.
1368.RE
1369.PP
1370"arenas\&.bin\&.<i>\&.run_size" (\fBsize_t\fR) r\-
1371.RS 4
1372Number of bytes per page run\&.
1373.RE
1374.PP
1375"arenas\&.nlruns" (\fBunsigned\fR) r\-
1376.RS 4
1377Total number of large size classes\&.
1378.RE
1379.PP
1380"arenas\&.lrun\&.<i>\&.size" (\fBsize_t\fR) r\-
1381.RS 4
1382Maximum size supported by this large size class\&.
1383.RE
1384.PP
1385"arenas\&.nhchunks" (\fBunsigned\fR) r\-
1386.RS 4
1387Total number of huge size classes\&.
1388.RE
1389.PP
1390"arenas\&.hchunk\&.<i>\&.size" (\fBsize_t\fR) r\-
1391.RS 4
1392Maximum size supported by this huge size class\&.
1393.RE
1394.PP
1395"arenas\&.extend" (\fBunsigned\fR) r\-
1396.RS 4
1397Extend the array of arenas by appending a new arena, and returning the new arena index\&.
1398.RE
1399.PP
1400"prof\&.thread_active_init" (\fBbool\fR) rw [\fB\-\-enable\-prof\fR]
1401.RS 4
1402Control the initial setting for
1403"thread\&.prof\&.active"
1404in newly created threads\&. See the
1405"opt\&.prof_thread_active_init"
1406option for additional information\&.
1407.RE
1408.PP
1409"prof\&.active" (\fBbool\fR) rw [\fB\-\-enable\-prof\fR]
1410.RS 4
1411Control whether sampling is currently active\&. See the
1412"opt\&.prof_active"
1413option for additional information, as well as the interrelated
1414"thread\&.prof\&.active"
1415mallctl\&.
1416.RE
1417.PP
1418"prof\&.dump" (\fBconst char *\fR) \-w [\fB\-\-enable\-prof\fR]
1419.RS 4
1420Dump a memory profile to the specified file, or if NULL is specified, to a file according to the pattern
1421<prefix>\&.<pid>\&.<seq>\&.m<mseq>\&.heap, where
1422<prefix>
1423is controlled by the
1424"opt\&.prof_prefix"
1425option\&.
1426.RE
1427.PP
1428"prof\&.gdump" (\fBbool\fR) rw [\fB\-\-enable\-prof\fR]
1429.RS 4
1430When enabled, trigger a memory profile dump every time the total virtual memory exceeds the previous maximum\&. Profiles are dumped to files named according to the pattern
1431<prefix>\&.<pid>\&.<seq>\&.u<useq>\&.heap, where
1432<prefix>
1433is controlled by the
1434"opt\&.prof_prefix"
1435option\&.
1436.RE
1437.PP
1438"prof\&.reset" (\fBsize_t\fR) \-w [\fB\-\-enable\-prof\fR]
1439.RS 4
1440Reset all memory profile statistics, and optionally update the sample rate (see
1441"opt\&.lg_prof_sample"
1442and
1443"prof\&.lg_sample")\&.
1444.RE
1445.PP
1446"prof\&.lg_sample" (\fBsize_t\fR) r\- [\fB\-\-enable\-prof\fR]
1447.RS 4
1448Get the current sample rate (see
1449"opt\&.lg_prof_sample")\&.
1450.RE
1451.PP
1452"prof\&.interval" (\fBuint64_t\fR) r\- [\fB\-\-enable\-prof\fR]
1453.RS 4
1454Average number of bytes allocated between inverval\-based profile dumps\&. See the
1455"opt\&.lg_prof_interval"
1456option for additional information\&.
1457.RE
1458.PP
1459"stats\&.cactive" (\fBsize_t *\fR) r\- [\fB\-\-enable\-stats\fR]
1460.RS 4
1461Pointer to a counter that contains an approximate count of the current number of bytes in active pages\&. The estimate may be high, but never low, because each arena rounds up when computing its contribution to the counter\&. Note that the
1462"epoch"
1463mallctl 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\&.
1464.RE
1465.PP
1466"stats\&.allocated" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1467.RS 4
1468Total number of bytes allocated by the application\&.
1469.RE
1470.PP
1471"stats\&.active" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1472.RS 4
1473Total number of bytes in active pages allocated by the application\&. This is a multiple of the page size, and greater than or equal to
1474"stats\&.allocated"\&. This does not include
1475"stats\&.arenas\&.<i>\&.pdirty", nor pages entirely devoted to allocator metadata\&.
1476.RE
1477.PP
1478"stats\&.metadata" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1479.RS 4
1480Total number of bytes dedicated to metadata, which comprise base allocations used for bootstrap\-sensitive internal allocator data structures, arena chunk headers (see
1481"stats\&.arenas\&.<i>\&.metadata\&.mapped"), and internal allocations (see
1482"stats\&.arenas\&.<i>\&.metadata\&.allocated")\&.
1483.RE
1484.PP
1485"stats\&.resident" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1486.RS 4
1487Maximum number of bytes in physically resident data pages mapped by the allocator, comprising all pages dedicated to allocator metadata, pages backing active allocations, and unused dirty pages\&. This is a maximum rather than precise because pages may not actually be physically resident if they correspond to demand\-zeroed virtual memory that has not yet been touched\&. This is a multiple of the page size, and is larger than
1488"stats\&.active"\&.
1489.RE
1490.PP
1491"stats\&.mapped" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1492.RS 4
1493Total number of bytes in active chunks mapped by the allocator\&. This is a multiple of the chunk size, and is larger than
1494"stats\&.active"\&. This does not include inactive chunks, even those that contain unused dirty pages, which means that there is no strict ordering between this and
1495"stats\&.resident"\&.
1496.RE
1497.PP
1498"stats\&.arenas\&.<i>\&.dss" (\fBconst char *\fR) r\-
1499.RS 4
1500dss (\fBsbrk\fR(2)) allocation precedence as related to
1501\fBmmap\fR(2)
1502allocation\&. See
1503"opt\&.dss"
1504for details\&.
1505.RE
1506.PP
1507"stats\&.arenas\&.<i>\&.lg_dirty_mult" (\fBssize_t\fR) r\-
1508.RS 4
1509Minimum ratio (log base 2) of active to dirty pages\&. See
1510"opt\&.lg_dirty_mult"
1511for details\&.
1512.RE
1513.PP
1514"stats\&.arenas\&.<i>\&.nthreads" (\fBunsigned\fR) r\-
1515.RS 4
1516Number of threads currently assigned to arena\&.
1517.RE
1518.PP
1519"stats\&.arenas\&.<i>\&.pactive" (\fBsize_t\fR) r\-
1520.RS 4
1521Number of pages in active runs\&.
1522.RE
1523.PP
1524"stats\&.arenas\&.<i>\&.pdirty" (\fBsize_t\fR) r\-
1525.RS 4
1526Number of pages within unused runs that are potentially dirty, and for which
1527\fBmadvise\fR\fB\fI\&.\&.\&.\fR\fR\fB \fR\fB\fI\fBMADV_DONTNEED\fR\fR\fR
1528or similar has not been called\&.
1529.RE
1530.PP
1531"stats\&.arenas\&.<i>\&.mapped" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1532.RS 4
1533Number of mapped bytes\&.
1534.RE
1535.PP
1536"stats\&.arenas\&.<i>\&.metadata\&.mapped" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1537.RS 4
1538Number of mapped bytes in arena chunk headers, which track the states of the non\-metadata pages\&.
1539.RE
1540.PP
1541"stats\&.arenas\&.<i>\&.metadata\&.allocated" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1542.RS 4
1543Number of bytes dedicated to internal allocations\&. Internal allocations differ from application\-originated allocations in that they are for internal use, and that they are omitted from heap profiles\&. This statistic is reported separately from
1544"stats\&.metadata"
1545and
1546"stats\&.arenas\&.<i>\&.metadata\&.mapped"
1547because it overlaps with e\&.g\&. the
1548"stats\&.allocated"
1549and
1550"stats\&.active"
1551statistics, whereas the other metadata statistics do not\&.
1552.RE
1553.PP
1554"stats\&.arenas\&.<i>\&.npurge" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1555.RS 4
1556Number of dirty page purge sweeps performed\&.
1557.RE
1558.PP
1559"stats\&.arenas\&.<i>\&.nmadvise" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1560.RS 4
1561Number of
1562\fBmadvise\fR\fB\fI\&.\&.\&.\fR\fR\fB \fR\fB\fI\fBMADV_DONTNEED\fR\fR\fR
1563or similar calls made to purge dirty pages\&.
1564.RE
1565.PP
1566"stats\&.arenas\&.<i>\&.purged" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1567.RS 4
1568Number of pages purged\&.
1569.RE
1570.PP
1571"stats\&.arenas\&.<i>\&.small\&.allocated" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1572.RS 4
1573Number of bytes currently allocated by small objects\&.
1574.RE
1575.PP
1576"stats\&.arenas\&.<i>\&.small\&.nmalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1577.RS 4
1578Cumulative number of allocation requests served by small bins\&.
1579.RE
1580.PP
1581"stats\&.arenas\&.<i>\&.small\&.ndalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1582.RS 4
1583Cumulative number of small objects returned to bins\&.
1584.RE
1585.PP
1586"stats\&.arenas\&.<i>\&.small\&.nrequests" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1587.RS 4
1588Cumulative number of small allocation requests\&.
1589.RE
1590.PP
1591"stats\&.arenas\&.<i>\&.large\&.allocated" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1592.RS 4
1593Number of bytes currently allocated by large objects\&.
1594.RE
1595.PP
1596"stats\&.arenas\&.<i>\&.large\&.nmalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1597.RS 4
1598Cumulative number of large allocation requests served directly by the arena\&.
1599.RE
1600.PP
1601"stats\&.arenas\&.<i>\&.large\&.ndalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1602.RS 4
1603Cumulative number of large deallocation requests served directly by the arena\&.
1604.RE
1605.PP
1606"stats\&.arenas\&.<i>\&.large\&.nrequests" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1607.RS 4
1608Cumulative number of large allocation requests\&.
1609.RE
1610.PP
1611"stats\&.arenas\&.<i>\&.huge\&.allocated" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1612.RS 4
1613Number of bytes currently allocated by huge objects\&.
1614.RE
1615.PP
1616"stats\&.arenas\&.<i>\&.huge\&.nmalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1617.RS 4
1618Cumulative number of huge allocation requests served directly by the arena\&.
1619.RE
1620.PP
1621"stats\&.arenas\&.<i>\&.huge\&.ndalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1622.RS 4
1623Cumulative number of huge deallocation requests served directly by the arena\&.
1624.RE
1625.PP
1626"stats\&.arenas\&.<i>\&.huge\&.nrequests" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1627.RS 4
1628Cumulative number of huge allocation requests\&.
1629.RE
1630.PP
1631"stats\&.arenas\&.<i>\&.bins\&.<j>\&.nmalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1632.RS 4
1633Cumulative number of allocations served by bin\&.
1634.RE
1635.PP
1636"stats\&.arenas\&.<i>\&.bins\&.<j>\&.ndalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1637.RS 4
1638Cumulative number of allocations returned to bin\&.
1639.RE
1640.PP
1641"stats\&.arenas\&.<i>\&.bins\&.<j>\&.nrequests" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1642.RS 4
1643Cumulative number of allocation requests\&.
1644.RE
1645.PP
1646"stats\&.arenas\&.<i>\&.bins\&.<j>\&.curregs" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1647.RS 4
1648Current number of regions for this size class\&.
1649.RE
1650.PP
1651"stats\&.arenas\&.<i>\&.bins\&.<j>\&.nfills" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR \fB\-\-enable\-tcache\fR]
1652.RS 4
1653Cumulative number of tcache fills\&.
1654.RE
1655.PP
1656"stats\&.arenas\&.<i>\&.bins\&.<j>\&.nflushes" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR \fB\-\-enable\-tcache\fR]
1657.RS 4
1658Cumulative number of tcache flushes\&.
1659.RE
1660.PP
1661"stats\&.arenas\&.<i>\&.bins\&.<j>\&.nruns" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1662.RS 4
1663Cumulative number of runs created\&.
1664.RE
1665.PP
1666"stats\&.arenas\&.<i>\&.bins\&.<j>\&.nreruns" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1667.RS 4
1668Cumulative number of times the current run from which to allocate changed\&.
1669.RE
1670.PP
1671"stats\&.arenas\&.<i>\&.bins\&.<j>\&.curruns" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1672.RS 4
1673Current number of runs\&.
1674.RE
1675.PP
1676"stats\&.arenas\&.<i>\&.lruns\&.<j>\&.nmalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1677.RS 4
1678Cumulative number of allocation requests for this size class served directly by the arena\&.
1679.RE
1680.PP
1681"stats\&.arenas\&.<i>\&.lruns\&.<j>\&.ndalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1682.RS 4
1683Cumulative number of deallocation requests for this size class served directly by the arena\&.
1684.RE
1685.PP
1686"stats\&.arenas\&.<i>\&.lruns\&.<j>\&.nrequests" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1687.RS 4
1688Cumulative number of allocation requests for this size class\&.
1689.RE
1690.PP
1691"stats\&.arenas\&.<i>\&.lruns\&.<j>\&.curruns" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1692.RS 4
1693Current number of runs for this size class\&.
1694.RE
1695.PP
1696"stats\&.arenas\&.<i>\&.hchunks\&.<j>\&.nmalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1697.RS 4
1698Cumulative number of allocation requests for this size class served directly by the arena\&.
1699.RE
1700.PP
1701"stats\&.arenas\&.<i>\&.hchunks\&.<j>\&.ndalloc" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1702.RS 4
1703Cumulative number of deallocation requests for this size class served directly by the arena\&.
1704.RE
1705.PP
1706"stats\&.arenas\&.<i>\&.hchunks\&.<j>\&.nrequests" (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1707.RS 4
1708Cumulative number of allocation requests for this size class\&.
1709.RE
1710.PP
1711"stats\&.arenas\&.<i>\&.hchunks\&.<j>\&.curhchunks" (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1712.RS 4
1713Current number of huge allocations for this size class\&.
1714.RE
1715.SH "DEBUGGING MALLOC PROBLEMS"
1716.PP
1717When debugging, it is a good idea to configure/build jemalloc with the
1718\fB\-\-enable\-debug\fR
1719and
1720\fB\-\-enable\-fill\fR
1721options, 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\&.
1722.PP
1723Programs often accidentally depend on \(lquninitialized\(rq memory actually being filled with zero bytes\&. Junk filling (see the
1724"opt\&.junk"
1725option) tends to expose such bugs in the form of obviously incorrect results and/or coredumps\&. Conversely, zero filling (see the
1726"opt\&.zero"
1727option) eliminates the symptoms of such bugs\&. Between these two options, it is usually possible to quickly detect, diagnose, and eliminate such bugs\&.
1728.PP
1729This implementation does not provide much detail about the problems it detects, because the performance impact for storing such information would be prohibitive\&. However, jemalloc does integrate with the most excellent
1730\m[blue]\fBValgrind\fR\m[]\&\s-2\u[2]\d\s+2
1731tool if the
1732\fB\-\-enable\-valgrind\fR
1733configuration option is enabled\&.
1734.SH "DIAGNOSTIC MESSAGES"
1735.PP
1736If any of the memory allocation/deallocation functions detect an error or warning condition, a message will be printed to file descriptor
1737\fBSTDERR_FILENO\fR\&. Errors will result in the process dumping core\&. If the
1738"opt\&.abort"
1739option is set, most warnings are treated as errors\&.
1740.PP
1741The
1742\fImalloc_message\fR
1743variable allows the programmer to override the function which emits the text strings forming the errors and warnings if for some reason the
1744\fBSTDERR_FILENO\fR
1745file descriptor is not suitable for this\&.
1746\fBmalloc_message\fR\fB\fR
1747takes the
1748\fIcbopaque\fR
1749pointer argument that is
1750\fBNULL\fR
1751unless overridden by the arguments in a call to
1752\fBmalloc_stats_print\fR\fB\fR, followed by a string pointer\&. Please note that doing anything which tries to allocate memory in this function is likely to result in a crash or deadlock\&.
1753.PP
1754All messages are prefixed by \(lq<jemalloc>:\(rq\&.
1755.SH "RETURN VALUES"
1756.SS "Standard API"
1757.PP
1758The
1759\fBmalloc\fR\fB\fR
1760and
1761\fBcalloc\fR\fB\fR
1762functions return a pointer to the allocated memory if successful; otherwise a
1763\fBNULL\fR
1764pointer is returned and
1765\fIerrno\fR
1766is set to
1767ENOMEM\&.
1768.PP
1769The
1770\fBposix_memalign\fR\fB\fR
1771function returns the value 0 if successful; otherwise it returns an error value\&. The
1772\fBposix_memalign\fR\fB\fR
1773function will fail if:
1774.PP
1775EINVAL
1776.RS 4
1777The
1778\fIalignment\fR
1779parameter is not a power of 2 at least as large as
1780sizeof(\fBvoid *\fR)\&.
1781.RE
1782.PP
1783ENOMEM
1784.RS 4
1785Memory allocation error\&.
1786.RE
1787.PP
1788The
1789\fBaligned_alloc\fR\fB\fR
1790function returns a pointer to the allocated memory if successful; otherwise a
1791\fBNULL\fR
1792pointer is returned and
1793\fIerrno\fR
1794is set\&. The
1795\fBaligned_alloc\fR\fB\fR
1796function will fail if:
1797.PP
1798EINVAL
1799.RS 4
1800The
1801\fIalignment\fR
1802parameter is not a power of 2\&.
1803.RE
1804.PP
1805ENOMEM
1806.RS 4
1807Memory allocation error\&.
1808.RE
1809.PP
1810The
1811\fBrealloc\fR\fB\fR
1812function returns a pointer, possibly identical to
1813\fIptr\fR, to the allocated memory if successful; otherwise a
1814\fBNULL\fR
1815pointer is returned, and
1816\fIerrno\fR
1817is set to
1818ENOMEM
1819if the error was the result of an allocation failure\&. The
1820\fBrealloc\fR\fB\fR
1821function always leaves the original buffer intact when an error occurs\&.
1822.PP
1823The
1824\fBfree\fR\fB\fR
1825function returns no value\&.
1826.SS "Non\-standard API"
1827.PP
1828The
1829\fBmallocx\fR\fB\fR
1830and
1831\fBrallocx\fR\fB\fR
1832functions return a pointer to the allocated memory if successful; otherwise a
1833\fBNULL\fR
1834pointer is returned to indicate insufficient contiguous memory was available to service the allocation request\&.
1835.PP
1836The
1837\fBxallocx\fR\fB\fR
1838function returns the real size of the resulting resized allocation pointed to by
1839\fIptr\fR, which is a value less than
1840\fIsize\fR
1841if the allocation could not be adequately grown in place\&.
1842.PP
1843The
1844\fBsallocx\fR\fB\fR
1845function returns the real size of the allocation pointed to by
1846\fIptr\fR\&.
1847.PP
1848The
1849\fBnallocx\fR\fB\fR
1850returns the real size that would result from a successful equivalent
1851\fBmallocx\fR\fB\fR
1852function call, or zero if insufficient memory is available to perform the size computation\&.
1853.PP
1854The
1855\fBmallctl\fR\fB\fR,
1856\fBmallctlnametomib\fR\fB\fR, and
1857\fBmallctlbymib\fR\fB\fR
1858functions return 0 on success; otherwise they return an error value\&. The functions will fail if:
1859.PP
1860EINVAL
1861.RS 4
1862\fInewp\fR
1863is not
1864\fBNULL\fR, and
1865\fInewlen\fR
1866is too large or too small\&. Alternatively,
1867\fI*oldlenp\fR
1868is too large or too small; in this case as much data as possible are read despite the error\&.
1869.RE
1870.PP
1871ENOENT
1872.RS 4
1873\fIname\fR
1874or
1875\fImib\fR
1876specifies an unknown/invalid value\&.
1877.RE
1878.PP
1879EPERM
1880.RS 4
1881Attempt to read or write void value, or attempt to write read\-only value\&.
1882.RE
1883.PP
1884EAGAIN
1885.RS 4
1886A memory allocation failure occurred\&.
1887.RE
1888.PP
1889EFAULT
1890.RS 4
1891An interface with side effects failed in some way not directly related to
1892\fBmallctl*\fR\fB\fR
1893read/write processing\&.
1894.RE
1895.PP
1896The
1897\fBmalloc_usable_size\fR\fB\fR
1898function returns the usable size of the allocation pointed to by
1899\fIptr\fR\&.
1900.SH "ENVIRONMENT"
1901.PP
1902The following environment variable affects the execution of the allocation functions:
1903.PP
1904\fBMALLOC_CONF\fR
1905.RS 4
1906If the environment variable
1907\fBMALLOC_CONF\fR
1908is set, the characters it contains will be interpreted as options\&.
1909.RE
1910.SH "EXAMPLES"
1911.PP
1912To dump core whenever a problem occurs:
1913.sp
1914.if n \{\
1915.RS 4
1916.\}
1917.nf
1918ln \-s \*(Aqabort:true\*(Aq /etc/malloc\&.conf
1919.fi
1920.if n \{\
1921.RE
1922.\}
1923.PP
1924To specify in the source a chunk size that is 16 MiB:
1925.sp
1926.if n \{\
1927.RS 4
1928.\}
1929.nf
1930malloc_conf = "lg_chunk:24";
1931.fi
1932.if n \{\
1933.RE
1934.\}
1935.SH "SEE ALSO"
1936.PP
1937\fBmadvise\fR(2),
1938\fBmmap\fR(2),
1939\fBsbrk\fR(2),
1940\fButrace\fR(2),
1941\fBalloca\fR(3),
1942\fBatexit\fR(3),
1943\fBgetpagesize\fR(3)
1944.SH "STANDARDS"
1945.PP
1946The
1947\fBmalloc\fR\fB\fR,
1948\fBcalloc\fR\fB\fR,
1949\fBrealloc\fR\fB\fR, and
1950\fBfree\fR\fB\fR
1951functions conform to ISO/IEC 9899:1990 (\(lqISO C90\(rq)\&.
1952.PP
1953The
1954\fBposix_memalign\fR\fB\fR
1955function conforms to IEEE Std 1003\&.1\-2001 (\(lqPOSIX\&.1\(rq)\&.
1956.SH "HISTORY"
1957.PP
1958The
1959\fBmalloc_usable_size\fR\fB\fR
1960and
1961\fBposix_memalign\fR\fB\fR
1962functions first appeared in FreeBSD 7\&.0\&.
1963.PP
1964The
1965\fBaligned_alloc\fR\fB\fR,
1966\fBmalloc_stats_print\fR\fB\fR, and
1967\fBmallctl*\fR\fB\fR
1968functions first appeared in FreeBSD 10\&.0\&.
1969.PP
1970The
1971\fB*allocx\fR\fB\fR
1972functions first appeared in FreeBSD 11\&.0\&.
1973.SH "AUTHOR"
1974.PP
1975\fBJason Evans\fR
1976.RS 4
1977.RE
1978.SH "NOTES"
1979.IP " 1." 4
1980jemalloc website
1981.RS 4
1982\%http://www.canonware.com/jemalloc/
1983.RE
1984.IP " 2." 4
1985Valgrind
1986.RS 4
1987\%http://valgrind.org/
1988.RE
1989.IP " 3." 4
1990gperftools package
1991.RS 4
1992\%http://code.google.com/p/gperftools/
1993.RE