From patchwork Wed Jan 24 04:51:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13528534 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 D669AC47E49 for ; Wed, 24 Jan 2024 04:51:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 70DBC6B007B; Tue, 23 Jan 2024 23:51:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6BECE6B007D; Tue, 23 Jan 2024 23:51:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 49B4E6B007E; Tue, 23 Jan 2024 23:51:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 3DC626B007B for ; Tue, 23 Jan 2024 23:51:20 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 18CC980B2E for ; Wed, 24 Jan 2024 04:51:20 +0000 (UTC) X-FDA: 81712980720.09.60C052A Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf07.hostedemail.com (Postfix) with ESMTP id 6715540008 for ; Wed, 24 Jan 2024 04:51:18 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=yPqzwVN9; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf07.hostedemail.com: domain of 3RZewZQoKCGogWaZgIPUMLOWWOTM.KWUTQVcf-UUSdIKS.WZO@flex--yosryahmed.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3RZewZQoKCGogWaZgIPUMLOWWOTM.KWUTQVcf-UUSdIKS.WZO@flex--yosryahmed.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706071878; 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=tZ4zMgobYN5FtUkXrR87lWOCtHQq0Np8Yg1aQ6/7PDQ=; b=F0nNJylirW5decg2gW34b4znt8GyK9P9oyoDNFNcb9/C/VvmZNQybPdju9nL5/JSTjW1JM wo5f4eYe/CPt51NXW2bTmpzBmH48uHYgBbsF/ihN/S8HcL8SfmvhQ54nlBaMDN5pm8GNAL dvZqzQL/6U04weD3l9u2TDB6EV9HB9g= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=yPqzwVN9; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf07.hostedemail.com: domain of 3RZewZQoKCGogWaZgIPUMLOWWOTM.KWUTQVcf-UUSdIKS.WZO@flex--yosryahmed.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3RZewZQoKCGogWaZgIPUMLOWWOTM.KWUTQVcf-UUSdIKS.WZO@flex--yosryahmed.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706071878; a=rsa-sha256; cv=none; b=lpmheXc5Sw+Lrz79YtnwKJ7mPvos84kJcnz7ZsYplHertGTEQxxw57FSwBdk6KH8zUTEo9 +pULp2AawCxysiGq72L+1m7I/dK5nP6m0P8Pp3NhRQonNJhRFQfWQmFqeITujVm3fhiQ0J RUUWn7mYmozuen0+RmTk63v4NSWW6h0= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-5ffa9b3659cso64736047b3.1 for ; Tue, 23 Jan 2024 20:51:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706071877; x=1706676677; 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=tZ4zMgobYN5FtUkXrR87lWOCtHQq0Np8Yg1aQ6/7PDQ=; b=yPqzwVN9ngt1HCwRre5vzHS/FbHEDwwv3PNZPWe/cEyjXb6OgBig+c6OQaugq6Go3A 0HOY0wn5fg9sWuRZtmUuLDj198lym97ZJD9NinW7mL7IIb1mC6PTD/5ue7QGrYkEwIeS b6nZfLBKHKmaMxRwa/aYN5WP2Xl5R8PJ9HfEufSJa1E5saaBDIHmDlKcA0oE57+SmocI klVkGP8eGT2ZdJGkGndH9sQkxLYyNx/Bpsn7yRdMqrRcdy8K3/kWtQAD24FwIu7YJfg4 QdpJX8N8/f2giuB0wHo3f3SutQAvkCp+OKzE9VfHkLAj+jhGukMbO5XJk3tQxC/fqtrL COJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706071877; x=1706676677; 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=tZ4zMgobYN5FtUkXrR87lWOCtHQq0Np8Yg1aQ6/7PDQ=; b=HtSRUIfyVmbrM1C2OUaJCEi59ccWwWMdYxdUtyOxdKRGKj9riHCm1c37mdKE3w8YmW V9wNLtNSLIotLdQ+Yg5InYcb3FRGiVWhh5CiSvZ4hBys8FW2tWuE96fCdp0CNG01zb+q qqRNLF7IG5wPovzdaYoJq4bFLLnz82ZMpmMsNAHBgLAKZWWyiWyC+uBL6kGlFFTSpikA bM4cf5GHFe9ODwUAEbMDzabxPviz+pQ2Ik6qPQMt70EL8IJ+0oaRie3s78hsV/5mXEME bWAAYUexu81VaFVXH69ZgaRQaljdUPrIM0yJdEg9pFmRqZ3cA/21z/RpCPjcttjnLEhX 5P0A== X-Gm-Message-State: AOJu0YwxW19FdfLh1H4AxAdQ7FqOSzesUSgKPRESwMsh+2wkcpGncg8A CZFfJMInOPedMW2xnKlwCInpKLj3p6G/9W89VqZaIAbnABywWC2jtMBQxyOYfi7tUv8WmIuR0AG 34ST0ooLi5kVPnPEabw== X-Google-Smtp-Source: AGHT+IH4dlOAA/aNVlbOqFDsv6qz2rL4n/3QH5h9ZkNH6atvYVWvPw72AEqTtaPY+eysFAbiENcG3HUSpBnk9xox X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a81:9806:0:b0:5fa:4896:7114 with SMTP id p6-20020a819806000000b005fa48967114mr148615ywg.5.1706071877573; Tue, 23 Jan 2024 20:51:17 -0800 (PST) Date: Wed, 24 Jan 2024 04:51:11 +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-2-yosryahmed@google.com> Subject: [PATCH v2 1/2] mm: swap: enforce updating inuse_pages at the end of swap_range_free() 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: 6715540008 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: umwjn4fzk4pat1z3qa3xekaijawfp53t X-HE-Tag: 1706071878-655618 X-HE-Meta: U2FsdGVkX1+mfA8IcFI1DuFRFJDxrR1AYJkzvlG6LyY/Vhs+cZla/vVr83yuOC0b2iZspZ0nwPvG0qkG8q/9W5i5CGSPyRUZqthnkDjfU7nyXslM0aNjfpF2De7CF/+3lSsBbypRPxAkJlpiWZtzHFzJkn45rZnPBqfMEinEJGPGPowdSjTyEISxdJCB0swyk+8Pl14dERjEm7RGr3RhBTGV8H7NepB13sJCReT/WJJQ8JTCCPNyEPAO96ciGrDhVcSM/9J4Zu2QR2/Jp4M/s+zVQZpeQdSpfW04PkB6+Di5Z/KDF768SULc7IpnT2wyCUI3oCxjs4Lq7gQod51sloAE1rs+Ogy6t15igHDDJ4A2kLlPbAM3GGmtsZD9wNWUtZoOjkUnHmwN8NucrVXmzBQ8gtYWkc1GUun/Y4PHWzwOuqqEkmXTkS4pOhnrOXZkNqlcXHAioGzq3B8mj8I4HeFHp2ydwn9puDlZ22BjJEDfiO7ygZd46gmp1doXk8AkDX6/hhWWkJu5zZ2/Fm1jk+LTxFsGAJyhUgFcDlR3cSM4DJzjca3cyhygOHn/g2Hu77N21ir8LqjY8f51QPEfoT+oF5dB8fjB3+0mE1J54wBp8xKwdcomaMrUorPQKOy7oy1OjKw/Wb4QrDuj0TLMQevxAXQdL4UaqtFoAJmTmvkoN30XGZVgVcxjc4IpgIg3wtEmHJT0Jz4j02HpUzybfYHHYf4FrB0Gj+fXeWgTCD+XrYJu3yHnQHgdLwyVdr3FZ60M+s7qtXzAIJ2GGOw3pwikvwMLUXCRDM2jGDBgYSLvkxyKg8aYnuKIa3zykJXE+GzZNq3fgyM5Zb9eUmCFMyIDGnKDNZSd0cidkgwKh3MHu0eqp/8rmylziMh3LQ/ya7o6Hom3IGYqoWXB1P3HvJzHiZvu1PtU9LK9mSD1zXYLwiSrWmUieVBgghDXrb2KbGgriaBmfFuDsPy3b4q iEAepmyD iU1ewdteMrwpocMDQ/GxdFZMMGddwTTS43mgcPE2jNrhfSl2Q7QotqPPfGJO+LV1Vibei+0B41G0f4GBfIcyQx65QBzNXhRUvu8PAHDzz7EB+M2D9yOpm5VNh54Qr0SSaDBmnAqycU8mb1LfEuqqdFXB+H9CTiw4aIrrONAMz70DDwUHY8MF7IYt6AOyQo8A6uXhzaZRtG/kGBcnYATLxdobWd/KaadIfifOn8cA8FHj+m0JH+Zw+3fV+JXAoiFqRChqe3W6upf7QqJd1CRGldpjAiRE6A33+cgCNpIUO6ZknWfjvEsrGS8sVdTY8UB9OU9dgPUnCwEmYNlTXXs9MUxgHaT9kuL3R8h1YtXKQT2DWazn7XAlOrP/lE09yoND3h1LnMybeIF4yX7ALwp/QrRCbkIljnYbMPYuPCz646Gkpmk5ox/naU4E8/nFoiubOYQa388in+8EHWA/1AT60r/5gT6RWmLqP6YAN5t3kIWr+xn0g94HbyU6ATpHKkfQpCrU0QA2Avikk2tTHSXvNzVVREN8OeK/fUKOvwPUOTEe2xaXIFP/RxXfRBRWvZgqWAXTk4OqNGeJ7f64IZBDAgCTbW1QAQ9Cl//tiT2sdz4LmL/Ya+R0nB7I9SgmaL/VZ8RrRvzcq33klggXHc2HBr6uU3P6B1FgNAthmbYFMiJV99tBFibEVzObfkQ== 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() checks that inuse_pages is 0 to make sure all swap entries are freed. Make sure we only update inuse_pages after we are done with the cleanups in swap_range_free(), and use the proper memory barriers to enforce it. This makes sure that code following try_to_unuse() can safely assume that swap_range_free() ran for all entries in thr swapfile (e.g. swap cache cleanup, zswap_swapoff()). In practice, this currently isn't a problem because swap_range_free() is called with the swap info lock held, and the swapoff code happens to spin for that after try_to_unuse(). However, this seems fragile and unintentional, so make it more relable and future-proof. This also facilitates a following simplification of zswap_swapoff(). Signed-off-by: Yosry Ahmed Reviewed-by: "Huang, Ying" --- mm/swapfile.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index b11b6057d8b5f..0580bb3e34d77 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,14 @@ static void swap_range_free(struct swap_info_struct *si, unsigned long offset, offset++; } clear_shadow_from_swap_cache(si->type, begin, end); + + /* + * Make sure that try_to_unuse() observes si->inuse_pages reaching 0 + * only after the above cleanups are done. + */ + smp_wmb(); + 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) @@ -2049,7 +2055,7 @@ static int try_to_unuse(unsigned int type) unsigned int i; if (!READ_ONCE(si->inuse_pages)) - return 0; + goto success; retry: retval = shmem_unuse(type); @@ -2130,6 +2136,12 @@ static int try_to_unuse(unsigned int type) return -EINTR; } +success: + /* + * Make sure that further cleanups after try_to_unuse() returns happen + * after swap_range_free() reduces si->inuse_pages to 0. + */ + smp_mb(); return 0; } 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/RCh8sBHxbUo78nzcz2PlslOKp9WRHFGWvBHnfMNC8zUagE7znR2Bgj/mS+tLdn6qzoEpnM6q28jUSEiNq7M6egcDKbiX5RQhICl/aSNIrXtGh+Kyt8HuWk12TH7NPCq0T1/egPKy3kHhHAI8zCxS2KwzSDl49X5q/HrnT47n586hZ9HnlTaluvrml20lKsvMfGykDsQXNDjCGLRNl3AdNUuQnq/46XtGMjcIsG0u0AZ1RhYGnhrGj75DU2ZzpFeFNtq32vY5TQfxiTvbn1Q7g/x9nBhCd72l6EY+ezygTLoKdh8NBdj7+WsHRiAZDGzSFLUN8r735QN3SY3/jf8AYwS2y1kaUwdMddRb4DAB8b4Mx66j3A3kzjV2PpQy/jG7mhTtnSKnF/Xk+SDz0hLxuX4+mgTiL3ZWY4VQXU+TIqfX3TMfQFHmHsHRR6SR7/vA8RP4pO59KCreQk1hqdm8Rr3drW6PlMfDCZKRO5AAMsr4ejtYW/VXSQC9ZUxVPlr6jMXvl1gV6HLkbGjXWASMhVyM9ar1hrcxjhowrLHoUnJ0oCUYW6DXDqwqXTyFhXMHbtbbhvLvWq6dGxGAFQmeEoVbNxuOrJzP6EEA0vbQ6vEFtJO444IcepFYeAHfuKlDPXixy17zz2qYInyEQeea5FrKZ5gkuNv/p5gsQHG74fdVX3j01A5cJEh0FxA3Zaz1drYnBQv5LB4KPOIzGePVDB5kQObUqFNRWxDx/sflS/PY7JJPTKEKUUM MzLI+yLM As248AwirUFajhPF3a8jBp3B27FJv7cuJlTWqe7/z9GR2nwmpY8gyd5fPGTOS7R7ChB0nhQ+an4aN6XjRW5ekpCnXZYDNXb7snzk5uedbko2vUUZkgTKPgKlJ0cLCqUecuFHXB/46hxU0t+tQLiSDLKINejIo1vKYpv16u+DzsR5B2jTFG0FfWWUWUdF7CzTPykNHSSsm5H28PQVNkzdfYB3BMAYNajtkufSah9senJuCoStF4Uh4y6mMPvS6RmVawyEQW/n6Zutv6XG752Tl55pZyHlYjqCJA18RjrJFxsPrGbbeA4hOtZgkb/ggBb0rn6oIxVLtEonIvrxwLpAR7cj5/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;