1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- #include <unistd.h>
- #include "dmm_config.h"
- #ifdef HAVE_LOCKS
- #include <pthread.h>
- #endif /* HAVE_LOCKS */
- #include "dmm_init.h"
- allocator_t * dmm_init(void) {
- 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;
- // Knobs initialization
- main_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;
- #ifdef HAVE_LOCKS
- pthread_mutex_init(&main_allocator->heaps[i].mutex, NULL);
- #endif /* HAVE_LOCKS */
- }
- // Custom number of fixed lists and their initialization
- // 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];
- maptablenode = (maptable_node_t *) sbrk((int)(12*(sizeof(maptable_node_t))));
- maptablenode->size = 32;
- maptablenode->fixed_list_head = NULL;
- maptablenode->next = maptablenode+1;
- current_heap->maptable_head = maptablenode;
- (maptablenode+1)->size = 64;
- (maptablenode+1)->fixed_list_head = NULL;
- (maptablenode+1)->next = maptablenode+2;
- (maptablenode+2)->size = 128;
- (maptablenode+2)->fixed_list_head = NULL;
- (maptablenode+2)->next = maptablenode+3;
- (maptablenode+3)->size = 256;
- (maptablenode+3)->fixed_list_head = NULL;
- (maptablenode+3)->next = NULL;
- current_heap = &main_allocator->heaps[1];
- maptablenode += 4;
- maptablenode->size = 32;
- maptablenode->fixed_list_head = NULL;
- maptablenode->next = maptablenode+1;
- current_heap->maptable_head = maptablenode;
- (maptablenode+1)->size = 64;
- (maptablenode+1)->fixed_list_head = NULL;
- (maptablenode+1)->next = maptablenode+2;
- (maptablenode+2)->size = 128;
- (maptablenode+2)->fixed_list_head = NULL;
- (maptablenode+2)->next = maptablenode+3;
- (maptablenode+3)->size = 256;
- (maptablenode+3)->fixed_list_head = NULL;
- (maptablenode+3)->next = NULL;
- current_heap = &main_allocator->heaps[2];
- maptablenode += 4;
- maptablenode->size = 64;
- maptablenode->fixed_list_head = NULL;
- maptablenode->next = maptablenode+1;
- current_heap->maptable_head = maptablenode;
- (maptablenode+1)->size = 256;
- (maptablenode+1)->fixed_list_head = NULL;
- (maptablenode+1)->next = NULL;
- current_heap = &main_allocator->heaps[3];
- maptablenode += 2;
- maptablenode->size = 64;
- maptablenode->fixed_list_head = NULL;
- maptablenode->next = maptablenode+1;
- current_heap->maptable_head = maptablenode;
- (maptablenode+1)->size = 256;
- (maptablenode+1)->fixed_list_head = NULL;
- (maptablenode+1)->next = NULL;
- return main_allocator;
- }
|