|
@@ -22,48 +22,69 @@
|
|
|
* @brief System allocator's global object initializer.
|
|
|
*/
|
|
|
|
|
|
+#include <fcntl.h> /* for open() */
|
|
|
+#include <sys/mman.h> /* for mmap() */
|
|
|
+
|
|
|
#include <dmmlib/config.h>
|
|
|
#include "dmmlib/dmmlib.h"
|
|
|
+#include "parse_env.h"
|
|
|
+
|
|
|
+__attribute__((constructor)) int initialize_allocator(void);
|
|
|
+
|
|
|
+/** Initializes space to store the allocator state in heap. */
|
|
|
+int initialize_allocator(void) {
|
|
|
|
|
|
-/** Global variable storing allocator's settings */
|
|
|
-allocator_t systemallocator =
|
|
|
- { .rb_head = {NULL}
|
|
|
+ int fd = open("/dev/zero", O_RDWR);
|
|
|
+ allocator_t *allocator = mmap(NULL, SYS_PAGESIZE,
|
|
|
+ PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
|
|
|
+
|
|
|
+ if(__builtin_expect(!!(allocator == MAP_FAILED), 0)) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ SLIST_INIT(&allocator->rb_head);
|
|
|
#ifdef HAVE_LOCKS
|
|
|
- , .creation_mutex = PTHREAD_MUTEX_INITIALIZER
|
|
|
+ pthread_mutex_init(&allocator->creation_mutex, NULL);
|
|
|
#endif /* HAVE_LOCKS */
|
|
|
#ifdef WITH_KNOBS
|
|
|
- , .dmm_knobs =
|
|
|
- { .sys_alloc_size = SYS_ALLOC_SIZE
|
|
|
+ allocator->dmm_knobs.sys_alloc_size = SYS_ALLOC_SIZE;
|
|
|
#ifdef GOOD_FIT
|
|
|
- , .fit_percentage = GOOD_FIT_PERCENTAGE
|
|
|
+ allocator->dmm_knobs.fit_percentage = GOOD_FIT_PERCENTAGE;
|
|
|
#endif /* GOOD_FIT */
|
|
|
#ifdef COALESCING_VARIABLE
|
|
|
- , .max_coal_size = MAX_COAL_SIZE
|
|
|
+ allocator->dmm_knobs.max_coal_size = MAX_COAL_SIZE;
|
|
|
#endif /* COALESCING_VARIABLE */
|
|
|
#ifdef SPLITTING_VARIABLE
|
|
|
- , .min_split_size = MIN_SPLIT_SIZE
|
|
|
+ allocator->dmm_knobs.min_split_size = MIN_SPLIT_SIZE;
|
|
|
#endif /* SPLITTING_VARIABLE */
|
|
|
- }
|
|
|
#endif /* WITH_KNOBS */
|
|
|
#ifdef WITH_ALLOCATOR_STATS
|
|
|
- , {
|
|
|
#ifdef REQUEST_SIZE_INFO
|
|
|
- 0,
|
|
|
+ allocator->dmm_stats.total_mem_requested = 0;
|
|
|
#endif /* REQUEST_SIZE_INFO */
|
|
|
- 0
|
|
|
- , 0
|
|
|
- , 0
|
|
|
- , 0
|
|
|
- , 0
|
|
|
+ allocator->dmm_stats.total_mem_allocated = 0;
|
|
|
+ allocator->dmm_stats.live_objects = 0;
|
|
|
+ allocator->dmm_stats.num_malloc = 0;
|
|
|
+ allocator->dmm_stats.num_free = 0;
|
|
|
+ allocator->dmm_stats.num_realloc= 0;
|
|
|
#ifdef WITH_MEMALIGN
|
|
|
- , 0
|
|
|
+ allocator->dmm_stats.num_memalign = 0;
|
|
|
#endif /* WITH_MEMALIGN */
|
|
|
- }
|
|
|
#endif /* WITH_ALLOCATOR_STATS */
|
|
|
#ifdef PARSE_ENV
|
|
|
#if defined WITH_MEM_TRACE || defined WITH_STATS_TRACE || defined WITH_DEBUG
|
|
|
- , .initialized = false
|
|
|
+ allocator->initialized = false;
|
|
|
+#endif /* WITH_MEM_TRACE || WITH_STATS_TRACE || WITH_DEBUG */
|
|
|
+#endif /* PARSE_ENV */
|
|
|
+
|
|
|
+ systemallocator = allocator;
|
|
|
+
|
|
|
+#ifdef PARSE_ENV
|
|
|
+ parse_env();
|
|
|
+#if defined WITH_MEM_TRACE || defined WITH_STATS_TRACE || defined WITH_DEBUG
|
|
|
+ allocator->initialized = true;
|
|
|
#endif /* WITH_MEM_TRACE || WITH_STATS_TRACE || WITH_DEBUG */
|
|
|
#endif /* PARSE_ENV */
|
|
|
-};
|
|
|
|
|
|
+ return 0;
|
|
|
+}
|