]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/jemalloc/doc/jemalloc.3
Upgrade to OpenPAM Radula.
[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: 12/04/2016
6 .\"    Manual: User Manual
7 .\"    Source: jemalloc 4.4.0-0-gf1f76357313e7dcad7262f17a48ff0a2e005fcdc
8 .\"  Language: English
9 .\"
10 .TH "JEMALLOC" "3" "12/04/2016" "jemalloc 4.4.0-0-gf1f76357313e" "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\&.4\&.0\-0\-gf1f76357313e7dcad7262f17a48ff0a2e005fcdc\&. 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 malloc()
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 calloc()
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 malloc()
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 posix_memalign()
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 aligned_alloc()
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 realloc()
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 realloc()
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 realloc()
161 function behaves identically to
162 malloc()
163 for the specified size\&.
164 .PP
165 The
166 free()
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 mallocx(),
177 rallocx(),
178 xallocx(),
179 sallocx(),
180 dallocx(),
181 sdallocx(), and
182 nallocx()
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 mallocx()
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 rallocx()
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 xallocx()
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 sallocx()
278 function returns the real size of the allocation at
279 \fIptr\fR\&.
280 .PP
281 The
282 dallocx()
283 function causes the memory referenced by
284 \fIptr\fR
285 to be made available for future allocations\&.
286 .PP
287 The
288 sdallocx()
289 function is an extension of
290 dallocx()
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 nallocx()
295 or
296 sallocx()\&.
297 .PP
298 The
299 nallocx()
300 function allocates no memory, but it performs the same size computation as the
301 mallocx()
302 function, and returns the real size of the allocation that would result from the equivalent
303 mallocx()
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 mallctl()
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 mallctlnametomib()
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
333 \(lqManagement Information Base\(rq
334 (MIB) that can be passed repeatedly to
335 mallctlbymib()\&. Upon successful return from
336 mallctlnametomib(),
337 \fImibp\fR
338 contains an array of
339 \fI*miblenp\fR
340 integers, where
341 \fI*miblenp\fR
342 is the lesser of the number of components in
343 \fIname\fR
344 and the input value of
345 \fI*miblenp\fR\&. Thus it is possible to pass a
346 \fI*miblenp\fR
347 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
348 arenas\&.bin\&.2\&.size), the corresponding MIB component will always be that integer\&. Therefore, it is legitimate to construct code like the following:
349 .sp
350 .if n \{\
351 .RS 4
352 .\}
353 .nf
354 unsigned nbins, i;
355 size_t mib[4];
356 size_t len, miblen;
357
358 len = sizeof(nbins);
359 mallctl("arenas\&.nbins", &nbins, &len, NULL, 0);
360
361 miblen = 4;
362 mallctlnametomib("arenas\&.bin\&.0\&.size", mib, &miblen);
363 for (i = 0; i < nbins; i++) {
364         size_t bin_size;
365
366         mib[2] = i;
367         len = sizeof(bin_size);
368         mallctlbymib(mib, miblen, (void *)&bin_size, &len, NULL, 0);
369         /* Do something with bin_size\&.\&.\&. */
370 }
371 .fi
372 .if n \{\
373 .RE
374 .\}
375 .PP
376 The
377 malloc_stats_print()
378 function writes summary statistics via the
379 \fIwrite_cb\fR
380 callback function pointer and
381 \fIcbopaque\fR
382 data passed to
383 \fIwrite_cb\fR, or
384 malloc_message()
385 if
386 \fIwrite_cb\fR
387 is
388 \fBNULL\fR\&. The statistics are presented in human\-readable form unless
389 \(lqJ\(rq
390 is specified as a character within the
391 \fIopts\fR
392 string, in which case the statistics are presented in
393 \m[blue]\fBJSON format\fR\m[]\&\s-2\u[2]\d\s+2\&. This function can be called repeatedly\&. General information that never changes during execution can be omitted by specifying
394 \(lqg\(rq
395 as a character within the
396 \fIopts\fR
397 string\&. Note that
398 malloc_message()
399 uses the
400 mallctl*()
401 functions internally, so inconsistent statistics can be reported if multiple threads use these functions simultaneously\&. If
402 \fB\-\-enable\-stats\fR
403 is specified during configuration,
404 \(lqm\(rq
405 and
406 \(lqa\(rq
407 can be specified to omit merged arena and per arena statistics, respectively;
408 \(lqb\(rq,
409 \(lql\(rq, and
410 \(lqh\(rq
411 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\&.
412 .PP
413 The
414 malloc_usable_size()
415 function returns the usable size of the allocation pointed to by
416 \fIptr\fR\&. The return value may be larger than the size that was requested during allocation\&. The
417 malloc_usable_size()
418 function is not a mechanism for in\-place
419 realloc(); rather it is provided solely as a tool for introspection purposes\&. Any discrepancy between the requested allocation size and the size reported by
420 malloc_usable_size()
421 should not be depended on, since such behavior is entirely implementation\-dependent\&.
422 .SH "TUNING"
423 .PP
424 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\&.
425 .PP
426 The string specified via
427 \fB\-\-with\-malloc\-conf\fR, the string pointed to by the global variable
428 \fImalloc_conf\fR, the
429 \(lqname\(rq
430 of the file referenced by the symbolic link named
431 /etc/malloc\&.conf, and the value of the environment variable
432 \fBMALLOC_CONF\fR, will be interpreted, in that order, from left to right as options\&. Note that
433 \fImalloc_conf\fR
434 may be read before
435 main()
436 is entered, so the declaration of
437 \fImalloc_conf\fR
438 should specify an initializer that contains the final value to be read by jemalloc\&.
439 \fB\-\-with\-malloc\-conf\fR
440 and
441 \fImalloc_conf\fR
442 are compile\-time mechanisms, whereas
443 /etc/malloc\&.conf
444 and
445 \fBMALLOC_CONF\fR
446 can be safely set any time prior to program invocation\&.
447 .PP
448 An options string is a comma\-separated list of option:value pairs\&. There is one key corresponding to each
449 opt\&.*
450 mallctl (see the
451 MALLCTL NAMESPACE
452 section for options documentation)\&. For example,
453 abort:true,narenas:1
454 sets the
455 opt\&.abort
456 and
457 opt\&.narenas
458 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\&.
459 .SH "IMPLEMENTATION NOTES"
460 .PP
461 Traditionally, allocators have used
462 \fBsbrk\fR(2)
463 to obtain memory, which is suboptimal for several reasons, including race conditions, increased fragmentation, and artificial limitations on maximum usable memory\&. If
464 \fBsbrk\fR(2)
465 is supported by the operating system, this allocator uses both
466 \fBmmap\fR(2)
467 and
468 \fBsbrk\fR(2), in that order of preference; otherwise only
469 \fBmmap\fR(2)
470 is used\&.
471 .PP
472 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\&.
473 .PP
474 In addition to multiple arenas, unless
475 \fB\-\-disable\-tcache\fR
476 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\&.
477 .PP
478 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\&.
479 .PP
480 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
481 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
482 opt\&.lg_chunk
483 option), and huge size classes extend from the chunk size up to the largest size class that does not exceed
484 \fBPTRDIFF_MAX\fR\&.
485 .PP
486 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\&.
487 .PP
488 The
489 realloc(),
490 rallocx(), and
491 xallocx()
492 functions may resize allocations without moving them under limited circumstances\&. Unlike the
493 *allocx()
494 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
495 realloc()
496 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
497 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\&.
498 .PP
499 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
500 Table 1\&.
501 .sp
502 .it 1 an-trap
503 .nr an-no-space-flag 1
504 .nr an-break-flag 1
505 .br
506 .B Table\ \&1.\ \&Size classes
507 .TS
508 allbox tab(:);
509 lB rB lB.
510 T{
511 Category
512 T}:T{
513 Spacing
514 T}:T{
515 Size
516 T}
517 .T&
518 l r l
519 ^ r l
520 ^ r l
521 ^ r l
522 ^ r l
523 ^ r l
524 ^ r l
525 ^ r l
526 ^ r l
527 l r l
528 ^ r l
529 ^ r l
530 ^ r l
531 ^ r l
532 ^ r l
533 ^ r l
534 ^ r l
535 l r l
536 ^ r l
537 ^ r l
538 ^ r l
539 ^ r l
540 ^ r l
541 ^ r l
542 ^ r l
543 ^ r l.
544 T{
545 Small
546 T}:T{
547 lg
548 T}:T{
549 [8]
550 T}
551 :T{
552 16
553 T}:T{
554 [16, 32, 48, 64, 80, 96, 112, 128]
555 T}
556 :T{
557 32
558 T}:T{
559 [160, 192, 224, 256]
560 T}
561 :T{
562 64
563 T}:T{
564 [320, 384, 448, 512]
565 T}
566 :T{
567 128
568 T}:T{
569 [640, 768, 896, 1024]
570 T}
571 :T{
572 256
573 T}:T{
574 [1280, 1536, 1792, 2048]
575 T}
576 :T{
577 512
578 T}:T{
579 [2560, 3072, 3584, 4096]
580 T}
581 :T{
582 1 KiB
583 T}:T{
584 [5 KiB, 6 KiB, 7 KiB, 8 KiB]
585 T}
586 :T{
587 2 KiB
588 T}:T{
589 [10 KiB, 12 KiB, 14 KiB]
590 T}
591 T{
592 Large
593 T}:T{
594 2 KiB
595 T}:T{
596 [16 KiB]
597 T}
598 :T{
599 4 KiB
600 T}:T{
601 [20 KiB, 24 KiB, 28 KiB, 32 KiB]
602 T}
603 :T{
604 8 KiB
605 T}:T{
606 [40 KiB, 48 KiB, 54 KiB, 64 KiB]
607 T}
608 :T{
609 16 KiB
610 T}:T{
611 [80 KiB, 96 KiB, 112 KiB, 128 KiB]
612 T}
613 :T{
614 32 KiB
615 T}:T{
616 [160 KiB, 192 KiB, 224 KiB, 256 KiB]
617 T}
618 :T{
619 64 KiB
620 T}:T{
621 [320 KiB, 384 KiB, 448 KiB, 512 KiB]
622 T}
623 :T{
624 128 KiB
625 T}:T{
626 [640 KiB, 768 KiB, 896 KiB, 1 MiB]
627 T}
628 :T{
629 256 KiB
630 T}:T{
631 [1280 KiB, 1536 KiB, 1792 KiB]
632 T}
633 T{
634 Huge
635 T}:T{
636 256 KiB
637 T}:T{
638 [2 MiB]
639 T}
640 :T{
641 512 KiB
642 T}:T{
643 [2560 KiB, 3 MiB, 3584 KiB, 4 MiB]
644 T}
645 :T{
646 1 MiB
647 T}:T{
648 [5 MiB, 6 MiB, 7 MiB, 8 MiB]
649 T}
650 :T{
651 2 MiB
652 T}:T{
653 [10 MiB, 12 MiB, 14 MiB, 16 MiB]
654 T}
655 :T{
656 4 MiB
657 T}:T{
658 [20 MiB, 24 MiB, 28 MiB, 32 MiB]
659 T}
660 :T{
661 8 MiB
662 T}:T{
663 [40 MiB, 48 MiB, 56 MiB, 64 MiB]
664 T}
665 :T{
666 \&.\&.\&.
667 T}:T{
668 \&.\&.\&.
669 T}
670 :T{
671 512 PiB
672 T}:T{
673 [2560 PiB, 3 EiB, 3584 PiB, 4 EiB]
674 T}
675 :T{
676 1 EiB
677 T}:T{
678 [5 EiB, 6 EiB, 7 EiB]
679 T}
680 .TE
681 .sp 1
682 .SH "MALLCTL NAMESPACE"
683 .PP
684 The following names are defined in the namespace accessible via the
685 mallctl*()
686 functions\&. Value types are specified in parentheses, their readable/writable statuses are encoded as
687 rw,
688 r\-,
689 \-w, or
690 \-\-, and required build configuration flags follow, if any\&. A name element encoded as
691 <i>
692 or
693 <j>
694 indicates an integer component, where the integer varies from 0 to some upper value that must be determined via introspection\&. In the case of
695 stats\&.arenas\&.<i>\&.*,
696 <i>
697 equal to
698 arenas\&.narenas
699 can be used to access the summation of statistics from all arenas\&. Take special note of the
700 epoch
701 mallctl, which controls refreshing of cached dynamic statistics\&.
702 .PP
703 version (\fBconst char *\fR) r\-
704 .RS 4
705 Return the jemalloc version string\&.
706 .RE
707 .PP
708 epoch (\fBuint64_t\fR) rw
709 .RS 4
710 If a value is passed in, refresh the data from which the
711 mallctl*()
712 functions report values, and increment the epoch\&. Return the current epoch\&. This is useful for detecting whether another thread caused a refresh\&.
713 .RE
714 .PP
715 config\&.cache_oblivious (\fBbool\fR) r\-
716 .RS 4
717 \fB\-\-enable\-cache\-oblivious\fR
718 was specified during build configuration\&.
719 .RE
720 .PP
721 config\&.debug (\fBbool\fR) r\-
722 .RS 4
723 \fB\-\-enable\-debug\fR
724 was specified during build configuration\&.
725 .RE
726 .PP
727 config\&.fill (\fBbool\fR) r\-
728 .RS 4
729 \fB\-\-enable\-fill\fR
730 was specified during build configuration\&.
731 .RE
732 .PP
733 config\&.lazy_lock (\fBbool\fR) r\-
734 .RS 4
735 \fB\-\-enable\-lazy\-lock\fR
736 was specified during build configuration\&.
737 .RE
738 .PP
739 config\&.malloc_conf (\fBconst char *\fR) r\-
740 .RS 4
741 Embedded configure\-time\-specified run\-time options string, empty unless
742 \fB\-\-with\-malloc\-conf\fR
743 was specified during build configuration\&.
744 .RE
745 .PP
746 config\&.munmap (\fBbool\fR) r\-
747 .RS 4
748 \fB\-\-enable\-munmap\fR
749 was specified during build configuration\&.
750 .RE
751 .PP
752 config\&.prof (\fBbool\fR) r\-
753 .RS 4
754 \fB\-\-enable\-prof\fR
755 was specified during build configuration\&.
756 .RE
757 .PP
758 config\&.prof_libgcc (\fBbool\fR) r\-
759 .RS 4
760 \fB\-\-disable\-prof\-libgcc\fR
761 was not specified during build configuration\&.
762 .RE
763 .PP
764 config\&.prof_libunwind (\fBbool\fR) r\-
765 .RS 4
766 \fB\-\-enable\-prof\-libunwind\fR
767 was specified during build configuration\&.
768 .RE
769 .PP
770 config\&.stats (\fBbool\fR) r\-
771 .RS 4
772 \fB\-\-enable\-stats\fR
773 was specified during build configuration\&.
774 .RE
775 .PP
776 config\&.tcache (\fBbool\fR) r\-
777 .RS 4
778 \fB\-\-disable\-tcache\fR
779 was not specified during build configuration\&.
780 .RE
781 .PP
782 config\&.tls (\fBbool\fR) r\-
783 .RS 4
784 \fB\-\-disable\-tls\fR
785 was not specified during build configuration\&.
786 .RE
787 .PP
788 config\&.utrace (\fBbool\fR) r\-
789 .RS 4
790 \fB\-\-enable\-utrace\fR
791 was specified during build configuration\&.
792 .RE
793 .PP
794 config\&.valgrind (\fBbool\fR) r\-
795 .RS 4
796 \fB\-\-enable\-valgrind\fR
797 was specified during build configuration\&.
798 .RE
799 .PP
800 config\&.xmalloc (\fBbool\fR) r\-
801 .RS 4
802 \fB\-\-enable\-xmalloc\fR
803 was specified during build configuration\&.
804 .RE
805 .PP
806 opt\&.abort (\fBbool\fR) r\-
807 .RS 4
808 Abort\-on\-warning enabled/disabled\&. If true, most warnings are fatal\&. The process will call
809 \fBabort\fR(3)
810 in these cases\&. This option is disabled by default unless
811 \fB\-\-enable\-debug\fR
812 is specified during configuration, in which case it is enabled by default\&.
813 .RE
814 .PP
815 opt\&.dss (\fBconst char *\fR) r\-
816 .RS 4
817 dss (\fBsbrk\fR(2)) allocation precedence as related to
818 \fBmmap\fR(2)
819 allocation\&. The following settings are supported if
820 \fBsbrk\fR(2)
821 is supported by the operating system:
822 \(lqdisabled\(rq,
823 \(lqprimary\(rq, and
824 \(lqsecondary\(rq; otherwise only
825 \(lqdisabled\(rq
826 is supported\&. The default is
827 \(lqsecondary\(rq
828 if
829 \fBsbrk\fR(2)
830 is supported by the operating system;
831 \(lqdisabled\(rq
832 otherwise\&.
833 .RE
834 .PP
835 opt\&.lg_chunk (\fBsize_t\fR) r\-
836 .RS 4
837 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)\&.
838 .RE
839 .PP
840 opt\&.narenas (\fBunsigned\fR) r\-
841 .RS 4
842 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\&.
843 .RE
844 .PP
845 opt\&.purge (\fBconst char *\fR) r\-
846 .RS 4
847 Purge mode is \(lqratio\(rq (default) or \(lqdecay\(rq\&. See
848 opt\&.lg_dirty_mult
849 for details of the ratio mode\&. See
850 opt\&.decay_time
851 for details of the decay mode\&.
852 .RE
853 .PP
854 opt\&.lg_dirty_mult (\fBssize_t\fR) r\-
855 .RS 4
856 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
857 \fBmadvise\fR(2)
858 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
859 arenas\&.lg_dirty_mult
860 and
861 arena\&.<i>\&.lg_dirty_mult
862 for related dynamic control options\&.
863 .RE
864 .PP
865 opt\&.decay_time (\fBssize_t\fR) r\-
866 .RS 4
867 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
868 arenas\&.decay_time
869 and
870 arena\&.<i>\&.decay_time
871 for related dynamic control options\&.
872 .RE
873 .PP
874 opt\&.stats_print (\fBbool\fR) r\-
875 .RS 4
876 Enable/disable statistics printing at exit\&. If enabled, the
877 malloc_stats_print()
878 function is called at program exit via an
879 \fBatexit\fR(3)
880 function\&. If
881 \fB\-\-enable\-stats\fR
882 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,
883 atexit()
884 may allocate memory during application initialization and then deadlock internally when jemalloc in turn calls
885 atexit(), so this option is not universally usable (though the application can register its own
886 atexit()
887 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\&.
888 .RE
889 .PP
890 opt\&.junk (\fBconst char *\fR) r\- [\fB\-\-enable\-fill\fR]
891 .RS 4
892 Junk filling\&. If set to
893 \(lqalloc\(rq, each byte of uninitialized allocated memory will be initialized to
894 0xa5\&. If set to
895 \(lqfree\(rq, all deallocated memory will be initialized to
896 0x5a\&. If set to
897 \(lqtrue\(rq, both allocated and deallocated memory will be initialized, and if set to
898 \(lqfalse\(rq, junk filling be disabled entirely\&. This is intended for debugging and will impact performance negatively\&. This option is
899 \(lqfalse\(rq
900 by default unless
901 \fB\-\-enable\-debug\fR
902 is specified during configuration, in which case it is
903 \(lqtrue\(rq
904 by default unless running inside
905 \m[blue]\fBValgrind\fR\m[]\&\s-2\u[3]\d\s+2\&.
906 .RE
907 .PP
908 opt\&.quarantine (\fBsize_t\fR) r\- [\fB\-\-enable\-fill\fR]
909 .RS 4
910 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
911 opt\&.junk
912 option is enabled\&. This feature is of particular use in combination with
913 \m[blue]\fBValgrind\fR\m[]\&\s-2\u[3]\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\&.
914 .RE
915 .PP
916 opt\&.redzone (\fBbool\fR) r\- [\fB\-\-enable\-fill\fR]
917 .RS 4
918 Redzones enabled/disabled\&. If enabled, small allocations have redzones before and after them\&. Furthermore, if the
919 opt\&.junk
920 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
921 \m[blue]\fBValgrind\fR\m[]\&\s-2\u[3]\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\&.
922 .RE
923 .PP
924 opt\&.zero (\fBbool\fR) r\- [\fB\-\-enable\-fill\fR]
925 .RS 4
926 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
927 realloc()
928 and
929 rallocx()
930 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\&.
931 .RE
932 .PP
933 opt\&.utrace (\fBbool\fR) r\- [\fB\-\-enable\-utrace\fR]
934 .RS 4
935 Allocation tracing based on
936 \fButrace\fR(2)
937 enabled/disabled\&. This option is disabled by default\&.
938 .RE
939 .PP
940 opt\&.xmalloc (\fBbool\fR) r\- [\fB\-\-enable\-xmalloc\fR]
941 .RS 4
942 Abort\-on\-out\-of\-memory enabled/disabled\&. If enabled, rather than returning failure for any allocation function, display a diagnostic message on
943 \fBSTDERR_FILENO\fR
944 and cause the program to drop core (using
945 \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:
946 .sp
947 .if n \{\
948 .RS 4
949 .\}
950 .nf
951 malloc_conf = "xmalloc:true";
952 .fi
953 .if n \{\
954 .RE
955 .\}
956 .sp
957 This option is disabled by default\&.
958 .RE
959 .PP
960 opt\&.tcache (\fBbool\fR) r\- [\fB\-\-enable\-tcache\fR]
961 .RS 4
962 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
963 opt\&.lg_tcache_max
964 option for related tuning information\&. This option is enabled by default unless running inside
965 \m[blue]\fBValgrind\fR\m[]\&\s-2\u[3]\d\s+2, in which case it is forcefully disabled\&.
966 .RE
967 .PP
968 opt\&.lg_tcache_max (\fBsize_t\fR) r\- [\fB\-\-enable\-tcache\fR]
969 .RS 4
970 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)\&.
971 .RE
972 .PP
973 opt\&.prof (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
974 .RS 4
975 Memory profiling enabled/disabled\&. If enabled, profile memory allocation activity\&. See the
976 opt\&.prof_active
977 option for on\-the\-fly activation/deactivation\&. See the
978 opt\&.lg_prof_sample
979 option for probabilistic sampling control\&. See the
980 opt\&.prof_accum
981 option for control of cumulative sample reporting\&. See the
982 opt\&.lg_prof_interval
983 option for information on interval\-triggered profile dumping, the
984 opt\&.prof_gdump
985 option for information on high\-water\-triggered profile dumping, and the
986 opt\&.prof_final
987 option for final profile dumping\&. Profile output is compatible with the
988 \fBjeprof\fR
989 command, which is based on the
990 \fBpprof\fR
991 that is developed as part of the
992 \m[blue]\fBgperftools package\fR\m[]\&\s-2\u[4]\d\s+2\&. See
993 HEAP PROFILE FORMAT
994 for heap profile format documentation\&.
995 .RE
996 .PP
997 opt\&.prof_prefix (\fBconst char *\fR) r\- [\fB\-\-enable\-prof\fR]
998 .RS 4
999 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
1000 jeprof\&.
1001 .RE
1002 .PP
1003 opt\&.prof_active (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
1004 .RS 4
1005 Profiling activated/deactivated\&. This is a secondary control mechanism that makes it possible to start the application with profiling enabled (see the
1006 opt\&.prof
1007 option) but inactive, then toggle profiling at any time during program execution with the
1008 prof\&.active
1009 mallctl\&. This option is enabled by default\&.
1010 .RE
1011 .PP
1012 opt\&.prof_thread_active_init (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
1013 .RS 4
1014 Initial setting for
1015 thread\&.prof\&.active
1016 in newly created threads\&. The initial setting for newly created threads can also be changed during execution via the
1017 prof\&.thread_active_init
1018 mallctl\&. This option is enabled by default\&.
1019 .RE
1020 .PP
1021 opt\&.lg_prof_sample (\fBsize_t\fR) r\- [\fB\-\-enable\-prof\fR]
1022 .RS 4
1023 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)\&.
1024 .RE
1025 .PP
1026 opt\&.prof_accum (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
1027 .RS 4
1028 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\&.
1029 .RE
1030 .PP
1031 opt\&.lg_prof_interval (\fBssize_t\fR) r\- [\fB\-\-enable\-prof\fR]
1032 .RS 4
1033 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
1034 <prefix>\&.<pid>\&.<seq>\&.i<iseq>\&.heap, where
1035 <prefix>
1036 is controlled by the
1037 opt\&.prof_prefix
1038 option\&. By default, interval\-triggered profile dumping is disabled (encoded as \-1)\&.
1039 .RE
1040 .PP
1041 opt\&.prof_gdump (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
1042 .RS 4
1043 Set the initial state of
1044 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\&.
1045 .RE
1046 .PP
1047 opt\&.prof_final (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
1048 .RS 4
1049 Use an
1050 \fBatexit\fR(3)
1051 function to dump final memory usage to a file named according to the pattern
1052 <prefix>\&.<pid>\&.<seq>\&.f\&.heap, where
1053 <prefix>
1054 is controlled by the
1055 opt\&.prof_prefix
1056 option\&. Note that
1057 atexit()
1058 may allocate memory during application initialization and then deadlock internally when jemalloc in turn calls
1059 atexit(), so this option is not universally usable (though the application can register its own
1060 atexit()
1061 function with equivalent functionality)\&. This option is disabled by default\&.
1062 .RE
1063 .PP
1064 opt\&.prof_leak (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
1065 .RS 4
1066 Leak reporting enabled/disabled\&. If enabled, use an
1067 \fBatexit\fR(3)
1068 function to report memory leaks detected by allocation sampling\&. See the
1069 opt\&.prof
1070 option for information on analyzing heap profile output\&. This option is disabled by default\&.
1071 .RE
1072 .PP
1073 thread\&.arena (\fBunsigned\fR) rw
1074 .RS 4
1075 Get or set the arena associated with the calling thread\&. If the specified arena was not initialized beforehand (see the
1076 arenas\&.initialized
1077 mallctl), it will be automatically initialized as a side effect of calling this interface\&.
1078 .RE
1079 .PP
1080 thread\&.allocated (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1081 .RS 4
1082 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\&.
1083 .RE
1084 .PP
1085 thread\&.allocatedp (\fBuint64_t *\fR) r\- [\fB\-\-enable\-stats\fR]
1086 .RS 4
1087 Get a pointer to the the value that is returned by the
1088 thread\&.allocated
1089 mallctl\&. This is useful for avoiding the overhead of repeated
1090 mallctl*()
1091 calls\&.
1092 .RE
1093 .PP
1094 thread\&.deallocated (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1095 .RS 4
1096 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\&.
1097 .RE
1098 .PP
1099 thread\&.deallocatedp (\fBuint64_t *\fR) r\- [\fB\-\-enable\-stats\fR]
1100 .RS 4
1101 Get a pointer to the the value that is returned by the
1102 thread\&.deallocated
1103 mallctl\&. This is useful for avoiding the overhead of repeated
1104 mallctl*()
1105 calls\&.
1106 .RE
1107 .PP
1108 thread\&.tcache\&.enabled (\fBbool\fR) rw [\fB\-\-enable\-tcache\fR]
1109 .RS 4
1110 Enable/disable calling thread\*(Aqs tcache\&. The tcache is implicitly flushed as a side effect of becoming disabled (see
1111 thread\&.tcache\&.flush)\&.
1112 .RE
1113 .PP
1114 thread\&.tcache\&.flush (\fBvoid\fR) \-\- [\fB\-\-enable\-tcache\fR]
1115 .RS 4
1116 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\&.
1117 .RE
1118 .PP
1119 thread\&.prof\&.name (\fBconst char *\fR) r\- or \-w [\fB\-\-enable\-prof\fR]
1120 .RS 4
1121 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
1122 \fBisgraph\fR(3)
1123 and
1124 \fBisblank\fR(3)\&.
1125 .RE
1126 .PP
1127 thread\&.prof\&.active (\fBbool\fR) rw [\fB\-\-enable\-prof\fR]
1128 .RS 4
1129 Control whether sampling is currently active for the calling thread\&. This is an activation mechanism in addition to
1130 prof\&.active; both must be active for the calling thread to sample\&. This flag is enabled by default\&.
1131 .RE
1132 .PP
1133 tcache\&.create (\fBunsigned\fR) r\- [\fB\-\-enable\-tcache\fR]
1134 .RS 4
1135 Create an explicit thread\-specific cache (tcache) and return an identifier that can be passed to the
1136 \fBMALLOCX_TCACHE(\fR\fB\fItc\fR\fR\fB)\fR
1137 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\&.
1138 .RE
1139 .PP
1140 tcache\&.flush (\fBunsigned\fR) \-w [\fB\-\-enable\-tcache\fR]
1141 .RS 4
1142 Flush the specified thread\-specific cache (tcache)\&. The same considerations apply to this interface as to
1143 thread\&.tcache\&.flush, except that the tcache will never be automatically discarded\&.
1144 .RE
1145 .PP
1146 tcache\&.destroy (\fBunsigned\fR) \-w [\fB\-\-enable\-tcache\fR]
1147 .RS 4
1148 Flush the specified thread\-specific cache (tcache) and make the identifier available for use during a future tcache creation\&.
1149 .RE
1150 .PP
1151 arena\&.<i>\&.purge (\fBvoid\fR) \-\-
1152 .RS 4
1153 Purge all unused dirty pages for arena <i>, or for all arenas if <i> equals
1154 arenas\&.narenas\&.
1155 .RE
1156 .PP
1157 arena\&.<i>\&.decay (\fBvoid\fR) \-\-
1158 .RS 4
1159 Trigger decay\-based purging of unused dirty pages for arena <i>, or for all arenas if <i> equals
1160 arenas\&.narenas\&. The proportion of unused dirty pages to be purged depends on the current time; see
1161 opt\&.decay_time
1162 for details\&.
1163 .RE
1164 .PP
1165 arena\&.<i>\&.reset (\fBvoid\fR) \-\-
1166 .RS 4
1167 Discard all of the arena\*(Aqs extant allocations\&. This interface can only be used with arenas created via
1168 arenas\&.extend\&. None of the arena\*(Aqs discarded/cached allocations may accessed afterward\&. As part of this requirement, all thread caches which were used to allocate/deallocate in conjunction with the arena must be flushed beforehand\&. This interface cannot be used if running inside Valgrind, nor if the
1169 quarantine
1170 size is non\-zero\&.
1171 .RE
1172 .PP
1173 arena\&.<i>\&.dss (\fBconst char *\fR) rw
1174 .RS 4
1175 Set the precedence of dss allocation as related to mmap allocation for arena <i>, or for all arenas if <i> equals
1176 arenas\&.narenas\&. See
1177 opt\&.dss
1178 for supported settings\&.
1179 .RE
1180 .PP
1181 arena\&.<i>\&.lg_dirty_mult (\fBssize_t\fR) rw
1182 .RS 4
1183 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
1184 opt\&.lg_dirty_mult
1185 for additional information\&.
1186 .RE
1187 .PP
1188 arena\&.<i>\&.decay_time (\fBssize_t\fR) rw
1189 .RS 4
1190 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
1191 opt\&.decay_time
1192 for additional information\&.
1193 .RE
1194 .PP
1195 arena\&.<i>\&.chunk_hooks (\fBchunk_hooks_t\fR) rw
1196 .RS 4
1197 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
1198 arenas\&.extend
1199 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\&.
1200 .sp
1201 .if n \{\
1202 .RS 4
1203 .\}
1204 .nf
1205 typedef struct {
1206         chunk_alloc_t           *alloc;
1207         chunk_dalloc_t          *dalloc;
1208         chunk_commit_t          *commit;
1209         chunk_decommit_t        *decommit;
1210         chunk_purge_t           *purge;
1211         chunk_split_t           *split;
1212         chunk_merge_t           *merge;
1213 } chunk_hooks_t;
1214 .fi
1215 .if n \{\
1216 .RE
1217 .\}
1218 .sp
1219 The
1220 \fBchunk_hooks_t\fR
1221 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\&.
1222 .HP \w'typedef\ void\ *(chunk_alloc_t)('u
1223 .BI "typedef void *(chunk_alloc_t)(void\ *" "chunk" ", size_t\ " "size" ", size_t\ " "alignment" ", bool\ *" "zero" ", bool\ *" "commit" ", unsigned\ " "arena_ind" ");"
1224 .sp
1225 .if n \{\
1226 .RS 4
1227 .\}
1228 .nf
1229 .fi
1230 .if n \{\
1231 .RE
1232 .\}
1233 .sp
1234 A chunk allocation function conforms to the
1235 \fBchunk_alloc_t\fR
1236 type and upon success returns a pointer to
1237 \fIsize\fR
1238 bytes of mapped memory on behalf of arena
1239 \fIarena_ind\fR
1240 such that the chunk\*(Aqs base address is a multiple of
1241 \fIalignment\fR, as well as setting
1242 \fI*zero\fR
1243 to indicate whether the chunk is zeroed and
1244 \fI*commit\fR
1245 to indicate whether the chunk is committed\&. Upon error the function returns
1246 \fBNULL\fR
1247 and leaves
1248 \fI*zero\fR
1249 and
1250 \fI*commit\fR
1251 unmodified\&. The
1252 \fIsize\fR
1253 parameter is always a multiple of the chunk size\&. The
1254 \fIalignment\fR
1255 parameter is always a power of two at least as large as the chunk size\&. Zeroing is mandatory if
1256 \fI*zero\fR
1257 is true upon function entry\&. Committing is mandatory if
1258 \fI*commit\fR
1259 is true upon function entry\&. If
1260 \fIchunk\fR
1261 is not
1262 \fBNULL\fR, the returned pointer must be
1263 \fIchunk\fR
1264 on success or
1265 \fBNULL\fR
1266 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
1267 arena\&.<i>\&.dss
1268 setting irrelevant\&.
1269 .HP \w'typedef\ bool\ (chunk_dalloc_t)('u
1270 .BI "typedef bool (chunk_dalloc_t)(void\ *" "chunk" ", size_t\ " "size" ", bool\ " "committed" ", unsigned\ " "arena_ind" ");"
1271 .sp
1272 .if n \{\
1273 .RS 4
1274 .\}
1275 .nf
1276 .fi
1277 .if n \{\
1278 .RE
1279 .\}
1280 .sp
1281 A chunk deallocation function conforms to the
1282 \fBchunk_dalloc_t\fR
1283 type and deallocates a
1284 \fIchunk\fR
1285 of given
1286 \fIsize\fR
1287 with
1288 \fIcommitted\fR/decommited memory as indicated, on behalf of arena
1289 \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\&.
1290 .HP \w'typedef\ bool\ (chunk_commit_t)('u
1291 .BI "typedef bool (chunk_commit_t)(void\ *" "chunk" ", size_t\ " "size" ", size_t\ " "offset" ", size_t\ " "length" ", unsigned\ " "arena_ind" ");"
1292 .sp
1293 .if n \{\
1294 .RS 4
1295 .\}
1296 .nf
1297 .fi
1298 .if n \{\
1299 .RE
1300 .\}
1301 .sp
1302 A chunk commit function conforms to the
1303 \fBchunk_commit_t\fR
1304 type and commits zeroed physical memory to back pages within a
1305 \fIchunk\fR
1306 of given
1307 \fIsize\fR
1308 at
1309 \fIoffset\fR
1310 bytes, extending for
1311 \fIlength\fR
1312 on behalf of arena
1313 \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\&.
1314 .HP \w'typedef\ bool\ (chunk_decommit_t)('u
1315 .BI "typedef bool (chunk_decommit_t)(void\ *" "chunk" ", size_t\ " "size" ", size_t\ " "offset" ", size_t\ " "length" ", unsigned\ " "arena_ind" ");"
1316 .sp
1317 .if n \{\
1318 .RS 4
1319 .\}
1320 .nf
1321 .fi
1322 .if n \{\
1323 .RE
1324 .\}
1325 .sp
1326 A chunk decommit function conforms to the
1327 \fBchunk_decommit_t\fR
1328 type and decommits any physical memory that is backing pages within a
1329 \fIchunk\fR
1330 of given
1331 \fIsize\fR
1332 at
1333 \fIoffset\fR
1334 bytes, extending for
1335 \fIlength\fR
1336 on behalf of arena
1337 \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\&.
1338 .HP \w'typedef\ bool\ (chunk_purge_t)('u
1339 .BI "typedef bool (chunk_purge_t)(void\ *" "chunk" ", size_t" "size" ", size_t\ " "offset" ", size_t\ " "length" ", unsigned\ " "arena_ind" ");"
1340 .sp
1341 .if n \{\
1342 .RS 4
1343 .\}
1344 .nf
1345 .fi
1346 .if n \{\
1347 .RE
1348 .\}
1349 .sp
1350 A chunk purge function conforms to the
1351 \fBchunk_purge_t\fR
1352 type and optionally discards physical pages within the virtual memory mapping associated with
1353 \fIchunk\fR
1354 of given
1355 \fIsize\fR
1356 at
1357 \fIoffset\fR
1358 bytes, extending for
1359 \fIlength\fR
1360 on behalf of arena
1361 \fIarena_ind\fR, returning false if pages within the purged virtual memory range will be zero\-filled the next time they are accessed\&.
1362 .HP \w'typedef\ bool\ (chunk_split_t)('u
1363 .BI "typedef bool (chunk_split_t)(void\ *" "chunk" ", size_t\ " "size" ", size_t\ " "size_a" ", size_t\ " "size_b" ", bool\ " "committed" ", unsigned\ " "arena_ind" ");"
1364 .sp
1365 .if n \{\
1366 .RS 4
1367 .\}
1368 .nf
1369 .fi
1370 .if n \{\
1371 .RE
1372 .\}
1373 .sp
1374 A chunk split function conforms to the
1375 \fBchunk_split_t\fR
1376 type and optionally splits
1377 \fIchunk\fR
1378 of given
1379 \fIsize\fR
1380 into two adjacent chunks, the first of
1381 \fIsize_a\fR
1382 bytes, and the second of
1383 \fIsize_b\fR
1384 bytes, operating on
1385 \fIcommitted\fR/decommitted memory as indicated, on behalf of arena
1386 \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\&.
1387 .HP \w'typedef\ bool\ (chunk_merge_t)('u
1388 .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" ");"
1389 .sp
1390 .if n \{\
1391 .RS 4
1392 .\}
1393 .nf
1394 .fi
1395 .if n \{\
1396 .RE
1397 .\}
1398 .sp
1399 A chunk merge function conforms to the
1400 \fBchunk_merge_t\fR
1401 type and optionally merges adjacent chunks,
1402 \fIchunk_a\fR
1403 of given
1404 \fIsize_a\fR
1405 and
1406 \fIchunk_b\fR
1407 of given
1408 \fIsize_b\fR
1409 into one contiguous chunk, operating on
1410 \fIcommitted\fR/decommitted memory as indicated, on behalf of arena
1411 \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\&.
1412 .RE
1413 .PP
1414 arenas\&.narenas (\fBunsigned\fR) r\-
1415 .RS 4
1416 Current limit on number of arenas\&.
1417 .RE
1418 .PP
1419 arenas\&.initialized (\fBbool *\fR) r\-
1420 .RS 4
1421 An array of
1422 arenas\&.narenas
1423 booleans\&. Each boolean indicates whether the corresponding arena is initialized\&.
1424 .RE
1425 .PP
1426 arenas\&.lg_dirty_mult (\fBssize_t\fR) rw
1427 .RS 4
1428 Current default per\-arena minimum ratio (log base 2) of active to dirty pages, used to initialize
1429 arena\&.<i>\&.lg_dirty_mult
1430 during arena creation\&. See
1431 opt\&.lg_dirty_mult
1432 for additional information\&.
1433 .RE
1434 .PP
1435 arenas\&.decay_time (\fBssize_t\fR) rw
1436 .RS 4
1437 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
1438 arena\&.<i>\&.decay_time
1439 during arena creation\&. See
1440 opt\&.decay_time
1441 for additional information\&.
1442 .RE
1443 .PP
1444 arenas\&.quantum (\fBsize_t\fR) r\-
1445 .RS 4
1446 Quantum size\&.
1447 .RE
1448 .PP
1449 arenas\&.page (\fBsize_t\fR) r\-
1450 .RS 4
1451 Page size\&.
1452 .RE
1453 .PP
1454 arenas\&.tcache_max (\fBsize_t\fR) r\- [\fB\-\-enable\-tcache\fR]
1455 .RS 4
1456 Maximum thread\-cached size class\&.
1457 .RE
1458 .PP
1459 arenas\&.nbins (\fBunsigned\fR) r\-
1460 .RS 4
1461 Number of bin size classes\&.
1462 .RE
1463 .PP
1464 arenas\&.nhbins (\fBunsigned\fR) r\- [\fB\-\-enable\-tcache\fR]
1465 .RS 4
1466 Total number of thread cache bin size classes\&.
1467 .RE
1468 .PP
1469 arenas\&.bin\&.<i>\&.size (\fBsize_t\fR) r\-
1470 .RS 4
1471 Maximum size supported by size class\&.
1472 .RE
1473 .PP
1474 arenas\&.bin\&.<i>\&.nregs (\fBuint32_t\fR) r\-
1475 .RS 4
1476 Number of regions per page run\&.
1477 .RE
1478 .PP
1479 arenas\&.bin\&.<i>\&.run_size (\fBsize_t\fR) r\-
1480 .RS 4
1481 Number of bytes per page run\&.
1482 .RE
1483 .PP
1484 arenas\&.nlruns (\fBunsigned\fR) r\-
1485 .RS 4
1486 Total number of large size classes\&.
1487 .RE
1488 .PP
1489 arenas\&.lrun\&.<i>\&.size (\fBsize_t\fR) r\-
1490 .RS 4
1491 Maximum size supported by this large size class\&.
1492 .RE
1493 .PP
1494 arenas\&.nhchunks (\fBunsigned\fR) r\-
1495 .RS 4
1496 Total number of huge size classes\&.
1497 .RE
1498 .PP
1499 arenas\&.hchunk\&.<i>\&.size (\fBsize_t\fR) r\-
1500 .RS 4
1501 Maximum size supported by this huge size class\&.
1502 .RE
1503 .PP
1504 arenas\&.extend (\fBunsigned\fR) r\-
1505 .RS 4
1506 Extend the array of arenas by appending a new arena, and returning the new arena index\&.
1507 .RE
1508 .PP
1509 prof\&.thread_active_init (\fBbool\fR) rw [\fB\-\-enable\-prof\fR]
1510 .RS 4
1511 Control the initial setting for
1512 thread\&.prof\&.active
1513 in newly created threads\&. See the
1514 opt\&.prof_thread_active_init
1515 option for additional information\&.
1516 .RE
1517 .PP
1518 prof\&.active (\fBbool\fR) rw [\fB\-\-enable\-prof\fR]
1519 .RS 4
1520 Control whether sampling is currently active\&. See the
1521 opt\&.prof_active
1522 option for additional information, as well as the interrelated
1523 thread\&.prof\&.active
1524 mallctl\&.
1525 .RE
1526 .PP
1527 prof\&.dump (\fBconst char *\fR) \-w [\fB\-\-enable\-prof\fR]
1528 .RS 4
1529 Dump a memory profile to the specified file, or if NULL is specified, to a file according to the pattern
1530 <prefix>\&.<pid>\&.<seq>\&.m<mseq>\&.heap, where
1531 <prefix>
1532 is controlled by the
1533 opt\&.prof_prefix
1534 option\&.
1535 .RE
1536 .PP
1537 prof\&.gdump (\fBbool\fR) rw [\fB\-\-enable\-prof\fR]
1538 .RS 4
1539 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
1540 <prefix>\&.<pid>\&.<seq>\&.u<useq>\&.heap, where
1541 <prefix>
1542 is controlled by the
1543 opt\&.prof_prefix
1544 option\&.
1545 .RE
1546 .PP
1547 prof\&.reset (\fBsize_t\fR) \-w [\fB\-\-enable\-prof\fR]
1548 .RS 4
1549 Reset all memory profile statistics, and optionally update the sample rate (see
1550 opt\&.lg_prof_sample
1551 and
1552 prof\&.lg_sample)\&.
1553 .RE
1554 .PP
1555 prof\&.lg_sample (\fBsize_t\fR) r\- [\fB\-\-enable\-prof\fR]
1556 .RS 4
1557 Get the current sample rate (see
1558 opt\&.lg_prof_sample)\&.
1559 .RE
1560 .PP
1561 prof\&.interval (\fBuint64_t\fR) r\- [\fB\-\-enable\-prof\fR]
1562 .RS 4
1563 Average number of bytes allocated between interval\-based profile dumps\&. See the
1564 opt\&.lg_prof_interval
1565 option for additional information\&.
1566 .RE
1567 .PP
1568 stats\&.cactive (\fBsize_t *\fR) r\- [\fB\-\-enable\-stats\fR]
1569 .RS 4
1570 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
1571 epoch
1572 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\&.
1573 .RE
1574 .PP
1575 stats\&.allocated (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1576 .RS 4
1577 Total number of bytes allocated by the application\&.
1578 .RE
1579 .PP
1580 stats\&.active (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1581 .RS 4
1582 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
1583 stats\&.allocated\&. This does not include
1584 stats\&.arenas\&.<i>\&.pdirty, nor pages entirely devoted to allocator metadata\&.
1585 .RE
1586 .PP
1587 stats\&.metadata (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1588 .RS 4
1589 Total number of bytes dedicated to metadata, which comprise base allocations used for bootstrap\-sensitive internal allocator data structures, arena chunk headers (see
1590 stats\&.arenas\&.<i>\&.metadata\&.mapped), and internal allocations (see
1591 stats\&.arenas\&.<i>\&.metadata\&.allocated)\&.
1592 .RE
1593 .PP
1594 stats\&.resident (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1595 .RS 4
1596 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
1597 stats\&.active\&.
1598 .RE
1599 .PP
1600 stats\&.mapped (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1601 .RS 4
1602 Total number of bytes in active chunks mapped by the allocator\&. This is a multiple of the chunk size, and is larger than
1603 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
1604 stats\&.resident\&.
1605 .RE
1606 .PP
1607 stats\&.retained (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1608 .RS 4
1609 Total number of bytes in virtual memory mappings that were retained rather than being returned to the operating system via e\&.g\&.
1610 \fBmunmap\fR(2)\&. Retained virtual memory is typically untouched, decommitted, or purged, so it has no strongly associated physical memory (see
1611 chunk hooks
1612 for details)\&. Retained memory is excluded from mapped memory statistics, e\&.g\&.
1613 stats\&.mapped\&.
1614 .RE
1615 .PP
1616 stats\&.arenas\&.<i>\&.dss (\fBconst char *\fR) r\-
1617 .RS 4
1618 dss (\fBsbrk\fR(2)) allocation precedence as related to
1619 \fBmmap\fR(2)
1620 allocation\&. See
1621 opt\&.dss
1622 for details\&.
1623 .RE
1624 .PP
1625 stats\&.arenas\&.<i>\&.lg_dirty_mult (\fBssize_t\fR) r\-
1626 .RS 4
1627 Minimum ratio (log base 2) of active to dirty pages\&. See
1628 opt\&.lg_dirty_mult
1629 for details\&.
1630 .RE
1631 .PP
1632 stats\&.arenas\&.<i>\&.decay_time (\fBssize_t\fR) r\-
1633 .RS 4
1634 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
1635 opt\&.decay_time
1636 for details\&.
1637 .RE
1638 .PP
1639 stats\&.arenas\&.<i>\&.nthreads (\fBunsigned\fR) r\-
1640 .RS 4
1641 Number of threads currently assigned to arena\&.
1642 .RE
1643 .PP
1644 stats\&.arenas\&.<i>\&.pactive (\fBsize_t\fR) r\-
1645 .RS 4
1646 Number of pages in active runs\&.
1647 .RE
1648 .PP
1649 stats\&.arenas\&.<i>\&.pdirty (\fBsize_t\fR) r\-
1650 .RS 4
1651 Number of pages within unused runs that are potentially dirty, and for which
1652 madvise\fI\&.\&.\&.\fR \fI\fBMADV_DONTNEED\fR\fR
1653 or similar has not been called\&.
1654 .RE
1655 .PP
1656 stats\&.arenas\&.<i>\&.mapped (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1657 .RS 4
1658 Number of mapped bytes\&.
1659 .RE
1660 .PP
1661 stats\&.arenas\&.<i>\&.retained (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1662 .RS 4
1663 Number of retained bytes\&. See
1664 stats\&.retained
1665 for details\&.
1666 .RE
1667 .PP
1668 stats\&.arenas\&.<i>\&.metadata\&.mapped (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1669 .RS 4
1670 Number of mapped bytes in arena chunk headers, which track the states of the non\-metadata pages\&.
1671 .RE
1672 .PP
1673 stats\&.arenas\&.<i>\&.metadata\&.allocated (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1674 .RS 4
1675 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
1676 stats\&.metadata
1677 and
1678 stats\&.arenas\&.<i>\&.metadata\&.mapped
1679 because it overlaps with e\&.g\&. the
1680 stats\&.allocated
1681 and
1682 stats\&.active
1683 statistics, whereas the other metadata statistics do not\&.
1684 .RE
1685 .PP
1686 stats\&.arenas\&.<i>\&.npurge (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1687 .RS 4
1688 Number of dirty page purge sweeps performed\&.
1689 .RE
1690 .PP
1691 stats\&.arenas\&.<i>\&.nmadvise (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1692 .RS 4
1693 Number of
1694 madvise\fI\&.\&.\&.\fR \fI\fBMADV_DONTNEED\fR\fR
1695 or similar calls made to purge dirty pages\&.
1696 .RE
1697 .PP
1698 stats\&.arenas\&.<i>\&.purged (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1699 .RS 4
1700 Number of pages purged\&.
1701 .RE
1702 .PP
1703 stats\&.arenas\&.<i>\&.small\&.allocated (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1704 .RS 4
1705 Number of bytes currently allocated by small objects\&.
1706 .RE
1707 .PP
1708 stats\&.arenas\&.<i>\&.small\&.nmalloc (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1709 .RS 4
1710 Cumulative number of allocation requests served by small bins\&.
1711 .RE
1712 .PP
1713 stats\&.arenas\&.<i>\&.small\&.ndalloc (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1714 .RS 4
1715 Cumulative number of small objects returned to bins\&.
1716 .RE
1717 .PP
1718 stats\&.arenas\&.<i>\&.small\&.nrequests (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1719 .RS 4
1720 Cumulative number of small allocation requests\&.
1721 .RE
1722 .PP
1723 stats\&.arenas\&.<i>\&.large\&.allocated (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1724 .RS 4
1725 Number of bytes currently allocated by large objects\&.
1726 .RE
1727 .PP
1728 stats\&.arenas\&.<i>\&.large\&.nmalloc (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1729 .RS 4
1730 Cumulative number of large allocation requests served directly by the arena\&.
1731 .RE
1732 .PP
1733 stats\&.arenas\&.<i>\&.large\&.ndalloc (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1734 .RS 4
1735 Cumulative number of large deallocation requests served directly by the arena\&.
1736 .RE
1737 .PP
1738 stats\&.arenas\&.<i>\&.large\&.nrequests (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1739 .RS 4
1740 Cumulative number of large allocation requests\&.
1741 .RE
1742 .PP
1743 stats\&.arenas\&.<i>\&.huge\&.allocated (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1744 .RS 4
1745 Number of bytes currently allocated by huge objects\&.
1746 .RE
1747 .PP
1748 stats\&.arenas\&.<i>\&.huge\&.nmalloc (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1749 .RS 4
1750 Cumulative number of huge allocation requests served directly by the arena\&.
1751 .RE
1752 .PP
1753 stats\&.arenas\&.<i>\&.huge\&.ndalloc (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1754 .RS 4
1755 Cumulative number of huge deallocation requests served directly by the arena\&.
1756 .RE
1757 .PP
1758 stats\&.arenas\&.<i>\&.huge\&.nrequests (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1759 .RS 4
1760 Cumulative number of huge allocation requests\&.
1761 .RE
1762 .PP
1763 stats\&.arenas\&.<i>\&.bins\&.<j>\&.nmalloc (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1764 .RS 4
1765 Cumulative number of allocations served by bin\&.
1766 .RE
1767 .PP
1768 stats\&.arenas\&.<i>\&.bins\&.<j>\&.ndalloc (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1769 .RS 4
1770 Cumulative number of allocations returned to bin\&.
1771 .RE
1772 .PP
1773 stats\&.arenas\&.<i>\&.bins\&.<j>\&.nrequests (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1774 .RS 4
1775 Cumulative number of allocation requests\&.
1776 .RE
1777 .PP
1778 stats\&.arenas\&.<i>\&.bins\&.<j>\&.curregs (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1779 .RS 4
1780 Current number of regions for this size class\&.
1781 .RE
1782 .PP
1783 stats\&.arenas\&.<i>\&.bins\&.<j>\&.nfills (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR \fB\-\-enable\-tcache\fR]
1784 .RS 4
1785 Cumulative number of tcache fills\&.
1786 .RE
1787 .PP
1788 stats\&.arenas\&.<i>\&.bins\&.<j>\&.nflushes (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR \fB\-\-enable\-tcache\fR]
1789 .RS 4
1790 Cumulative number of tcache flushes\&.
1791 .RE
1792 .PP
1793 stats\&.arenas\&.<i>\&.bins\&.<j>\&.nruns (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1794 .RS 4
1795 Cumulative number of runs created\&.
1796 .RE
1797 .PP
1798 stats\&.arenas\&.<i>\&.bins\&.<j>\&.nreruns (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1799 .RS 4
1800 Cumulative number of times the current run from which to allocate changed\&.
1801 .RE
1802 .PP
1803 stats\&.arenas\&.<i>\&.bins\&.<j>\&.curruns (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1804 .RS 4
1805 Current number of runs\&.
1806 .RE
1807 .PP
1808 stats\&.arenas\&.<i>\&.lruns\&.<j>\&.nmalloc (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1809 .RS 4
1810 Cumulative number of allocation requests for this size class served directly by the arena\&.
1811 .RE
1812 .PP
1813 stats\&.arenas\&.<i>\&.lruns\&.<j>\&.ndalloc (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1814 .RS 4
1815 Cumulative number of deallocation requests for this size class served directly by the arena\&.
1816 .RE
1817 .PP
1818 stats\&.arenas\&.<i>\&.lruns\&.<j>\&.nrequests (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1819 .RS 4
1820 Cumulative number of allocation requests for this size class\&.
1821 .RE
1822 .PP
1823 stats\&.arenas\&.<i>\&.lruns\&.<j>\&.curruns (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1824 .RS 4
1825 Current number of runs for this size class\&.
1826 .RE
1827 .PP
1828 stats\&.arenas\&.<i>\&.hchunks\&.<j>\&.nmalloc (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1829 .RS 4
1830 Cumulative number of allocation requests for this size class served directly by the arena\&.
1831 .RE
1832 .PP
1833 stats\&.arenas\&.<i>\&.hchunks\&.<j>\&.ndalloc (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1834 .RS 4
1835 Cumulative number of deallocation requests for this size class served directly by the arena\&.
1836 .RE
1837 .PP
1838 stats\&.arenas\&.<i>\&.hchunks\&.<j>\&.nrequests (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1839 .RS 4
1840 Cumulative number of allocation requests for this size class\&.
1841 .RE
1842 .PP
1843 stats\&.arenas\&.<i>\&.hchunks\&.<j>\&.curhchunks (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1844 .RS 4
1845 Current number of huge allocations for this size class\&.
1846 .RE
1847 .SH "HEAP PROFILE FORMAT"
1848 .PP
1849 Although the heap profiling functionality was originally designed to be compatible with the
1850 \fBpprof\fR
1851 command that is developed as part of the
1852 \m[blue]\fBgperftools package\fR\m[]\&\s-2\u[4]\d\s+2, the addition of per thread heap profiling functionality required a different heap profile format\&. The
1853 \fBjeprof\fR
1854 command is derived from
1855 \fBpprof\fR, with enhancements to support the heap profile format described here\&.
1856 .PP
1857 In the following hypothetical heap profile,
1858 \fB[\&.\&.\&.]\fR
1859 indicates elision for the sake of compactness\&.
1860 .sp
1861 .if n \{\
1862 .RS 4
1863 .\}
1864 .nf
1865 heap_v2/524288
1866   t*: 28106: 56637512 [0: 0]
1867   [\&.\&.\&.]
1868   t3: 352: 16777344 [0: 0]
1869   [\&.\&.\&.]
1870   t99: 17754: 29341640 [0: 0]
1871   [\&.\&.\&.]
1872 @ 0x5f86da8 0x5f5a1dc [\&.\&.\&.] 0x29e4d4e 0xa200316 0xabb2988 [\&.\&.\&.]
1873   t*: 13: 6688 [0: 0]
1874   t3: 12: 6496 [0: ]
1875   t99: 1: 192 [0: 0]
1876 [\&.\&.\&.]
1877
1878 MAPPED_LIBRARIES:
1879 [\&.\&.\&.]
1880 .fi
1881 .if n \{\
1882 .RE
1883 .\}
1884 .sp
1885 The following matches the above heap profile, but most tokens are replaced with
1886 \fB<description>\fR
1887 to indicate descriptions of the corresponding fields\&.
1888 .sp
1889 .if n \{\
1890 .RS 4
1891 .\}
1892 .nf
1893 <heap_profile_format_version>/<mean_sample_interval>
1894   <aggregate>: <curobjs>: <curbytes> [<cumobjs>: <cumbytes>]
1895   [\&.\&.\&.]
1896   <thread_3_aggregate>: <curobjs>: <curbytes>[<cumobjs>: <cumbytes>]
1897   [\&.\&.\&.]
1898   <thread_99_aggregate>: <curobjs>: <curbytes>[<cumobjs>: <cumbytes>]
1899   [\&.\&.\&.]
1900 @ <top_frame> <frame> [\&.\&.\&.] <frame> <frame> <frame> [\&.\&.\&.]
1901   <backtrace_aggregate>: <curobjs>: <curbytes> [<cumobjs>: <cumbytes>]
1902   <backtrace_thread_3>: <curobjs>: <curbytes> [<cumobjs>: <cumbytes>]
1903   <backtrace_thread_99>: <curobjs>: <curbytes> [<cumobjs>: <cumbytes>]
1904 [\&.\&.\&.]
1905
1906 MAPPED_LIBRARIES:
1907 </proc/<pid>/maps>
1908 .fi
1909 .if n \{\
1910 .RE
1911 .\}
1912 .SH "DEBUGGING MALLOC PROBLEMS"
1913 .PP
1914 When debugging, it is a good idea to configure/build jemalloc with the
1915 \fB\-\-enable\-debug\fR
1916 and
1917 \fB\-\-enable\-fill\fR
1918 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\&.
1919 .PP
1920 Programs often accidentally depend on
1921 \(lquninitialized\(rq
1922 memory actually being filled with zero bytes\&. Junk filling (see the
1923 opt\&.junk
1924 option) tends to expose such bugs in the form of obviously incorrect results and/or coredumps\&. Conversely, zero filling (see the
1925 opt\&.zero
1926 option) eliminates the symptoms of such bugs\&. Between these two options, it is usually possible to quickly detect, diagnose, and eliminate such bugs\&.
1927 .PP
1928 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
1929 \m[blue]\fBValgrind\fR\m[]\&\s-2\u[3]\d\s+2
1930 tool if the
1931 \fB\-\-enable\-valgrind\fR
1932 configuration option is enabled\&.
1933 .SH "DIAGNOSTIC MESSAGES"
1934 .PP
1935 If any of the memory allocation/deallocation functions detect an error or warning condition, a message will be printed to file descriptor
1936 \fBSTDERR_FILENO\fR\&. Errors will result in the process dumping core\&. If the
1937 opt\&.abort
1938 option is set, most warnings are treated as errors\&.
1939 .PP
1940 The
1941 \fImalloc_message\fR
1942 variable allows the programmer to override the function which emits the text strings forming the errors and warnings if for some reason the
1943 \fBSTDERR_FILENO\fR
1944 file descriptor is not suitable for this\&.
1945 malloc_message()
1946 takes the
1947 \fIcbopaque\fR
1948 pointer argument that is
1949 \fBNULL\fR
1950 unless overridden by the arguments in a call to
1951 malloc_stats_print(), 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\&.
1952 .PP
1953 All messages are prefixed by
1954 \(lq<jemalloc>: \(rq\&.
1955 .SH "RETURN VALUES"
1956 .SS "Standard API"
1957 .PP
1958 The
1959 malloc()
1960 and
1961 calloc()
1962 functions return a pointer to the allocated memory if successful; otherwise a
1963 \fBNULL\fR
1964 pointer is returned and
1965 \fIerrno\fR
1966 is set to
1967 ENOMEM\&.
1968 .PP
1969 The
1970 posix_memalign()
1971 function returns the value 0 if successful; otherwise it returns an error value\&. The
1972 posix_memalign()
1973 function will fail if:
1974 .PP
1975 EINVAL
1976 .RS 4
1977 The
1978 \fIalignment\fR
1979 parameter is not a power of 2 at least as large as
1980 sizeof(\fBvoid *\fR)\&.
1981 .RE
1982 .PP
1983 ENOMEM
1984 .RS 4
1985 Memory allocation error\&.
1986 .RE
1987 .PP
1988 The
1989 aligned_alloc()
1990 function returns a pointer to the allocated memory if successful; otherwise a
1991 \fBNULL\fR
1992 pointer is returned and
1993 \fIerrno\fR
1994 is set\&. The
1995 aligned_alloc()
1996 function will fail if:
1997 .PP
1998 EINVAL
1999 .RS 4
2000 The
2001 \fIalignment\fR
2002 parameter is not a power of 2\&.
2003 .RE
2004 .PP
2005 ENOMEM
2006 .RS 4
2007 Memory allocation error\&.
2008 .RE
2009 .PP
2010 The
2011 realloc()
2012 function returns a pointer, possibly identical to
2013 \fIptr\fR, to the allocated memory if successful; otherwise a
2014 \fBNULL\fR
2015 pointer is returned, and
2016 \fIerrno\fR
2017 is set to
2018 ENOMEM
2019 if the error was the result of an allocation failure\&. The
2020 realloc()
2021 function always leaves the original buffer intact when an error occurs\&.
2022 .PP
2023 The
2024 free()
2025 function returns no value\&.
2026 .SS "Non\-standard API"
2027 .PP
2028 The
2029 mallocx()
2030 and
2031 rallocx()
2032 functions return a pointer to the allocated memory if successful; otherwise a
2033 \fBNULL\fR
2034 pointer is returned to indicate insufficient contiguous memory was available to service the allocation request\&.
2035 .PP
2036 The
2037 xallocx()
2038 function returns the real size of the resulting resized allocation pointed to by
2039 \fIptr\fR, which is a value less than
2040 \fIsize\fR
2041 if the allocation could not be adequately grown in place\&.
2042 .PP
2043 The
2044 sallocx()
2045 function returns the real size of the allocation pointed to by
2046 \fIptr\fR\&.
2047 .PP
2048 The
2049 nallocx()
2050 returns the real size that would result from a successful equivalent
2051 mallocx()
2052 function call, or zero if insufficient memory is available to perform the size computation\&.
2053 .PP
2054 The
2055 mallctl(),
2056 mallctlnametomib(), and
2057 mallctlbymib()
2058 functions return 0 on success; otherwise they return an error value\&. The functions will fail if:
2059 .PP
2060 EINVAL
2061 .RS 4
2062 \fInewp\fR
2063 is not
2064 \fBNULL\fR, and
2065 \fInewlen\fR
2066 is too large or too small\&. Alternatively,
2067 \fI*oldlenp\fR
2068 is too large or too small; in this case as much data as possible are read despite the error\&.
2069 .RE
2070 .PP
2071 ENOENT
2072 .RS 4
2073 \fIname\fR
2074 or
2075 \fImib\fR
2076 specifies an unknown/invalid value\&.
2077 .RE
2078 .PP
2079 EPERM
2080 .RS 4
2081 Attempt to read or write void value, or attempt to write read\-only value\&.
2082 .RE
2083 .PP
2084 EAGAIN
2085 .RS 4
2086 A memory allocation failure occurred\&.
2087 .RE
2088 .PP
2089 EFAULT
2090 .RS 4
2091 An interface with side effects failed in some way not directly related to
2092 mallctl*()
2093 read/write processing\&.
2094 .RE
2095 .PP
2096 The
2097 malloc_usable_size()
2098 function returns the usable size of the allocation pointed to by
2099 \fIptr\fR\&.
2100 .SH "ENVIRONMENT"
2101 .PP
2102 The following environment variable affects the execution of the allocation functions:
2103 .PP
2104 \fBMALLOC_CONF\fR
2105 .RS 4
2106 If the environment variable
2107 \fBMALLOC_CONF\fR
2108 is set, the characters it contains will be interpreted as options\&.
2109 .RE
2110 .SH "EXAMPLES"
2111 .PP
2112 To dump core whenever a problem occurs:
2113 .sp
2114 .if n \{\
2115 .RS 4
2116 .\}
2117 .nf
2118 ln \-s \*(Aqabort:true\*(Aq /etc/malloc\&.conf
2119 .fi
2120 .if n \{\
2121 .RE
2122 .\}
2123 .PP
2124 To specify in the source a chunk size that is 16 MiB:
2125 .sp
2126 .if n \{\
2127 .RS 4
2128 .\}
2129 .nf
2130 malloc_conf = "lg_chunk:24";
2131 .fi
2132 .if n \{\
2133 .RE
2134 .\}
2135 .SH "SEE ALSO"
2136 .PP
2137 \fBmadvise\fR(2),
2138 \fBmmap\fR(2),
2139 \fBsbrk\fR(2),
2140 \fButrace\fR(2),
2141 \fBalloca\fR(3),
2142 \fBatexit\fR(3),
2143 \fBgetpagesize\fR(3)
2144 .SH "STANDARDS"
2145 .PP
2146 The
2147 malloc(),
2148 calloc(),
2149 realloc(), and
2150 free()
2151 functions conform to ISO/IEC 9899:1990 (\(lqISO C90\(rq)\&.
2152 .PP
2153 The
2154 posix_memalign()
2155 function conforms to IEEE Std 1003\&.1\-2001 (\(lqPOSIX\&.1\(rq)\&.
2156 .SH "HISTORY"
2157 .PP
2158 The
2159 malloc_usable_size()
2160 and
2161 posix_memalign()
2162 functions first appeared in FreeBSD 7\&.0\&.
2163 .PP
2164 The
2165 aligned_alloc(),
2166 malloc_stats_print(), and
2167 mallctl*()
2168 functions first appeared in FreeBSD 10\&.0\&.
2169 .PP
2170 The
2171 *allocx()
2172 functions first appeared in FreeBSD 11\&.0\&.
2173 .SH "AUTHOR"
2174 .PP
2175 \fBJason Evans\fR
2176 .RS 4
2177 .RE
2178 .SH "NOTES"
2179 .IP " 1." 4
2180 jemalloc website
2181 .RS 4
2182 \%http://jemalloc.net/
2183 .RE
2184 .IP " 2." 4
2185 JSON format
2186 .RS 4
2187 \%http://www.json.org/
2188 .RE
2189 .IP " 3." 4
2190 Valgrind
2191 .RS 4
2192 \%http://valgrind.org/
2193 .RE
2194 .IP " 4." 4
2195 gperftools package
2196 .RS 4
2197 \%http://code.google.com/p/gperftools/
2198 .RE