0001
0002 #ifndef _LINUX_MBCACHE_H
0003 #define _LINUX_MBCACHE_H
0004
0005 #include <linux/hash.h>
0006 #include <linux/list_bl.h>
0007 #include <linux/list.h>
0008 #include <linux/atomic.h>
0009 #include <linux/fs.h>
0010
0011 struct mb_cache;
0012
0013 struct mb_cache_entry {
0014
0015 struct list_head e_list;
0016
0017
0018
0019
0020 struct hlist_bl_node e_hash_list;
0021
0022
0023
0024
0025
0026 atomic_t e_refcnt;
0027
0028 u32 e_key;
0029 u32 e_referenced:1;
0030 u32 e_reusable:1;
0031
0032 u64 e_value;
0033 };
0034
0035 struct mb_cache *mb_cache_create(int bucket_bits);
0036 void mb_cache_destroy(struct mb_cache *cache);
0037
0038 int mb_cache_entry_create(struct mb_cache *cache, gfp_t mask, u32 key,
0039 u64 value, bool reusable);
0040 void __mb_cache_entry_free(struct mb_cache *cache,
0041 struct mb_cache_entry *entry);
0042 void mb_cache_entry_wait_unused(struct mb_cache_entry *entry);
0043 static inline void mb_cache_entry_put(struct mb_cache *cache,
0044 struct mb_cache_entry *entry)
0045 {
0046 unsigned int cnt = atomic_dec_return(&entry->e_refcnt);
0047
0048 if (cnt > 0) {
0049 if (cnt <= 2)
0050 wake_up_var(&entry->e_refcnt);
0051 return;
0052 }
0053 __mb_cache_entry_free(cache, entry);
0054 }
0055
0056 struct mb_cache_entry *mb_cache_entry_delete_or_get(struct mb_cache *cache,
0057 u32 key, u64 value);
0058 struct mb_cache_entry *mb_cache_entry_get(struct mb_cache *cache, u32 key,
0059 u64 value);
0060 struct mb_cache_entry *mb_cache_entry_find_first(struct mb_cache *cache,
0061 u32 key);
0062 struct mb_cache_entry *mb_cache_entry_find_next(struct mb_cache *cache,
0063 struct mb_cache_entry *entry);
0064 void mb_cache_entry_touch(struct mb_cache *cache,
0065 struct mb_cache_entry *entry);
0066
0067 #endif