Lines Matching refs:cache

47 static unsigned long mb_cache_shrink(struct mb_cache *cache,
50 static inline struct hlist_bl_head *mb_cache_entry_head(struct mb_cache *cache, in mb_cache_entry_head() argument
53 return &cache->c_hash[hash_32(key, cache->c_bucket_bits)]; in mb_cache_entry_head()
74 int mb_cache_entry_create(struct mb_cache *cache, gfp_t mask, u32 key, in mb_cache_entry_create() argument
82 if (cache->c_entry_count >= cache->c_max_entries) in mb_cache_entry_create()
83 schedule_work(&cache->c_shrink_work); in mb_cache_entry_create()
85 if (cache->c_entry_count >= 2*cache->c_max_entries) in mb_cache_entry_create()
86 mb_cache_shrink(cache, SYNC_SHRINK_BATCH); in mb_cache_entry_create()
106 head = mb_cache_entry_head(cache, key); in mb_cache_entry_create()
117 spin_lock(&cache->c_list_lock); in mb_cache_entry_create()
118 list_add_tail(&entry->e_list, &cache->c_list); in mb_cache_entry_create()
119 cache->c_entry_count++; in mb_cache_entry_create()
120 spin_unlock(&cache->c_list_lock); in mb_cache_entry_create()
121 mb_cache_entry_put(cache, entry); in mb_cache_entry_create()
127 void __mb_cache_entry_free(struct mb_cache *cache, struct mb_cache_entry *entry) in __mb_cache_entry_free() argument
131 head = mb_cache_entry_head(cache, entry->e_key); in __mb_cache_entry_free()
152 static struct mb_cache_entry *__entry_find(struct mb_cache *cache, in __entry_find() argument
160 head = mb_cache_entry_head(cache, key); in __entry_find()
179 mb_cache_entry_put(cache, old_entry); in __entry_find()
192 struct mb_cache_entry *mb_cache_entry_find_first(struct mb_cache *cache, in mb_cache_entry_find_first() argument
195 return __entry_find(cache, NULL, key); in mb_cache_entry_find_first()
209 struct mb_cache_entry *mb_cache_entry_find_next(struct mb_cache *cache, in mb_cache_entry_find_next() argument
212 return __entry_find(cache, entry, entry->e_key); in mb_cache_entry_find_next()
222 struct mb_cache_entry *mb_cache_entry_get(struct mb_cache *cache, u32 key, in mb_cache_entry_get() argument
229 head = mb_cache_entry_head(cache, key); in mb_cache_entry_get()
254 struct mb_cache_entry *mb_cache_entry_delete_or_get(struct mb_cache *cache, in mb_cache_entry_delete_or_get() argument
259 entry = mb_cache_entry_get(cache, key, value); in mb_cache_entry_delete_or_get()
270 spin_lock(&cache->c_list_lock); in mb_cache_entry_delete_or_get()
273 cache->c_entry_count--; in mb_cache_entry_delete_or_get()
274 spin_unlock(&cache->c_list_lock); in mb_cache_entry_delete_or_get()
275 __mb_cache_entry_free(cache, entry); in mb_cache_entry_delete_or_get()
286 void mb_cache_entry_touch(struct mb_cache *cache, in mb_cache_entry_touch() argument
296 struct mb_cache *cache = container_of(shrink, struct mb_cache, in mb_cache_count() local
299 return cache->c_entry_count; in mb_cache_count()
303 static unsigned long mb_cache_shrink(struct mb_cache *cache, in mb_cache_shrink() argument
309 spin_lock(&cache->c_list_lock); in mb_cache_shrink()
310 while (nr_to_scan-- && !list_empty(&cache->c_list)) { in mb_cache_shrink()
311 entry = list_first_entry(&cache->c_list, in mb_cache_shrink()
317 list_move_tail(&entry->e_list, &cache->c_list); in mb_cache_shrink()
321 cache->c_entry_count--; in mb_cache_shrink()
322 spin_unlock(&cache->c_list_lock); in mb_cache_shrink()
323 __mb_cache_entry_free(cache, entry); in mb_cache_shrink()
326 spin_lock(&cache->c_list_lock); in mb_cache_shrink()
328 spin_unlock(&cache->c_list_lock); in mb_cache_shrink()
336 struct mb_cache *cache = container_of(shrink, struct mb_cache, in mb_cache_scan() local
338 return mb_cache_shrink(cache, sc->nr_to_scan); in mb_cache_scan()
346 struct mb_cache *cache = container_of(work, struct mb_cache, in mb_cache_shrink_worker() local
348 mb_cache_shrink(cache, cache->c_max_entries / SHRINK_DIVISOR); in mb_cache_shrink_worker()
359 struct mb_cache *cache; in mb_cache_create() local
363 cache = kzalloc(sizeof(struct mb_cache), GFP_KERNEL); in mb_cache_create()
364 if (!cache) in mb_cache_create()
366 cache->c_bucket_bits = bucket_bits; in mb_cache_create()
367 cache->c_max_entries = bucket_count << 4; in mb_cache_create()
368 INIT_LIST_HEAD(&cache->c_list); in mb_cache_create()
369 spin_lock_init(&cache->c_list_lock); in mb_cache_create()
370 cache->c_hash = kmalloc_array(bucket_count, in mb_cache_create()
373 if (!cache->c_hash) { in mb_cache_create()
374 kfree(cache); in mb_cache_create()
378 INIT_HLIST_BL_HEAD(&cache->c_hash[i]); in mb_cache_create()
380 cache->c_shrink.count_objects = mb_cache_count; in mb_cache_create()
381 cache->c_shrink.scan_objects = mb_cache_scan; in mb_cache_create()
382 cache->c_shrink.seeks = DEFAULT_SEEKS; in mb_cache_create()
383 if (register_shrinker(&cache->c_shrink, "mbcache-shrinker")) { in mb_cache_create()
384 kfree(cache->c_hash); in mb_cache_create()
385 kfree(cache); in mb_cache_create()
389 INIT_WORK(&cache->c_shrink_work, mb_cache_shrink_worker); in mb_cache_create()
391 return cache; in mb_cache_create()
405 void mb_cache_destroy(struct mb_cache *cache) in mb_cache_destroy() argument
409 unregister_shrinker(&cache->c_shrink); in mb_cache_destroy()
415 list_for_each_entry_safe(entry, next, &cache->c_list, e_list) { in mb_cache_destroy()
418 mb_cache_entry_put(cache, entry); in mb_cache_destroy()
420 kfree(cache->c_hash); in mb_cache_destroy()
421 kfree(cache); in mb_cache_destroy()