heap.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Copyright 2011 Institute of Communication and Computer Systems (ICCS)
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. */
  17. /**
  18. * \file heap.h
  19. * \author Ioannis Koutras (joko@microlab.ntua.gr)
  20. * \date September, 2011
  21. * Basic structures needed for the dmmlib allocator.
  22. */
  23. #ifndef HEAP_H
  24. #define HEAP_H
  25. #include "dmm_config.h"
  26. #include <stdint.h>
  27. #include <stddef.h> /* For size_t support */
  28. #include <stdbool.h>
  29. #ifdef HAVE_LOCKS
  30. #include <pthread.h>
  31. #endif /* HAVE_LOCKS */
  32. /**
  33. * A structure for knobs states (currently 5)
  34. *
  35. * FIXME Have to check them
  36. *
  37. * */
  38. typedef uint8_t knob_state_t;
  39. /** A structure to represent a maptable node. */
  40. typedef struct maptable_node_s {
  41. unsigned int size; /**< The size of the blocks of the fixed list. */
  42. void *fixed_list_head; /**< Pointer to the head node of the fixed list. */
  43. struct maptable_node_s *next; /**< Pointer to the next node of the
  44. maptable. */
  45. } maptable_node_t;
  46. #ifdef WITH_STATS
  47. /** Statistics data structure. */
  48. typedef struct dmmstats_s {
  49. size_t max_mem_allocated; /**< Maximum total memory allocated. */
  50. size_t max_mem_requested; /**< Maximum total memory requested. */
  51. size_t mem_allocated; /**< Total memory currently allocated. */
  52. size_t mem_requested; /**< Total memory currently requested. */
  53. uint32_t live_objects; /**< Number of the currently used blocks. */
  54. uint32_t read_mem_accesses; /**< Number of read accesses. */
  55. uint32_t write_mem_accesses; /**< Number of write accesses. */
  56. uint32_t num_malloc; /**< Number of malloc()'s served. */
  57. uint32_t num_free; /**< Number of free()'s served. */
  58. } dmmstats_t;
  59. #endif /* WITH_STATS */
  60. #ifdef WITH_KNOBS
  61. /** A structure to represent tunable parameters of a heap */
  62. typedef struct dmmknobs_s {
  63. float frag_threshold; /**< Fragmentation threshold to enable coalescing
  64. or not. */
  65. uint32_t mem_threshold; /**< Memory size threshold. */
  66. #ifdef COALESCING_VARIABLE
  67. size_t max_coalesce_size; /**< Maximum coalesce size; -1 if coalescing
  68. is not supported */
  69. #endif /* COALESCING_VARIABLE */
  70. #ifdef SPLITTING_VARIABLE
  71. size_t min_split_size; /**< Minimum split size. */
  72. #endif /* SPLITTING_VARIABLE */
  73. /* FIXME Need to find explanation */
  74. float empty_threshold; /**< Empty Threshold */
  75. uint32_t percentage; /**< Percentage value */
  76. knob_state_t frag_state; /**< The current state of fragmentation. */
  77. knob_state_t foot_state; /**< The current state of footprint. */
  78. } dmmknobs_t;
  79. #endif /* WITH_KNOBS */
  80. /** A structure to store heap information. */
  81. typedef struct heap_s {
  82. #ifdef WITH_FIXED_LISTS
  83. maptable_node_t *maptable_head; /**< The head of the maptable list. */
  84. #endif /* WITH_FIXED_LISTS */
  85. void *free_list_head; /**< The head of the free list. */
  86. void *used_blocks_head; /**< The head of the used blocks list. */
  87. void *rov_ptr; /**< Roving pointer. */
  88. uint64_t num_objects; /**< Number of objects in the heap. */
  89. #ifdef WITH_STATS
  90. dmmstats_t dmm_stats; /**< Statistics of the heap. */
  91. #endif /* WITH_STATS */
  92. #ifdef WITH_KNOBS
  93. dmmknobs_t dmm_knobs; /**< Tunable parameters of the heap. */
  94. #endif /* WITH_KNOBS */
  95. #ifdef HAVE_LOCKS
  96. pthread_mutex_t mutex;/**< Mutex when POSIX Threads are used. */
  97. #endif /* HAVE_LOCKS */
  98. } heap_t;
  99. /** The allocator structure of dmmlib. */
  100. typedef struct allocator_s {
  101. heap_t heaps[NUM_HEAPS]; /**< The heaps that the allocator manages. */
  102. bool initialized; /**< Initialization flag of the allocator. */
  103. void *border_ptr; /**< Border pointer of the allocator. */
  104. #ifdef WITH_MEMORY_SPACE_AWARENESS
  105. size_t remaining_size; /**< The size of the remaining free space which
  106. is handled by the allocator. */
  107. #endif /* WITH_MEMORY_SPACE_AWARENESS */
  108. } allocator_t;
  109. #endif /* HEAP_H */