From patchwork Sat Jan 20 02:40:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13524320 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 DB562C47DAF for ; Sat, 20 Jan 2024 02:40:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A5F2C6B0078; Fri, 19 Jan 2024 21:40:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9E7716B007B; Fri, 19 Jan 2024 21:40:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8881A6B007D; Fri, 19 Jan 2024 21:40:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 78FD06B0078 for ; Fri, 19 Jan 2024 21:40:14 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 4CC971401BC for ; Sat, 20 Jan 2024 02:40:14 +0000 (UTC) X-FDA: 81698135148.16.2BB9AA0 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf24.hostedemail.com (Postfix) with ESMTP id 88E2F180009 for ; Sat, 20 Jan 2024 02:40:12 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=MM+YNc4r; spf=pass (imf24.hostedemail.com: domain of 3izKrZQoKCNAKAEDKw380z2AA270.yA8749GJ-886Hwy6.AD2@flex--yosryahmed.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3izKrZQoKCNAKAEDKw380z2AA270.yA8749GJ-886Hwy6.AD2@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1705718412; a=rsa-sha256; cv=none; b=RX7d5d9wLFa1tAOYpT3RBbHFKX7ymxSksMiGYfEgwdbXo1UuHW9/8F+8yPFl0vtyrzc/uu 7Osp+lMn+N7eRQf/BxAiN1H2eqLW7t5h/hDREFlw30V1717t4J2CQL3OboQf3eUoYGhq1f 0F76icZ0wU+8Ppym7bVLknYucr9RrBU= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=MM+YNc4r; spf=pass (imf24.hostedemail.com: domain of 3izKrZQoKCNAKAEDKw380z2AA270.yA8749GJ-886Hwy6.AD2@flex--yosryahmed.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3izKrZQoKCNAKAEDKw380z2AA270.yA8749GJ-886Hwy6.AD2@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=1705718412; 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=rd1qGVyD1ykzuzHvmAyHpTUAK3rrqoLF0G2J9vWoPEg=; b=vGqptsoFC7g53NYqowFvO4i7KcZQvFDa9wAeM7bLieAnGEy7m++0fVsC94nJ/kTChMTUQH Ea217pw/sb2Ukt2h3qaK1XBzWVmmWXQK4exBktFl7x7zfKyITfhsG2ZDCSCCLpPIvqpg+s OH4R/ne/UJ7NoCa1VQs8leUZ75FQj3w= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-5f325796097so28524457b3.1 for ; Fri, 19 Jan 2024 18:40:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1705718411; x=1706323211; 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=rd1qGVyD1ykzuzHvmAyHpTUAK3rrqoLF0G2J9vWoPEg=; b=MM+YNc4r0fW3Q45GZ4CS2VE1VVK6D5SkZWj9d3BgPYNasbDqQTF45Ml9pSNqiIVHIB 3nuKf6PMFCRgK7lc9WcUirWv+XEXkDwuNWI8xQ6NV0KaDb2KbgutG2brWQB54GURMTaO TKt6qE0M4uSN/cvQYyDDdy0tMRINtryYpk4KIPqnriRzB5bpZ4wOs8cbHoa8yhX8/4km Cn3M/P24qewrG2ndnxMBPQMfdCQreuxTaM09Sc3UW+8uCvvthsK7CdL028KpjyS1VfvR tZ+prLia4li6K8w7RVobB5TOkWaV7jIywZmHlFW0PGKYA5P6NM+dCVdluPdi+FZJ8Mw1 M3bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705718411; x=1706323211; 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=rd1qGVyD1ykzuzHvmAyHpTUAK3rrqoLF0G2J9vWoPEg=; b=e9VXW1M89u/A6ZljrLVN6xHbV6NyGldCpk60QZIYWH0MrL515DJ3LbAuilPCBwuONI retQUzfauXYBb+1dgQIfVqJSGPC8sdgvNMtRLu5WBOo/o/Jy2I56/Thsw9iTSk80m1b+ +PEqxIbjYos/K8biWGEO54upjayVn1IpEKf8LKHaJEkb+jmz5K07m+jmE08+OwpWtLNp y0aUkVRTRJ4MnVJtzZbnqiTFTpyTfFPibu+Jk9RHKnQg6qihUbioORqc6/ggUpMNevJF pEkR1aeJsuPDNl50hSif56B4saxwcfsir3qyNkhseqbQfF39/KgV0p7+GCsw0kZMTjX1 iGJw== X-Gm-Message-State: AOJu0Yxgbs/a0Atd4oPsrkYe8HBX68vOG2OpxNSzZ+ZhwLmu7M7EQbSg 6vv8NLJwXcl+5Y04741XbTBnZFl+ThmUMW6CIXJYDfPvWbWqkd++U9v5jgPKc9PT8sGjm6A6gbW H/mITsrAWFwubUZWIMA== X-Google-Smtp-Source: AGHT+IGlzWtqjzUJGH6Nvhp7hFYQayoidp39fFZ1FF6ynSjqhu4fayTUmM2j9bMmUmgkgFBRYlOjhIVRaw6xjzai X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a0d:cc52:0:b0:5ff:a9fa:2722 with SMTP id o79-20020a0dcc52000000b005ffa9fa2722mr367712ywd.3.1705718411731; Fri, 19 Jan 2024 18:40:11 -0800 (PST) Date: Sat, 20 Jan 2024 02:40:06 +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-2-yosryahmed@google.com> Subject: [PATCH 1/2] mm: swap: update inuse_pages after all cleanups are done 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-Server: rspam08 X-Rspamd-Queue-Id: 88E2F180009 X-Stat-Signature: 9dwho5xxsgrcxzocr1apztrojcfp46ib X-Rspam-User: X-HE-Tag: 1705718412-371605 X-HE-Meta: U2FsdGVkX194OE5PkHXkgNa9tTprvqkICg7oKdjmQYe2crHMZPsqOZ10l8jHH7dBoAvMpDxDW2ls8wL7xB/OwAC4vcBTcTPUjA16MObufQCPGFXAI4ywdYReHufr3n23Bj4Oz1RBUmlBJbRdNwZHvu1bkrlJSLluvbEmNDtTW4z86erahF0suEsU5bRDbjaRZZMag0pXWtD/jovXoxuM6M2IfxnneUONeAerhuiR3JTXwGE1BCiagvD3jzQ6Br5dRhZuloFDm3y7Bk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FhbOxFACpbWtANAEKtMxNy0hIKCGqPTw+KoP+0J2rVgPv0uofCeaGwe3JEeNLeFsSoD8vp9SzIzDOVUnf7fNGzVKJVGUEG8rwHLTR+uxvZC/kYxldmsOC/a3YjNgdr0cuKTZA93HAWVZgd2h/SoZiXYP1rpLKR5htCtJ1+4agiz3yMsf34kEuqST1QBwAmhUfc1WfP8Ht+yREO8Zu/M+5qR9e7WW1z9HJrBamvUc98SROQgSUlMAk/h9Cd7J2IRPhFTdsd91uwhnFfBsuBp5P8fX07xWfDsyRW2TK5sVNxVJ6HK9Hr2OdgX7n4orADpz3pcVf1pqZafbV7sXIMEDi5KIzhjW83nQRpFBCg== 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: In swap_range_free(), we update inuse_pages then do some cleanups (arch invalidation, zswap invalidation, swap cache cleanups, etc). During swapoff, try_to_unuse() uses inuse_pages to make sure all swap entries are freed. Make sure we only update inuse_pages after we are done with the cleanups. In practice, this shouldn't matter, because swap_range_free() is called with the swap info lock held, and the swapoff code will spin for that lock after try_to_unuse() anyway. The goal is to make it obvious and more future proof that once try_to_unuse() returns, all cleanups are done. This also facilitates a following zswap cleanup patch which uses this fact to simplify zswap_swapoff(). Signed-off-by: Yosry Ahmed Reviewed-by: Chengming Zhou --- mm/swapfile.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 556ff7347d5f0..2fedb148b9404 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -737,8 +737,6 @@ static void swap_range_free(struct swap_info_struct *si, unsigned long offset, if (was_full && (si->flags & SWP_WRITEOK)) add_to_avail_list(si); } - atomic_long_add(nr_entries, &nr_swap_pages); - WRITE_ONCE(si->inuse_pages, si->inuse_pages - nr_entries); if (si->flags & SWP_BLKDEV) swap_slot_free_notify = si->bdev->bd_disk->fops->swap_slot_free_notify; @@ -752,6 +750,8 @@ static void swap_range_free(struct swap_info_struct *si, unsigned long offset, offset++; } clear_shadow_from_swap_cache(si->type, begin, end); + atomic_long_add(nr_entries, &nr_swap_pages); + WRITE_ONCE(si->inuse_pages, si->inuse_pages - nr_entries); } static void set_cluster_next(struct swap_info_struct *si, unsigned long next) 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: U2FsdGVkX192wNO1PFTRLy0ud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Nf3d3L0Jn+GPdXJzkYgmW/alOiIT/tpAH2CnoShkTvcV6WzJWer/hMcu1Oq3NbQka/FHmIHuqrpAjvSxQOtulyiHooNXc4GOe8SC3fI7JDmvSiVOkpfsGhXbk2fJInujRXEqv/Qs5k7RISaoIJCBkglbhNzF5hy4X7Wo/Gtdx6E9UTSVhU94Jj0Q4CLlOEqKg87KYNxBjRLljTBzz/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; }