Skip to content

Commit

Permalink
mm: zswap: remove unnecessary trees cleanups in zswap_swapoff()
Browse files Browse the repository at this point in the history
During swapoff, try_to_unuse() makes sure that zswap_invalidate() is
called for all swap entries before zswap_swapoff() is called.  This means
that all zswap entries should already be removed from the tree.  Simplify
zswap_swapoff() by removing the trees cleanup code, and leave an assertion
in its place.

Link: https://lkml.kernel.org/r/20240124045113.415378-3-yosryahmed@google.com
Signed-off-by: Yosry Ahmed <yosryahmed@google.com>
Reviewed-by: Chengming Zhou <zhouchengming@bytedance.com>
Cc: Chris Li <chrisl@kernel.org>
Cc: "Huang, Ying" <ying.huang@intel.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Nhat Pham <nphamcs@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
  • Loading branch information
Yosry Ahmed authored and Andrew Morton committed Feb 22, 2024
1 parent 64cf264 commit 83e68f2
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions mm/zswap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1808,19 +1808,9 @@ void zswap_swapoff(int type)
if (!trees)
return;

for (i = 0; i < nr_zswap_trees[type]; i++) {
struct zswap_tree *tree = trees + i;
struct zswap_entry *entry, *n;

/* walk the tree and free everything */
spin_lock(&tree->lock);
rbtree_postorder_for_each_entry_safe(entry, n,
&tree->rbroot,
rbnode)
zswap_free_entry(entry);
tree->rbroot = RB_ROOT;
spin_unlock(&tree->lock);
}
/* try_to_unuse() invalidated all the entries already */
for (i = 0; i < nr_zswap_trees[type]; i++)
WARN_ON_ONCE(!RB_EMPTY_ROOT(&trees[i].rbroot));

kvfree(trees);
nr_zswap_trees[type] = 0;
Expand Down

0 comments on commit 83e68f2

Please sign in to comment.