heap.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #ifndef HEAP_H
  2. #define HEAP_H
  3. #include <stdint.h>
  4. #include <pthread.h>
  5. #define NUM_HEAPS 4
  6. /**
  7. * A structure to represent a singly linked list node
  8. */
  9. typedef struct node_s {
  10. void *data; /**< pointer to the actual data */
  11. struct node_s *next; /**< pointer to the next item of the list */
  12. } NODE;
  13. /**
  14. * A structure to represent a maptable node
  15. *
  16. * Heaps contain
  17. */
  18. typedef struct maptable_node_s {
  19. unsigned int size; /**< the size of the blocks of the fixed list */
  20. NODE *fixed_list_head; /**< pointer to the head node of the fixed list */
  21. struct maptable_node_s *next; /**< pointer to the next node of the maptable */
  22. } MAPTABLE_NODE;
  23. typedef struct dmmstats_s {
  24. uint32_t max_mem_allocated; /**< maximum total memory allocated */
  25. uint32_t max_mem_requested; /**< maximum total memory requested */
  26. uint32_t mem_allocated; /**< total memory currently allocated */
  27. uint32_t mem_requested; /**< total memory currently requested */
  28. uint32_t live_objects; /**< number of live objects */
  29. uint32_t read_mem_accesses; /**< number of read accesses */
  30. uint32_t write_mem_accesses; /**< number of write accesses */
  31. uint32_t num_malloc; /**< number of malloc()'s served */
  32. uint32_t num_free; /**< number of free()'s served */
  33. } dmmstats_t;
  34. typedef struct dmmknobs_s {
  35. uint32_t maxCoalesceSize;
  36. uint32_t minSplitSize;
  37. float empty_threshold;
  38. uint32_t percentage;
  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 *maptable_head;
  43. NODE *free_list_head;
  44. NODE *rov_ptr;
  45. uint64_t num_objects;
  46. dmmstats_t dmm_stats;
  47. dmmknobs_t dmm_knobs;
  48. pthread_mutex_t mutex;
  49. } heap_t;
  50. typedef struct allocator_s {
  51. heap_t heaps[NUM_HEAPS];
  52. char *border_ptr;
  53. } allocator_t;
  54. #endif /* HEAP_H */