/* * initialize allocator a with a custom free_set_size * If the thread is not subscribed to the list of timestamps (used for GC), * additionally subscribe the thread to the list */ void ssmem_alloc_init_fs_size(ssmem_allocator_t* a, size_t size, size_t free_set_size, int id) { ssmem_num_allocators++; ssmem_allocator_list = ssmem_list_node_new((void*) a, ssmem_allocator_list); if (id == 0) { printf("[ALLOC] initializing allocator with fs size: %zu objects\n", free_set_size); } a->mem = (void*) memalign(CACHE_LINE_SIZE, size); assert(a->mem != NULL); a->mem_curr = 0; a->mem_size = size; a->tot_size = size; a->fs_size = free_set_size; a->mem_chunks = ssmem_list_node_new(a->mem, NULL); ssmem_gc_thread_init(a, id); a->free_set_list = ssmem_free_set_new(a->fs_size, NULL); a->free_set_num = 1; a->collected_set_list = NULL; a->collected_set_num = 0; a->available_set_list = NULL; a->released_mem_list = NULL; a->released_num = 0; }
/* * initialize allocator a with a custom free_set_size * If the thread is not subscribed to the list of timestamps (used for GC), * additionally subscribe the thread to the list */ void ssmem_alloc_init_fs_size(ssmem_allocator_t* a, size_t size, size_t free_set_size, int id) { ssmem_num_allocators++; ssmem_allocator_list = ssmem_list_node_new((void*) a, ssmem_allocator_list); if (id == 0) { printf("[ALLOC] initializing allocator with fs size: %zu objects\n", free_set_size); } #if SSMEM_TRANSPARENT_HUGE_PAGES int ret = posix_memalign(&a->mem, CACHE_LINE_SIZE, size); assert(ret == 0); #else a->mem = (void*) memalign(CACHE_LINE_SIZE, size); #endif assert(a->mem != NULL); #if SSMEM_ZERO_MEMORY == 1 memset(a->mem, 0, size); #endif a->mem_curr = 0; a->mem_size = size; a->tot_size = size; a->fs_size = free_set_size; a->mem_chunks = ssmem_list_node_new(a->mem, NULL); ssmem_gc_thread_init(a, id); a->free_set_list = ssmem_free_set_new(a->fs_size, NULL); a->free_set_num = 1; a->collected_set_list = NULL; a->collected_set_num = 0; a->available_set_list = NULL; a->released_mem_list = NULL; a->released_num = 0; }
ssmem_free_set_t* ssmem_free_set_get_avail(ssmem_allocator_t* a, size_t size, ssmem_free_set_t* next) { ssmem_free_set_t* fs; if (a->available_set_list != NULL) { fs = a->available_set_list; a->available_set_list = fs->set_next; fs->curr = 0; fs->set_next = next; /* printf("[ALLOC] got free_set from available_set : %p\n", fs); */ } else { fs = ssmem_free_set_new(size, next); } return fs; }