[v2,2/2] mm: zswap: remove unnecessary trees cleanups in zswap_swapoff()

Message ID 20240124045113.415378-3-yosryahmed@google.com
State New
Headers
Series mm: zswap: simplify zswap_swapoff() |

Commit Message

Yosry Ahmed Jan. 24, 2024, 4:51 a.m. UTC
  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.

Signed-off-by: Yosry Ahmed <yosryahmed@google.com>
---
 mm/zswap.c | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)
  

Comments

Yosry Ahmed Jan. 24, 2024, 4:52 a.m. UTC | #1
On Tue, Jan 23, 2024 at 8:51 PM Yosry Ahmed <yosryahmed@google.com> wrote:
>
> 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.
>
> Signed-off-by: Yosry Ahmed <yosryahmed@google.com>

Johannes, Nhat, I didn't carry the Acks forward after the rebase as
the code changed significantly.
  
Chengming Zhou Jan. 24, 2024, 7:34 a.m. UTC | #2
On 2024/1/24 12:51, Yosry Ahmed wrote:
> 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.
> 
> Signed-off-by: Yosry Ahmed <yosryahmed@google.com>

Looks good to me, thanks!

Reviewed-by: Chengming Zhou <zhouchengming@bytedance.com>

> ---
>  mm/zswap.c | 16 +++-------------
>  1 file changed, 3 insertions(+), 13 deletions(-)
> 
> diff --git a/mm/zswap.c b/mm/zswap.c
> index dcdd5ecfedb09..78df16d307aa8 100644
> --- a/mm/zswap.c
> +++ b/mm/zswap.c
> @@ -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;
  

Patch

diff --git a/mm/zswap.c b/mm/zswap.c
index dcdd5ecfedb09..78df16d307aa8 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -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;