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_reusable = reusable; in mb_cache_entry_create()
104 entry->e_referenced = 0; in mb_cache_entry_create()
110 kmem_cache_free(mb_entry_cache, entry); in mb_cache_entry_create()
114 hlist_bl_add_head(&entry->e_hash_list, head); in mb_cache_entry_create()
117 list_add_tail(&entry->e_list, &cache->c_list); in mb_cache_entry_create()
120 mb_cache_entry_put(cache, entry); in mb_cache_entry_create()
126 void __mb_cache_entry_free(struct mb_cache *cache, struct mb_cache_entry *entry) in __mb_cache_entry_free() argument
130 head = mb_cache_entry_head(cache, entry->e_key); in __mb_cache_entry_free()
132 hlist_bl_del(&entry->e_hash_list); in __mb_cache_entry_free()
134 kmem_cache_free(mb_entry_cache, entry); in __mb_cache_entry_free()
139 * mb_cache_entry_wait_unused - wait to be the last user of the entry
141 * @entry - entry to work on
143 * Wait to be the last user of the entry.
145 void mb_cache_entry_wait_unused(struct mb_cache_entry *entry) in mb_cache_entry_wait_unused() argument
147 wait_var_event(&entry->e_refcnt, atomic_read(&entry->e_refcnt) <= 2); in mb_cache_entry_wait_unused()
152 struct mb_cache_entry *entry, in __entry_find() argument
155 struct mb_cache_entry *old_entry = entry; in __entry_find()
161 if (entry && !hlist_bl_unhashed(&entry->e_hash_list)) in __entry_find()
162 node = entry->e_hash_list.next; in __entry_find()
166 entry = hlist_bl_entry(node, struct mb_cache_entry, in __entry_find()
168 if (entry->e_key == key && entry->e_reusable && in __entry_find()
169 atomic_inc_not_zero(&entry->e_refcnt)) in __entry_find()
173 entry = NULL; in __entry_find()
179 return entry; in __entry_find()
183 * mb_cache_entry_find_first - find the first reusable entry with the given key
187 * Search in @cache for a reusable entry with key @key. Grabs reference to the
188 * first reusable entry found and returns the entry.
198 * mb_cache_entry_find_next - find next reusable entry with the same key
200 * @entry: entry to start search from
202 * Finds next reusable entry in the hash chain which has the same key as @entry.
203 * If @entry is unhashed (which can happen when deletion of entry races with the
204 * search), finds the first reusable entry in the hash chain. The function drops
205 * reference to @entry and returns with a reference to the found entry.
208 struct mb_cache_entry *entry) in mb_cache_entry_find_next() argument
210 return __entry_find(cache, entry, entry->e_key); in mb_cache_entry_find_next()
215 * mb_cache_entry_get - get a cache entry by value (and key)
225 struct mb_cache_entry *entry; in mb_cache_entry_get() local
229 hlist_bl_for_each_entry(entry, node, head, e_hash_list) { in mb_cache_entry_get()
230 if (entry->e_key == key && entry->e_value == value && in mb_cache_entry_get()
231 atomic_inc_not_zero(&entry->e_refcnt)) in mb_cache_entry_get()
234 entry = NULL; in mb_cache_entry_get()
237 return entry; in mb_cache_entry_get()
241 /* mb_cache_entry_delete_or_get - remove a cache entry if it has no users
246 * Remove entry from cache @cache with key @key and value @value. The removal
247 * happens only if the entry is unused. The function returns NULL in case the
248 * entry was successfully removed or there's no entry in cache. Otherwise the
249 * function grabs reference of the entry that we failed to delete because it
255 struct mb_cache_entry *entry; in mb_cache_entry_delete_or_get() local
257 entry = mb_cache_entry_get(cache, key, value); in mb_cache_entry_delete_or_get()
258 if (!entry) in mb_cache_entry_delete_or_get()
265 if (atomic_cmpxchg(&entry->e_refcnt, 2, 0) != 2) in mb_cache_entry_delete_or_get()
266 return entry; in mb_cache_entry_delete_or_get()
269 if (!list_empty(&entry->e_list)) in mb_cache_entry_delete_or_get()
270 list_del_init(&entry->e_list); in mb_cache_entry_delete_or_get()
273 __mb_cache_entry_free(cache, entry); in mb_cache_entry_delete_or_get()
278 /* mb_cache_entry_touch - cache entry got used
279 * @cache - cache the entry belongs to
280 * @entry - entry that got used
282 * Marks entry as used to give hit higher chances of surviving in cache.
285 struct mb_cache_entry *entry) in mb_cache_entry_touch() argument
287 entry->e_referenced = 1; in mb_cache_entry_touch()
304 struct mb_cache_entry *entry; in mb_cache_shrink() local
309 entry = list_first_entry(&cache->c_list, in mb_cache_shrink()
312 if (entry->e_referenced || in mb_cache_shrink()
313 atomic_cmpxchg(&entry->e_refcnt, 1, 0) != 1) { in mb_cache_shrink()
314 entry->e_referenced = 0; in mb_cache_shrink()
315 list_move_tail(&entry->e_list, &cache->c_list); in mb_cache_shrink()
318 list_del_init(&entry->e_list); in mb_cache_shrink()
321 __mb_cache_entry_free(cache, entry); in mb_cache_shrink()
405 struct mb_cache_entry *entry, *next; in mb_cache_destroy() local
413 list_for_each_entry_safe(entry, next, &cache->c_list, e_list) { in mb_cache_destroy()
414 list_del(&entry->e_list); in mb_cache_destroy()
415 WARN_ON(atomic_read(&entry->e_refcnt) != 1); in mb_cache_destroy()
416 mb_cache_entry_put(cache, entry); in mb_cache_destroy()