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