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 95EA8C4345F for ; Thu, 11 Apr 2024 14:54:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2761B6B0083; Thu, 11 Apr 2024 10:54:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 227946B0087; Thu, 11 Apr 2024 10:54:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0EF566B0089; Thu, 11 Apr 2024 10:54:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E629C6B0083 for ; Thu, 11 Apr 2024 10:54:26 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 7D5081A0BBB for ; Thu, 11 Apr 2024 14:54:26 +0000 (UTC) X-FDA: 81997546932.12.4CEF955 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf30.hostedemail.com (Postfix) with ESMTP id A86B48001C for ; Thu, 11 Apr 2024 14:54:23 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; spf=pass (imf30.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=1712847264; 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=9MECKgRxyLJbIrWzS54R6GHWONA4rvJRUkTQt8ONUMs=; b=BE9ncVzBakRBJGS7hNGqm4BcU1LELxpFtJxvI2FuuxGtU70qWq4ZEio+1BG2Lu/1h0UBq7 bo55yGEGhr1dymL7q29U/7f1gtAacr6ue7T+hf7sWog+efWMbwpHLyW5FkVoSaB4IKs2xP A3BpG3PN8U4iRS7DbIN5tqqnrYtBRjk= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; spf=pass (imf30.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712847264; a=rsa-sha256; cv=none; b=kQVP1rfoiP8YOFY2AfWdKzHj0ZKsaGpSxxcrQgBKlqLPVClvKMp/S+Z59eEje4/UHffhBt oLSJ96I4JI0vTsc+Te3NebG7uBC5PheqL10qkhRspbWpLSU/frDqQwciumjnATV5fFKmjG v9ZWQTttFI9B6tS38VXsMzRbCrdfc4I= 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 3A66F113E; Thu, 11 Apr 2024 07:54:52 -0700 (PDT) Received: from [10.1.38.151] (XHFQ2J9959.cambridge.arm.com [10.1.38.151]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7634A3F6C4; Thu, 11 Apr 2024 07:54:20 -0700 (PDT) Message-ID: <744f795b-7ce8-40ab-911b-60906aa4fed1@arm.com> Date: Thu, 11 Apr 2024 15:54:19 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 3/5] mm: swap_pte_batch: add an output argument to reture if all swap entries are exclusive Content-Language: en-GB To: Barry Song <21cnbao@gmail.com>, akpm@linux-foundation.org, linux-mm@kvack.org Cc: baolin.wang@linux.alibaba.com, chrisl@kernel.org, david@redhat.com, hanchuanhua@oppo.com, hannes@cmpxchg.org, hughd@google.com, kasong@tencent.com, surenb@google.com, v-songbaohua@oppo.com, willy@infradead.org, xiang@kernel.org, ying.huang@intel.com, yosryahmed@google.com, yuzhao@google.com, ziy@nvidia.com, linux-kernel@vger.kernel.org References: <20240409082631.187483-1-21cnbao@gmail.com> <20240409082631.187483-4-21cnbao@gmail.com> From: Ryan Roberts In-Reply-To: <20240409082631.187483-4-21cnbao@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: A86B48001C X-Rspam-User: X-Stat-Signature: bu5444hrjph8y79y16ugt7zzdnth7a63 X-Rspamd-Server: rspam01 X-HE-Tag: 1712847263-482611 X-HE-Meta: U2FsdGVkX18qTW61iUkIvLDUcZRJOlrSuTrKKyyRmMnxbJ9anN1VrtC2R1c1yMymme0N09MK7m91x8P4WiUVNdh9iznWr2I8PVlsUpZpSsqShE8/9qlkOWymmvlG4urrU0WSF6yjTUp1ebSGLoZV0ThwZnm7dxay13hjsmo2sMfXPasM/IFtl0Nif2KyHznZoGqeDrRKZU7TMksv/Ytbpcd7bcTzgXDvSI5ICEnpZjTLnQ6kng5Ksu8Vb/lwajr0drfMXhc7m8WvRiSo2Uf+zvaftoFbw1HPB9vRfKin9fAg9ZvdJBdkkFBZuEK+KpwnHpyIu3l+A0H1cU3wXB3w5ayjErPhLuFw85ifWa63MsQNoj0qnPpsfl/0jycyaH2SFU58NFES61k30IwV/p9mknd0h057OLgykoMvxuVW5DEFY/+TmcjuwlwnyOzex3lE5bzccAx2EAtb4kvMZZ5qeNSXX8MSqPm5Zlg3iLyH55gvFBeW0ern3+KlqMw1F8Wka6bWD1vzM3aJ605D3hHZW5GlwUbCEjJ6khwuJ3YSfc9iv2iu8tnXBZ1b27r66BS9eLp6a4j7khpdT083hWb6Vnx/hBiGLd9ctRro3ZQDHuEywNqOYCxyk0xJVwwdOBq0x3sgngxKHWTvogH4Lt64CzGQSFFaKYGq1m9ANbgUufXdLMjMd+t/9JzPxs7wZFk8nTCkKTDiuhPzE82SkZP+JZrYGmZG5c0F8foPS/zYDGOY9NFxLwuFePM+KiCq9fpB1D9TOsG0krI7qfUmdivMpKzGHGWKYjVMWVP+JITx43hw0Zk/zvIr3W3jiDZaOrCpyroBd4SdtSBe3Djhxrxsjrvc4/b0crZTCFdSklm1iU4hhnCDER3QjCtUtuH36rI8EFzs6KJ5R8eZVv01/VL1mgtkSsp+WDZEFaiqGbg/892RA1rkIEWrxOd3iTtmAKoESs9A+p2bljJDCVcN9a0 iHG3TMSj UOMm+On9O8T+/fy1MNfOV6Hum7VnoVzdkVEZifX1BMZiuHek18sNwmMJym77ND8dQFvliUHC/B33/Kwd/5S9b9HcBENn4TU1hh7YoUvnk43GdXC0Yq1UuSg/Svmn5IUaIhUR03yPBuCdW/EZU5RQ3TRlTfy9VnWxFgLG6LN0RDnGsthDdqZqyI0O1AWU9FKXFFD2dDSg5op+GnlMkwD3cJKnitL3GGs8bMGlEB8fz/nO5ZADDAiSp55amJl04r9CCQ6fs 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 09/04/2024 09:26, Barry Song wrote: > From: Barry Song > > Add a boolean argument named any_shared. If any of the swap entries are > non-exclusive, set any_shared to true. The function do_swap_page() can > then utilize this information to determine whether the entire large > folio can be reused. > > Signed-off-by: Barry Song > --- > mm/internal.h | 9 ++++++++- > mm/madvise.c | 2 +- > mm/memory.c | 2 +- > 3 files changed, 10 insertions(+), 3 deletions(-) > > diff --git a/mm/internal.h b/mm/internal.h > index 9d3250b4a08a..cae39c372bfc 100644 > --- a/mm/internal.h > +++ b/mm/internal.h > @@ -238,7 +238,8 @@ static inline pte_t pte_next_swp_offset(pte_t pte) > * > * Return: the number of table entries in the batch. > */ > -static inline int swap_pte_batch(pte_t *start_ptep, int max_nr, pte_t pte) > +static inline int swap_pte_batch(pte_t *start_ptep, int max_nr, pte_t pte, > + bool *any_shared) Please update the docs in the comment above this for the new param; follow folio_pte_batch()'s docs as a template. > { > pte_t expected_pte = pte_next_swp_offset(pte); > const pte_t *end_ptep = start_ptep + max_nr; > @@ -248,12 +249,18 @@ static inline int swap_pte_batch(pte_t *start_ptep, int max_nr, pte_t pte) > VM_WARN_ON(!is_swap_pte(pte)); > VM_WARN_ON(non_swap_entry(pte_to_swp_entry(pte))); > > + if (any_shared) > + *any_shared |= !pte_swp_exclusive(pte); This is different from the approach in folio_pte_batch(). It inits *any_shared to false and does NOT include the value of the first pte. I think that's odd, personally and I prefer your approach. I'm not sure if there was a good reason that David chose the other approach? Regardless, I think both functions should follow the same pattern here. If sticking with your approach, why is this initial flag being ORed? Surely it should just be initialized to get rid of any previous guff? Thanks, Ryan > + > while (ptep < end_ptep) { > pte = ptep_get(ptep); > > if (!pte_same(pte, expected_pte)) > break; > > + if (any_shared) > + *any_shared |= !pte_swp_exclusive(pte); > + > expected_pte = pte_next_swp_offset(expected_pte); > ptep++; > } > diff --git a/mm/madvise.c b/mm/madvise.c > index f59169888b8e..d34ca6983227 100644 > --- a/mm/madvise.c > +++ b/mm/madvise.c > @@ -671,7 +671,7 @@ static int madvise_free_pte_range(pmd_t *pmd, unsigned long addr, > entry = pte_to_swp_entry(ptent); > if (!non_swap_entry(entry)) { > max_nr = (end - addr) / PAGE_SIZE; > - nr = swap_pte_batch(pte, max_nr, ptent); > + nr = swap_pte_batch(pte, max_nr, ptent, NULL); > nr_swap -= nr; > free_swap_and_cache_nr(entry, nr); > clear_not_present_full_ptes(mm, addr, pte, nr, tlb->fullmm); > diff --git a/mm/memory.c b/mm/memory.c > index 2702d449880e..c4a52e8d740a 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -1638,7 +1638,7 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb, > folio_put(folio); > } else if (!non_swap_entry(entry)) { > max_nr = (end - addr) / PAGE_SIZE; > - nr = swap_pte_batch(pte, max_nr, ptent); > + nr = swap_pte_batch(pte, max_nr, ptent, NULL); > /* Genuine swap entries, hence a private anon pages */ > if (!should_zap_cows(details)) > continue;