dmm_init.c 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #include <unistd.h>
  2. #include "dmm_config.h"
  3. #ifdef HAVE_LOCKS
  4. #include <pthread.h>
  5. #endif /* HAVE_LOCKS */
  6. #include "dmm_init.h"
  7. allocator_t * dmm_init(void) {
  8. int i;
  9. allocator_t *main_allocator;
  10. heap_t *current_heap;
  11. maptable_node_t *maptablenode;
  12. /* FIXME Replace sbrk with a library call */
  13. main_allocator = (allocator_t *) sbrk((int) sizeof(allocator_t));
  14. for(i = 0; i < NUM_HEAPS; i++) {
  15. main_allocator->heaps[i].maptable_head = NULL;
  16. main_allocator->heaps[i].free_list_head = NULL;
  17. main_allocator->heaps[i].used_blocks_head = NULL;
  18. main_allocator->heaps[i].rov_ptr = NULL;
  19. main_allocator->heaps[i].num_objects = 0;
  20. main_allocator->heaps[i].dmm_stats.mem_allocated = 0;
  21. main_allocator->heaps[i].dmm_stats.mem_requested = 0;
  22. main_allocator->heaps[i].dmm_stats.live_objects = 0;
  23. main_allocator->heaps[i].dmm_stats.num_malloc = 0;
  24. main_allocator->heaps[i].dmm_stats.num_free = 0;
  25. // Knobs initialization
  26. main_allocator->heaps[i].dmm_knobs.max_coalesce_size = -1;
  27. // FIXME Create a constant for the initial value of the next
  28. // variables
  29. main_allocator->heaps[i].dmm_knobs.frag_threshold = 1.0;
  30. main_allocator->heaps[i].dmm_knobs.mem_threshold = 17000;
  31. #ifdef HAVE_LOCKS
  32. pthread_mutex_init(&main_allocator->heaps[i].mutex, NULL);
  33. #endif /* HAVE_LOCKS */
  34. }
  35. // Custom number of fixed lists and their initialization
  36. // 2 first ones with 32, 64, 128 and 256 (4 fixed lists per heap)
  37. // 2 last ones with 64 and 256 (2 fixed lists per heap)
  38. // 2 * 4 + 2 * 2 = 12 maptable nodes
  39. current_heap = &main_allocator->heaps[0];
  40. maptablenode = (maptable_node_t *) sbrk((int)(12*(sizeof(maptable_node_t))));
  41. maptablenode->size = 32;
  42. maptablenode->fixed_list_head = NULL;
  43. maptablenode->next = maptablenode+1;
  44. current_heap->maptable_head = maptablenode;
  45. (maptablenode+1)->size = 64;
  46. (maptablenode+1)->fixed_list_head = NULL;
  47. (maptablenode+1)->next = maptablenode+2;
  48. (maptablenode+2)->size = 128;
  49. (maptablenode+2)->fixed_list_head = NULL;
  50. (maptablenode+2)->next = maptablenode+3;
  51. (maptablenode+3)->size = 256;
  52. (maptablenode+3)->fixed_list_head = NULL;
  53. (maptablenode+3)->next = NULL;
  54. current_heap = &main_allocator->heaps[1];
  55. maptablenode += 4;
  56. maptablenode->size = 32;
  57. maptablenode->fixed_list_head = NULL;
  58. maptablenode->next = maptablenode+1;
  59. current_heap->maptable_head = maptablenode;
  60. (maptablenode+1)->size = 64;
  61. (maptablenode+1)->fixed_list_head = NULL;
  62. (maptablenode+1)->next = maptablenode+2;
  63. (maptablenode+2)->size = 128;
  64. (maptablenode+2)->fixed_list_head = NULL;
  65. (maptablenode+2)->next = maptablenode+3;
  66. (maptablenode+3)->size = 256;
  67. (maptablenode+3)->fixed_list_head = NULL;
  68. (maptablenode+3)->next = NULL;
  69. current_heap = &main_allocator->heaps[2];
  70. maptablenode += 4;
  71. maptablenode->size = 64;
  72. maptablenode->fixed_list_head = NULL;
  73. maptablenode->next = maptablenode+1;
  74. current_heap->maptable_head = maptablenode;
  75. (maptablenode+1)->size = 256;
  76. (maptablenode+1)->fixed_list_head = NULL;
  77. (maptablenode+1)->next = NULL;
  78. current_heap = &main_allocator->heaps[3];
  79. maptablenode += 2;
  80. maptablenode->size = 64;
  81. maptablenode->fixed_list_head = NULL;
  82. maptablenode->next = maptablenode+1;
  83. current_heap->maptable_head = maptablenode;
  84. (maptablenode+1)->size = 256;
  85. (maptablenode+1)->fixed_list_head = NULL;
  86. (maptablenode+1)->next = NULL;
  87. return main_allocator;
  88. }