heap.h 2.1 KB

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