49 #define LP_PREALLOCATION_INITIAL_ADDRESS (void *)0x0000008000000000 51 #define MIN_CHUNK_SIZE 128U // Size (in bytes) of the smallest chunk provideable by DyMeLoR 52 #define MAX_CHUNK_SIZE 4194304 // Size (in bytes) of the biggest one. Notice that if this number 58 #define NUM_AREAS (log2(MAX_CHUNK_SIZE) - log2(MIN_CHUNK_SIZE) + 1) // Number of initial malloc_areas available (will be increased at runtime if needed) 59 #define MAX_NUM_AREAS (NUM_AREAS * 32) // Maximum number of allocatable malloc_areas. If MAX_NUM_AREAS 62 #define MAX_LIMIT_NUM_AREAS MAX_NUM_AREAS 63 #define MIN_NUM_CHUNKS 512 // Minimum number of chunks per malloc_area 64 #define MAX_NUM_CHUNKS 4096 // Maximum number of chunks per malloc_area 66 #define MAX_LOG_THRESHOLD 1.7 // Threshold to check if a malloc_area is underused TODO: retest 67 #define MIN_LOG_THRESHOLD 1.7 // Threshold to check if a malloc_area is overused TODO: retest 69 #ifndef INCREMENTAL_GRANULARITY 70 #define INCREMENTAL_GRANULARITY 50 // Number of incremental logs before a full log is forced 74 #define LITTLE_SIZE 32 75 #define CHECK_SIZE 0.25 // Must be <= 0.25! 78 #define GET_CACHE_LINE_NUMBER(P) ((unsigned long)((P >> 4) & (CACHE_SIZE - 1))) 81 #define SET_LOG_MODE_BIT(m_area) (((malloc_area*)(m_area))->chunk_size |= (1UL << 0)) 82 #define RESET_LOG_MODE_BIT(m_area) (((malloc_area*)(m_area))->chunk_size &= ~(1UL << 0)) 83 #define CHECK_LOG_MODE_BIT(m_area) (((malloc_area*)(m_area))->chunk_size & (1UL << 0)) 85 #define SET_AREA_LOCK_BIT(m_area) (((malloc_area*)(m_area))->chunk_size |= (1UL << 1)) 86 #define RESET_AREA_LOCK_BIT(m_area) (((malloc_area*)(m_area))->chunk_size &= ~(1UL << 1)) 87 #define CHECK_AREA_LOCK_BIT(m_area) (((malloc_area*)(m_area))->chunk_size & (1UL << 1)) 89 #define UNTAGGED_CHUNK_SIZE(m_area) (((malloc_area*)(m_area))->chunk_size & ~((1UL << 0) | (1UL << 1))) 91 #define POWEROF2(x) (1UL << (1 + (63 - __builtin_clzl((x) - 1)))) 92 #define IS_POWEROF2(x) ((x) != 0 && ((x) & ((x) - 1)) == 0) 94 #define PER_LP_PREALLOCATED_MEMORY (262144L * PAGE_SIZE) // This should be power of 2 multiplied by a page size. This is 1GB per LP. 122 size_t total_log_size;
123 size_t total_inc_size;
132 #define is_incremental(ckpt) (((malloc_state *)ckpt)->is_incremental == true) 134 #define get_top_pointer(ptr) ((unsigned long long *)((char *)ptr - sizeof(unsigned long long))) 135 #define get_area_top_pointer(ptr) ( (malloc_area **)(*get_top_pointer(ptr)) ) 136 #define get_area(ptr) ( *(get_area_top_pointer(ptr)) ) 138 #define PER_LP_PREALLOCATED_MEMORY (262144L * PAGE_SIZE) // This should be power of 2 multiplied by a page size. This is 1GB per LP. 139 #define BUDDY_GRANULARITY PAGE_SIZE // This is the smallest chunk released by the buddy in bytes. PER_LP_PREALLOCATED_MEMORY/BUDDY_GRANULARITY must be integer and a power of 2 147 extern size_t __page_size;
148 #define PAGE_SIZE ({ \ 149 if(unlikely(__page_size == 0))\ 150 __page_size = getpagesize();\ 162 uint8_t data[] __attribute__((aligned(
sizeof(
void *))));
167 size_t itemsize, itemcount;
168 size_t slabsize, pages_per_alloc;
169 uint64_t initial_slotmask, empty_slotmask;
170 uintptr_t alignment_mask;
180 extern void set_force_full(
unsigned int,
int);
182 extern size_t get_state_size(
int);
184 extern size_t get_inc_log_size(
void *);
185 extern int get_granularity(
void);
186 extern size_t dirty_size(
unsigned int,
void *,
double *);
189 extern void do_free(
struct lp_struct *,
void *ptr);
190 extern void *allocate_lp_memory(
struct lp_struct *,
size_t);
191 extern void free_lp_memory(
struct lp_struct *,
void *);
206 #define BUDDY_BLOCK_SIZE_EXP 12 211 size_t longest[] __attribute__((aligned(
sizeof(
size_t))));
215 extern void buddy_destroy(
struct buddy *
self);
216 extern void *allocate_buddy_memory(
struct buddy *
self,
void *base_mem,
size_t requested_size);
217 extern void free_buddy_memory(
struct buddy *
self,
void *base_mem,
void *ptr);
221 #pragma GCC poison malloc free realloc calloc void dirty_mem(void *, int)
malloc_state * malloc_state_init(void)
struct buddy * buddy_new(size_t requested_size)
void * do_malloc(struct lp_struct *, size_t)
Core ROOT-Sim functionalities.
void * __wrap_calloc(size_t, size_t)
void * __wrap_realloc(void *, size_t)
bool is_incremental
Tells if it is an incremental log or a full one (when used for logging)
double simtime_t
This defines the type with whom timestamps are represented.
size_t get_log_size(malloc_state *)
Definition of the memory map.
unsigned char rootsim_bitmap
This defines a generic bitmap.
void * __wrap_malloc(size_t)
This structure let DyMeLoR handle one malloc area (for serving given-size memory requests) ...