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