From patchwork Thu Feb 29 00:37:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 13576147 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 D6248C5475B for ; Thu, 29 Feb 2024 00:38:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6543E6B00A3; Wed, 28 Feb 2024 19:38:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 603616B00A4; Wed, 28 Feb 2024 19:38:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 47F046B00A5; Wed, 28 Feb 2024 19:38:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 35D596B00A3 for ; Wed, 28 Feb 2024 19:38:52 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id D6A86A1886 for ; Thu, 29 Feb 2024 00:38:51 +0000 (UTC) X-FDA: 81842981262.22.F6C0BDD Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by imf06.hostedemail.com (Postfix) with ESMTP id 06DC418000B for ; Thu, 29 Feb 2024 00:38:49 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=nZggVojL; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf06.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.178 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709167130; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=UdVUS/tLhNyeqOoyodd3YqCiZJm0fvc/nLmJZ8OGUGI=; b=YVJ/dIMPd5CNuAJ97JkoF7w4neiFbHc3fvJlQOpoAkKLAQFbDfVO0SqLGgmGVagzohra0F gWIIcADDMKc6+NA+kJf/1cUPi2RAoRl99s96V2Xoub/i1Wp4qoxTwtOiHWKNlTdnauHbvf y/ZUcJFOUyk4a5h7XBSmCTpCfm9RnRY= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=nZggVojL; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf06.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.178 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709167130; a=rsa-sha256; cv=none; b=p29Dp7K0mb712evgeHDceLT5z7pO9b9IBOe4UR6iIP6YcHBS1Dcc76rp5hFX7pR7993YQu TreHqzqVfhOzCoRem5m7/2iMxRfGOgZbb/CkojeJ3oNaLwgTEUSQIf1BB4+g6cH4KtnkOc pjkiy5RJoj8bVElcyPLEb6OPBW+0aiU= Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1d944e8f367so3068405ad.0 for ; Wed, 28 Feb 2024 16:38:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709167129; x=1709771929; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UdVUS/tLhNyeqOoyodd3YqCiZJm0fvc/nLmJZ8OGUGI=; b=nZggVojLaWfFmBFrvEcwT7RB8lsuumQx0zi/uwcG0Bptp16CO6VuHdOSMmhQuQmNzO 16fHGN6/sIOGkMSYa17v6jFg9A7hukaQnmJhDvAAzBFtfqZbQvS4evPPtu8fYaDgJaVY z+3uPebqS8XOMy7JqcoKhZjF/ZyzSbjSqS9G+61xhyd1tYJz5E1uhztvPrdtYTSMikHJ WjnfZWf6Xikdv1SF1C+2rhn0OrNTuSg/jl6TrdN6eukl8nMdva2bav5NjR5ke0U5W4fk +fchQalOlU+Xm3GjCyLFyr4qt2z/n84PJDUxMuZZAai7GClvJ468ejwWG6yML7E5pX24 mSIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709167129; x=1709771929; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UdVUS/tLhNyeqOoyodd3YqCiZJm0fvc/nLmJZ8OGUGI=; b=Kv+V52gUIlKhv6JqV4F1oc+pKIj45f6gibjm5nfgBxtThOhGHv0aS4DDq9ClxNvIdy QbpKzKz4KxYdzUD8SH4iIFLB+zrGK63tj4nyL017bq3PQYtxo2YGn0cT4Rt8x0wAqtJA ZLhEmz4WxfAbHSxH7lFxaMa2hMMyS47MZYZj3C47LF06H3H1w5UoyRGmOuejRlx34PsX NkXd278BXMatMGtrNWdxn8dGzpi4eOvg5AQ1MT1QHEw9pHIrjU7xa3+Gyz+QON6K8YKr XjA0g4YhJwBjN2xGUcBYL24HN/w3R16IHh9Bb+TfVQasbpLWJ8sqtWtLwXpjYu+pe+NQ uDCQ== X-Forwarded-Encrypted: i=1; AJvYcCXb6m7Ol5yptfV70CVrUSuXta9wwkeKKNM5xLgK3murYooDTBtSg8tgeHZTiHKAQFWejuwkHXl5Ja6dMj7+1Ns7ApE= X-Gm-Message-State: AOJu0YxcCib59bLXthCDWQeqLlB35fG26JxRgo0WNUfz4p+EHIq0URI4 rqE7MLNHbvnsNiVfWptVgA4EKH/F5sM0UWgGzY3SOGD8pEpCo/D1 X-Google-Smtp-Source: AGHT+IEuGt8EvEpQqxAVqcPMvnU0WfE0nNgN4CSstXtrAZpJfq6DmLPZKApzsi42Su3R2d3MnQpTcA== X-Received: by 2002:a17:902:7d82:b0:1dc:b320:9475 with SMTP id a2-20020a1709027d8200b001dcb3209475mr648542plm.13.1709167128925; Wed, 28 Feb 2024 16:38:48 -0800 (PST) Received: from localhost.localdomain ([2407:7000:8942:5500:5158:ed66:78b3:7fda]) by smtp.gmail.com with ESMTPSA id p3-20020a170902780300b001d9641003cfsm62647pll.142.2024.02.28.16.38.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 16:38:48 -0800 (PST) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, david@redhat.com, linux-mm@kvack.org, ryan.roberts@arm.com, chrisl@kernel.org Cc: 21cnbao@gmail.com, linux-kernel@vger.kernel.org, mhocko@suse.com, shy828301@gmail.com, steven.price@arm.com, surenb@google.com, wangkefeng.wang@huawei.com, willy@infradead.org, xiang@kernel.org, ying.huang@intel.com, yuzhao@google.com, kasong@tencent.com, yosryahmed@google.com, nphamcs@gmail.com, chengming.zhou@linux.dev, hannes@cmpxchg.org, linux-arm-kernel@lists.infradead.org, Chuanhua Han , Barry Song Subject: [PATCH RFC v2 3/5] mm: swap: make should_try_to_free_swap() support large-folio Date: Thu, 29 Feb 2024 13:37:51 +1300 Message-Id: <20240229003753.134193-4-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240229003753.134193-1-21cnbao@gmail.com> References: <20240229003753.134193-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 06DC418000B X-Stat-Signature: i36m6mocn97x1hynpbxuctz6sjq6udo1 X-Rspam-User: X-HE-Tag: 1709167129-144957 X-HE-Meta: U2FsdGVkX1/b2sufBPTpUhqtOOYaa6tZjIiy/M0eEvsQFqhwaqp1Mf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4QGKc/kwCefszoKVKXpMsdt7entxQHvDTeDnoHEuMNPKQxE+P60npHM6W+9FzpeBa2bsUKlOFFflEYJPsvzYSA+YK5SLj6sKyl0F0C02Lv17ShfQkiUG4juSzCNtexLAHNmvs5QBv2XYWAYlDqJlvYJS/vI7rNBm7XV6CCMC2EwdS4O7w2A3s4sQ4QMug6Q3Lahdd9IPocKeu1vjFMiQXhRbLHYd6mZfayXqUGVC/29hhLizOZJHpGCPCVIks3XighxRLy1ZQKtCMunARZoUyO5JmbKBE6Bjg6lfVoCJ3lovHbU5D3rPv1f0tP1prnKStALqdACyYAXGpt/TNf1bkrzcAmjDZLljSWYsnOtF46f/vvyMwQV8qVqgoIpFs5tarCINxoJjRkSisLBZwDWWFD6+bZHmWirZsiA/Bjf85V2GHxbJidQ2WAFu8b+sNhKFtV0qsBVyqRV1PawmBb82g27FTbafv3njVQq8En3WEK9BQaeN55Y272I87 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: From: Chuanhua Han should_try_to_free_swap() works with an assumption that swap-in is always done at normal page granularity, aka, folio_nr_pages = 1. To support large folio swap-in, this patch removes the assumption. Signed-off-by: Chuanhua Han Co-developed-by: Barry Song Signed-off-by: Barry Song Acked-by: Chris Li --- mm/memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/memory.c b/mm/memory.c index 319b3be05e75..90b08b7cbaac 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3904,7 +3904,7 @@ static inline bool should_try_to_free_swap(struct folio *folio, * reference only in case it's likely that we'll be the exlusive user. */ return (fault_flags & FAULT_FLAG_WRITE) && !folio_test_ksm(folio) && - folio_ref_count(folio) == 2; + folio_ref_count(folio) == (1 + folio_nr_pages(folio)); } static vm_fault_t pte_marker_clear(struct vm_fault *vmf)