dmm_init.c 3.3 KB

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