heap.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #ifndef HEAP_H
  2. #define HEAP_H
  3. #include <stdint.h>
  4. #include <pthread.h>
  5. #include "block_header.h"
  6. #define NUM_HEAPS 4
  7. /**
  8. * A structure to represent a maptable node
  9. */
  10. typedef struct maptable_node_s {
  11. unsigned int size; /**< the size of the blocks of the fixed list */
  12. void *fixed_list_head; /**< pointer to the head node of the fixed list */
  13. struct maptable_node_s *next; /**< pointer to the next node of the maptable */
  14. } maptable_node_t;
  15. typedef struct dmmstats_s {
  16. uint32_t max_mem_allocated; /**< maximum total memory allocated */
  17. uint32_t max_mem_requested; /**< maximum total memory requested */
  18. uint32_t mem_allocated; /**< total memory currently allocated */
  19. uint32_t mem_requested; /**< total memory currently requested */
  20. uint32_t mem_reserved; /**< total memory currently reserved */
  21. uint32_t live_objects; /**< number of live objects */
  22. uint32_t read_mem_accesses; /**< number of read accesses */
  23. uint32_t write_mem_accesses; /**< number of write accesses */
  24. uint32_t num_malloc; /**< number of malloc()'s served */
  25. uint32_t num_free; /**< number of free()'s served */
  26. } dmmstats_t;
  27. /**
  28. * A structure to represent tunable parameters of a heap
  29. */
  30. typedef struct dmmknobs_s {
  31. int32_t max_coalesce_size; /**< maximum coalesce size; -1 if coalescing
  32. is not supported */
  33. float frag_threshold; /**< fragmentation threshold to enable
  34. coalescing or not */
  35. uint32_t mem_threshold; /**< memory size threshold */
  36. uint32_t min_split_size; // FIXME to be investigated if needed
  37. float empty_threshold; // FIXME to be investigated if needed
  38. uint32_t percentage; // FIXME to be investigated if needed
  39. char frag_state; //FIXME It was in the old code to refresh the frag check
  40. } dmmknobs_t;
  41. typedef struct heap_s {
  42. maptable_node_t *maptable_head;
  43. void *free_list_head;
  44. void *used_blocks_head;
  45. void *rov_ptr;
  46. uint64_t num_objects;
  47. dmmstats_t dmm_stats;
  48. dmmknobs_t dmm_knobs;
  49. pthread_mutex_t mutex;
  50. } heap_t;
  51. typedef struct allocator_s {
  52. heap_t heaps[NUM_HEAPS];
  53. } allocator_t;
  54. #endif /* HEAP_H */