heap.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * \file heap.h
  3. * \author Ioannis Koutras (joko@microlab.ntua.gr)
  4. * \date September, 2011
  5. * Basic structures needed for the dmmlib allocator.
  6. */
  7. #ifndef HEAP_H
  8. #define HEAP_H
  9. #include <stdint.h>
  10. #include <stddef.h> // For size_t support
  11. #include <stdbool.h>
  12. #include "dmm_config.h"
  13. #ifdef HAVE_LOCKS
  14. #include <pthread.h>
  15. #endif /* HAVE_LOCKS */
  16. /**
  17. * A structure for knobs states (currently 5)
  18. *
  19. * FIXME Have to check them
  20. *
  21. * */
  22. typedef uint8_t knob_state_t;
  23. /** A structure to represent a maptable node. */
  24. typedef struct maptable_node_s {
  25. unsigned int size; /**< The size of the blocks of the fixed list. */
  26. void *fixed_list_head; /**< Pointer to the head node of the fixed list. */
  27. struct maptable_node_s *next; /**< Pointer to the next node of the
  28. maptable. */
  29. } maptable_node_t;
  30. /** Statistics data structure. */
  31. typedef struct dmmstats_s {
  32. uint32_t max_mem_allocated; /**< Maximum total memory allocated. */
  33. uint32_t max_mem_requested; /**< Maximum total memory requested. */
  34. uint32_t mem_allocated; /**< Total memory currently allocated. */
  35. uint32_t mem_requested; /**< Total memory currently requested. */
  36. uint32_t mem_reserved; /**< Total memory currently reserved. */
  37. uint32_t live_objects; /**< Number of live objects. */
  38. uint32_t read_mem_accesses; /**< Number of read accesses. */
  39. uint32_t write_mem_accesses; /**< Number of write accesses. */
  40. uint32_t num_malloc; /**< Number of malloc()'s served. */
  41. uint32_t num_free; /**< Number of free()'s served. */
  42. } dmmstats_t;
  43. /** A structure to represent tunable parameters of a heap */
  44. typedef struct dmmknobs_s {
  45. float frag_threshold; /**< Fragmentation threshold to enable coalescing
  46. or not. */
  47. uint32_t mem_threshold; /**< Memory size threshold. */
  48. int32_t max_coalesce_size; /**< Maximum coalesce size; -1 if coalescing
  49. is not supported */
  50. uint32_t min_split_size; /**< Minimum split size. */
  51. /* FIXME Need to find explanation */
  52. float empty_threshold; /**< Empty Threshold */
  53. uint32_t percentage; /**< Percentage value */
  54. knob_state_t frag_state; /**< The current state of fragmentation. */
  55. knob_state_t foot_state; /**< The current state of footprint. */
  56. } dmmknobs_t;
  57. /** A structure to store heap information. */
  58. typedef struct heap_s {
  59. maptable_node_t *maptable_head; /**< The head of the maptable list. */
  60. void *free_list_head; /**< The head of the free list. */
  61. void *used_blocks_head; /**< The head of the used blocks list. */
  62. void *rov_ptr; /**< Roving pointer. */
  63. uint64_t num_objects; /**< Number of objects in the heap. */
  64. dmmstats_t dmm_stats; /**< Statistics of the heap. */
  65. dmmknobs_t dmm_knobs; /**< Tunable parameters of the heap. */
  66. #ifdef HAVE_LOCKS
  67. pthread_mutex_t mutex;/**< Mutex when POSIX Threads are used. */
  68. #endif /* HAVE_LOCKS */
  69. } heap_t;
  70. /** The allocator structure of dmmlib. */
  71. typedef struct allocator_s {
  72. heap_t heaps[NUM_HEAPS]; /**< The heaps that the allocator manages. */
  73. bool initialized; /**< Initialization flag of the allocator. */
  74. void *border_ptr; /**< Border pointer of the allocator. */
  75. #ifdef WITH_MEMORY_SPACE_AWARENESS
  76. size_t remaining_size; /**< The size of the remaining free space which
  77. is handled by the allocator. */
  78. #endif /* WITH_MEMORY_SPACE_AWARENESS */
  79. } allocator_t;
  80. #endif /* HEAP_H */