dmm_init.c 3.3 KB

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