|
@@ -4,36 +4,32 @@
|
|
|
#endif /* HAVE_LOCKS */
|
|
|
#include "dmm_init.h"
|
|
|
|
|
|
-allocator_t * dmm_init(void) {
|
|
|
+void dmm_init(allocator_t *allocator) {
|
|
|
int i;
|
|
|
- allocator_t *main_allocator;
|
|
|
heap_t *current_heap;
|
|
|
maptable_node_t *maptablenode;
|
|
|
|
|
|
- /* FIXME Replace sbrk with a library call */
|
|
|
- main_allocator = (allocator_t *) sbrk((int) sizeof(allocator_t));
|
|
|
-
|
|
|
for(i = 0; i < NUM_HEAPS; i++) {
|
|
|
- main_allocator->heaps[i].maptable_head = NULL;
|
|
|
- main_allocator->heaps[i].free_list_head = NULL;
|
|
|
- main_allocator->heaps[i].used_blocks_head = NULL;
|
|
|
- main_allocator->heaps[i].rov_ptr = NULL;
|
|
|
- main_allocator->heaps[i].num_objects = 0;
|
|
|
- main_allocator->heaps[i].dmm_stats.mem_allocated = 0;
|
|
|
- main_allocator->heaps[i].dmm_stats.mem_requested = 0;
|
|
|
- main_allocator->heaps[i].dmm_stats.live_objects = 0;
|
|
|
- main_allocator->heaps[i].dmm_stats.num_malloc = 0;
|
|
|
- main_allocator->heaps[i].dmm_stats.num_free = 0;
|
|
|
+ allocator->heaps[i].maptable_head = NULL;
|
|
|
+ allocator->heaps[i].free_list_head = NULL;
|
|
|
+ allocator->heaps[i].used_blocks_head = NULL;
|
|
|
+ allocator->heaps[i].rov_ptr = NULL;
|
|
|
+ allocator->heaps[i].num_objects = 0;
|
|
|
+ allocator->heaps[i].dmm_stats.mem_allocated = 0;
|
|
|
+ allocator->heaps[i].dmm_stats.mem_requested = 0;
|
|
|
+ allocator->heaps[i].dmm_stats.live_objects = 0;
|
|
|
+ allocator->heaps[i].dmm_stats.num_malloc = 0;
|
|
|
+ allocator->heaps[i].dmm_stats.num_free = 0;
|
|
|
|
|
|
// Knobs initialization
|
|
|
- main_allocator->heaps[i].dmm_knobs.max_coalesce_size = -1;
|
|
|
+ allocator->heaps[i].dmm_knobs.max_coalesce_size = -1;
|
|
|
// FIXME Create a constant for the initial value of the next
|
|
|
// variables
|
|
|
- main_allocator->heaps[i].dmm_knobs.frag_threshold = 1.0;
|
|
|
- main_allocator->heaps[i].dmm_knobs.mem_threshold = 17000;
|
|
|
+ allocator->heaps[i].dmm_knobs.frag_threshold = 1.0;
|
|
|
+ allocator->heaps[i].dmm_knobs.mem_threshold = 17000;
|
|
|
|
|
|
#ifdef HAVE_LOCKS
|
|
|
- pthread_mutex_init(&main_allocator->heaps[i].mutex, NULL);
|
|
|
+ pthread_mutex_init(&allocator->heaps[i].mutex, NULL);
|
|
|
#endif /* HAVE_LOCKS */
|
|
|
}
|
|
|
|
|
@@ -41,7 +37,7 @@ allocator_t * dmm_init(void) {
|
|
|
// 2 first ones with 32, 64, 128 and 256 (4 fixed lists per heap)
|
|
|
// 2 last ones with 64 and 256 (2 fixed lists per heap)
|
|
|
// 2 * 4 + 2 * 2 = 12 maptable nodes
|
|
|
- current_heap = &main_allocator->heaps[0];
|
|
|
+ current_heap = &allocator->heaps[0];
|
|
|
maptablenode = (maptable_node_t *) sbrk((int)(12*(sizeof(maptable_node_t))));
|
|
|
|
|
|
maptablenode->size = 32;
|
|
@@ -57,7 +53,7 @@ allocator_t * dmm_init(void) {
|
|
|
(maptablenode+3)->size = 256;
|
|
|
(maptablenode+3)->fixed_list_head = NULL;
|
|
|
(maptablenode+3)->next = NULL;
|
|
|
- current_heap = &main_allocator->heaps[1];
|
|
|
+ current_heap = &allocator->heaps[1];
|
|
|
maptablenode += 4;
|
|
|
maptablenode->size = 32;
|
|
|
maptablenode->fixed_list_head = NULL;
|
|
@@ -72,7 +68,7 @@ allocator_t * dmm_init(void) {
|
|
|
(maptablenode+3)->size = 256;
|
|
|
(maptablenode+3)->fixed_list_head = NULL;
|
|
|
(maptablenode+3)->next = NULL;
|
|
|
- current_heap = &main_allocator->heaps[2];
|
|
|
+ current_heap = &allocator->heaps[2];
|
|
|
maptablenode += 4;
|
|
|
maptablenode->size = 64;
|
|
|
maptablenode->fixed_list_head = NULL;
|
|
@@ -81,7 +77,7 @@ allocator_t * dmm_init(void) {
|
|
|
(maptablenode+1)->size = 256;
|
|
|
(maptablenode+1)->fixed_list_head = NULL;
|
|
|
(maptablenode+1)->next = NULL;
|
|
|
- current_heap = &main_allocator->heaps[3];
|
|
|
+ current_heap = &allocator->heaps[3];
|
|
|
maptablenode += 2;
|
|
|
maptablenode->size = 64;
|
|
|
maptablenode->fixed_list_head = NULL;
|
|
@@ -90,7 +86,5 @@ allocator_t * dmm_init(void) {
|
|
|
(maptablenode+1)->size = 256;
|
|
|
(maptablenode+1)->fixed_list_head = NULL;
|
|
|
(maptablenode+1)->next = NULL;
|
|
|
-
|
|
|
- return main_allocator;
|
|
|
}
|
|
|
|