Received: by 2002:a05:7412:7c14:b0:fa:6e18:a558 with SMTP id ii20csp316162rdb; Mon, 22 Jan 2024 05:18:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IHEJKIWtzvNoMnCnFkFd/27pZfivocESYaAA5tREVXXZwkKTW7B/LmILC39VEgOxJpHsu90 X-Received: by 2002:a17:907:592:b0:a2c:30ff:f762 with SMTP id vw18-20020a170907059200b00a2c30fff762mr1757616ejb.42.1705929513205; Mon, 22 Jan 2024 05:18:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705929513; cv=pass; d=google.com; s=arc-20160816; b=BnXvoJb716VDbVPALrZ3OrU+WInYaqr8S1u71ENyGcuM/pa/ebbLsFKlJmb8cBRbXu TX7EwNwcLZZ/B/xwWINxL7+7XnDYeB4/mEzVRPLDuND7OBVeGkdFa3/wwdDD8Au3twMy q8ejAe4ByoqWSCBIvyIbifKb5GkxnTSGPIDS5v78jwrf63clr6I8JEMVd2cw/w+TRck3 XI1xCje9sqVFkDPDmlRHuuSiTpsOKqAFALXG8LFE5NYtRhs+zYv9cF/2umqBCPbyMRGM IuFRx4LJX5o93ScoaVhoIzYk0Ii8qCXE0G/ZmDvGkO/BmHv1INXjdNE26VMeox3tZ9jD rbaw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=cDTywOhHts8IqwvBm49PSHeY+lSXu3apx9HFTNA8DEk=; fh=lVn5Vv1E5zjFBwIiwHewYZcpfWd8hZBYmUaHHCLEnzo=; b=czJ8HhCePtCcu3TRQo57ratNHaYtZVD6OZmcpoETBBCqKZNqZA6yb7iied6UblYu86 1Su6D9Hv0OSkxAjFhe5Czw7vvGrmeQHrTQDPYKrTDjT+y979mvaG71BlQj0XSFiGYRsW 7WNDG4Uy1laItyTZGioqgU+2kV3TQU7rLfw2i3O+KGxLk+WTF+5eg1D6lwjeEHp20jx2 84aRNPjuTj9XhES3k7UJrEQ8oDSUgI34+VcDeNIExTezToo4OaTrv2Pez86Pozmy+MOi TkcuzR3EfZJARz3k5z3FY7X1ClZx2SQLDMpXTfk9GxkDIYO5IsJc2R8JX7PvYV0x6leY iFOg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=fdfbwNxU; arc=pass (i=1 spf=pass spfdomain=bytedance.com dkim=pass dkdomain=bytedance.com dmarc=pass fromdomain=bytedance.com); spf=pass (google.com: domain of linux-kernel+bounces-33087-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-33087-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id g3-20020a170906520300b00a27e16a5906si10611507ejm.562.2024.01.22.05.18.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 05:18:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-33087-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=fdfbwNxU; arc=pass (i=1 spf=pass spfdomain=bytedance.com dkim=pass dkdomain=bytedance.com dmarc=pass fromdomain=bytedance.com); spf=pass (google.com: domain of linux-kernel+bounces-33087-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-33087-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id F309D1F21F79 for ; Mon, 22 Jan 2024 13:18:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 24C473CF6D; Mon, 22 Jan 2024 13:17:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="fdfbwNxU" Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CB5313CF59 for ; Mon, 22 Jan 2024 13:17:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705929471; cv=none; b=b4m36GqDK6NEv8yTIiRiTexOIIt5FqMOi8DFY4NrY7bR5x8X7BMzB7JHqcijDPNE/sVWsjKPLk87OTLELuXPpVFwiU1yt0YEtob6bNI1bHo/N4HSdwUocYwlga/nttzRN3btLvZNZ+qP1zcjzWJLWpSKrtSwixpyEd6cCuVDhbU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705929471; c=relaxed/simple; bh=adhOBxAX1pnGbHkGlDUuuNqMcPJbfJRL5CYSh6J/Npc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Mi3YotTE7ebOWCJ6W2xkq6GLK2ZcXj/hHNzgx2KjaSnvCYm09al8ZeE7pJ/j/CtSUBivUj/ZMDRCHcHPgWlJ4RKWbn12TeQJM4S3DBD2gYSMjWYO107pXXQLdhKip7kZwnldTyOxdPukhb86I099AtYiYzUrb/pIBqsXH6s65Jk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=fdfbwNxU; arc=none smtp.client-ip=209.85.210.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-6daa89a6452so1829964b3a.2 for ; Mon, 22 Jan 2024 05:17:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1705929469; x=1706534269; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=cDTywOhHts8IqwvBm49PSHeY+lSXu3apx9HFTNA8DEk=; b=fdfbwNxUCofIJS4BVn4ELYhLvqiHEvMS85EMbzhFmY+UoIhI6U0yuZ7YiaKdcucoEb ocS8gZP9jthCikftihU6Mp7HSd2VvrEnGRScEowq1JNBRowNt0+L9Rv6oM8hxUfsBxz9 LaVy4KNMp7J/DgpKhqyfSFrGFg6+9KCnSHaw8mQVqqFFRYc3Z42ZS3QcAboF66lzYIgK 2guMux7aKbnZ/eckPVfFcR30VUIh9sQ4aF4+NvO7XyQlM4xJCH9M7JDCMrvRulXSjaVb QXxXQOLv44e4Iw1J/87k7PwONPr80WxtiPSN2okhO3CrhGw+gN/SXyCpbUhJcHJVqZSH Vjag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705929469; x=1706534269; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cDTywOhHts8IqwvBm49PSHeY+lSXu3apx9HFTNA8DEk=; b=BuXE0+qWbZeBJ7bTS/xmUREXniKY66eUDXJJJaprYVPWbUAcbiNEQPf+p5K514JHvZ 0n/e1gNyop6pEwrdreQ8mY1Kr38p4ZjxP2iX0Iy5TyqZ3G/ynLCcR1emQ682cnKXUvLc rq5UZ0WUtnpCBTLMQrjVGAAwMG7YYBRJ/J8ryyYNtyDlCi0gMGMYWDfIVQvF+QSAaMyq cXIyR8fT4U16xMSy/xRKVaBdV5GaCaBeujBWFWua5TNREQdVvSL1LU888VH2iIt6+myj gnd53Jwhpbb0xmqxgGSAb1gvBYGxVPV405N8FERztVmR4Sbsh23NOfuf3i9os9vwAOXM cXng== X-Gm-Message-State: AOJu0YzOoAaaVbquq/ZCaXYhaKXLwwKRS2S7jiUtR3fe4FwPyrYiVm0s jcqYmfLRfzbvwHQUFPdNQWb3yxgWm9OREGpuSFUoAAVG7Y0rAJVrj2I7cSysglHz9BmLBVs88yc 7 X-Received: by 2002:a05:6a20:7353:b0:19b:42ea:3154 with SMTP id v19-20020a056a20735300b0019b42ea3154mr1552997pzc.76.1705929469055; Mon, 22 Jan 2024 05:17:49 -0800 (PST) Received: from [10.4.246.34] ([139.177.225.245]) by smtp.gmail.com with ESMTPSA id b4-20020aa78104000000b006da022d1bc8sm9566352pfi.25.2024.01.22.05.17.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 22 Jan 2024 05:17:48 -0800 (PST) Message-ID: Date: Mon, 22 Jan 2024 21:17:43 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/2] mm: swap: update inuse_pages after all cleanups are done Content-Language: en-US To: Yosry Ahmed , Andrew Morton Cc: Johannes Weiner , Nhat Pham , Chris Li , Huang Ying , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20240120024007.2850671-1-yosryahmed@google.com> <20240120024007.2850671-2-yosryahmed@google.com> From: Chengming Zhou In-Reply-To: <20240120024007.2850671-2-yosryahmed@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 2024/1/20 10:40, Yosry Ahmed wrote: > 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 Thanks. > --- > 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)