Lines Matching full:entry

21  * identifies a cache entry.
24 * and a special "delete entry with given key-value pair" operation. Fixed
63 * mb_cache_entry_create - create entry in cache
64 * @cache - cache where the entry should be created
65 * @mask - gfp mask with which the entry should be allocated
66 * @key - key of the entry
67 * @value - value of the entry
68 * @reusable - is the entry reusable by others?
70 * Creates entry in @cache with key @key and value @value. The function returns
71 * -EBUSY if entry with the same key and value already exists in cache.
77 struct mb_cache_entry *entry, *dup; in mb_cache_entry_create() local
88 entry = kmem_cache_alloc(mb_entry_cache, mask); in mb_cache_entry_create()
89 if (!entry) in mb_cache_entry_create()
92 INIT_LIST_HEAD(&entry->e_list); in mb_cache_entry_create()
94 * We create entry with two references. One reference is kept by the in mb_cache_entry_create()
96 * mb_cache_entry_delete_or_get() until the entry is fully setup. This in mb_cache_entry_create()
100 atomic_set(&entry->e_refcnt, 2); in mb_cache_entry_create()
101 entry->e_key = key; in mb_cache_entry_create()
102 entry->e_value = value; in mb_cache_entry_create()
103 entry->e_flags = 0; in mb_cache_entry_create()
105 set_bit(MBE_REUSABLE_B, &entry->e_flags); in mb_cache_entry_create()
111 kmem_cache_free(mb_entry_cache, entry); in mb_cache_entry_create()
115 hlist_bl_add_head(&entry->e_hash_list, head); in mb_cache_entry_create()
118 list_add_tail(&entry->e_list, &cache->c_list); 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()
133 hlist_bl_del(&entry->e_hash_list); in __mb_cache_entry_free()
135 kmem_cache_free(mb_entry_cache, entry); in __mb_cache_entry_free()
140 * mb_cache_entry_wait_unused - wait to be the last user of the entry
142 * @entry - entry to work on
144 * Wait to be the last user of the entry.
146 void mb_cache_entry_wait_unused(struct mb_cache_entry *entry) in mb_cache_entry_wait_unused() argument
148 wait_var_event(&entry->e_refcnt, atomic_read(&entry->e_refcnt) <= 2); in mb_cache_entry_wait_unused()
153 struct mb_cache_entry *entry, in __entry_find() argument
156 struct mb_cache_entry *old_entry = entry; in __entry_find()
162 if (entry && !hlist_bl_unhashed(&entry->e_hash_list)) in __entry_find()
163 node = entry->e_hash_list.next; in __entry_find()
167 entry = hlist_bl_entry(node, struct mb_cache_entry, in __entry_find()
169 if (entry->e_key == key && in __entry_find()
170 test_bit(MBE_REUSABLE_B, &entry->e_flags) && in __entry_find()
171 atomic_inc_not_zero(&entry->e_refcnt)) in __entry_find()
175 entry = NULL; in __entry_find()
181 return entry; in __entry_find()
185 * mb_cache_entry_find_first - find the first reusable entry with the given key
189 * Search in @cache for a reusable entry with key @key. Grabs reference to the
190 * first reusable entry found and returns the entry.
200 * mb_cache_entry_find_next - find next reusable entry with the same key
202 * @entry: entry to start search from
204 * Finds next reusable entry in the hash chain which has the same key as @entry.
205 * If @entry is unhashed (which can happen when deletion of entry races with the
206 * search), finds the first reusable entry in the hash chain. The function drops
207 * reference to @entry and returns with a reference to the found entry.
210 struct mb_cache_entry *entry) in mb_cache_entry_find_next() argument
212 return __entry_find(cache, entry, entry->e_key); in mb_cache_entry_find_next()
217 * mb_cache_entry_get - get a cache entry by value (and key)
227 struct mb_cache_entry *entry; in mb_cache_entry_get() local
231 hlist_bl_for_each_entry(entry, node, head, e_hash_list) { in mb_cache_entry_get()
232 if (entry->e_key == key && entry->e_value == value && in mb_cache_entry_get()
233 atomic_inc_not_zero(&entry->e_refcnt)) in mb_cache_entry_get()
236 entry = NULL; in mb_cache_entry_get()
239 return entry; in mb_cache_entry_get()
243 /* mb_cache_entry_delete_or_get - remove a cache entry if it has no users
248 * Remove entry from cache @cache with key @key and value @value. The removal
249 * happens only if the entry is unused. The function returns NULL in case the
250 * entry was successfully removed or there's no entry in cache. Otherwise the
251 * function grabs reference of the entry that we failed to delete because it
257 struct mb_cache_entry *entry; in mb_cache_entry_delete_or_get() local
259 entry = mb_cache_entry_get(cache, key, value); in mb_cache_entry_delete_or_get()
260 if (!entry) in mb_cache_entry_delete_or_get()
267 if (atomic_cmpxchg(&entry->e_refcnt, 2, 0) != 2) in mb_cache_entry_delete_or_get()
268 return entry; in mb_cache_entry_delete_or_get()
271 if (!list_empty(&entry->e_list)) in mb_cache_entry_delete_or_get()
272 list_del_init(&entry->e_list); in mb_cache_entry_delete_or_get()
275 __mb_cache_entry_free(cache, entry); in mb_cache_entry_delete_or_get()
280 /* mb_cache_entry_touch - cache entry got used
281 * @cache - cache the entry belongs to
282 * @entry - entry that got used
284 * Marks entry as used to give hit higher chances of surviving in cache.
287 struct mb_cache_entry *entry) in mb_cache_entry_touch() argument
289 set_bit(MBE_REFERENCED_B, &entry->e_flags); in mb_cache_entry_touch()
305 struct mb_cache_entry *entry; in mb_cache_shrink() local
310 entry = list_first_entry(&cache->c_list, in mb_cache_shrink()
313 if (test_bit(MBE_REFERENCED_B, &entry->e_flags) || in mb_cache_shrink()
314 atomic_cmpxchg(&entry->e_refcnt, 1, 0) != 1) { in mb_cache_shrink()
315 clear_bit(MBE_REFERENCED_B, &entry->e_flags); in mb_cache_shrink()
316 list_move_tail(&entry->e_list, &cache->c_list); in mb_cache_shrink()
319 list_del_init(&entry->e_list); in mb_cache_shrink()
322 __mb_cache_entry_free(cache, entry); in mb_cache_shrink()
409 struct mb_cache_entry *entry, *next; in mb_cache_destroy() local
417 list_for_each_entry_safe(entry, next, &cache->c_list, e_list) { in mb_cache_destroy()
418 list_del(&entry->e_list); in mb_cache_destroy()
419 WARN_ON(atomic_read(&entry->e_refcnt) != 1); in mb_cache_destroy()
420 mb_cache_entry_put(cache, entry); in mb_cache_destroy()