Lines Matching refs: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;
88 entry = kmem_cache_alloc(mb_entry_cache, mask);
89 if (!entry)
92 INIT_LIST_HEAD(&entry->e_list);
94 * We create entry with two references. One reference is kept by the
96 * mb_cache_entry_delete_or_get() until the entry is fully setup. This
100 atomic_set(&entry->e_refcnt, 2);
101 entry->e_key = key;
102 entry->e_value = value;
103 entry->e_flags = 0;
105 set_bit(MBE_REUSABLE_B, &entry->e_flags);
111 kmem_cache_free(mb_entry_cache, entry);
115 hlist_bl_add_head(&entry->e_hash_list, head);
118 list_add_tail(&entry->e_list, &cache->c_list);
121 mb_cache_entry_put(cache, entry);
127 void __mb_cache_entry_free(struct mb_cache *cache, struct mb_cache_entry *entry)
131 head = mb_cache_entry_head(cache, entry->e_key);
133 hlist_bl_del(&entry->e_hash_list);
135 kmem_cache_free(mb_entry_cache, entry);
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)
148 wait_var_event(&entry->e_refcnt, atomic_read(&entry->e_refcnt) <= 2);
153 struct mb_cache_entry *entry,
156 struct mb_cache_entry *old_entry = entry;
162 if (entry && !hlist_bl_unhashed(&entry->e_hash_list))
163 node = entry->e_hash_list.next;
167 entry = hlist_bl_entry(node, struct mb_cache_entry,
169 if (entry->e_key == key &&
170 test_bit(MBE_REUSABLE_B, &entry->e_flags) &&
171 atomic_inc_not_zero(&entry->e_refcnt))
175 entry = NULL;
181 return entry;
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)
212 return __entry_find(cache, entry, entry->e_key);
217 * mb_cache_entry_get - get a cache entry by value (and key)
227 struct mb_cache_entry *entry;
231 hlist_bl_for_each_entry(entry, node, head, e_hash_list) {
232 if (entry->e_key == key && entry->e_value == value &&
233 atomic_inc_not_zero(&entry->e_refcnt))
236 entry = NULL;
239 return entry;
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;
259 entry = mb_cache_entry_get(cache, key, value);
260 if (!entry)
267 if (atomic_cmpxchg(&entry->e_refcnt, 2, 0) != 2)
268 return entry;
271 if (!list_empty(&entry->e_list))
272 list_del_init(&entry->e_list);
275 __mb_cache_entry_free(cache, entry);
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)
289 set_bit(MBE_REFERENCED_B, &entry->e_flags);
306 struct mb_cache_entry *entry;
311 entry = list_first_entry(&cache->c_list,
314 if (test_bit(MBE_REFERENCED_B, &entry->e_flags) ||
315 atomic_cmpxchg(&entry->e_refcnt, 1, 0) != 1) {
316 clear_bit(MBE_REFERENCED_B, &entry->e_flags);
317 list_move_tail(&entry->e_list, &cache->c_list);
320 list_del_init(&entry->e_list);
323 __mb_cache_entry_free(cache, entry);
407 struct mb_cache_entry *entry, *next;
415 list_for_each_entry_safe(entry, next, &cache->c_list, e_list) {
416 list_del(&entry->e_list);
417 WARN_ON(atomic_read(&entry->e_refcnt) != 1);
418 mb_cache_entry_put(cache, entry);