heap.h 3.1 KB

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