• Home
  • Raw
  • Download

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()
99 head = mb_cache_entry_head(cache, key); in mb_cache_entry_create()
111 spin_lock(&cache->c_list_lock); in mb_cache_entry_create()
112 list_add_tail(&entry->e_list, &cache->c_list); in mb_cache_entry_create()
115 cache->c_entry_count++; in mb_cache_entry_create()
116 spin_unlock(&cache->c_list_lock); in mb_cache_entry_create()
128 static struct mb_cache_entry *__entry_find(struct mb_cache *cache, in __entry_find() argument
136 head = mb_cache_entry_head(cache, key); in __entry_find()
155 mb_cache_entry_put(cache, old_entry); in __entry_find()
168 struct mb_cache_entry *mb_cache_entry_find_first(struct mb_cache *cache, in mb_cache_entry_find_first() argument
171 return __entry_find(cache, NULL, key); in mb_cache_entry_find_first()
185 struct mb_cache_entry *mb_cache_entry_find_next(struct mb_cache *cache, in mb_cache_entry_find_next() argument
188 return __entry_find(cache, entry, entry->e_key); in mb_cache_entry_find_next()
198 struct mb_cache_entry *mb_cache_entry_get(struct mb_cache *cache, u32 key, in mb_cache_entry_get() argument
205 head = mb_cache_entry_head(cache, key); in mb_cache_entry_get()
227 void mb_cache_entry_delete(struct mb_cache *cache, u32 key, u64 value) in mb_cache_entry_delete() argument
233 head = mb_cache_entry_head(cache, key); in mb_cache_entry_delete()
240 spin_lock(&cache->c_list_lock); in mb_cache_entry_delete()
243 if (!WARN_ONCE(cache->c_entry_count == 0, in mb_cache_entry_delete()
245 cache->c_entry_count--; in mb_cache_entry_delete()
248 spin_unlock(&cache->c_list_lock); in mb_cache_entry_delete()
249 mb_cache_entry_put(cache, entry); in mb_cache_entry_delete()
263 void mb_cache_entry_touch(struct mb_cache *cache, in mb_cache_entry_touch() argument
273 struct mb_cache *cache = container_of(shrink, struct mb_cache, in mb_cache_count() local
276 return cache->c_entry_count; in mb_cache_count()
280 static unsigned long mb_cache_shrink(struct mb_cache *cache, in mb_cache_shrink() argument
287 spin_lock(&cache->c_list_lock); in mb_cache_shrink()
288 while (nr_to_scan-- && !list_empty(&cache->c_list)) { in mb_cache_shrink()
289 entry = list_first_entry(&cache->c_list, in mb_cache_shrink()
293 list_move_tail(&entry->e_list, &cache->c_list); in mb_cache_shrink()
297 cache->c_entry_count--; in mb_cache_shrink()
302 spin_unlock(&cache->c_list_lock); in mb_cache_shrink()
303 head = mb_cache_entry_head(cache, entry->e_key); in mb_cache_shrink()
310 if (mb_cache_entry_put(cache, entry)) in mb_cache_shrink()
313 spin_lock(&cache->c_list_lock); in mb_cache_shrink()
315 spin_unlock(&cache->c_list_lock); in mb_cache_shrink()
323 struct mb_cache *cache = container_of(shrink, struct mb_cache, in mb_cache_scan() local
325 return mb_cache_shrink(cache, sc->nr_to_scan); in mb_cache_scan()
333 struct mb_cache *cache = container_of(work, struct mb_cache, in mb_cache_shrink_worker() local
335 mb_cache_shrink(cache, cache->c_max_entries / SHRINK_DIVISOR); in mb_cache_shrink_worker()
346 struct mb_cache *cache; in mb_cache_create() local
350 cache = kzalloc(sizeof(struct mb_cache), GFP_KERNEL); in mb_cache_create()
351 if (!cache) in mb_cache_create()
353 cache->c_bucket_bits = bucket_bits; in mb_cache_create()
354 cache->c_max_entries = bucket_count << 4; in mb_cache_create()
355 INIT_LIST_HEAD(&cache->c_list); in mb_cache_create()
356 spin_lock_init(&cache->c_list_lock); in mb_cache_create()
357 cache->c_hash = kmalloc_array(bucket_count, in mb_cache_create()
360 if (!cache->c_hash) { in mb_cache_create()
361 kfree(cache); in mb_cache_create()
365 INIT_HLIST_BL_HEAD(&cache->c_hash[i]); in mb_cache_create()
367 cache->c_shrink.count_objects = mb_cache_count; in mb_cache_create()
368 cache->c_shrink.scan_objects = mb_cache_scan; in mb_cache_create()
369 cache->c_shrink.seeks = DEFAULT_SEEKS; in mb_cache_create()
370 if (register_shrinker(&cache->c_shrink)) { in mb_cache_create()
371 kfree(cache->c_hash); in mb_cache_create()
372 kfree(cache); in mb_cache_create()
376 INIT_WORK(&cache->c_shrink_work, mb_cache_shrink_worker); in mb_cache_create()
378 return cache; in mb_cache_create()
392 void mb_cache_destroy(struct mb_cache *cache) in mb_cache_destroy() argument
396 unregister_shrinker(&cache->c_shrink); in mb_cache_destroy()
402 list_for_each_entry_safe(entry, next, &cache->c_list, e_list) { in mb_cache_destroy()
410 mb_cache_entry_put(cache, entry); in mb_cache_destroy()
412 kfree(cache->c_hash); in mb_cache_destroy()
413 kfree(cache); in mb_cache_destroy()