Skip to content

Commit

Permalink
mm: zswap: tighten up entry invalidation
Browse files Browse the repository at this point in the history
Removing a zswap entry from the tree is tied to an explicit operation
that's supposed to drop the base reference: swap invalidation, exclusive
load, duplicate store.  Don't silently remove the entry on final put, but
instead warn if an entry is in tree without reference.

While in that diff context, convert a BUG_ON to a WARN_ON_ONCE.  No need
to crash on a refcount underflow.

Link: https://lkml.kernel.org/r/20230727162343.1415598-3-hannes@cmpxchg.org
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Reviewed-by: Yosry Ahmed <yosryahmed@google.com>
Cc: Barry Song <song.bao.hua@hisilicon.com>
Cc: Domenico Cerasuolo <cerasuolodomenico@gmail.com>
Cc: Nhat Pham <nphamcs@gmail.com>
Cc: Seth Jennings <sjenning@redhat.com>
Cc: Vitaly Wool <vitaly.wool@konsulko.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
  • Loading branch information
Johannes Weiner authored and Andrew Morton committed Aug 21, 2023
1 parent 56c6704 commit 7310895
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mm/zswap.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,9 @@ static void zswap_entry_put(struct zswap_tree *tree,
{
int refcount = --entry->refcount;

BUG_ON(refcount < 0);
WARN_ON_ONCE(refcount < 0);
if (refcount == 0) {
zswap_rb_erase(&tree->rbroot, entry);
WARN_ON_ONCE(!RB_EMPTY_NODE(&entry->rbnode));
zswap_free_entry(entry);
}
}
Expand Down

0 comments on commit 7310895

Please sign in to comment.