Lines Matching refs:entry
64 /* Store failed because the entry metadata could not be allocated (rare) */
147 * rbnode - links the entry into red-black tree for the appropriate swap type
148 * offset - the swap offset for the entry. Index into the red-black tree.
149 * refcount - the number of outstanding reference to the entry. This is needed
150 * to protect against premature freeing of the entry by code
152 * for the zswap_tree structure that contains the entry must
157 * pool - the zswap_pool the entry's data is in
180 * - the refcount field of each entry in the tree
250 * zswap entry functions
267 struct zswap_entry *entry;
268 entry = kmem_cache_alloc(zswap_entry_cache, gfp);
269 if (!entry)
271 entry->refcount = 1;
272 RB_CLEAR_NODE(&entry->rbnode);
273 return entry;
276 static void zswap_entry_cache_free(struct zswap_entry *entry)
278 kmem_cache_free(zswap_entry_cache, entry);
287 struct zswap_entry *entry;
290 entry = rb_entry(node, struct zswap_entry, rbnode);
291 if (entry->offset > offset)
293 else if (entry->offset < offset)
296 return entry;
302 * In the case that a entry with the same offset is found, a pointer to
303 * the existing entry is stored in dupentry and the function returns -EEXIST
305 static int zswap_rb_insert(struct rb_root *root, struct zswap_entry *entry,
314 if (myentry->offset > entry->offset)
316 else if (myentry->offset < entry->offset)
323 rb_link_node(&entry->rbnode, parent, link);
324 rb_insert_color(&entry->rbnode, root);
328 static void zswap_rb_erase(struct rb_root *root, struct zswap_entry *entry)
330 if (!RB_EMPTY_NODE(&entry->rbnode)) {
331 rb_erase(&entry->rbnode, root);
332 RB_CLEAR_NODE(&entry->rbnode);
337 * Carries out the common pattern of freeing and entry's zpool allocation,
338 * freeing the entry itself, and decrementing the number of stored pages.
340 static void zswap_free_entry(struct zswap_entry *entry)
342 if (!entry->length)
345 zpool_free(entry->pool->zpool, entry->handle);
346 zswap_pool_put(entry->pool);
348 zswap_entry_cache_free(entry);
354 static void zswap_entry_get(struct zswap_entry *entry)
356 entry->refcount++;
360 * remove from the tree and free it, if nobody reference the entry
363 struct zswap_entry *entry)
365 int refcount = --entry->refcount;
369 zswap_rb_erase(&tree->rbroot, entry);
370 zswap_free_entry(entry);
378 struct zswap_entry *entry;
380 entry = zswap_rb_search(root, offset);
381 if (entry)
382 zswap_entry_get(entry);
384 return entry;
834 * This function tries to find a page with the given swap entry
845 static int zswap_get_swap_cache_page(swp_entry_t entry,
850 *retpage = __read_swap_cache_async(entry, GFP_KERNEL,
860 * Attempts to free an entry by adding a page to the swap cache,
861 * decompressing the entry data into the page, and issuing a
877 struct zswap_entry *entry;
899 /* find and ref zswap entry */
901 entry = zswap_entry_find_get(&tree->rbroot, offset);
902 if (!entry) {
903 /* entry was invalidated */
910 BUG_ON(offset != entry->offset);
914 memcpy(tmp, src, entry->length);
935 tfm = *get_cpu_ptr(entry->pool->tfm);
936 ret = crypto_comp_decompress(tfm, src, entry->length,
938 put_cpu_ptr(entry->pool->tfm);
957 zswap_entry_put(tree, entry);
960 * There are two possible situations for entry here:
961 * (1) refcount is 1(normal case), entry is valid and on the tree
962 * (2) refcount is 0, entry is freed and not on the tree
964 * search the tree and free the entry if find entry
966 if (entry == zswap_rb_search(&tree->rbroot, offset))
967 zswap_entry_put(tree, entry);
975 * it is safe and okay to not free the entry
976 * if we free the entry in the following put
981 zswap_entry_put(tree, entry);
1023 struct zswap_entry *entry, *dupentry;
1065 /* allocate entry */
1066 entry = zswap_entry_cache_alloc(GFP_KERNEL);
1067 if (!entry) {
1077 entry->offset = offset;
1078 entry->length = 0;
1079 entry->value = value;
1086 /* if entry is successfully added, it keeps the reference */
1087 entry->pool = zswap_pool_current_get();
1088 if (!entry->pool) {
1095 tfm = *get_cpu_ptr(entry->pool->tfm);
1099 put_cpu_ptr(entry->pool->tfm);
1106 hlen = zpool_evictable(entry->pool->zpool) ? sizeof(zhdr) : 0;
1108 if (zpool_malloc_support_movable(entry->pool->zpool))
1110 ret = zpool_malloc(entry->pool->zpool, hlen + dlen, gfp, &handle);
1119 buf = zpool_map_handle(entry->pool->zpool, handle, ZPOOL_MM_RW);
1122 zpool_unmap_handle(entry->pool->zpool, handle);
1125 /* populate entry */
1126 entry->offset = offset;
1127 entry->handle = handle;
1128 entry->length = dlen;
1134 ret = zswap_rb_insert(&tree->rbroot, entry, &dupentry);
1152 zswap_pool_put(entry->pool);
1154 zswap_entry_cache_free(entry);
1161 * return -1 on entry not found or error
1167 struct zswap_entry *entry;
1175 entry = zswap_entry_find_get(&tree->rbroot, offset);
1176 if (!entry) {
1177 /* entry was written back */
1183 if (!entry->length) {
1185 zswap_fill_page(dst, entry->value);
1191 if (!zpool_can_sleep_mapped(entry->pool->zpool)) {
1192 tmp = kmalloc(entry->length, GFP_ATOMIC);
1201 src = zpool_map_handle(entry->pool->zpool, entry->handle, ZPOOL_MM_RO);
1202 if (zpool_evictable(entry->pool->zpool))
1205 if (!zpool_can_sleep_mapped(entry->pool->zpool)) {
1206 memcpy(tmp, src, entry->length);
1208 zpool_unmap_handle(entry->pool->zpool, entry->handle);
1212 tfm = *get_cpu_ptr(entry->pool->tfm);
1213 ret = crypto_comp_decompress(tfm, src, entry->length, dst, &dlen);
1214 put_cpu_ptr(entry->pool->tfm);
1217 if (zpool_can_sleep_mapped(entry->pool->zpool))
1218 zpool_unmap_handle(entry->pool->zpool, entry->handle);
1226 zswap_entry_put(tree, entry);
1232 /* frees an entry in zswap */
1236 struct zswap_entry *entry;
1240 entry = zswap_rb_search(&tree->rbroot, offset);
1241 if (!entry) {
1242 /* entry was written back */
1248 zswap_rb_erase(&tree->rbroot, entry);
1250 /* drop the initial reference from entry creation */
1251 zswap_entry_put(tree, entry);
1260 struct zswap_entry *entry, *n;
1267 rbtree_postorder_for_each_entry_safe(entry, n, &tree->rbroot, rbnode)
1268 zswap_free_entry(entry);
1361 pr_err("entry cache creation failed\n");