1JEMALLOC(3)                       User Manual                      JEMALLOC(3)
2
3
4

NAME

6       jemalloc - general purpose memory allocation functions
7

LIBRARY

9       This manual describes jemalloc
10       2.2.5-0-gfc1bb70e5f0d9a58b39efa39cc549b5af5104760. More information can
11       be found at the jemalloc website[1].
12

SYNOPSIS

14       #include <stdlib.h>
15       #include <jemalloc/jemalloc.h>
16
17   Standard API
18       void *malloc(size_t size);
19
20       void *calloc(size_t number, size_t size);
21
22       int posix_memalign(void **ptr, size_t alignment, size_t size);
23
24       void *realloc(void *ptr, size_t size);
25
26       void free(void *ptr);
27
28   Non-standard API
29       size_t malloc_usable_size(const void *ptr);
30
31       void malloc_stats_print(void (*write_cb) (void *, const char *),
32                               void *cbopaque, const char *opts);
33
34       int mallctl(const char *name, void *oldp, size_t *oldlenp, void *newp,
35                   size_t newlen);
36
37       int mallctlnametomib(const char *name, size_t *mibp, size_t *miblenp);
38
39       int mallctlbymib(const size_t *mib, size_t miblen, void *oldp,
40                        size_t *oldlenp, void *newp, size_t newlen);
41
42       void (*malloc_message)(void *cbopaque, const char *s);
43
44       const char *malloc_conf;
45
46   Experimental API
47       int allocm(void **ptr, size_t *rsize, size_t size, int flags);
48
49       int rallocm(void **ptr, size_t *rsize, size_t size, size_t extra,
50                   int flags);
51
52       int sallocm(const void *ptr, size_t *rsize, int flags);
53
54       int dallocm(void *ptr, int flags);
55

DESCRIPTION

57   Standard API
58       The malloc function allocates size bytes of uninitialized memory. The
59       allocated space is suitably aligned (after possible pointer coercion)
60       for storage of any type of object.
61
62       The calloc function allocates space for number objects, each size bytes
63       in length. The result is identical to calling malloc with an argument
64       of number * size, with the exception that the allocated memory is
65       explicitly initialized to zero bytes.
66
67       The posix_memalign function allocates size bytes of memory such that
68       the allocation's base address is an even multiple of alignment, and
69       returns the allocation in the value pointed to by ptr. The requested
70       alignment must be a power of 2 at least as large as sizeof(void *).
71
72       The realloc function changes the size of the previously allocated
73       memory referenced by ptr to size bytes. The contents of the memory are
74       unchanged up to the lesser of the new and old sizes. If the new size is
75       larger, the contents of the newly allocated portion of the memory are
76       undefined. Upon success, the memory referenced by ptr is freed and a
77       pointer to the newly allocated memory is returned. Note that realloc
78       may move the memory allocation, resulting in a different return value
79       than ptr. If ptr is NULL, the realloc function behaves identically to
80       malloc for the specified size.
81
82       The free function causes the allocated memory referenced by ptr to be
83       made available for future allocations. If ptr is NULL, no action
84       occurs.
85
86   Non-standard API
87       The malloc_usable_size function returns the usable size of the
88       allocation pointed to by ptr. The return value may be larger than the
89       size that was requested during allocation. The malloc_usable_size
90       function is not a mechanism for in-place realloc; rather it is provided
91       solely as a tool for introspection purposes. Any discrepancy between
92       the requested allocation size and the size reported by
93       malloc_usable_size should not be depended on, since such behavior is
94       entirely implementation-dependent.
95
96       The malloc_stats_print function writes human-readable summary
97       statistics via the write_cb callback function pointer and cbopaque data
98       passed to write_cb, or malloc_message if write_cb is NULL. This
99       function can be called repeatedly. General information that never
100       changes during execution can be omitted by specifying "g" as a
101       character within the opts string. Note that malloc_message uses the
102       mallctl* functions internally, so inconsistent statistics can be
103       reported if multiple threads use these functions simultaneously. If
104       --enable-stats is specified during configuration, “m” and “a” can be
105       specified to omit merged arena and per arena statistics, respectively;
106       “b” and “l” can be specified to omit per size class statistics for bins
107       and large objects, respectively. Unrecognized characters are silently
108       ignored. Note that thread caching may prevent some statistics from
109       being completely up to date, since extra locking would be required to
110       merge counters that track thread cache operations.
111
112       The mallctl function provides a general interface for introspecting the
113       memory allocator, as well as setting modifiable parameters and
114       triggering actions. The period-separated name argument specifies a
115       location in a tree-structured namespace; see the MALLCTL NAMESPACE
116       section for documentation on the tree contents. To read a value, pass a
117       pointer via oldp to adequate space to contain the value, and a pointer
118       to its length via oldlenp; otherwise pass NULL and NULL. Similarly, to
119       write a value, pass a pointer to the value via newp, and its length via
120       newlen; otherwise pass NULL and 0.
121
122       The mallctlnametomib function provides a way to avoid repeated name
123       lookups for applications that repeatedly query the same portion of the
124       namespace, by translating a name to a “Management Information Base”
125       (MIB) that can be passed repeatedly to mallctlbymib. Upon successful
126       return from mallctlnametomib, mibp contains an array of *miblenp
127       integers, where *miblenp is the lesser of the number of components in
128       name and the input value of *miblenp. Thus it is possible to pass a
129       *miblenp that is smaller than the number of period-separated name
130       components, which results in a partial MIB that can be used as the
131       basis for constructing a complete MIB. For name components that are
132       integers (e.g. the 2 in "arenas.bin.2.size"), the corresponding MIB
133       component will always be that integer. Therefore, it is legitimate to
134       construct code like the following:
135
136           unsigned nbins, i;
137
138           int mib[4];
139           size_t len, miblen;
140
141           len = sizeof(nbins);
142           mallctl("arenas.nbins", &nbins, &len, NULL, 0);
143
144           miblen = 4;
145           mallnametomib("arenas.bin.0.size", mib, &miblen);
146           for (i = 0; i < nbins; i++) {
147                size_t bin_size;
148
149                mib[2] = i;
150                len = sizeof(bin_size);
151                mallctlbymib(mib, miblen, &bin_size, &len, NULL, 0);
152                /* Do something with bin_size... */
153           }
154
155   Experimental API
156       The experimental API is subject to change or removal without regard for
157       backward compatibility.
158
159       The allocm, rallocm, sallocm, and dallocm functions all have a flags
160       argument that can be used to specify options. The functions only check
161       the options that are contextually relevant. Use bitwise or (|)
162       operations to specify one or more of the following:
163
164       ALLOCM_LG_ALIGN(la)
165           Align the memory allocation to start at an address that is a
166           multiple of (1 << la). This macro does not validate that la is
167           within the valid range.
168
169       ALLOCM_ALIGN(a)
170           Align the memory allocation to start at an address that is a
171           multiple of a, where a is a power of two. This macro does not
172           validate that a is a power of 2.
173
174       ALLOCM_ZERO
175           Initialize newly allocated memory to contain zero bytes. In the
176           growing reallocation case, the real size prior to reallocation
177           defines the boundary between untouched bytes and those that are
178           initialized to contain zero bytes. If this option is absent, newly
179           allocated memory is uninitialized.
180
181       ALLOCM_NO_MOVE
182           For reallocation, fail rather than moving the object. This
183           constraint can apply to both growth and shrinkage.
184
185       The allocm function allocates at least size bytes of memory, sets *ptr
186       to the base address of the allocation, and sets *rsize to the real size
187       of the allocation if rsize is not NULL.
188
189       The rallocm function resizes the allocation at *ptr to be at least size
190       bytes, sets *ptr to the base address of the allocation if it moved, and
191       sets *rsize to the real size of the allocation if rsize is not NULL. If
192       extra is non-zero, an attempt is made to resize the allocation to be at
193       least size + extra) bytes, though inability to allocate the extra
194       byte(s) will not by itself result in failure. Behavior is undefined if
195       (size + extra > SIZE_T_MAX).
196
197       The sallocm function sets *rsize to the real size of the allocation.
198
199       The dallocm function causes the memory referenced by ptr to be made
200       available for future allocations.
201

TUNING

203       Once, when the first call is made to one of the memory allocation
204       routines, the allocator initializes its internals based in part on
205       various options that can be specified at compile- or run-time.
206
207       The string pointed to by the global variable malloc_conf, the “name” of
208       the file referenced by the symbolic link named /etc/malloc.conf, and
209       the value of the environment variable MALLOC_CONF, will be interpreted,
210       in that order, from left to right as options.
211
212       An options string is a comma-separated list of option:value pairs.
213       There is one key corresponding to each "opt.*"  mallctl (see the
214       MALLCTL NAMESPACE section for options documentation). For example,
215       abort:true,narenas:1 sets the "opt.abort" and "opt.narenas" options.
216       Some options have boolean values (true/false), others have integer
217       values (base 8, 10, or 16, depending on prefix), and yet others have
218       raw string values.
219

IMPLEMENTATION NOTES

221       Traditionally, allocators have used sbrk(2) to obtain memory, which is
222       suboptimal for several reasons, including race conditions, increased
223       fragmentation, and artificial limitations on maximum usable memory. If
224       --enable-dss is specified during configuration, this allocator uses
225       both sbrk(2) and mmap(2), in that order of preference; otherwise only
226       mmap(2) is used.
227
228       This allocator uses multiple arenas in order to reduce lock contention
229       for threaded programs on multi-processor systems. This works well with
230       regard to threading scalability, but incurs some costs. There is a
231       small fixed per-arena overhead, and additionally, arenas manage memory
232       completely independently of each other, which means a small fixed
233       increase in overall memory fragmentation. These overheads are not
234       generally an issue, given the number of arenas normally used. Note that
235       using substantially more arenas than the default is not likely to
236       improve performance, mainly due to reduced cache performance. However,
237       it may make sense to reduce the number of arenas if an application does
238       not make much use of the allocation functions.
239
240       In addition to multiple arenas, unless --disable-tcache is specified
241       during configuration, this allocator supports thread-specific caching
242       for small and large objects, in order to make it possible to completely
243       avoid synchronization for most allocation requests. Such caching allows
244       very fast allocation in the common case, but it increases memory usage
245       and fragmentation, since a bounded number of objects can remain
246       allocated in each thread cache.
247
248       Memory is conceptually broken into equal-sized chunks, where the chunk
249       size is a power of two that is greater than the page size. Chunks are
250       always aligned to multiples of the chunk size. This alignment makes it
251       possible to find metadata for user objects very quickly.
252
253       User objects are broken into three categories according to size: small,
254       large, and huge. Small objects are smaller than one page. Large objects
255       are smaller than the chunk size. Huge objects are a multiple of the
256       chunk size. Small and large objects are managed by arenas; huge objects
257       are managed separately in a single data structure that is shared by all
258       threads. Huge objects are used by applications infrequently enough that
259       this single data structure is not a scalability issue.
260
261       Each chunk that is managed by an arena tracks its contents as runs of
262       contiguous pages (unused, backing a set of small objects, or backing
263       one large object). The combination of chunk alignment and chunk page
264       maps makes it possible to determine all metadata regarding small and
265       large allocations in constant time.
266
267       Small objects are managed in groups by page runs. Each run maintains a
268       frontier and free list to track which regions are in use. Unless
269       --disable-tiny is specified during configuration, allocation requests
270       that are no more than half the quantum (8 or 16, depending on
271       architecture) are rounded up to the nearest power of two that is at
272       least sizeof(void *). Allocation requests that are more than half the
273       quantum, but no more than the minimum cacheline-multiple size class
274       (see the "opt.lg_qspace_max" option) are rounded up to the nearest
275       multiple of the quantum. Allocation requests that are more than the
276       minimum cacheline-multiple size class, but no more than the minimum
277       subpage-multiple size class (see the "opt.lg_cspace_max" option) are
278       rounded up to the nearest multiple of the cacheline size (64).
279       Allocation requests that are more than the minimum subpage-multiple
280       size class, but no more than the maximum subpage-multiple size class
281       are rounded up to the nearest multiple of the subpage size (256).
282       Allocation requests that are more than the maximum subpage-multiple
283       size class, but small enough to fit in an arena-managed chunk (see the
284       "opt.lg_chunk" option), are rounded up to the nearest run size.
285       Allocation requests that are too large to fit in an arena-managed chunk
286       are rounded up to the nearest multiple of the chunk size.
287
288       Allocations are packed tightly together, which can be an issue for
289       multi-threaded applications. If you need to assure that allocations do
290       not suffer from cacheline sharing, round your allocation requests up to
291       the nearest multiple of the cacheline size, or specify cacheline
292       alignment when allocating.
293
294       Assuming 4 MiB chunks, 4 KiB pages, and a 16-byte quantum on a 64-bit
295       system, the size classes in each category are as shown in Table 1.
296
297       Table 1. Size classes
298       ┌─────────┬──────────────────┬─────────────────────┐
299Category Subcategory      Size                
300       ├─────────┼──────────────────┼─────────────────────┤
301       │         │ Tiny             │ [8]                 │
302       │         ├──────────────────┼─────────────────────┤
303       │         │ Quantum-spaced   │ [16, 32, 48, ...,   │
304       │         │                  │ 128]                │
305       │Small    ├──────────────────┼─────────────────────┤
306       │         │ Cacheline-spaced │ [192, 256, 320,     │
307       │         │                  │ ..., 512]           │
308       │         ├──────────────────┼─────────────────────┤
309       │         │ Subpage-spaced   │ [768, 1024, 1280,   │
310       │         │                  │ ..., 3840]          │
311       ├─────────┴──────────────────┼─────────────────────┤
312       │Large                       │ [4 KiB, 8 KiB, 12   │
313       │                            │ KiB, ..., 4072 KiB] │
314       ├────────────────────────────┼─────────────────────┤
315       │Huge                        │ [4 MiB, 8 MiB, 12   │
316       │                            │ MiB, ...]           │
317       └────────────────────────────┴─────────────────────┘
318

MALLCTL NAMESPACE

320       The following names are defined in the namespace accessible via the
321       mallctl* functions. Value types are specified in parentheses, their
322       readable/writable statuses are encoded as rw, r-, -w, or --, and
323       required build configuration flags follow, if any. A name element
324       encoded as <i> or <j> indicates an integer component, where the integer
325       varies from 0 to some upper value that must be determined via
326       introspection. In the case of "stats.arenas.<i>.*", <i> equal to
327       "arenas.narenas" can be used to access the summation of statistics from
328       all arenas. Take special note of the "epoch" mallctl, which controls
329       refreshing of cached dynamic statistics.
330
331       "version" (const char *) r-
332           Return the jemalloc version string.
333
334       "epoch" (uint64_t) rw
335           If a value is passed in, refresh the data from which the mallctl*
336           functions report values, and increment the epoch. Return the
337           current epoch. This is useful for detecting whether another thread
338           caused a refresh.
339
340       "config.debug" (bool) r-
341           --enable-debug was specified during build configuration.
342
343       "config.dss" (bool) r-
344           --enable-dss was specified during build configuration.
345
346       "config.dynamic_page_shift" (bool) r-
347           --enable-dynamic-page-shift was specified during build
348           configuration.
349
350       "config.fill" (bool) r-
351           --enable-fill was specified during build configuration.
352
353       "config.lazy_lock" (bool) r-
354           --enable-lazy-lock was specified during build configuration.
355
356       "config.prof" (bool) r-
357           --enable-prof was specified during build configuration.
358
359       "config.prof_libgcc" (bool) r-
360           --disable-prof-libgcc was not specified during build configuration.
361
362       "config.prof_libunwind" (bool) r-
363           --enable-prof-libunwind was specified during build configuration.
364
365       "config.stats" (bool) r-
366           --enable-stats was specified during build configuration.
367
368       "config.swap" (bool) r-
369           --enable-swap was specified during build configuration.
370
371       "config.sysv" (bool) r-
372           --enable-sysv was specified during build configuration.
373
374       "config.tcache" (bool) r-
375           --disable-tcache was not specified during build configuration.
376
377       "config.tiny" (bool) r-
378           --disable-tiny was not specified during build configuration.
379
380       "config.tls" (bool) r-
381           --disable-tls was not specified during build configuration.
382
383       "config.xmalloc" (bool) r-
384           --enable-xmalloc was specified during build configuration.
385
386       "opt.abort" (bool) r-
387           Abort-on-warning enabled/disabled. If true, most warnings are
388           fatal. The process will call abort(3) in these cases. This option
389           is disabled by default unless --enable-debug is specified during
390           configuration, in which case it is enabled by default.
391
392       "opt.lg_qspace_max" (size_t) r-
393           Size (log base 2) of the maximum size class that is a multiple of
394           the quantum (8 or 16 bytes, depending on architecture). Above this
395           size, cacheline spacing is used for size classes. The default value
396           is 128 bytes (2^7).
397
398       "opt.lg_cspace_max" (size_t) r-
399           Size (log base 2) of the maximum size class that is a multiple of
400           the cacheline size (64). Above this size, subpage spacing (256
401           bytes) is used for size classes. The default value is 512 bytes
402           (2^9).
403
404       "opt.lg_chunk" (size_t) r-
405           Virtual memory chunk size (log base 2). The default chunk size is 4
406           MiB (2^22).
407
408       "opt.narenas" (size_t) r-
409           Maximum number of arenas to use. The default maximum number of
410           arenas is four times the number of CPUs, or one if there is a
411           single CPU.
412
413       "opt.lg_dirty_mult" (ssize_t) r-
414           Per-arena minimum ratio (log base 2) of active to dirty pages. Some
415           dirty unused pages may be allowed to accumulate, within the limit
416           set by the ratio (or one chunk worth of dirty pages, whichever is
417           greater), before informing the kernel about some of those pages via
418           madvise(2) or a similar system call. This provides the kernel with
419           sufficient information to recycle dirty pages if physical memory
420           becomes scarce and the pages remain unused. The default minimum
421           ratio is 32:1 (2^5:1); an option value of -1 will disable dirty
422           page purging.
423
424       "opt.stats_print" (bool) r-
425           Enable/disable statistics printing at exit. If enabled, the
426           malloc_stats_print function is called at program exit via an
427           atexit(3) function. If --enable-stats is specified during
428           configuration, this has the potential to cause deadlock for a
429           multi-threaded process that exits while one or more threads are
430           executing in the memory allocation functions. Therefore, this
431           option should only be used with care; it is primarily intended as a
432           performance tuning aid during application development. This option
433           is disabled by default.
434
435       "opt.junk" (bool) r- [--enable-fill]
436           Junk filling enabled/disabled. If enabled, each byte of
437           uninitialized allocated memory will be initialized to 0xa5. All
438           deallocated memory will be initialized to 0x5a. This is intended
439           for debugging and will impact performance negatively. This option
440           is disabled by default unless --enable-debug is specified during
441           configuration, in which case it is enabled by default.
442
443       "opt.zero" (bool) r- [--enable-fill]
444           Zero filling enabled/disabled. If enabled, each byte of
445           uninitialized allocated memory will be initialized to 0. Note that
446           this initialization only happens once for each byte, so realloc and
447           rallocm calls do not zero memory that was previously allocated.
448           This is intended for debugging and will impact performance
449           negatively. This option is disabled by default.
450
451       "opt.sysv" (bool) r- [--enable-sysv]
452           If enabled, attempting to allocate zero bytes will return a NULL
453           pointer instead of a valid pointer. (The default behavior is to
454           make a minimal allocation and return a pointer to it.) This option
455           is provided for System V compatibility. This option is incompatible
456           with the "opt.xmalloc" option. This option is disabled by default.
457
458       "opt.xmalloc" (bool) r- [--enable-xmalloc]
459           Abort-on-out-of-memory enabled/disabled. If enabled, rather than
460           returning failure for any allocation function, display a diagnostic
461           message on STDERR_FILENO and cause the program to drop core (using
462           abort(3)). If an application is designed to depend on this
463           behavior, set the option at compile time by including the following
464           in the source code:
465
466               malloc_conf = "xmalloc:true";
467
468           This option is disabled by default.
469
470       "opt.tcache" (bool) r- [--enable-tcache]
471           Thread-specific caching enabled/disabled. When there are multiple
472           threads, each thread uses a thread-specific cache for objects up to
473           a certain size. Thread-specific caching allows many allocations to
474           be satisfied without performing any thread synchronization, at the
475           cost of increased memory use. See the "opt.lg_tcache_gc_sweep" and
476           "opt.lg_tcache_max" options for related tuning information. This
477           option is enabled by default.
478
479       "opt.lg_tcache_gc_sweep" (ssize_t) r- [--enable-tcache]
480           Approximate interval (log base 2) between full thread-specific
481           cache garbage collection sweeps, counted in terms of
482           thread-specific cache allocation/deallocation events. Garbage
483           collection is actually performed incrementally, one size class at a
484           time, in order to avoid large collection pauses. The default sweep
485           interval is 8192 (2^13); setting this option to -1 will disable
486           garbage collection.
487
488       "opt.lg_tcache_max" (size_t) r- [--enable-tcache]
489           Maximum size class (log base 2) to cache in the thread-specific
490           cache. At a minimum, all small size classes are cached, and at a
491           maximum all large size classes are cached. The default maximum is
492           32 KiB (2^15).
493
494       "opt.prof" (bool) r- [--enable-prof]
495           Memory profiling enabled/disabled. If enabled, profile memory
496           allocation activity, and use an atexit(3) function to dump final
497           memory usage to a file named according to the pattern
498           <prefix>.<pid>.<seq>.f.heap, where <prefix> is controlled by the
499           "opt.prof_prefix" option. See the "opt.lg_prof_bt_max" option for
500           backtrace depth control. See the "opt.prof_active" option for
501           on-the-fly activation/deactivation. See the "opt.lg_prof_sample"
502           option for probabilistic sampling control. See the "opt.prof_accum"
503           option for control of cumulative sample reporting. See the
504           "opt.lg_prof_tcmax" option for control of per thread backtrace
505           caching. See the "opt.lg_prof_interval" option for information on
506           interval-triggered profile dumping, and the "opt.prof_gdump" option
507           for information on high-water-triggered profile dumping. Profile
508           output is compatible with the included pprof Perl script, which
509           originates from the google-perftools package[2].
510
511       "opt.prof_prefix" (const char *) r- [--enable-prof]
512           Filename prefix for profile dumps. If the prefix is set to the
513           empty string, no automatic dumps will occur; this is primarily
514           useful for disabling the automatic final heap dump (which also
515           disables leak reporting, if enabled). The default prefix is jeprof.
516
517       "opt.lg_prof_bt_max" (size_t) r- [--enable-prof]
518           Maximum backtrace depth (log base 2) when profiling memory
519           allocation activity. The default is 128 (2^7).
520
521       "opt.prof_active" (bool) r- [--enable-prof]
522           Profiling activated/deactivated. This is a secondary control
523           mechanism that makes it possible to start the application with
524           profiling enabled (see the "opt.prof" option) but inactive, then
525           toggle profiling at any time during program execution with the
526           "prof.active" mallctl. This option is enabled by default.
527
528       "opt.lg_prof_sample" (ssize_t) r- [--enable-prof]
529           Average interval (log base 2) between allocation samples, as
530           measured in bytes of allocation activity. Increasing the sampling
531           interval decreases profile fidelity, but also decreases the
532           computational overhead. The default sample interval is 1 (2^0)
533           (i.e. all allocations are sampled).
534
535       "opt.prof_accum" (bool) r- [--enable-prof]
536           Reporting of cumulative object/byte counts in profile dumps
537           enabled/disabled. If this option is enabled, every unique backtrace
538           must be stored for the duration of execution. Depending on the
539           application, this can impose a large memory overhead, and the
540           cumulative counts are not always of interest. See the
541           "opt.lg_prof_tcmax" option for control of per thread backtrace
542           caching, which has important interactions. This option is enabled
543           by default.
544
545       "opt.lg_prof_tcmax" (ssize_t) r- [--enable-prof]
546           Maximum per thread backtrace cache (log base 2) used for heap
547           profiling. A backtrace can only be discarded if the
548           "opt.prof_accum" option is disabled, and no thread caches currently
549           refer to the backtrace. Therefore, a backtrace cache limit should
550           be imposed if the intention is to limit how much memory is used by
551           backtraces. By default, no limit is imposed (encoded as -1).
552
553       "opt.lg_prof_interval" (ssize_t) r- [--enable-prof]
554           Average interval (log base 2) between memory profile dumps, as
555           measured in bytes of allocation activity. The actual interval
556           between dumps may be sporadic because decentralized allocation
557           counters are used to avoid synchronization bottlenecks. Profiles
558           are dumped to files named according to the pattern
559           <prefix>.<pid>.<seq>.i<iseq>.heap, where <prefix> is controlled by
560           the "opt.prof_prefix" option. By default, interval-triggered
561           profile dumping is disabled (encoded as -1).
562
563       "opt.prof_gdump" (bool) r- [--enable-prof]
564           Trigger a memory profile dump every time the total virtual memory
565           exceeds the previous maximum. Profiles are dumped to files named
566           according to the pattern <prefix>.<pid>.<seq>.u<useq>.heap, where
567           <prefix> is controlled by the "opt.prof_prefix" option. This option
568           is disabled by default.
569
570       "opt.prof_leak" (bool) r- [--enable-prof]
571           Leak reporting enabled/disabled. If enabled, use an atexit(3)
572           function to report memory leaks detected by allocation sampling.
573           See the "opt.lg_prof_bt_max" option for backtrace depth control.
574           See the "opt.prof" option for information on analyzing heap profile
575           output. This option is disabled by default.
576
577       "opt.overcommit" (bool) r- [--enable-swap]
578           Over-commit enabled/disabled. If enabled, over-commit memory as a
579           side effect of using anonymous mmap(2) or sbrk(2) for virtual
580           memory allocation. In order for overcommit to be disabled, the
581           "swap.fds" mallctl must have been successfully written to. This
582           option is enabled by default.
583
584       "tcache.flush" (void) -- [--enable-tcache]
585           Flush calling thread's tcache. This interface releases all cached
586           objects and internal data structures associated with the calling
587           thread's thread-specific cache. Ordinarily, this interface need not
588           be called, since automatic periodic incremental garbage collection
589           occurs, and the thread cache is automatically discarded when a
590           thread exits. However, garbage collection is triggered by
591           allocation activity, so it is possible for a thread that stops
592           allocating/deallocating to retain its cache indefinitely, in which
593           case the developer may find manual flushing useful.
594
595       "thread.arena" (unsigned) rw
596           Get or set the arena associated with the calling thread. The arena
597           index must be less than the maximum number of arenas (see the
598           "arenas.narenas" mallctl). If the specified arena was not
599           initialized beforehand (see the "arenas.initialized" mallctl), it
600           will be automatically initialized as a side effect of calling this
601           interface.
602
603       "thread.allocated" (uint64_t) r- [--enable-stats]
604           Get the total number of bytes ever allocated by the calling thread.
605           This counter has the potential to wrap around; it is up to the
606           application to appropriately interpret the counter in such cases.
607
608       "thread.allocatedp" (uint64_t *) r- [--enable-stats]
609           Get a pointer to the the value that is returned by the
610           "thread.allocated" mallctl. This is useful for avoiding the
611           overhead of repeated mallctl* calls.
612
613       "thread.deallocated" (uint64_t) r- [--enable-stats]
614           Get the total number of bytes ever deallocated by the calling
615           thread. This counter has the potential to wrap around; it is up to
616           the application to appropriately interpret the counter in such
617           cases.
618
619       "thread.deallocatedp" (uint64_t *) r- [--enable-stats]
620           Get a pointer to the the value that is returned by the
621           "thread.deallocated" mallctl. This is useful for avoiding the
622           overhead of repeated mallctl* calls.
623
624       "arenas.narenas" (unsigned) r-
625           Maximum number of arenas.
626
627       "arenas.initialized" (bool *) r-
628           An array of "arenas.narenas" booleans. Each boolean indicates
629           whether the corresponding arena is initialized.
630
631       "arenas.quantum" (size_t) r-
632           Quantum size.
633
634       "arenas.cacheline" (size_t) r-
635           Assumed cacheline size.
636
637       "arenas.subpage" (size_t) r-
638           Subpage size class interval.
639
640       "arenas.pagesize" (size_t) r-
641           Page size.
642
643       "arenas.chunksize" (size_t) r-
644           Chunk size.
645
646       "arenas.tspace_min" (size_t) r-
647           Minimum tiny size class. Tiny size classes are powers of two.
648
649       "arenas.tspace_max" (size_t) r-
650           Maximum tiny size class. Tiny size classes are powers of two.
651
652       "arenas.qspace_min" (size_t) r-
653           Minimum quantum-spaced size class.
654
655       "arenas.qspace_max" (size_t) r-
656           Maximum quantum-spaced size class.
657
658       "arenas.cspace_min" (size_t) r-
659           Minimum cacheline-spaced size class.
660
661       "arenas.cspace_max" (size_t) r-
662           Maximum cacheline-spaced size class.
663
664       "arenas.sspace_min" (size_t) r-
665           Minimum subpage-spaced size class.
666
667       "arenas.sspace_max" (size_t) r-
668           Maximum subpage-spaced size class.
669
670       "arenas.tcache_max" (size_t) r- [--enable-tcache]
671           Maximum thread-cached size class.
672
673       "arenas.ntbins" (unsigned) r-
674           Number of tiny bin size classes.
675
676       "arenas.nqbins" (unsigned) r-
677           Number of quantum-spaced bin size classes.
678
679       "arenas.ncbins" (unsigned) r-
680           Number of cacheline-spaced bin size classes.
681
682       "arenas.nsbins" (unsigned) r-
683           Number of subpage-spaced bin size classes.
684
685       "arenas.nbins" (unsigned) r-
686           Total number of bin size classes.
687
688       "arenas.nhbins" (unsigned) r- [--enable-tcache]
689           Total number of thread cache bin size classes.
690
691       "arenas.bin.<i>.size" (size_t) r-
692           Maximum size supported by size class.
693
694       "arenas.bin.<i>.nregs" (uint32_t) r-
695           Number of regions per page run.
696
697       "arenas.bin.<i>.run_size" (size_t) r-
698           Number of bytes per page run.
699
700       "arenas.nlruns" (size_t) r-
701           Total number of large size classes.
702
703       "arenas.lrun.<i>.size" (size_t) r-
704           Maximum size supported by this large size class.
705
706       "arenas.purge" (unsigned) -w
707           Purge unused dirty pages for the specified arena, or for all arenas
708           if none is specified.
709
710       "prof.active" (bool) rw [--enable-prof]
711           Control whether sampling is currently active. See the
712           "opt.prof_active" option for additional information.
713
714       "prof.dump" (const char *) -w [--enable-prof]
715           Dump a memory profile to the specified file, or if NULL is
716           specified, to a file according to the pattern
717           <prefix>.<pid>.<seq>.m<mseq>.heap, where <prefix> is controlled by
718           the "opt.prof_prefix" option.
719
720       "prof.interval" (uint64_t) r- [--enable-prof]
721           Average number of bytes allocated between inverval-based profile
722           dumps. See the "opt.lg_prof_interval" option for additional
723           information.
724
725       "stats.cactive" (size_t *) r- [--enable-stats]
726           Pointer to a counter that contains an approximate count of the
727           current number of bytes in active pages. The estimate may be high,
728           but never low, because each arena rounds up to the nearest multiple
729           of the chunk size when computing its contribution to the counter.
730           Note that the "epoch" mallctl has no bearing on this counter.
731           Furthermore, counter consistency is maintained via atomic
732           operations, so it is necessary to use an atomic operation in order
733           to guarantee a consistent read when dereferencing the pointer.
734
735       "stats.allocated" (size_t) r- [--enable-stats]
736           Total number of bytes allocated by the application.
737
738       "stats.active" (size_t) r- [--enable-stats]
739           Total number of bytes in active pages allocated by the application.
740           This is a multiple of the page size, and greater than or equal to
741           "stats.allocated".
742
743       "stats.mapped" (size_t) r- [--enable-stats]
744           Total number of bytes in chunks mapped on behalf of the
745           application. This is a multiple of the chunk size, and is at least
746           as large as "stats.active". This does not include inactive chunks
747           backed by swap files. his does not include inactive chunks embedded
748           in the DSS.
749
750       "stats.chunks.current" (size_t) r- [--enable-stats]
751           Total number of chunks actively mapped on behalf of the
752           application. This does not include inactive chunks backed by swap
753           files. This does not include inactive chunks embedded in the DSS.
754
755       "stats.chunks.total" (uint64_t) r- [--enable-stats]
756           Cumulative number of chunks allocated.
757
758       "stats.chunks.high" (size_t) r- [--enable-stats]
759           Maximum number of active chunks at any time thus far.
760
761       "stats.huge.allocated" (size_t) r- [--enable-stats]
762           Number of bytes currently allocated by huge objects.
763
764       "stats.huge.nmalloc" (uint64_t) r- [--enable-stats]
765           Cumulative number of huge allocation requests.
766
767       "stats.huge.ndalloc" (uint64_t) r- [--enable-stats]
768           Cumulative number of huge deallocation requests.
769
770       "stats.arenas.<i>.nthreads" (unsigned) r-
771           Number of threads currently assigned to arena.
772
773       "stats.arenas.<i>.pactive" (size_t) r-
774           Number of pages in active runs.
775
776       "stats.arenas.<i>.pdirty" (size_t) r-
777           Number of pages within unused runs that are potentially dirty, and
778           for which madvise... MADV_DONTNEED or similar has not been called.
779
780       "stats.arenas.<i>.mapped" (size_t) r- [--enable-stats]
781           Number of mapped bytes.
782
783       "stats.arenas.<i>.npurge" (uint64_t) r- [--enable-stats]
784           Number of dirty page purge sweeps performed.
785
786       "stats.arenas.<i>.nmadvise" (uint64_t) r- [--enable-stats]
787           Number of madvise... MADV_DONTNEED or similar calls made to purge
788           dirty pages.
789
790       "stats.arenas.<i>.npurged" (uint64_t) r- [--enable-stats]
791           Number of pages purged.
792
793       "stats.arenas.<i>.small.allocated" (size_t) r- [--enable-stats]
794           Number of bytes currently allocated by small objects.
795
796       "stats.arenas.<i>.small.nmalloc" (uint64_t) r- [--enable-stats]
797           Cumulative number of allocation requests served by small bins.
798
799       "stats.arenas.<i>.small.ndalloc" (uint64_t) r- [--enable-stats]
800           Cumulative number of small objects returned to bins.
801
802       "stats.arenas.<i>.small.nrequests" (uint64_t) r- [--enable-stats]
803           Cumulative number of small allocation requests.
804
805       "stats.arenas.<i>.large.allocated" (size_t) r- [--enable-stats]
806           Number of bytes currently allocated by large objects.
807
808       "stats.arenas.<i>.large.nmalloc" (uint64_t) r- [--enable-stats]
809           Cumulative number of large allocation requests served directly by
810           the arena.
811
812       "stats.arenas.<i>.large.ndalloc" (uint64_t) r- [--enable-stats]
813           Cumulative number of large deallocation requests served directly by
814           the arena.
815
816       "stats.arenas.<i>.large.nrequests" (uint64_t) r- [--enable-stats]
817           Cumulative number of large allocation requests.
818
819       "stats.arenas.<i>.bins.<j>.allocated" (size_t) r- [--enable-stats]
820           Current number of bytes allocated by bin.
821
822       "stats.arenas.<i>.bins.<j>.nmalloc" (uint64_t) r- [--enable-stats]
823           Cumulative number of allocations served by bin.
824
825       "stats.arenas.<i>.bins.<j>.ndalloc" (uint64_t) r- [--enable-stats]
826           Cumulative number of allocations returned to bin.
827
828       "stats.arenas.<i>.bins.<j>.nrequests" (uint64_t) r- [--enable-stats]
829           Cumulative number of allocation requests.
830
831       "stats.arenas.<i>.bins.<j>.nfills" (uint64_t) r- [--enable-stats
832       --enable-tcache]
833           Cumulative number of tcache fills.
834
835       "stats.arenas.<i>.bins.<j>.nflushes" (uint64_t) r- [--enable-stats
836       --enable-tcache]
837           Cumulative number of tcache flushes.
838
839       "stats.arenas.<i>.bins.<j>.nruns" (uint64_t) r- [--enable-stats]
840           Cumulative number of runs created.
841
842       "stats.arenas.<i>.bins.<j>.nreruns" (uint64_t) r- [--enable-stats]
843           Cumulative number of times the current run from which to allocate
844           changed.
845
846       "stats.arenas.<i>.bins.<j>.highruns" (size_t) r- [--enable-stats]
847           Maximum number of runs at any time thus far.
848
849       "stats.arenas.<i>.bins.<j>.curruns" (size_t) r- [--enable-stats]
850           Current number of runs.
851
852       "stats.arenas.<i>.lruns.<j>.nmalloc" (uint64_t) r- [--enable-stats]
853           Cumulative number of allocation requests for this size class served
854           directly by the arena.
855
856       "stats.arenas.<i>.lruns.<j>.ndalloc" (uint64_t) r- [--enable-stats]
857           Cumulative number of deallocation requests for this size class
858           served directly by the arena.
859
860       "stats.arenas.<i>.lruns.<j>.nrequests" (uint64_t) r- [--enable-stats]
861           Cumulative number of allocation requests for this size class.
862
863       "stats.arenas.<i>.lruns.<j>.highruns" (size_t) r- [--enable-stats]
864           Maximum number of runs at any time thus far for this size class.
865
866       "stats.arenas.<i>.lruns.<j>.curruns" (size_t) r- [--enable-stats]
867           Current number of runs for this size class.
868
869       "swap.avail" (size_t) r- [--enable-stats --enable-swap]
870           Number of swap file bytes that are currently not associated with
871           any chunk (i.e. mapped, but otherwise completely unmanaged).
872
873       "swap.prezeroed" (bool) rw [--enable-swap]
874           If true, the allocator assumes that the swap file(s) contain
875           nothing but nil bytes. If this assumption is violated, allocator
876           behavior is undefined. This value becomes read-only after
877           "swap.fds" is successfully written to.
878
879       "swap.nfds" (size_t) r- [--enable-swap]
880           Number of file descriptors in use for swap.
881
882       "swap.fds" (int *) rw [--enable-swap]
883           When written to, the files associated with the specified file
884           descriptors are contiguously mapped via mmap(2). The resulting
885           virtual memory region is preferred over anonymous mmap(2) and
886           sbrk(2) memory. Note that if a file's size is not a multiple of the
887           page size, it is automatically truncated to the nearest page size
888           multiple. See the "swap.prezeroed" mallctl for specifying that the
889           files are pre-zeroed.
890

DEBUGGING MALLOC PROBLEMS

892       When debugging, it is a good idea to configure/build jemalloc with the
893       --enable-debug and --enable-fill options, and recompile the program
894       with suitable options and symbols for debugger support. When so
895       configured, jemalloc incorporates a wide variety of run-time assertions
896       that catch application errors such as double-free, write-after-free,
897       etc.
898
899       Programs often accidentally depend on “uninitialized” memory actually
900       being filled with zero bytes. Junk filling (see the "opt.junk" option)
901       tends to expose such bugs in the form of obviously incorrect results
902       and/or coredumps. Conversely, zero filling (see the "opt.zero" option)
903       eliminates the symptoms of such bugs. Between these two options, it is
904       usually possible to quickly detect, diagnose, and eliminate such bugs.
905
906       This implementation does not provide much detail about the problems it
907       detects, because the performance impact for storing such information
908       would be prohibitive. There are a number of allocator implementations
909       available on the Internet which focus on detecting and pinpointing
910       problems by trading performance for extra sanity checks and detailed
911       diagnostics.
912

DIAGNOSTIC MESSAGES

914       If any of the memory allocation/deallocation functions detect an error
915       or warning condition, a message will be printed to file descriptor
916       STDERR_FILENO. Errors will result in the process dumping core. If the
917       "opt.abort" option is set, most warnings are treated as errors.
918
919       The malloc_message variable allows the programmer to override the
920       function which emits the text strings forming the errors and warnings
921       if for some reason the STDERR_FILENO file descriptor is not suitable
922       for this.  malloc_message takes the cbopaque pointer argument that is
923       NULL unless overridden by the arguments in a call to
924       malloc_stats_print, followed by a string pointer. Please note that
925       doing anything which tries to allocate memory in this function is
926       likely to result in a crash or deadlock.
927
928       All messages are prefixed by “<jemalloc>:”.
929

RETURN VALUES

931   Standard API
932       The malloc and calloc functions return a pointer to the allocated
933       memory if successful; otherwise a NULL pointer is returned and errno is
934       set to ENOMEM.
935
936       The posix_memalign function returns the value 0 if successful;
937       otherwise it returns an error value. The posix_memalign function will
938       fail if:
939
940       EINVAL
941           The alignment parameter is not a power of 2 at least as large as
942           sizeof(void *).
943
944       ENOMEM
945           Memory allocation error.
946
947       The realloc function returns a pointer, possibly identical to ptr, to
948       the allocated memory if successful; otherwise a NULL pointer is
949       returned, and errno is set to ENOMEM if the error was the result of an
950       allocation failure. The realloc function always leaves the original
951       buffer intact when an error occurs.
952
953       The free function returns no value.
954
955   Non-standard API
956       The malloc_usable_size function returns the usable size of the
957       allocation pointed to by ptr.
958
959       The mallctl, mallctlnametomib, and mallctlbymib functions return 0 on
960       success; otherwise they return an error value. The functions will fail
961       if:
962
963       EINVAL
964           newp is not NULL, and newlen is too large or too small.
965           Alternatively, *oldlenp is too large or too small; in this case as
966           much data as possible are read despite the error.
967
968       ENOMEM
969           *oldlenp is too short to hold the requested value.
970
971       ENOENT
972           name or mib specifies an unknown/invalid value.
973
974       EPERM
975           Attempt to read or write void value, or attempt to write read-only
976           value.
977
978       EAGAIN
979           A memory allocation failure occurred.
980
981       EFAULT
982           An interface with side effects failed in some way not directly
983           related to mallctl* read/write processing.
984
985   Experimental API
986       The allocm, rallocm, sallocm, and dallocm functions return
987       ALLOCM_SUCCESS on success; otherwise they return an error value. The
988       allocm and rallocm functions will fail if:
989
990       ALLOCM_ERR_OOM
991           Out of memory. Insufficient contiguous memory was available to
992           service the allocation request. The allocm function additionally
993           sets *ptr to NULL, whereas the rallocm function leaves *ptr
994           unmodified.
995       The rallocm function will also fail if:
996
997       ALLOCM_ERR_NOT_MOVED
998           ALLOCM_NO_MOVE was specified, but the reallocation request could
999           not be serviced without moving the object.
1000

ENVIRONMENT

1002       The following environment variable affects the execution of the
1003       allocation functions:
1004
1005       MALLOC_CONF
1006           If the environment variable MALLOC_CONF is set, the characters it
1007           contains will be interpreted as options.
1008

EXAMPLES

1010       To dump core whenever a problem occurs:
1011
1012           ln -s 'abort:true' /etc/malloc.conf
1013
1014       To specify in the source a chunk size that is 16 MiB:
1015
1016           malloc_conf = "lg_chunk:24";
1017

SEE ALSO

1019       madvise(2), mmap(2), sbrk(2), alloca(3), atexit(3), getpagesize(3)
1020

STANDARDS

1022       The malloc, calloc, realloc, and free functions conform to ISO/IEC
1023       9899:1990 (“ISO C90”).
1024
1025       The posix_memalign function conforms to IEEE Std 1003.1-2001
1026       (“POSIX.1”).
1027

AUTHOR

1029       Jason Evans
1030

NOTES

1032        1. jemalloc website
1033           http://www.canonware.com/jemalloc/
1034
1035        2. google-perftools package
1036           http://code.google.com/p/google-perftools/
1037
1038
1039
1040jemalloc 2.2.5-0-gfc1bb70e5f0d    11/14/2011                       JEMALLOC(3)
Impressum