Lines Matching refs:cache

49     struct bcache *cache;  in bcache_create()  local
51 cache = malloc(sizeof(struct bcache)); in bcache_create()
53 cache->dev = dev; in bcache_create()
54 cache->block_size = block_size; in bcache_create()
55 cache->count = block_count; in bcache_create()
56 memset(&cache->stats, 0, sizeof(cache->stats)); in bcache_create()
58 list_initialize(&cache->free_list); in bcache_create()
59 list_initialize(&cache->lru_list); in bcache_create()
61 cache->blocks = malloc(sizeof(struct bcache_block) * block_count); in bcache_create()
64 cache->blocks[i].ref_count = 0; in bcache_create()
65 cache->blocks[i].is_dirty = false; in bcache_create()
66 cache->blocks[i].ptr = malloc(block_size); in bcache_create()
68 list_add_head(&cache->free_list, &cache->blocks[i].node); in bcache_create()
71 return (bcache_t)cache; in bcache_create()
74 static int flush_block(struct bcache *cache, struct bcache_block *block) { in flush_block() argument
77 rc = bio_write(cache->dev, block->ptr, in flush_block()
78 (off_t)block->blocknum * cache->block_size, in flush_block()
79 cache->block_size); in flush_block()
84 cache->stats.writes++; in flush_block()
91 struct bcache *cache = _cache; in bcache_destroy() local
94 for (i=0; i < cache->count; i++) { in bcache_destroy()
95 DEBUG_ASSERT(cache->blocks[i].ref_count == 0); in bcache_destroy()
97 if (cache->blocks[i].is_dirty) in bcache_destroy()
99 cache->blocks[i].blocknum); in bcache_destroy()
101 free(cache->blocks[i].ptr); in bcache_destroy()
104 free(cache); in bcache_destroy()
108 static struct bcache_block *find_block(struct bcache *cache, uint blocknum) { in find_block() argument
115 list_for_every_entry(&cache->lru_list, block, struct bcache_block, node) { in find_block()
121 list_add_tail(&cache->lru_list, &block->node); in find_block()
122 cache->stats.hits++; in find_block()
123 cache->stats.depth += depth; in find_block()
128 cache->stats.misses++; in find_block()
133 static struct bcache_block *alloc_block(struct bcache *cache) { in alloc_block() argument
138 block = list_remove_head_type(&cache->free_list, struct bcache_block, node); in alloc_block()
141 list_add_tail(&cache->lru_list, &block->node); in alloc_block()
147 list_for_every_entry(&cache->lru_list, block, struct bcache_block, node) { in alloc_block()
151 err = flush_block(cache, block); in alloc_block()
158 list_add_tail(&cache->lru_list, &block->node); in alloc_block()
166 static struct bcache_block *find_or_fill_block(struct bcache *cache, uint blocknum) { in find_or_fill_block() argument
172 struct bcache_block *block = find_block(cache, blocknum); in find_or_fill_block()
177 block = alloc_block(cache); in find_or_fill_block()
183 … err = bio_read(cache->dev, block->ptr, (off_t)blocknum * cache->block_size, cache->block_size); in find_or_fill_block()
186 list_add_tail(&cache->free_list, &block->node); in find_or_fill_block()
190 cache->stats.reads++; in find_or_fill_block()
199 struct bcache *cache = _cache; in bcache_read_block() local
203 struct bcache_block *block = find_or_fill_block(cache, blocknum); in bcache_read_block()
209 memcpy(buf, block->ptr, cache->block_size); in bcache_read_block()
214 struct bcache *cache = _cache; in bcache_get_block() local
220 struct bcache_block *block = find_or_fill_block(cache, blocknum); in bcache_get_block()
234 struct bcache *cache = _cache; in bcache_put_block() local
238 struct bcache_block *block = find_block(cache, blocknum); in bcache_put_block()
251 struct bcache *cache = priv; in bcache_mark_block_dirty() local
254 block = find_block(cache, blocknum); in bcache_mark_block_dirty()
268 struct bcache *cache = priv; in bcache_zero_block() local
271 block = find_block(cache, blocknum); in bcache_zero_block()
273 block = alloc_block(cache); in bcache_zero_block()
282 memset(block->ptr, 0, cache->block_size); in bcache_zero_block()
291 struct bcache *cache = priv; in bcache_flush() local
294 list_for_every_entry(&cache->lru_list, block, struct bcache_block, node) { in bcache_flush()
296 err = flush_block(cache, block); in bcache_flush()
309 struct bcache *cache = priv; in bcache_dump() local
311 finds = cache->stats.hits + cache->stats.misses; in bcache_dump()
315 cache->stats.hits, in bcache_dump()
316 finds ? (cache->stats.hits * 100) / finds : 0, in bcache_dump()
317 cache->stats.hits ? cache->stats.depth / cache->stats.hits : 0, in bcache_dump()
318 cache->stats.misses, in bcache_dump()
319 finds ? (cache->stats.misses * 100) / finds : 0, in bcache_dump()
320 cache->stats.reads, in bcache_dump()
321 cache->stats.writes); in bcache_dump()