int ffile_cache_init(struct file_cache *cache, size_t read_size, size_t write_size) { int ret; if (cache == NULL) { return -EINVAL; } ret = mem_cache_init(&cache->read_cache, read_size); if (ret < 0) { return ret; } ret = mem_cache_init(&cache->write_cache, write_size); if (ret < 0) { goto out_read_cache_deinit; } return 0; out_read_cache_deinit: mem_cache_deinit(&cache->read_cache); return ret; }
/* * Initialize a memcache that is aligned to utcb size */ void l4_utcb_alloc_init(void) { BUG_ON(!(utcb_cache = mem_cache_init((void *)utcb, UTCB_SIZE * (THREADS_TOTAL + 1), UTCB_SIZE, UTCB_SIZE))); }
void l4_stack_alloc_init(void) { BUG_ON(!(stack_cache = mem_cache_init((void *)stack, STACK_SIZE * (THREADS_TOTAL + 1), STACK_SIZE, STACK_SIZE))); }
void l4_thread_list_init(void) { struct l4_thread_list *tlist = &l4_thread_list; /* Initialize the head struct */ memset(tlist, 0, sizeof (*tlist)); link_init(&tlist->thread_list); l4_mutex_init(&tlist->lock); /* Initialize a cache of l4_thread_list structs */ if (!(tlist->thread_cache = mem_cache_init(&l4_thread_list_buf, L4_THREAD_LIST_BUFFER_SIZE, sizeof(struct l4_thread), 0))) { printf("FATAL: Could not initialize internal " "thread struct cache.\n"); BUG(); } }
int test_memcache_init_aligned(int *items_max, int item_size) { if (item_size * 10 > MEM_CACHE_SIZE) MEM_CACHE_SIZE = item_size * 10; if (!(buffer = calloc(1, MEM_CACHE_SIZE))) { printf("System out of memory.\n"); BUG(); } if ((this = mem_cache_init(buffer, MEM_CACHE_SIZE, item_size, 1)) == 0) { printf("Unable to initialise cache.\n"); return -1; } *items_max = mem_cache_total_empty(this); printf("\nMEMCACHE TEST: ALIGNED ELEMENTS\n==========================\n"); printf("%-30s%d\n", "Item size:", item_size); printf("%-30s0x%x\n", "Cache occupied space:", MEM_CACHE_SIZE); printf("%-30s%d\n","Total items in cache:", *items_max); printf("%-30s0x%x\n","Total items space:", (*items_max * item_size)); return 0; }