On Mon, Jun 05, 2023 at 10:54:18AM +0200, Domenico Cerasuolo wrote: > @@ -1142,9 +1122,6 @@ static int zswap_writeback_entry(struct zpool *pool, unsigned long handle) > zswap_written_back_pages++; > > spin_lock(&tree->lock); > - /* drop local reference */ > - zswap_entry_put(tree, entry); > - > /* > * There are two possible situations for entry here: > * (1) refcount is 1(normal case), entry is valid and on the tree > @@ -1152,7 +1129,7 @@ static int zswap_writeback_entry(struct zpool *pool, unsigned long handle) > * because invalidate happened during writeback > * search the tree and free the entry if find entry > */ > - if (entry == zswap_rb_search(&tree->rbroot, offset)) > + if (entry == zswap_rb_search(&tree->rbroot, swp_offset(swpentry))) > zswap_entry_put(tree, entry); > spin_unlock(&tree->lock); This can be moved to zswap_shrink() as well. It already has a post-writeback tree->lock section for lru putback and dropping its local reference, it should do this as well. Writeback is then is done after it bumped zswap_written_pages.