1Name: dlmalloc 2Description: Doug Lea's Memory Allocator 3URL: http://g.oswego.edu/dl/html/malloc.html 4License: Public Domain 5Version: 2.8.6 (29 Aug 2012) 6 7Usage: add this to your program and link against libdmalloc. 8 9 #include <dmalloc/dmalloc.h> 10 11 typedef void *(*alt_malloc_t)(size_t bytes); 12 extern alt_malloc_t alt_malloc; 13 14 typedef void (*alt_free_t)(void *p); 15 extern alt_free_t alt_free; 16 17 typedef void *(*alt_realloc_t)(void *p, size_t bytes); 18 extern alt_realloc_t alt_realloc; 19 20 __attribute__((constructor)) static void init_dmalloc(void) { 21 alt_malloc = &dlmalloc; 22 alt_free = &dlfree; 23 alt_realloc = &dlrealloc; 24 } 25 26This vastly outperforms the default allocator in oldc and it is not unusual to 27see substantial performance improvements in large applications (e.g. SharedDB). 28 29The header file <dmalloc/dmalloc.h> exports the standard allocation routines 30(dlmalloc, dlfree, dlcalloc, dlrealloc) along with aligned/chunked variants and 31functions to retrieve statistics. 32 33Keep in mind there also may be some incompatibilities: 34* The switch to dlmalloc only happens once constructors functions run. Ideally 35 this happen before any C++ ctors as they may allocate memory. In addition, 36 there is a small window between `barrelfish_init_onthread` and `crtbegin` 37 where memory may be allocated via oldc. 38* Unresolved issue with domain spanning: 39 https://lists.inf.ethz.ch/pipermail/barrelfish-users/2013-February/000912.html 40 41Changes: 42* The header doesn't declare `dlmallinfo` or `struct mallinfo` because the 43 field types don't match with Newlib's <malloc.h> (size_t vs. int). These are 44 still enabled in the implementation if you want to try though. 45* Similarly, support for independent allocation spaces (MSPACES=0) is not 46 exposed for now. 47* Allocates backing memory with morecore instead of mmap. Does not currently 48 release memory back to the system. 49* Uses Barrelfish mutex instead of its own custom spin lock variant. 50