/jemalloc-3.0.0/doc/jemalloc.3

# · Unknown · 1447 lines · 1443 code · 4 blank · 0 comment · 0 complexity · c410c8301ec1c47e8d43b7ad5e3f7838 MD5 · raw file

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