• Home
  • Raw
  • Download

Lines Matching full:cache

15  * Ext2 and ext4 use this cache for deduplication of extended attribute blocks.
20 * identifies a cache entry.
32 /* Maximum entries in cache to avoid degrading hash too much */
37 /* Number of entries in cache */
40 /* Work for shrinking when the cache has too many entries */
46 static unsigned long mb_cache_shrink(struct mb_cache *cache,
49 static inline struct hlist_bl_head *mb_cache_entry_head(struct mb_cache *cache, in mb_cache_entry_head() argument
52 return &cache->c_hash[hash_32(key, cache->c_bucket_bits)]; in mb_cache_entry_head()
57 * in cache
62 * mb_cache_entry_create - create entry in cache
63 * @cache - cache where the entry should be created
69 * Creates entry in @cache with key @key and value @value. The function returns
70 * -EBUSY if entry with the same key and value already exists in cache.
73 int mb_cache_entry_create(struct mb_cache *cache, gfp_t mask, u32 key, in mb_cache_entry_create() argument
81 if (cache->c_entry_count >= cache->c_max_entries) in mb_cache_entry_create()
82 schedule_work(&cache->c_shrink_work); in mb_cache_entry_create()
84 if (cache->c_entry_count >= 2*cache->c_max_entries) in mb_cache_entry_create()
85 mb_cache_shrink(cache, SYNC_SHRINK_BATCH); in mb_cache_entry_create()
98 head = mb_cache_entry_head(cache, key); in mb_cache_entry_create()
110 spin_lock(&cache->c_list_lock); in mb_cache_entry_create()
111 list_add_tail(&entry->e_list, &cache->c_list); in mb_cache_entry_create()
114 cache->c_entry_count++; in mb_cache_entry_create()
115 spin_unlock(&cache->c_list_lock); in mb_cache_entry_create()
127 static struct mb_cache_entry *__entry_find(struct mb_cache *cache, in __entry_find() argument
135 head = mb_cache_entry_head(cache, key); in __entry_find()
154 mb_cache_entry_put(cache, old_entry); in __entry_find()
161 * @cache: cache where we should search
164 * Search in @cache for a reusable entry with key @key. Grabs reference to the
167 struct mb_cache_entry *mb_cache_entry_find_first(struct mb_cache *cache, in mb_cache_entry_find_first() argument
170 return __entry_find(cache, NULL, key); in mb_cache_entry_find_first()
176 * @cache: cache where we should search
184 struct mb_cache_entry *mb_cache_entry_find_next(struct mb_cache *cache, in mb_cache_entry_find_next() argument
187 return __entry_find(cache, entry, entry->e_key); in mb_cache_entry_find_next()
192 * mb_cache_entry_get - get a cache entry by value (and key)
193 * @cache - cache we work with
197 struct mb_cache_entry *mb_cache_entry_get(struct mb_cache *cache, u32 key, in mb_cache_entry_get() argument
204 head = mb_cache_entry_head(cache, key); in mb_cache_entry_get()
219 /* mb_cache_entry_delete - remove a cache entry
220 * @cache - cache we work with
224 * Remove entry from cache @cache with key @key and value @value.
226 void mb_cache_entry_delete(struct mb_cache *cache, u32 key, u64 value) in mb_cache_entry_delete() argument
232 head = mb_cache_entry_head(cache, key); in mb_cache_entry_delete()
239 spin_lock(&cache->c_list_lock); in mb_cache_entry_delete()
242 if (!WARN_ONCE(cache->c_entry_count == 0, in mb_cache_entry_delete()
244 cache->c_entry_count--; in mb_cache_entry_delete()
247 spin_unlock(&cache->c_list_lock); in mb_cache_entry_delete()
248 mb_cache_entry_put(cache, entry); in mb_cache_entry_delete()
256 /* mb_cache_entry_touch - cache entry got used
257 * @cache - cache the entry belongs to
260 * Marks entry as used to give hit higher chances of surviving in cache.
262 void mb_cache_entry_touch(struct mb_cache *cache, in mb_cache_entry_touch() argument
272 struct mb_cache *cache = container_of(shrink, struct mb_cache, in mb_cache_count() local
275 return cache->c_entry_count; in mb_cache_count()
278 /* Shrink number of entries in cache */
279 static unsigned long mb_cache_shrink(struct mb_cache *cache, in mb_cache_shrink() argument
286 spin_lock(&cache->c_list_lock); in mb_cache_shrink()
287 while (nr_to_scan-- && !list_empty(&cache->c_list)) { in mb_cache_shrink()
288 entry = list_first_entry(&cache->c_list, in mb_cache_shrink()
292 list_move_tail(&entry->e_list, &cache->c_list); in mb_cache_shrink()
296 cache->c_entry_count--; in mb_cache_shrink()
301 spin_unlock(&cache->c_list_lock); in mb_cache_shrink()
302 head = mb_cache_entry_head(cache, entry->e_key); in mb_cache_shrink()
309 if (mb_cache_entry_put(cache, entry)) in mb_cache_shrink()
312 spin_lock(&cache->c_list_lock); in mb_cache_shrink()
314 spin_unlock(&cache->c_list_lock); in mb_cache_shrink()
322 struct mb_cache *cache = container_of(shrink, struct mb_cache, in mb_cache_scan() local
324 return mb_cache_shrink(cache, sc->nr_to_scan); in mb_cache_scan()
327 /* We shrink 1/X of the cache when we have too many entries in it */
332 struct mb_cache *cache = container_of(work, struct mb_cache, in mb_cache_shrink_worker() local
334 mb_cache_shrink(cache, cache->c_max_entries / SHRINK_DIVISOR); in mb_cache_shrink_worker()
338 * mb_cache_create - create cache
341 * Create cache for keys with 2^bucket_bits hash entries.
345 struct mb_cache *cache; in mb_cache_create() local
349 cache = kzalloc(sizeof(struct mb_cache), GFP_KERNEL); in mb_cache_create()
350 if (!cache) in mb_cache_create()
352 cache->c_bucket_bits = bucket_bits; in mb_cache_create()
353 cache->c_max_entries = bucket_count << 4; in mb_cache_create()
354 INIT_LIST_HEAD(&cache->c_list); in mb_cache_create()
355 spin_lock_init(&cache->c_list_lock); in mb_cache_create()
356 cache->c_hash = kmalloc_array(bucket_count, in mb_cache_create()
359 if (!cache->c_hash) { in mb_cache_create()
360 kfree(cache); in mb_cache_create()
364 INIT_HLIST_BL_HEAD(&cache->c_hash[i]); in mb_cache_create()
366 cache->c_shrink.count_objects = mb_cache_count; in mb_cache_create()
367 cache->c_shrink.scan_objects = mb_cache_scan; in mb_cache_create()
368 cache->c_shrink.seeks = DEFAULT_SEEKS; in mb_cache_create()
369 if (register_shrinker(&cache->c_shrink)) { in mb_cache_create()
370 kfree(cache->c_hash); in mb_cache_create()
371 kfree(cache); in mb_cache_create()
375 INIT_WORK(&cache->c_shrink_work, mb_cache_shrink_worker); in mb_cache_create()
377 return cache; in mb_cache_create()
385 * mb_cache_destroy - destroy cache
386 * @cache: the cache to destroy
388 * Free all entries in cache and cache itself. Caller must make sure nobody
389 * (except shrinker) can reach @cache when calling this.
391 void mb_cache_destroy(struct mb_cache *cache) in mb_cache_destroy() argument
395 unregister_shrinker(&cache->c_shrink); in mb_cache_destroy()
398 * We don't bother with any locking. Cache must not be used at this in mb_cache_destroy()
401 list_for_each_entry_safe(entry, next, &cache->c_list, e_list) { in mb_cache_destroy()
409 mb_cache_entry_put(cache, entry); in mb_cache_destroy()
411 kfree(cache->c_hash); in mb_cache_destroy()
412 kfree(cache); in mb_cache_destroy()
435 MODULE_DESCRIPTION("Meta block cache (for extended attributes)");