Lines Matching refs:cache
53 struct squashfs_cache *cache, u64 block, int length) in squashfs_cache_get() argument
58 spin_lock(&cache->lock); in squashfs_cache_get()
61 for (i = cache->curr_blk, n = 0; n < cache->entries; n++) { in squashfs_cache_get()
62 if (cache->entry[i].block == block) { in squashfs_cache_get()
63 cache->curr_blk = i; in squashfs_cache_get()
66 i = (i + 1) % cache->entries; in squashfs_cache_get()
69 if (n == cache->entries) { in squashfs_cache_get()
74 if (cache->unused == 0) { in squashfs_cache_get()
75 cache->num_waiters++; in squashfs_cache_get()
76 spin_unlock(&cache->lock); in squashfs_cache_get()
77 wait_event(cache->wait_queue, cache->unused); in squashfs_cache_get()
78 spin_lock(&cache->lock); in squashfs_cache_get()
79 cache->num_waiters--; in squashfs_cache_get()
88 i = cache->next_blk; in squashfs_cache_get()
89 for (n = 0; n < cache->entries; n++) { in squashfs_cache_get()
90 if (cache->entry[i].refcount == 0) in squashfs_cache_get()
92 i = (i + 1) % cache->entries; in squashfs_cache_get()
95 cache->next_blk = (i + 1) % cache->entries; in squashfs_cache_get()
96 entry = &cache->entry[i]; in squashfs_cache_get()
102 cache->unused--; in squashfs_cache_get()
108 spin_unlock(&cache->lock); in squashfs_cache_get()
113 spin_lock(&cache->lock); in squashfs_cache_get()
126 spin_unlock(&cache->lock); in squashfs_cache_get()
129 spin_unlock(&cache->lock); in squashfs_cache_get()
140 entry = &cache->entry[i]; in squashfs_cache_get()
142 cache->unused--; in squashfs_cache_get()
151 spin_unlock(&cache->lock); in squashfs_cache_get()
154 spin_unlock(&cache->lock); in squashfs_cache_get()
161 cache->name, i, entry->block, entry->refcount, entry->error); in squashfs_cache_get()
164 ERROR("Unable to read %s cache entry [%llx]\n", cache->name, in squashfs_cache_get()
175 struct squashfs_cache *cache = entry->cache; in squashfs_cache_put() local
177 spin_lock(&cache->lock); in squashfs_cache_put()
180 cache->unused++; in squashfs_cache_put()
185 if (cache->num_waiters) { in squashfs_cache_put()
186 spin_unlock(&cache->lock); in squashfs_cache_put()
187 wake_up(&cache->wait_queue); in squashfs_cache_put()
191 spin_unlock(&cache->lock); in squashfs_cache_put()
197 void squashfs_cache_delete(struct squashfs_cache *cache) in squashfs_cache_delete() argument
201 if (cache == NULL) in squashfs_cache_delete()
204 for (i = 0; i < cache->entries; i++) { in squashfs_cache_delete()
205 if (cache->entry[i].data) { in squashfs_cache_delete()
206 for (j = 0; j < cache->pages; j++) in squashfs_cache_delete()
207 kfree(cache->entry[i].data[j]); in squashfs_cache_delete()
208 kfree(cache->entry[i].data); in squashfs_cache_delete()
210 kfree(cache->entry[i].actor); in squashfs_cache_delete()
213 kfree(cache->entry); in squashfs_cache_delete()
214 kfree(cache); in squashfs_cache_delete()
227 struct squashfs_cache *cache = kzalloc(sizeof(*cache), GFP_KERNEL); in squashfs_cache_init() local
229 if (cache == NULL) { in squashfs_cache_init()
234 cache->entry = kcalloc(entries, sizeof(*(cache->entry)), GFP_KERNEL); in squashfs_cache_init()
235 if (cache->entry == NULL) { in squashfs_cache_init()
240 cache->curr_blk = 0; in squashfs_cache_init()
241 cache->next_blk = 0; in squashfs_cache_init()
242 cache->unused = entries; in squashfs_cache_init()
243 cache->entries = entries; in squashfs_cache_init()
244 cache->block_size = block_size; in squashfs_cache_init()
245 cache->pages = block_size >> PAGE_SHIFT; in squashfs_cache_init()
246 cache->pages = cache->pages ? cache->pages : 1; in squashfs_cache_init()
247 cache->name = name; in squashfs_cache_init()
248 cache->num_waiters = 0; in squashfs_cache_init()
249 spin_lock_init(&cache->lock); in squashfs_cache_init()
250 init_waitqueue_head(&cache->wait_queue); in squashfs_cache_init()
253 struct squashfs_cache_entry *entry = &cache->entry[i]; in squashfs_cache_init()
255 init_waitqueue_head(&cache->entry[i].wait_queue); in squashfs_cache_init()
256 entry->cache = cache; in squashfs_cache_init()
258 entry->data = kcalloc(cache->pages, sizeof(void *), GFP_KERNEL); in squashfs_cache_init()
264 for (j = 0; j < cache->pages; j++) { in squashfs_cache_init()
273 cache->pages, 0); in squashfs_cache_init()
280 return cache; in squashfs_cache_init()
283 squashfs_cache_delete(cache); in squashfs_cache_init()