From patchwork Sat Jan 20 02:40:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13524321 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3FBC7C47DAF for ; Sat, 20 Jan 2024 02:40:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 754156B007D; Fri, 19 Jan 2024 21:40:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 68D936B007E; Fri, 19 Jan 2024 21:40:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4BB736B0080; Fri, 19 Jan 2024 21:40:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 258906B007D for ; Fri, 19 Jan 2024 21:40:16 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id EA718A0402 for ; Sat, 20 Jan 2024 02:40:15 +0000 (UTC) X-FDA: 81698135190.12.B4FA5B4 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf24.hostedemail.com (Postfix) with ESMTP id 2DDD6180012 for ; Sat, 20 Jan 2024 02:40:13 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=p3s8rEa9; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf24.hostedemail.com: domain of 3jTKrZQoKCNIMCGFMy5A214CC492.0CA96BIL-AA8Jy08.CF4@flex--yosryahmed.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3jTKrZQoKCNIMCGFMy5A214CC492.0CA96BIL-AA8Jy08.CF4@flex--yosryahmed.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1705718414; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=fLiPaqnX6yFRN11bVOzAvgH/n62qJ4AjDWPdtJN5Ujg=; b=MlX5tv59ZKuJfdDtGQVjQSKuT1Z4dX6H84QEf2JZCQ5NwW/SdeWgcZR/2j4AqJQ1Z77kwm xCl4m0WPXFKSQBOyAWrm5hPh4fvN6xAO9tDRBb1mV0VczNc7SBtsBtFZ4qWBLe7JMc0q2C vIAOucjX4VXwsjJvcHBkCyCDmj8txnE= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=p3s8rEa9; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf24.hostedemail.com: domain of 3jTKrZQoKCNIMCGFMy5A214CC492.0CA96BIL-AA8Jy08.CF4@flex--yosryahmed.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3jTKrZQoKCNIMCGFMy5A214CC492.0CA96BIL-AA8Jy08.CF4@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1705718414; a=rsa-sha256; cv=none; b=QftAvUq+VwcoIhMG12mAm00p6FRSw4CA8dmQwcD72zu6BM1Nd6DOxYrimvWI1tPRJwSI+Q GsFsZIR3K8rWyTrH8pKUdA3zqpi5mvAftpj7f2e+4vBg5CimvcaKyBPf5l5PuLS/agwXkj P5jdoyyXqi3WGiRHISEbnLF3sLcQj34= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc26605c3aaso1704993276.0 for ; Fri, 19 Jan 2024 18:40:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1705718413; x=1706323213; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=fLiPaqnX6yFRN11bVOzAvgH/n62qJ4AjDWPdtJN5Ujg=; b=p3s8rEa9cS8d8x+1h9im3dc4flR2HXzywEU0BGJvE/xjeM9Wr84qEh2oo+4KHaceH0 lPFnDP1frsL4JwRY3zqwPtPcgPhtdKHlV1xnhNJpTLr5k1mr7Y+B7yaMZ32ztTbvteJp k/pWee+oube7kChwcWERCNF1nCm1D8wjdT0L+UI6YRtSWuFO1VbVorYHujN4Gbg7BPlY nUmBLdoD/l5AgExbnPvgrp+yjVIR2W27B2YXgh6vyheP+/T/cO0Iw5Ou4pIdNg5zQM4N wIAYoqmLCiAaQQjZ2ErNS1TGC3o8bz0RwI9bqinBWxmOvdiHvkb80UNSYiKNoy3j9ZwS XfYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705718413; x=1706323213; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fLiPaqnX6yFRN11bVOzAvgH/n62qJ4AjDWPdtJN5Ujg=; b=M7/9pKEkgr5QmFn+MeTlECx3CVgtE0nWoqWrIYBVELS+gsOKiy+/KQ9ord5D5fDJIp dBLTRJrM/NgGzVEDBKqP9CKhCc/l3KJmi8sfmWgKQPla/CaiVbx6HhVFPqQ+t9mTkBf3 uQLqsdFJQWPXetg9HyjcA7wCYST8IJxAVneIp1NsSSPeA5rcr+Y7w7r2Fd/QWb1mWHkn cGW88KNCt/jepAX5+RiKksp9bCTIzmvNUdU4h6I8w/GMOal0SXEvbGnR+KWclTAECRJ3 fKNsXTCCstp9pDbsXnstOKT6nU+qfyHKTB9L62eGdrjjeDk2P/mLhqpKJAcdUQ0YKSiG 7kiQ== X-Gm-Message-State: AOJu0Yxbde/sItmnJxXw6lLJhQrii5IhfugbXZ0wpKW46s6fVu+i+qLi aRMJahzMtSTotxE/hvXxxQ0CnckHzATVBIwFjLge83DLFuVLpop5f5ha8efdtF5+IVhhRPjdys1 uS4CJXTtH+u2/ktD2VQ== X-Google-Smtp-Source: AGHT+IH62W2NQREKfSMAniaidxoTrzRePf8+sI0VOkuK1PVXyK3gj/XmLpZGQU6WH8o8uGiygsMnl+Yr/Hd/Kj2B X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:6902:b1f:b0:dbe:abc7:ae5c with SMTP id ch31-20020a0569020b1f00b00dbeabc7ae5cmr76590ybb.3.1705718413333; Fri, 19 Jan 2024 18:40:13 -0800 (PST) Date: Sat, 20 Jan 2024 02:40:07 +0000 In-Reply-To: <20240120024007.2850671-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20240120024007.2850671-1-yosryahmed@google.com> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: <20240120024007.2850671-3-yosryahmed@google.com> Subject: [PATCH 2/2] mm: zswap: remove unnecessary tree cleanups in zswap_swapoff() From: Yosry Ahmed To: Andrew Morton Cc: Johannes Weiner , Nhat Pham , Chris Li , Chengming Zhou , Huang Ying , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yosry Ahmed X-Rspamd-Queue-Id: 2DDD6180012 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 8p41psr1i8a9wexbw661i815i9n6xkhy X-HE-Tag: 1705718413-234124 X-HE-Meta: U2FsdGVkX192wNO1PFTRLy0ud0rVvA59PNS36i0UIVbNNl7b8aAGMRRxxTorlERWi66M5zNk1/Na1NgVhigt17SaA3bNx14YBB+J2UYI+Ma83JYrX8NWCq17NAi+++7KHReAt6XH5FIA4nWRhnMViFiH8j8tAC72dJnrVR5rt9TIUib6oFF3In5NsWTO9uCsu+SbTUU6hOTStmR+nPtI3bhCfsaLhxrowolP5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qKg87KYNxBjRLljTBzz/AIbhdLVdE7ix/L9dTmXKV0ogVKb1V52VrtzZ6JYGi0iKIBEGpsyg2a4BaRdsIFbpNBev1DOT/9QHRm9tTZrMWXhKRfg2KIaFBUg+/0IGIeFrLKwRrwNPEkaDZc2vLOotB9VZXuaLYhJHOLkYE7JryufBZpoEjHL/ig+b1WP31EvOMooAokK5Inhy0hBcjZ8eKCEopIVZq7hyXcG8WSdyyob9ITrPFNp3XYG3OePwXTqzvxRdT/sRIXWYhb3EbQKGsOSX3FmJY8hiB5n45ihD/XFRCvQbLXG/V6/4MGiGm38qdvJp3xwVZ7ZNBprhvMkGwitcGI1nvPKI+FrRyzn+qQRiJ7EkrF9ARr1uDCg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 tree cleanup loop, and leaving an assertion in its place. Signed-off-by: Yosry Ahmed Reviewed-by: Chengming Zhou Acked-by: Johannes Weiner Acked-by: Nhat Pham Acked-by: Chris Li (Google) --- Chengming, Chris, I think this should make the tree split and the xarray conversion patches simpler (especially the former). If others agree, both changes can be rebased on top of this. --- mm/zswap.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index f8bc9e0892687..9675c3c27f9d1 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1790,17 +1790,12 @@ void zswap_swapon(int type) void zswap_swapoff(int type) { struct zswap_tree *tree = zswap_trees[type]; - struct zswap_entry *entry, *n; if (!tree) return; - /* 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 entries already */ + WARN_ON_ONCE(!RB_EMPTY_ROOT(&tree->rbroot)); kfree(tree); zswap_trees[type] = NULL; }