]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/jemalloc/doc/jemalloc.3
MFV r319951: 8311 ZFS_READONLY is a little too strict
[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/2017
6 .\"    Manual: User Manual
7 .\"    Source: jemalloc 4.5.0-0-g04380e79f1e2428bd0ad000bbc6e3d2dfc6b66a5
8 .\"  Language: English
9 .\"
10 .TH "JEMALLOC" "3" "02/28/2017" "jemalloc 4.5.0-0-g04380e79f1e2" "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\&.5\&.0\-0\-g04380e79f1e2428bd0ad000bbc6e3d2dfc6b66a5\&. 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\&.thp (\fBbool\fR) r\-
783 .RS 4
784 \fB\-\-disable\-thp\fR
785 was not specified during build configuration, and the system supports transparent huge page manipulation\&.
786 .RE
787 .PP
788 config\&.tls (\fBbool\fR) r\-
789 .RS 4
790 \fB\-\-disable\-tls\fR
791 was not specified during build configuration\&.
792 .RE
793 .PP
794 config\&.utrace (\fBbool\fR) r\-
795 .RS 4
796 \fB\-\-enable\-utrace\fR
797 was specified during build configuration\&.
798 .RE
799 .PP
800 config\&.valgrind (\fBbool\fR) r\-
801 .RS 4
802 \fB\-\-enable\-valgrind\fR
803 was specified during build configuration\&.
804 .RE
805 .PP
806 config\&.xmalloc (\fBbool\fR) r\-
807 .RS 4
808 \fB\-\-enable\-xmalloc\fR
809 was specified during build configuration\&.
810 .RE
811 .PP
812 opt\&.abort (\fBbool\fR) r\-
813 .RS 4
814 Abort\-on\-warning enabled/disabled\&. If true, most warnings are fatal\&. The process will call
815 \fBabort\fR(3)
816 in these cases\&. This option is disabled by default unless
817 \fB\-\-enable\-debug\fR
818 is specified during configuration, in which case it is enabled by default\&.
819 .RE
820 .PP
821 opt\&.dss (\fBconst char *\fR) r\-
822 .RS 4
823 dss (\fBsbrk\fR(2)) allocation precedence as related to
824 \fBmmap\fR(2)
825 allocation\&. The following settings are supported if
826 \fBsbrk\fR(2)
827 is supported by the operating system:
828 \(lqdisabled\(rq,
829 \(lqprimary\(rq, and
830 \(lqsecondary\(rq; otherwise only
831 \(lqdisabled\(rq
832 is supported\&. The default is
833 \(lqsecondary\(rq
834 if
835 \fBsbrk\fR(2)
836 is supported by the operating system;
837 \(lqdisabled\(rq
838 otherwise\&.
839 .RE
840 .PP
841 opt\&.lg_chunk (\fBsize_t\fR) r\-
842 .RS 4
843 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)\&.
844 .RE
845 .PP
846 opt\&.narenas (\fBunsigned\fR) r\-
847 .RS 4
848 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\&.
849 .RE
850 .PP
851 opt\&.purge (\fBconst char *\fR) r\-
852 .RS 4
853 Purge mode is \(lqratio\(rq (default) or \(lqdecay\(rq\&. See
854 opt\&.lg_dirty_mult
855 for details of the ratio mode\&. See
856 opt\&.decay_time
857 for details of the decay mode\&.
858 .RE
859 .PP
860 opt\&.lg_dirty_mult (\fBssize_t\fR) r\-
861 .RS 4
862 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
863 \fBmadvise\fR(2)
864 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
865 arenas\&.lg_dirty_mult
866 and
867 arena\&.<i>\&.lg_dirty_mult
868 for related dynamic control options\&.
869 .RE
870 .PP
871 opt\&.decay_time (\fBssize_t\fR) r\-
872 .RS 4
873 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
874 arenas\&.decay_time
875 and
876 arena\&.<i>\&.decay_time
877 for related dynamic control options\&.
878 .RE
879 .PP
880 opt\&.stats_print (\fBbool\fR) r\-
881 .RS 4
882 Enable/disable statistics printing at exit\&. If enabled, the
883 malloc_stats_print()
884 function is called at program exit via an
885 \fBatexit\fR(3)
886 function\&. If
887 \fB\-\-enable\-stats\fR
888 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,
889 atexit()
890 may allocate memory during application initialization and then deadlock internally when jemalloc in turn calls
891 atexit(), so this option is not universally usable (though the application can register its own
892 atexit()
893 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\&.
894 .RE
895 .PP
896 opt\&.junk (\fBconst char *\fR) r\- [\fB\-\-enable\-fill\fR]
897 .RS 4
898 Junk filling\&. If set to
899 \(lqalloc\(rq, each byte of uninitialized allocated memory will be initialized to
900 0xa5\&. If set to
901 \(lqfree\(rq, all deallocated memory will be initialized to
902 0x5a\&. If set to
903 \(lqtrue\(rq, both allocated and deallocated memory will be initialized, and if set to
904 \(lqfalse\(rq, junk filling be disabled entirely\&. This is intended for debugging and will impact performance negatively\&. This option is
905 \(lqfalse\(rq
906 by default unless
907 \fB\-\-enable\-debug\fR
908 is specified during configuration, in which case it is
909 \(lqtrue\(rq
910 by default unless running inside
911 \m[blue]\fBValgrind\fR\m[]\&\s-2\u[3]\d\s+2\&.
912 .RE
913 .PP
914 opt\&.quarantine (\fBsize_t\fR) r\- [\fB\-\-enable\-fill\fR]
915 .RS 4
916 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
917 opt\&.junk
918 option is enabled\&. This feature is of particular use in combination with
919 \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\&.
920 .RE
921 .PP
922 opt\&.redzone (\fBbool\fR) r\- [\fB\-\-enable\-fill\fR]
923 .RS 4
924 Redzones enabled/disabled\&. If enabled, small allocations have redzones before and after them\&. Furthermore, if the
925 opt\&.junk
926 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
927 \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\&.
928 .RE
929 .PP
930 opt\&.zero (\fBbool\fR) r\- [\fB\-\-enable\-fill\fR]
931 .RS 4
932 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
933 realloc()
934 and
935 rallocx()
936 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\&.
937 .RE
938 .PP
939 opt\&.utrace (\fBbool\fR) r\- [\fB\-\-enable\-utrace\fR]
940 .RS 4
941 Allocation tracing based on
942 \fButrace\fR(2)
943 enabled/disabled\&. This option is disabled by default\&.
944 .RE
945 .PP
946 opt\&.xmalloc (\fBbool\fR) r\- [\fB\-\-enable\-xmalloc\fR]
947 .RS 4
948 Abort\-on\-out\-of\-memory enabled/disabled\&. If enabled, rather than returning failure for any allocation function, display a diagnostic message on
949 \fBSTDERR_FILENO\fR
950 and cause the program to drop core (using
951 \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:
952 .sp
953 .if n \{\
954 .RS 4
955 .\}
956 .nf
957 malloc_conf = "xmalloc:true";
958 .fi
959 .if n \{\
960 .RE
961 .\}
962 .sp
963 This option is disabled by default\&.
964 .RE
965 .PP
966 opt\&.tcache (\fBbool\fR) r\- [\fB\-\-enable\-tcache\fR]
967 .RS 4
968 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
969 opt\&.lg_tcache_max
970 option for related tuning information\&. This option is enabled by default unless running inside
971 \m[blue]\fBValgrind\fR\m[]\&\s-2\u[3]\d\s+2, in which case it is forcefully disabled\&.
972 .RE
973 .PP
974 opt\&.thp (\fBbool\fR) r\- [\fB\-\-enable\-thp\fR]
975 .RS 4
976 Transparent huge page (THP) integration enabled/disabled\&. When enabled, THPs are explicitly disabled as a side effect of unused dirty page purging for chunks that back small and/or large allocations, because such chunks typically comprise active, unused dirty, and untouched clean pages\&. This option is enabled by default\&.
977 .RE
978 .PP
979 opt\&.lg_tcache_max (\fBsize_t\fR) r\- [\fB\-\-enable\-tcache\fR]
980 .RS 4
981 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)\&.
982 .RE
983 .PP
984 opt\&.prof (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
985 .RS 4
986 Memory profiling enabled/disabled\&. If enabled, profile memory allocation activity\&. See the
987 opt\&.prof_active
988 option for on\-the\-fly activation/deactivation\&. See the
989 opt\&.lg_prof_sample
990 option for probabilistic sampling control\&. See the
991 opt\&.prof_accum
992 option for control of cumulative sample reporting\&. See the
993 opt\&.lg_prof_interval
994 option for information on interval\-triggered profile dumping, the
995 opt\&.prof_gdump
996 option for information on high\-water\-triggered profile dumping, and the
997 opt\&.prof_final
998 option for final profile dumping\&. Profile output is compatible with the
999 \fBjeprof\fR
1000 command, which is based on the
1001 \fBpprof\fR
1002 that is developed as part of the
1003 \m[blue]\fBgperftools package\fR\m[]\&\s-2\u[4]\d\s+2\&. See
1004 HEAP PROFILE FORMAT
1005 for heap profile format documentation\&.
1006 .RE
1007 .PP
1008 opt\&.prof_prefix (\fBconst char *\fR) r\- [\fB\-\-enable\-prof\fR]
1009 .RS 4
1010 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
1011 jeprof\&.
1012 .RE
1013 .PP
1014 opt\&.prof_active (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
1015 .RS 4
1016 Profiling activated/deactivated\&. This is a secondary control mechanism that makes it possible to start the application with profiling enabled (see the
1017 opt\&.prof
1018 option) but inactive, then toggle profiling at any time during program execution with the
1019 prof\&.active
1020 mallctl\&. This option is enabled by default\&.
1021 .RE
1022 .PP
1023 opt\&.prof_thread_active_init (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
1024 .RS 4
1025 Initial setting for
1026 thread\&.prof\&.active
1027 in newly created threads\&. The initial setting for newly created threads can also be changed during execution via the
1028 prof\&.thread_active_init
1029 mallctl\&. This option is enabled by default\&.
1030 .RE
1031 .PP
1032 opt\&.lg_prof_sample (\fBsize_t\fR) r\- [\fB\-\-enable\-prof\fR]
1033 .RS 4
1034 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)\&.
1035 .RE
1036 .PP
1037 opt\&.prof_accum (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
1038 .RS 4
1039 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\&.
1040 .RE
1041 .PP
1042 opt\&.lg_prof_interval (\fBssize_t\fR) r\- [\fB\-\-enable\-prof\fR]
1043 .RS 4
1044 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
1045 <prefix>\&.<pid>\&.<seq>\&.i<iseq>\&.heap, where
1046 <prefix>
1047 is controlled by the
1048 opt\&.prof_prefix
1049 option\&. By default, interval\-triggered profile dumping is disabled (encoded as \-1)\&.
1050 .RE
1051 .PP
1052 opt\&.prof_gdump (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
1053 .RS 4
1054 Set the initial state of
1055 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\&.
1056 .RE
1057 .PP
1058 opt\&.prof_final (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
1059 .RS 4
1060 Use an
1061 \fBatexit\fR(3)
1062 function to dump final memory usage to a file named according to the pattern
1063 <prefix>\&.<pid>\&.<seq>\&.f\&.heap, where
1064 <prefix>
1065 is controlled by the
1066 opt\&.prof_prefix
1067 option\&. Note that
1068 atexit()
1069 may allocate memory during application initialization and then deadlock internally when jemalloc in turn calls
1070 atexit(), so this option is not universally usable (though the application can register its own
1071 atexit()
1072 function with equivalent functionality)\&. This option is disabled by default\&.
1073 .RE
1074 .PP
1075 opt\&.prof_leak (\fBbool\fR) r\- [\fB\-\-enable\-prof\fR]
1076 .RS 4
1077 Leak reporting enabled/disabled\&. If enabled, use an
1078 \fBatexit\fR(3)
1079 function to report memory leaks detected by allocation sampling\&. See the
1080 opt\&.prof
1081 option for information on analyzing heap profile output\&. This option is disabled by default\&.
1082 .RE
1083 .PP
1084 thread\&.arena (\fBunsigned\fR) rw
1085 .RS 4
1086 Get or set the arena associated with the calling thread\&. If the specified arena was not initialized beforehand (see the
1087 arenas\&.initialized
1088 mallctl), it will be automatically initialized as a side effect of calling this interface\&.
1089 .RE
1090 .PP
1091 thread\&.allocated (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1092 .RS 4
1093 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\&.
1094 .RE
1095 .PP
1096 thread\&.allocatedp (\fBuint64_t *\fR) r\- [\fB\-\-enable\-stats\fR]
1097 .RS 4
1098 Get a pointer to the the value that is returned by the
1099 thread\&.allocated
1100 mallctl\&. This is useful for avoiding the overhead of repeated
1101 mallctl*()
1102 calls\&.
1103 .RE
1104 .PP
1105 thread\&.deallocated (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1106 .RS 4
1107 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\&.
1108 .RE
1109 .PP
1110 thread\&.deallocatedp (\fBuint64_t *\fR) r\- [\fB\-\-enable\-stats\fR]
1111 .RS 4
1112 Get a pointer to the the value that is returned by the
1113 thread\&.deallocated
1114 mallctl\&. This is useful for avoiding the overhead of repeated
1115 mallctl*()
1116 calls\&.
1117 .RE
1118 .PP
1119 thread\&.tcache\&.enabled (\fBbool\fR) rw [\fB\-\-enable\-tcache\fR]
1120 .RS 4
1121 Enable/disable calling thread\*(Aqs tcache\&. The tcache is implicitly flushed as a side effect of becoming disabled (see
1122 thread\&.tcache\&.flush)\&.
1123 .RE
1124 .PP
1125 thread\&.tcache\&.flush (\fBvoid\fR) \-\- [\fB\-\-enable\-tcache\fR]
1126 .RS 4
1127 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\&.
1128 .RE
1129 .PP
1130 thread\&.prof\&.name (\fBconst char *\fR) r\- or \-w [\fB\-\-enable\-prof\fR]
1131 .RS 4
1132 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
1133 \fBisgraph\fR(3)
1134 and
1135 \fBisblank\fR(3)\&.
1136 .RE
1137 .PP
1138 thread\&.prof\&.active (\fBbool\fR) rw [\fB\-\-enable\-prof\fR]
1139 .RS 4
1140 Control whether sampling is currently active for the calling thread\&. This is an activation mechanism in addition to
1141 prof\&.active; both must be active for the calling thread to sample\&. This flag is enabled by default\&.
1142 .RE
1143 .PP
1144 tcache\&.create (\fBunsigned\fR) r\- [\fB\-\-enable\-tcache\fR]
1145 .RS 4
1146 Create an explicit thread\-specific cache (tcache) and return an identifier that can be passed to the
1147 \fBMALLOCX_TCACHE(\fR\fB\fItc\fR\fR\fB)\fR
1148 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\&.
1149 .RE
1150 .PP
1151 tcache\&.flush (\fBunsigned\fR) \-w [\fB\-\-enable\-tcache\fR]
1152 .RS 4
1153 Flush the specified thread\-specific cache (tcache)\&. The same considerations apply to this interface as to
1154 thread\&.tcache\&.flush, except that the tcache will never be automatically discarded\&.
1155 .RE
1156 .PP
1157 tcache\&.destroy (\fBunsigned\fR) \-w [\fB\-\-enable\-tcache\fR]
1158 .RS 4
1159 Flush the specified thread\-specific cache (tcache) and make the identifier available for use during a future tcache creation\&.
1160 .RE
1161 .PP
1162 arena\&.<i>\&.purge (\fBvoid\fR) \-\-
1163 .RS 4
1164 Purge all unused dirty pages for arena <i>, or for all arenas if <i> equals
1165 arenas\&.narenas\&.
1166 .RE
1167 .PP
1168 arena\&.<i>\&.decay (\fBvoid\fR) \-\-
1169 .RS 4
1170 Trigger decay\-based purging of unused dirty pages for arena <i>, or for all arenas if <i> equals
1171 arenas\&.narenas\&. The proportion of unused dirty pages to be purged depends on the current time; see
1172 opt\&.decay_time
1173 for details\&.
1174 .RE
1175 .PP
1176 arena\&.<i>\&.reset (\fBvoid\fR) \-\-
1177 .RS 4
1178 Discard all of the arena\*(Aqs extant allocations\&. This interface can only be used with arenas created via
1179 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
1180 quarantine
1181 size is non\-zero\&.
1182 .RE
1183 .PP
1184 arena\&.<i>\&.dss (\fBconst char *\fR) rw
1185 .RS 4
1186 Set the precedence of dss allocation as related to mmap allocation for arena <i>, or for all arenas if <i> equals
1187 arenas\&.narenas\&. See
1188 opt\&.dss
1189 for supported settings\&.
1190 .RE
1191 .PP
1192 arena\&.<i>\&.lg_dirty_mult (\fBssize_t\fR) rw
1193 .RS 4
1194 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
1195 opt\&.lg_dirty_mult
1196 for additional information\&.
1197 .RE
1198 .PP
1199 arena\&.<i>\&.decay_time (\fBssize_t\fR) rw
1200 .RS 4
1201 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
1202 opt\&.decay_time
1203 for additional information\&.
1204 .RE
1205 .PP
1206 arena\&.<i>\&.chunk_hooks (\fBchunk_hooks_t\fR) rw
1207 .RS 4
1208 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
1209 arenas\&.extend
1210 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\&.
1211 .sp
1212 .if n \{\
1213 .RS 4
1214 .\}
1215 .nf
1216 typedef struct {
1217         chunk_alloc_t           *alloc;
1218         chunk_dalloc_t          *dalloc;
1219         chunk_commit_t          *commit;
1220         chunk_decommit_t        *decommit;
1221         chunk_purge_t           *purge;
1222         chunk_split_t           *split;
1223         chunk_merge_t           *merge;
1224 } chunk_hooks_t;
1225 .fi
1226 .if n \{\
1227 .RE
1228 .\}
1229 .sp
1230 The
1231 \fBchunk_hooks_t\fR
1232 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\&.
1233 .HP \w'typedef\ void\ *(chunk_alloc_t)('u
1234 .BI "typedef void *(chunk_alloc_t)(void\ *" "chunk" ", size_t\ " "size" ", size_t\ " "alignment" ", bool\ *" "zero" ", bool\ *" "commit" ", 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 allocation function conforms to the
1246 \fBchunk_alloc_t\fR
1247 type and upon success returns a pointer to
1248 \fIsize\fR
1249 bytes of mapped memory on behalf of arena
1250 \fIarena_ind\fR
1251 such that the chunk\*(Aqs base address is a multiple of
1252 \fIalignment\fR, as well as setting
1253 \fI*zero\fR
1254 to indicate whether the chunk is zeroed and
1255 \fI*commit\fR
1256 to indicate whether the chunk is committed\&. Upon error the function returns
1257 \fBNULL\fR
1258 and leaves
1259 \fI*zero\fR
1260 and
1261 \fI*commit\fR
1262 unmodified\&. The
1263 \fIsize\fR
1264 parameter is always a multiple of the chunk size\&. The
1265 \fIalignment\fR
1266 parameter is always a power of two at least as large as the chunk size\&. Zeroing is mandatory if
1267 \fI*zero\fR
1268 is true upon function entry\&. Committing is mandatory if
1269 \fI*commit\fR
1270 is true upon function entry\&. If
1271 \fIchunk\fR
1272 is not
1273 \fBNULL\fR, the returned pointer must be
1274 \fIchunk\fR
1275 on success or
1276 \fBNULL\fR
1277 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
1278 arena\&.<i>\&.dss
1279 setting irrelevant\&.
1280 .HP \w'typedef\ bool\ (chunk_dalloc_t)('u
1281 .BI "typedef bool (chunk_dalloc_t)(void\ *" "chunk" ", size_t\ " "size" ", bool\ " "committed" ", unsigned\ " "arena_ind" ");"
1282 .sp
1283 .if n \{\
1284 .RS 4
1285 .\}
1286 .nf
1287 .fi
1288 .if n \{\
1289 .RE
1290 .\}
1291 .sp
1292 A chunk deallocation function conforms to the
1293 \fBchunk_dalloc_t\fR
1294 type and deallocates a
1295 \fIchunk\fR
1296 of given
1297 \fIsize\fR
1298 with
1299 \fIcommitted\fR/decommited memory as indicated, on behalf of arena
1300 \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\&.
1301 .HP \w'typedef\ bool\ (chunk_commit_t)('u
1302 .BI "typedef bool (chunk_commit_t)(void\ *" "chunk" ", size_t\ " "size" ", size_t\ " "offset" ", size_t\ " "length" ", unsigned\ " "arena_ind" ");"
1303 .sp
1304 .if n \{\
1305 .RS 4
1306 .\}
1307 .nf
1308 .fi
1309 .if n \{\
1310 .RE
1311 .\}
1312 .sp
1313 A chunk commit function conforms to the
1314 \fBchunk_commit_t\fR
1315 type and commits zeroed physical memory to back pages within a
1316 \fIchunk\fR
1317 of given
1318 \fIsize\fR
1319 at
1320 \fIoffset\fR
1321 bytes, extending for
1322 \fIlength\fR
1323 on behalf of arena
1324 \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\&.
1325 .HP \w'typedef\ bool\ (chunk_decommit_t)('u
1326 .BI "typedef bool (chunk_decommit_t)(void\ *" "chunk" ", size_t\ " "size" ", size_t\ " "offset" ", size_t\ " "length" ", unsigned\ " "arena_ind" ");"
1327 .sp
1328 .if n \{\
1329 .RS 4
1330 .\}
1331 .nf
1332 .fi
1333 .if n \{\
1334 .RE
1335 .\}
1336 .sp
1337 A chunk decommit function conforms to the
1338 \fBchunk_decommit_t\fR
1339 type and decommits any physical memory that is backing pages within a
1340 \fIchunk\fR
1341 of given
1342 \fIsize\fR
1343 at
1344 \fIoffset\fR
1345 bytes, extending for
1346 \fIlength\fR
1347 on behalf of arena
1348 \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\&.
1349 .HP \w'typedef\ bool\ (chunk_purge_t)('u
1350 .BI "typedef bool (chunk_purge_t)(void\ *" "chunk" ", size_t" "size" ", size_t\ " "offset" ", size_t\ " "length" ", unsigned\ " "arena_ind" ");"
1351 .sp
1352 .if n \{\
1353 .RS 4
1354 .\}
1355 .nf
1356 .fi
1357 .if n \{\
1358 .RE
1359 .\}
1360 .sp
1361 A chunk purge function conforms to the
1362 \fBchunk_purge_t\fR
1363 type and optionally discards physical pages within the virtual memory mapping associated with
1364 \fIchunk\fR
1365 of given
1366 \fIsize\fR
1367 at
1368 \fIoffset\fR
1369 bytes, extending for
1370 \fIlength\fR
1371 on behalf of arena
1372 \fIarena_ind\fR, returning false if pages within the purged virtual memory range will be zero\-filled the next time they are accessed\&.
1373 .HP \w'typedef\ bool\ (chunk_split_t)('u
1374 .BI "typedef bool (chunk_split_t)(void\ *" "chunk" ", size_t\ " "size" ", size_t\ " "size_a" ", size_t\ " "size_b" ", bool\ " "committed" ", unsigned\ " "arena_ind" ");"
1375 .sp
1376 .if n \{\
1377 .RS 4
1378 .\}
1379 .nf
1380 .fi
1381 .if n \{\
1382 .RE
1383 .\}
1384 .sp
1385 A chunk split function conforms to the
1386 \fBchunk_split_t\fR
1387 type and optionally splits
1388 \fIchunk\fR
1389 of given
1390 \fIsize\fR
1391 into two adjacent chunks, the first of
1392 \fIsize_a\fR
1393 bytes, and the second of
1394 \fIsize_b\fR
1395 bytes, operating on
1396 \fIcommitted\fR/decommitted memory as indicated, on behalf of arena
1397 \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\&.
1398 .HP \w'typedef\ bool\ (chunk_merge_t)('u
1399 .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" ");"
1400 .sp
1401 .if n \{\
1402 .RS 4
1403 .\}
1404 .nf
1405 .fi
1406 .if n \{\
1407 .RE
1408 .\}
1409 .sp
1410 A chunk merge function conforms to the
1411 \fBchunk_merge_t\fR
1412 type and optionally merges adjacent chunks,
1413 \fIchunk_a\fR
1414 of given
1415 \fIsize_a\fR
1416 and
1417 \fIchunk_b\fR
1418 of given
1419 \fIsize_b\fR
1420 into one contiguous chunk, operating on
1421 \fIcommitted\fR/decommitted memory as indicated, on behalf of arena
1422 \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\&.
1423 .RE
1424 .PP
1425 arenas\&.narenas (\fBunsigned\fR) r\-
1426 .RS 4
1427 Current limit on number of arenas\&.
1428 .RE
1429 .PP
1430 arenas\&.initialized (\fBbool *\fR) r\-
1431 .RS 4
1432 An array of
1433 arenas\&.narenas
1434 booleans\&. Each boolean indicates whether the corresponding arena is initialized\&.
1435 .RE
1436 .PP
1437 arenas\&.lg_dirty_mult (\fBssize_t\fR) rw
1438 .RS 4
1439 Current default per\-arena minimum ratio (log base 2) of active to dirty pages, used to initialize
1440 arena\&.<i>\&.lg_dirty_mult
1441 during arena creation\&. See
1442 opt\&.lg_dirty_mult
1443 for additional information\&.
1444 .RE
1445 .PP
1446 arenas\&.decay_time (\fBssize_t\fR) rw
1447 .RS 4
1448 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
1449 arena\&.<i>\&.decay_time
1450 during arena creation\&. See
1451 opt\&.decay_time
1452 for additional information\&.
1453 .RE
1454 .PP
1455 arenas\&.quantum (\fBsize_t\fR) r\-
1456 .RS 4
1457 Quantum size\&.
1458 .RE
1459 .PP
1460 arenas\&.page (\fBsize_t\fR) r\-
1461 .RS 4
1462 Page size\&.
1463 .RE
1464 .PP
1465 arenas\&.tcache_max (\fBsize_t\fR) r\- [\fB\-\-enable\-tcache\fR]
1466 .RS 4
1467 Maximum thread\-cached size class\&.
1468 .RE
1469 .PP
1470 arenas\&.nbins (\fBunsigned\fR) r\-
1471 .RS 4
1472 Number of bin size classes\&.
1473 .RE
1474 .PP
1475 arenas\&.nhbins (\fBunsigned\fR) r\- [\fB\-\-enable\-tcache\fR]
1476 .RS 4
1477 Total number of thread cache bin size classes\&.
1478 .RE
1479 .PP
1480 arenas\&.bin\&.<i>\&.size (\fBsize_t\fR) r\-
1481 .RS 4
1482 Maximum size supported by size class\&.
1483 .RE
1484 .PP
1485 arenas\&.bin\&.<i>\&.nregs (\fBuint32_t\fR) r\-
1486 .RS 4
1487 Number of regions per page run\&.
1488 .RE
1489 .PP
1490 arenas\&.bin\&.<i>\&.run_size (\fBsize_t\fR) r\-
1491 .RS 4
1492 Number of bytes per page run\&.
1493 .RE
1494 .PP
1495 arenas\&.nlruns (\fBunsigned\fR) r\-
1496 .RS 4
1497 Total number of large size classes\&.
1498 .RE
1499 .PP
1500 arenas\&.lrun\&.<i>\&.size (\fBsize_t\fR) r\-
1501 .RS 4
1502 Maximum size supported by this large size class\&.
1503 .RE
1504 .PP
1505 arenas\&.nhchunks (\fBunsigned\fR) r\-
1506 .RS 4
1507 Total number of huge size classes\&.
1508 .RE
1509 .PP
1510 arenas\&.hchunk\&.<i>\&.size (\fBsize_t\fR) r\-
1511 .RS 4
1512 Maximum size supported by this huge size class\&.
1513 .RE
1514 .PP
1515 arenas\&.extend (\fBunsigned\fR) r\-
1516 .RS 4
1517 Extend the array of arenas by appending a new arena, and returning the new arena index\&.
1518 .RE
1519 .PP
1520 prof\&.thread_active_init (\fBbool\fR) rw [\fB\-\-enable\-prof\fR]
1521 .RS 4
1522 Control the initial setting for
1523 thread\&.prof\&.active
1524 in newly created threads\&. See the
1525 opt\&.prof_thread_active_init
1526 option for additional information\&.
1527 .RE
1528 .PP
1529 prof\&.active (\fBbool\fR) rw [\fB\-\-enable\-prof\fR]
1530 .RS 4
1531 Control whether sampling is currently active\&. See the
1532 opt\&.prof_active
1533 option for additional information, as well as the interrelated
1534 thread\&.prof\&.active
1535 mallctl\&.
1536 .RE
1537 .PP
1538 prof\&.dump (\fBconst char *\fR) \-w [\fB\-\-enable\-prof\fR]
1539 .RS 4
1540 Dump a memory profile to the specified file, or if NULL is specified, to a file according to the pattern
1541 <prefix>\&.<pid>\&.<seq>\&.m<mseq>\&.heap, where
1542 <prefix>
1543 is controlled by the
1544 opt\&.prof_prefix
1545 option\&.
1546 .RE
1547 .PP
1548 prof\&.gdump (\fBbool\fR) rw [\fB\-\-enable\-prof\fR]
1549 .RS 4
1550 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
1551 <prefix>\&.<pid>\&.<seq>\&.u<useq>\&.heap, where
1552 <prefix>
1553 is controlled by the
1554 opt\&.prof_prefix
1555 option\&.
1556 .RE
1557 .PP
1558 prof\&.reset (\fBsize_t\fR) \-w [\fB\-\-enable\-prof\fR]
1559 .RS 4
1560 Reset all memory profile statistics, and optionally update the sample rate (see
1561 opt\&.lg_prof_sample
1562 and
1563 prof\&.lg_sample)\&.
1564 .RE
1565 .PP
1566 prof\&.lg_sample (\fBsize_t\fR) r\- [\fB\-\-enable\-prof\fR]
1567 .RS 4
1568 Get the current sample rate (see
1569 opt\&.lg_prof_sample)\&.
1570 .RE
1571 .PP
1572 prof\&.interval (\fBuint64_t\fR) r\- [\fB\-\-enable\-prof\fR]
1573 .RS 4
1574 Average number of bytes allocated between interval\-based profile dumps\&. See the
1575 opt\&.lg_prof_interval
1576 option for additional information\&.
1577 .RE
1578 .PP
1579 stats\&.cactive (\fBsize_t *\fR) r\- [\fB\-\-enable\-stats\fR]
1580 .RS 4
1581 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
1582 epoch
1583 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\&.
1584 .RE
1585 .PP
1586 stats\&.allocated (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1587 .RS 4
1588 Total number of bytes allocated by the application\&.
1589 .RE
1590 .PP
1591 stats\&.active (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1592 .RS 4
1593 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
1594 stats\&.allocated\&. This does not include
1595 stats\&.arenas\&.<i>\&.pdirty, nor pages entirely devoted to allocator metadata\&.
1596 .RE
1597 .PP
1598 stats\&.metadata (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1599 .RS 4
1600 Total number of bytes dedicated to metadata, which comprise base allocations used for bootstrap\-sensitive internal allocator data structures, arena chunk headers (see
1601 stats\&.arenas\&.<i>\&.metadata\&.mapped), and internal allocations (see
1602 stats\&.arenas\&.<i>\&.metadata\&.allocated)\&.
1603 .RE
1604 .PP
1605 stats\&.resident (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1606 .RS 4
1607 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
1608 stats\&.active\&.
1609 .RE
1610 .PP
1611 stats\&.mapped (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1612 .RS 4
1613 Total number of bytes in active chunks mapped by the allocator\&. This is a multiple of the chunk size, and is larger than
1614 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
1615 stats\&.resident\&.
1616 .RE
1617 .PP
1618 stats\&.retained (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1619 .RS 4
1620 Total number of bytes in virtual memory mappings that were retained rather than being returned to the operating system via e\&.g\&.
1621 \fBmunmap\fR(2)\&. Retained virtual memory is typically untouched, decommitted, or purged, so it has no strongly associated physical memory (see
1622 chunk hooks
1623 for details)\&. Retained memory is excluded from mapped memory statistics, e\&.g\&.
1624 stats\&.mapped\&.
1625 .RE
1626 .PP
1627 stats\&.arenas\&.<i>\&.dss (\fBconst char *\fR) r\-
1628 .RS 4
1629 dss (\fBsbrk\fR(2)) allocation precedence as related to
1630 \fBmmap\fR(2)
1631 allocation\&. See
1632 opt\&.dss
1633 for details\&.
1634 .RE
1635 .PP
1636 stats\&.arenas\&.<i>\&.lg_dirty_mult (\fBssize_t\fR) r\-
1637 .RS 4
1638 Minimum ratio (log base 2) of active to dirty pages\&. See
1639 opt\&.lg_dirty_mult
1640 for details\&.
1641 .RE
1642 .PP
1643 stats\&.arenas\&.<i>\&.decay_time (\fBssize_t\fR) r\-
1644 .RS 4
1645 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
1646 opt\&.decay_time
1647 for details\&.
1648 .RE
1649 .PP
1650 stats\&.arenas\&.<i>\&.nthreads (\fBunsigned\fR) r\-
1651 .RS 4
1652 Number of threads currently assigned to arena\&.
1653 .RE
1654 .PP
1655 stats\&.arenas\&.<i>\&.pactive (\fBsize_t\fR) r\-
1656 .RS 4
1657 Number of pages in active runs\&.
1658 .RE
1659 .PP
1660 stats\&.arenas\&.<i>\&.pdirty (\fBsize_t\fR) r\-
1661 .RS 4
1662 Number of pages within unused runs that are potentially dirty, and for which
1663 madvise\fI\&.\&.\&.\fR \fI\fBMADV_DONTNEED\fR\fR
1664 or similar has not been called\&.
1665 .RE
1666 .PP
1667 stats\&.arenas\&.<i>\&.mapped (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1668 .RS 4
1669 Number of mapped bytes\&.
1670 .RE
1671 .PP
1672 stats\&.arenas\&.<i>\&.retained (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1673 .RS 4
1674 Number of retained bytes\&. See
1675 stats\&.retained
1676 for details\&.
1677 .RE
1678 .PP
1679 stats\&.arenas\&.<i>\&.metadata\&.mapped (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1680 .RS 4
1681 Number of mapped bytes in arena chunk headers, which track the states of the non\-metadata pages\&.
1682 .RE
1683 .PP
1684 stats\&.arenas\&.<i>\&.metadata\&.allocated (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1685 .RS 4
1686 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
1687 stats\&.metadata
1688 and
1689 stats\&.arenas\&.<i>\&.metadata\&.mapped
1690 because it overlaps with e\&.g\&. the
1691 stats\&.allocated
1692 and
1693 stats\&.active
1694 statistics, whereas the other metadata statistics do not\&.
1695 .RE
1696 .PP
1697 stats\&.arenas\&.<i>\&.npurge (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1698 .RS 4
1699 Number of dirty page purge sweeps performed\&.
1700 .RE
1701 .PP
1702 stats\&.arenas\&.<i>\&.nmadvise (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1703 .RS 4
1704 Number of
1705 madvise\fI\&.\&.\&.\fR \fI\fBMADV_DONTNEED\fR\fR
1706 or similar calls made to purge dirty pages\&.
1707 .RE
1708 .PP
1709 stats\&.arenas\&.<i>\&.purged (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1710 .RS 4
1711 Number of pages purged\&.
1712 .RE
1713 .PP
1714 stats\&.arenas\&.<i>\&.small\&.allocated (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1715 .RS 4
1716 Number of bytes currently allocated by small objects\&.
1717 .RE
1718 .PP
1719 stats\&.arenas\&.<i>\&.small\&.nmalloc (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1720 .RS 4
1721 Cumulative number of allocation requests served by small bins\&.
1722 .RE
1723 .PP
1724 stats\&.arenas\&.<i>\&.small\&.ndalloc (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1725 .RS 4
1726 Cumulative number of small objects returned to bins\&.
1727 .RE
1728 .PP
1729 stats\&.arenas\&.<i>\&.small\&.nrequests (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1730 .RS 4
1731 Cumulative number of small allocation requests\&.
1732 .RE
1733 .PP
1734 stats\&.arenas\&.<i>\&.large\&.allocated (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1735 .RS 4
1736 Number of bytes currently allocated by large objects\&.
1737 .RE
1738 .PP
1739 stats\&.arenas\&.<i>\&.large\&.nmalloc (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1740 .RS 4
1741 Cumulative number of large allocation requests served directly by the arena\&.
1742 .RE
1743 .PP
1744 stats\&.arenas\&.<i>\&.large\&.ndalloc (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1745 .RS 4
1746 Cumulative number of large deallocation requests served directly by the arena\&.
1747 .RE
1748 .PP
1749 stats\&.arenas\&.<i>\&.large\&.nrequests (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1750 .RS 4
1751 Cumulative number of large allocation requests\&.
1752 .RE
1753 .PP
1754 stats\&.arenas\&.<i>\&.huge\&.allocated (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1755 .RS 4
1756 Number of bytes currently allocated by huge objects\&.
1757 .RE
1758 .PP
1759 stats\&.arenas\&.<i>\&.huge\&.nmalloc (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1760 .RS 4
1761 Cumulative number of huge allocation requests served directly by the arena\&.
1762 .RE
1763 .PP
1764 stats\&.arenas\&.<i>\&.huge\&.ndalloc (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1765 .RS 4
1766 Cumulative number of huge deallocation requests served directly by the arena\&.
1767 .RE
1768 .PP
1769 stats\&.arenas\&.<i>\&.huge\&.nrequests (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1770 .RS 4
1771 Cumulative number of huge allocation requests\&.
1772 .RE
1773 .PP
1774 stats\&.arenas\&.<i>\&.bins\&.<j>\&.nmalloc (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1775 .RS 4
1776 Cumulative number of allocations served by bin\&.
1777 .RE
1778 .PP
1779 stats\&.arenas\&.<i>\&.bins\&.<j>\&.ndalloc (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1780 .RS 4
1781 Cumulative number of allocations returned to bin\&.
1782 .RE
1783 .PP
1784 stats\&.arenas\&.<i>\&.bins\&.<j>\&.nrequests (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1785 .RS 4
1786 Cumulative number of allocation requests\&.
1787 .RE
1788 .PP
1789 stats\&.arenas\&.<i>\&.bins\&.<j>\&.curregs (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1790 .RS 4
1791 Current number of regions for this size class\&.
1792 .RE
1793 .PP
1794 stats\&.arenas\&.<i>\&.bins\&.<j>\&.nfills (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR \fB\-\-enable\-tcache\fR]
1795 .RS 4
1796 Cumulative number of tcache fills\&.
1797 .RE
1798 .PP
1799 stats\&.arenas\&.<i>\&.bins\&.<j>\&.nflushes (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR \fB\-\-enable\-tcache\fR]
1800 .RS 4
1801 Cumulative number of tcache flushes\&.
1802 .RE
1803 .PP
1804 stats\&.arenas\&.<i>\&.bins\&.<j>\&.nruns (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1805 .RS 4
1806 Cumulative number of runs created\&.
1807 .RE
1808 .PP
1809 stats\&.arenas\&.<i>\&.bins\&.<j>\&.nreruns (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1810 .RS 4
1811 Cumulative number of times the current run from which to allocate changed\&.
1812 .RE
1813 .PP
1814 stats\&.arenas\&.<i>\&.bins\&.<j>\&.curruns (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1815 .RS 4
1816 Current number of runs\&.
1817 .RE
1818 .PP
1819 stats\&.arenas\&.<i>\&.lruns\&.<j>\&.nmalloc (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1820 .RS 4
1821 Cumulative number of allocation requests for this size class served directly by the arena\&.
1822 .RE
1823 .PP
1824 stats\&.arenas\&.<i>\&.lruns\&.<j>\&.ndalloc (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1825 .RS 4
1826 Cumulative number of deallocation requests for this size class served directly by the arena\&.
1827 .RE
1828 .PP
1829 stats\&.arenas\&.<i>\&.lruns\&.<j>\&.nrequests (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1830 .RS 4
1831 Cumulative number of allocation requests for this size class\&.
1832 .RE
1833 .PP
1834 stats\&.arenas\&.<i>\&.lruns\&.<j>\&.curruns (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1835 .RS 4
1836 Current number of runs for this size class\&.
1837 .RE
1838 .PP
1839 stats\&.arenas\&.<i>\&.hchunks\&.<j>\&.nmalloc (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1840 .RS 4
1841 Cumulative number of allocation requests for this size class served directly by the arena\&.
1842 .RE
1843 .PP
1844 stats\&.arenas\&.<i>\&.hchunks\&.<j>\&.ndalloc (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1845 .RS 4
1846 Cumulative number of deallocation requests for this size class served directly by the arena\&.
1847 .RE
1848 .PP
1849 stats\&.arenas\&.<i>\&.hchunks\&.<j>\&.nrequests (\fBuint64_t\fR) r\- [\fB\-\-enable\-stats\fR]
1850 .RS 4
1851 Cumulative number of allocation requests for this size class\&.
1852 .RE
1853 .PP
1854 stats\&.arenas\&.<i>\&.hchunks\&.<j>\&.curhchunks (\fBsize_t\fR) r\- [\fB\-\-enable\-stats\fR]
1855 .RS 4
1856 Current number of huge allocations for this size class\&.
1857 .RE
1858 .SH "HEAP PROFILE FORMAT"
1859 .PP
1860 Although the heap profiling functionality was originally designed to be compatible with the
1861 \fBpprof\fR
1862 command that is developed as part of the
1863 \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
1864 \fBjeprof\fR
1865 command is derived from
1866 \fBpprof\fR, with enhancements to support the heap profile format described here\&.
1867 .PP
1868 In the following hypothetical heap profile,
1869 \fB[\&.\&.\&.]\fR
1870 indicates elision for the sake of compactness\&.
1871 .sp
1872 .if n \{\
1873 .RS 4
1874 .\}
1875 .nf
1876 heap_v2/524288
1877   t*: 28106: 56637512 [0: 0]
1878   [\&.\&.\&.]
1879   t3: 352: 16777344 [0: 0]
1880   [\&.\&.\&.]
1881   t99: 17754: 29341640 [0: 0]
1882   [\&.\&.\&.]
1883 @ 0x5f86da8 0x5f5a1dc [\&.\&.\&.] 0x29e4d4e 0xa200316 0xabb2988 [\&.\&.\&.]
1884   t*: 13: 6688 [0: 0]
1885   t3: 12: 6496 [0: ]
1886   t99: 1: 192 [0: 0]
1887 [\&.\&.\&.]
1888
1889 MAPPED_LIBRARIES:
1890 [\&.\&.\&.]
1891 .fi
1892 .if n \{\
1893 .RE
1894 .\}
1895 .sp
1896 The following matches the above heap profile, but most tokens are replaced with
1897 \fB<description>\fR
1898 to indicate descriptions of the corresponding fields\&.
1899 .sp
1900 .if n \{\
1901 .RS 4
1902 .\}
1903 .nf
1904 <heap_profile_format_version>/<mean_sample_interval>
1905   <aggregate>: <curobjs>: <curbytes> [<cumobjs>: <cumbytes>]
1906   [\&.\&.\&.]
1907   <thread_3_aggregate>: <curobjs>: <curbytes>[<cumobjs>: <cumbytes>]
1908   [\&.\&.\&.]
1909   <thread_99_aggregate>: <curobjs>: <curbytes>[<cumobjs>: <cumbytes>]
1910   [\&.\&.\&.]
1911 @ <top_frame> <frame> [\&.\&.\&.] <frame> <frame> <frame> [\&.\&.\&.]
1912   <backtrace_aggregate>: <curobjs>: <curbytes> [<cumobjs>: <cumbytes>]
1913   <backtrace_thread_3>: <curobjs>: <curbytes> [<cumobjs>: <cumbytes>]
1914   <backtrace_thread_99>: <curobjs>: <curbytes> [<cumobjs>: <cumbytes>]
1915 [\&.\&.\&.]
1916
1917 MAPPED_LIBRARIES:
1918 </proc/<pid>/maps>
1919 .fi
1920 .if n \{\
1921 .RE
1922 .\}
1923 .SH "DEBUGGING MALLOC PROBLEMS"
1924 .PP
1925 When debugging, it is a good idea to configure/build jemalloc with the
1926 \fB\-\-enable\-debug\fR
1927 and
1928 \fB\-\-enable\-fill\fR
1929 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\&.
1930 .PP
1931 Programs often accidentally depend on
1932 \(lquninitialized\(rq
1933 memory actually being filled with zero bytes\&. Junk filling (see the
1934 opt\&.junk
1935 option) tends to expose such bugs in the form of obviously incorrect results and/or coredumps\&. Conversely, zero filling (see the
1936 opt\&.zero
1937 option) eliminates the symptoms of such bugs\&. Between these two options, it is usually possible to quickly detect, diagnose, and eliminate such bugs\&.
1938 .PP
1939 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
1940 \m[blue]\fBValgrind\fR\m[]\&\s-2\u[3]\d\s+2
1941 tool if the
1942 \fB\-\-enable\-valgrind\fR
1943 configuration option is enabled\&.
1944 .SH "DIAGNOSTIC MESSAGES"
1945 .PP
1946 If any of the memory allocation/deallocation functions detect an error or warning condition, a message will be printed to file descriptor
1947 \fBSTDERR_FILENO\fR\&. Errors will result in the process dumping core\&. If the
1948 opt\&.abort
1949 option is set, most warnings are treated as errors\&.
1950 .PP
1951 The
1952 \fImalloc_message\fR
1953 variable allows the programmer to override the function which emits the text strings forming the errors and warnings if for some reason the
1954 \fBSTDERR_FILENO\fR
1955 file descriptor is not suitable for this\&.
1956 malloc_message()
1957 takes the
1958 \fIcbopaque\fR
1959 pointer argument that is
1960 \fBNULL\fR
1961 unless overridden by the arguments in a call to
1962 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\&.
1963 .PP
1964 All messages are prefixed by
1965 \(lq<jemalloc>: \(rq\&.
1966 .SH "RETURN VALUES"
1967 .SS "Standard API"
1968 .PP
1969 The
1970 malloc()
1971 and
1972 calloc()
1973 functions return a pointer to the allocated memory if successful; otherwise a
1974 \fBNULL\fR
1975 pointer is returned and
1976 \fIerrno\fR
1977 is set to
1978 ENOMEM\&.
1979 .PP
1980 The
1981 posix_memalign()
1982 function returns the value 0 if successful; otherwise it returns an error value\&. The
1983 posix_memalign()
1984 function will fail if:
1985 .PP
1986 EINVAL
1987 .RS 4
1988 The
1989 \fIalignment\fR
1990 parameter is not a power of 2 at least as large as
1991 sizeof(\fBvoid *\fR)\&.
1992 .RE
1993 .PP
1994 ENOMEM
1995 .RS 4
1996 Memory allocation error\&.
1997 .RE
1998 .PP
1999 The
2000 aligned_alloc()
2001 function returns a pointer to the allocated memory if successful; otherwise a
2002 \fBNULL\fR
2003 pointer is returned and
2004 \fIerrno\fR
2005 is set\&. The
2006 aligned_alloc()
2007 function will fail if:
2008 .PP
2009 EINVAL
2010 .RS 4
2011 The
2012 \fIalignment\fR
2013 parameter is not a power of 2\&.
2014 .RE
2015 .PP
2016 ENOMEM
2017 .RS 4
2018 Memory allocation error\&.
2019 .RE
2020 .PP
2021 The
2022 realloc()
2023 function returns a pointer, possibly identical to
2024 \fIptr\fR, to the allocated memory if successful; otherwise a
2025 \fBNULL\fR
2026 pointer is returned, and
2027 \fIerrno\fR
2028 is set to
2029 ENOMEM
2030 if the error was the result of an allocation failure\&. The
2031 realloc()
2032 function always leaves the original buffer intact when an error occurs\&.
2033 .PP
2034 The
2035 free()
2036 function returns no value\&.
2037 .SS "Non\-standard API"
2038 .PP
2039 The
2040 mallocx()
2041 and
2042 rallocx()
2043 functions return a pointer to the allocated memory if successful; otherwise a
2044 \fBNULL\fR
2045 pointer is returned to indicate insufficient contiguous memory was available to service the allocation request\&.
2046 .PP
2047 The
2048 xallocx()
2049 function returns the real size of the resulting resized allocation pointed to by
2050 \fIptr\fR, which is a value less than
2051 \fIsize\fR
2052 if the allocation could not be adequately grown in place\&.
2053 .PP
2054 The
2055 sallocx()
2056 function returns the real size of the allocation pointed to by
2057 \fIptr\fR\&.
2058 .PP
2059 The
2060 nallocx()
2061 returns the real size that would result from a successful equivalent
2062 mallocx()
2063 function call, or zero if insufficient memory is available to perform the size computation\&.
2064 .PP
2065 The
2066 mallctl(),
2067 mallctlnametomib(), and
2068 mallctlbymib()
2069 functions return 0 on success; otherwise they return an error value\&. The functions will fail if:
2070 .PP
2071 EINVAL
2072 .RS 4
2073 \fInewp\fR
2074 is not
2075 \fBNULL\fR, and
2076 \fInewlen\fR
2077 is too large or too small\&. Alternatively,
2078 \fI*oldlenp\fR
2079 is too large or too small; in this case as much data as possible are read despite the error\&.
2080 .RE
2081 .PP
2082 ENOENT
2083 .RS 4
2084 \fIname\fR
2085 or
2086 \fImib\fR
2087 specifies an unknown/invalid value\&.
2088 .RE
2089 .PP
2090 EPERM
2091 .RS 4
2092 Attempt to read or write void value, or attempt to write read\-only value\&.
2093 .RE
2094 .PP
2095 EAGAIN
2096 .RS 4
2097 A memory allocation failure occurred\&.
2098 .RE
2099 .PP
2100 EFAULT
2101 .RS 4
2102 An interface with side effects failed in some way not directly related to
2103 mallctl*()
2104 read/write processing\&.
2105 .RE
2106 .PP
2107 The
2108 malloc_usable_size()
2109 function returns the usable size of the allocation pointed to by
2110 \fIptr\fR\&.
2111 .SH "ENVIRONMENT"
2112 .PP
2113 The following environment variable affects the execution of the allocation functions:
2114 .PP
2115 \fBMALLOC_CONF\fR
2116 .RS 4
2117 If the environment variable
2118 \fBMALLOC_CONF\fR
2119 is set, the characters it contains will be interpreted as options\&.
2120 .RE
2121 .SH "EXAMPLES"
2122 .PP
2123 To dump core whenever a problem occurs:
2124 .sp
2125 .if n \{\
2126 .RS 4
2127 .\}
2128 .nf
2129 ln \-s \*(Aqabort:true\*(Aq /etc/malloc\&.conf
2130 .fi
2131 .if n \{\
2132 .RE
2133 .\}
2134 .PP
2135 To specify in the source a chunk size that is 16 MiB:
2136 .sp
2137 .if n \{\
2138 .RS 4
2139 .\}
2140 .nf
2141 malloc_conf = "lg_chunk:24";
2142 .fi
2143 .if n \{\
2144 .RE
2145 .\}
2146 .SH "SEE ALSO"
2147 .PP
2148 \fBmadvise\fR(2),
2149 \fBmmap\fR(2),
2150 \fBsbrk\fR(2),
2151 \fButrace\fR(2),
2152 \fBalloca\fR(3),
2153 \fBatexit\fR(3),
2154 \fBgetpagesize\fR(3)
2155 .SH "STANDARDS"
2156 .PP
2157 The
2158 malloc(),
2159 calloc(),
2160 realloc(), and
2161 free()
2162 functions conform to ISO/IEC 9899:1990 (\(lqISO C90\(rq)\&.
2163 .PP
2164 The
2165 posix_memalign()
2166 function conforms to IEEE Std 1003\&.1\-2001 (\(lqPOSIX\&.1\(rq)\&.
2167 .SH "HISTORY"
2168 .PP
2169 The
2170 malloc_usable_size()
2171 and
2172 posix_memalign()
2173 functions first appeared in FreeBSD 7\&.0\&.
2174 .PP
2175 The
2176 aligned_alloc(),
2177 malloc_stats_print(), and
2178 mallctl*()
2179 functions first appeared in FreeBSD 10\&.0\&.
2180 .PP
2181 The
2182 *allocx()
2183 functions first appeared in FreeBSD 11\&.0\&.
2184 .SH "AUTHOR"
2185 .PP
2186 \fBJason Evans\fR
2187 .RS 4
2188 .RE
2189 .SH "NOTES"
2190 .IP " 1." 4
2191 jemalloc website
2192 .RS 4
2193 \%http://jemalloc.net/
2194 .RE
2195 .IP " 2." 4
2196 JSON format
2197 .RS 4
2198 \%http://www.json.org/
2199 .RE
2200 .IP " 3." 4
2201 Valgrind
2202 .RS 4
2203 \%http://valgrind.org/
2204 .RE
2205 .IP " 4." 4
2206 gperftools package
2207 .RS 4
2208 \%http://code.google.com/p/gperftools/
2209 .RE