From patchwork Wed Jan 24 04:51:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13528535 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 CDC9EC46CD2 for ; Wed, 24 Jan 2024 04:51:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 589416B007E; Tue, 23 Jan 2024 23:51:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 538646B0080; Tue, 23 Jan 2024 23:51:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3D7EE6B0082; Tue, 23 Jan 2024 23:51:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 2D6BB6B007E for ; Tue, 23 Jan 2024 23:51:22 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 062E01C1049 for ; Wed, 24 Jan 2024 04:51:22 +0000 (UTC) X-FDA: 81712980804.01.49F7F64 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf30.hostedemail.com (Postfix) with ESMTP id 394E180016 for ; Wed, 24 Jan 2024 04:51:20 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=X6dMJnic; spf=pass (imf30.hostedemail.com: domain of 3R5ewZQoKCGwiYcbiKRWONQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--yosryahmed.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3R5ewZQoKCGwiYcbiKRWONQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706071880; 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=tkuiKBs8Z3LCxzx9sFvb10Ddko8C8l9RPXC0zaKu0yw=; b=JPz4/qcxUZ10HhcP8Judg6sXNYAziRho5B76McJ8IInd8C4XsiiJvLF+dG3zIZJUTAWWwX GyWGASbtHeAj3UHKsQ96iEZLdL0osswxk2PY4mpwTB76Mce5O6gf45K31+x3jlQuSrNZ5m +Itcij5l4fKLT1ZcwElZK6KWFd39Ebs= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=X6dMJnic; spf=pass (imf30.hostedemail.com: domain of 3R5ewZQoKCGwiYcbiKRWONQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--yosryahmed.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3R5ewZQoKCGwiYcbiKRWONQYYQVO.MYWVSXeh-WWUfKMU.YbQ@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706071880; a=rsa-sha256; cv=none; b=DxznwW3xusw8tu21voYaprE+/RwRlHdhisthFwlnG55BErfXZdA152PXC/Ba8d1XfTH6UG 4MEPakpRa5vyQKxL49wMLPK3mun3hw+qIAJXCSvqF5ZjpwJ6tjERzNOdDfcQSrayUxTV/P dRR/I/vBG2ORXJ8PIXrg3FUMOJBAsuE= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dbeac1f5045so6555580276.1 for ; Tue, 23 Jan 2024 20:51:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706071879; x=1706676679; 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=tkuiKBs8Z3LCxzx9sFvb10Ddko8C8l9RPXC0zaKu0yw=; b=X6dMJnic/l3dosczVaryprauQhlBZpsFzgYiQjpVKLyl2wbpWtgQVQ9hKlWE+aDKo+ GBMuPdVscJKGJjF9xmdKZ850g5Dxp9mWbQKyWc3uAVjpZNeiHlZGRxApcWaaY4WWmo29 YXX25k4dMv0sQ92EWMwzx/2O8/oQw9yvtTwzW6xDgU9AMyubYmvhPeJSOPSfvwzjxNKJ EcDFTAiUGNk/N+d+oAPBWwoQZ1NKZvuMKzCByN2d4H09eP30mzgd70QZe+Rp4t6lRHLw 6R6fTX8GhHDTGirZ3w6vtOjyMA7tOuoQaPS+Bgmh5Lpq6a8Vd9aqHUDrZ0VFb8Z73iM9 c6Yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706071879; x=1706676679; 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=tkuiKBs8Z3LCxzx9sFvb10Ddko8C8l9RPXC0zaKu0yw=; b=vWcn/zcxgrni8+UAQCBQxtuY8XlZF46Z4BoWYp+YIGgC+OmZvO4mHovqaATANyBkY4 re8xS42Cy81PdVSRP3RmHDXl7BotrvirlSzAK/q9TIGnCNkai1XEOBKb+fD7kWCxbkZw IbiYuW7uJuX3O5WITl7NfCbgnqwZpOdU1D79QdpXFVc6d0Sdh6z5S+rBf5xHKEEayoFH W7q/ExScBIxM+Oy36cP7+BSgs6zNuiVe69erPJqkz027mejpnPZ+Ml7COBSbznAfWkFz sidYfk5ro/I15vw1w9WUTLYHK9gH2WlUzmcprn1Aiatdxo+T41Nmuc0u/hh7izPaeUO6 ZOdw== X-Gm-Message-State: AOJu0Yz9K5GoR/JX0HJ+NeBbPsx7/5vWkioS34U2D8tlfKrq3Cp3IHTg z9Hq/qoxGwHuldlq3T7gla5GxVmLamgeSxfdG2M/wC1L6visUszsCAFAEjj8sH5+z6lye7r28FF qIGGaxPwZVU+5xNkOUQ== X-Google-Smtp-Source: AGHT+IHUBuTswzf59MXI254TJk24hUrp1Y6H9iQqapqBpe212J3nM0SfBnTsOF5kbITCa8mamWqtFQowkAG0He9g X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:6902:a82:b0:dc3:6b67:9342 with SMTP id cd2-20020a0569020a8200b00dc36b679342mr126270ybb.4.1706071879410; Tue, 23 Jan 2024 20:51:19 -0800 (PST) Date: Wed, 24 Jan 2024 04:51:12 +0000 In-Reply-To: <20240124045113.415378-1-yosryahmed@google.com> Mime-Version: 1.0 References: <20240124045113.415378-1-yosryahmed@google.com> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: <20240124045113.415378-3-yosryahmed@google.com> Subject: [PATCH v2 2/2] mm: zswap: remove unnecessary trees 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: 394E180016 X-Rspam-User: X-Stat-Signature: zy6uqcour9k5nm5o35kfsacygj79yxhd X-Rspamd-Server: rspam01 X-HE-Tag: 1706071880-601716 X-HE-Meta: U2FsdGVkX1/hFTg3xR5YOKcCQ07b9OFOHG2mglBw/aL9OOWPeUlZGor4L/aZno90oO1EY2v2PlDarvuvaSk4nHsoakMfrsHfknU0v5cFR7QE7NlUV3T/XVTGYlj1efxDxNusysalOWirxCBBLk4ilR53GjKjvTJmMvQElvQfG96QcOu0/siS86Xb38ImToqy3LmWxliEEACRebM6rGbDVQdhndr/RCh8sBHxbUo78nzcz2PlslOKp9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xwLpAR7cj5/xkyoLqHYjj3nphICo7xbRWLuT+M686Ml/XcSZRg077r1rjjoMs//n5V0LqOQaqGb6dyEZZAnQ4H/hbFiWBNGro9BxwYFMBLlHxNlmnb6ZfGJ0mjTUROXpidftkMSopCpL4soSQNHOIhBixxJoP3HfQXm4D59vapnPILAIMubIbuFRimB/SHXOWAgKEiVnEZIZ1gKWIzg+HFjC8RYrKzVaZoKxyDKyB+P0u8VV+XVX+gMk9nO0so2ymmltmXecjn3UhR/Dqli7yPXmlpKuLGe0iN2QVf3rdi7aI81DouDzDwgEE6A5pNILClqwxI/hfGK3GrLVipv1eoEMW62dVOZtnbdr45vEX/NQ== 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 trees cleanup code, and leave an assertion in its place. Signed-off-by: Yosry Ahmed Reviewed-by: Chengming Zhou --- 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;