From mboxrd@z Thu Jan 1 00:00:00 1970 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 EBEBFC54E60 for ; Tue, 12 Mar 2024 12:34:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1DB0A8D0040; Tue, 12 Mar 2024 08:34:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1632B8D0036; Tue, 12 Mar 2024 08:34:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F1ED28D0040; Tue, 12 Mar 2024 08:34:38 -0400 (EDT) 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 D58CC8D0036 for ; Tue, 12 Mar 2024 08:34:38 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B0ABAA1242 for ; Tue, 12 Mar 2024 12:34:38 +0000 (UTC) X-FDA: 81888330636.04.DC40B0F Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf10.hostedemail.com (Postfix) with ESMTP id 31F19C0007 for ; Tue, 12 Mar 2024 12:34:35 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=none; spf=pass (imf10.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1710246876; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OfWFuv8p5fTBu2yY135tF1HCs/abpLQ+AkJc7p2Kckc=; b=RHuQLHedRfNP7h3rAUgS03C6Dp/H4G7kb33IM3bk9ao1Ggv2kG/QVNXA2AMk6/1VeerKec QplWbwZqlxwceZdXY5Te9OioXnsjEfsyk95VaaOABrxYySCy3onn9/JGIP88WJQlSdVUmb XH/+4ZYK947LzKFlY2w7I9XN61jE73U= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710246876; a=rsa-sha256; cv=none; b=hffjKSeWBHlegQc0dfZEZPjs9fVqy9/VwLEAV6lpjVRifockT89b1L11BVohKQUWNzdjIm wzJe47h6H7v8e47VkFUR4tCF/t7Uc2D33cBi6z3L9SYz2YufyONzheP5bDb6MoeDwmYT/k NaB5A7hagcLVrFylUAlyi3mGRAE5k+A= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=none; spf=pass (imf10.hostedemail.com: domain of ryan.roberts@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=ryan.roberts@arm.com; dmarc=pass (policy=none) header.from=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2FB4D1007; Tue, 12 Mar 2024 05:35:12 -0700 (PDT) Received: from [10.1.27.122] (XHFQ2J9959.cambridge.arm.com [10.1.27.122]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 696043F73F; Tue, 12 Mar 2024 05:34:29 -0700 (PDT) Message-ID: Date: Tue, 12 Mar 2024 12:34:27 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH v3 3/5] mm: swap: make should_try_to_free_swap() support large-folio Content-Language: en-GB To: Barry Song <21cnbao@gmail.com>, akpm@linux-foundation.org, linux-mm@kvack.org Cc: chengming.zhou@linux.dev, chrisl@kernel.org, david@redhat.com, hannes@cmpxchg.org, kasong@tencent.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, mhocko@suse.com, nphamcs@gmail.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, yosryahmed@google.com, yuzhao@google.com, Chuanhua Han , Barry Song References: <20240304081348.197341-1-21cnbao@gmail.com> <20240304081348.197341-4-21cnbao@gmail.com> From: Ryan Roberts In-Reply-To: <20240304081348.197341-4-21cnbao@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Stat-Signature: qucj3pjjrzyqzosdpgt3gsggqohaon33 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 31F19C0007 X-Rspam-User: X-HE-Tag: 1710246875-629771 X-HE-Meta: U2FsdGVkX18GNy5dN5Z9lvAj2hTmk1Y/SC3kJZ/ZBbOBsRv7hqO++RyrbjMqRyczx8nebvprSDlzKrQpKQfAhRl7UxxT/7lKcJ/y56nl9FUBeRW5pXq+3+yuc9ItHI5epp6MG5yZTfDewXne+Ucgy+14QF+yXo3sEjCu1gGvwAitG1Matco6EKnYo4F/uxT0gSq3kv1A3ZdRZPbNksOWLrMCCOCRcS7eJg/exRUM9OcsD+iS4ffCO8U4l+D5wwVW9zoSRwFpNLGDkEhBo30z9CbAgn6iZCcI1nplhGPJS4l9VzN9xarvuxRQqL+U6fi6l/ZjLFMFtTwY6gsrMHfia7x+S+nlm4Nb5YiO+Efw+5VuSGbdmpj38pAQUeEWecga0kgSugPQLFrYCxw8ASChGKr2C8mEsZEzgLMttpJUo+OHEqp0xj+EayIAtditzj8w4jrxyjrEDMjc5UPYu4qVzM4iC1oUmMdXHJ5ne+DWbTgGGHFuI2GTGQvXCh1Cc17OBBw8pms35EWo7FLPKek9lyy9PeA7ibk4CfQt4yqgTyZIfalqv6xHKwGSuY4T30gKaOy2ZtBBcFLXnBrypxLZyU3u+Fijr/qlAWZ5fUAGQAAIj49310wG4Gnb0H1fWiJxQurA0RsGHg7CavwKN7/ErJ4BSrUnJzBLp9vRmb0OiyVCp0Lr1QWGlz3/oom31QrBI+f3H4ksNnZ83rQJqjs879V9w/yXYTzZQvVYv8Qg/hLHjh9GD/ya22BrQVH1JvRmgM2pbi6H0nwb1LKyx4hGoU93ZO4OIXw7e6Y7QwQ+fHx1+hGeu3sE8OltekwsNLC82pjH00S0kB7iZ3iyZCv1Bsa6SIS+5H++JwrmC4jCDxWF/Jbxx6NUdh+9FH/e+shOIf/BaF4Aauo= 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: On 04/03/2024 08:13, Barry Song wrote: > 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 abd4f33d62c9..e0d34d705e07 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -3837,7 +3837,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)); I don't think this is correct; one reference has just been added to the folio in do_swap_page(), either by getting from swapcache (swap_cache_get_folio()) or by allocating. If it came from the swapcache, it could be a large folio, because we swapped out a large folio and never removed it from swapcache. But in that case, others may have partially mapped it, so the refcount could legitimately equal the number of pages while still not being exclusively mapped. I'm guessing this logic is trying to estimate when we are likely exclusive so that we remove from swapcache (release ref) and can then reuse rather than CoW the folio? The main CoW path currently CoWs page-by-page even for large folios, and with Barry's recent patch, even the last page gets copied. So not sure what this change is really trying to achieve? > } > > static vm_fault_t pte_marker_clear(struct vm_fault *vmf)