jemalloc.3 54 KB

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