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)