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 EFDDEC4345F for ; Thu, 11 Apr 2024 15:36:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6E1CF6B007B; Thu, 11 Apr 2024 11:36:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 692416B0082; Thu, 11 Apr 2024 11:36:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 581006B0088; Thu, 11 Apr 2024 11:36:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 3AED06B007B for ; Thu, 11 Apr 2024 11:36:23 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id CCAC7160C3F for ; Thu, 11 Apr 2024 15:36:22 +0000 (UTC) X-FDA: 81997652604.29.EAAD399 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf28.hostedemail.com (Postfix) with ESMTP id ED5C6C000C for ; Thu, 11 Apr 2024 15:36:20 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; spf=pass (imf28.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=1712849781; a=rsa-sha256; cv=none; b=CgMgnqyXyFh1QOSHETfrtrpeNk63zVkgoqXj7+BOidOBHOaILcTLOvZTCJWA56xO+YWoIY QUKtH9gEQDyC5gP/a70wbjsLLus9taZtP8rJkfTAmK1aBsi86/Lbiz0zIlvpyjb89bg035 iZvevoW6HV6KkZH5y0IwRU95Ul1hvT0= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; spf=pass (imf28.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=1712849781; 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=C4H9LpoyLcRyyMrriUt26rIi+6RJgo2b9WKybnTgEDs=; b=uR6G9C5r4NwGvAqA8kbx5JNd/jRJuil4o7SDBkAwlOpM14qOWN/tLVEtULLZvqMOVAyn5b y8h6oLnmYZmkZfy72Gr8bRNm6qxrnHsY85ZoUdRG/SAl6nc6PuEyT9hjlhG8TJjVoWvgy6 8cxmFqvP2/QtgwBkuR1pfVi7WsnLraU= 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 B6FEC113E; Thu, 11 Apr 2024 08:36:49 -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 04FD43F6C4; Thu, 11 Apr 2024 08:36:17 -0700 (PDT) Message-ID: Date: Thu, 11 Apr 2024 16:36:16 +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: David Hildenbrand , Barry Song <21cnbao@gmail.com>, akpm@linux-foundation.org, linux-mm@kvack.org Cc: baolin.wang@linux.alibaba.com, chrisl@kernel.org, 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> <744f795b-7ce8-40ab-911b-60906aa4fed1@arm.com> From: Ryan Roberts In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: ED5C6C000C X-Stat-Signature: nf38nqhzhw8b3ynfgkkmatpekdojpsaf X-HE-Tag: 1712849780-171722 X-HE-Meta: U2FsdGVkX19wWQByPUwGQAmXiENiMi3J6PAqm5p3YZmye1STADtkKv1Y6ogYe3Jxau1I9J5xpdTdsn5bu8FUUi0QON7JHwH2VYQAw7KcHL1bXfsdSbtLkWyCLpDTpaZQLHOUzN5/Xkin1UHlFzGsETC2hGG6KrcqWfoCB0uQoRFMdC7oCqu2j2vcVahOLh4XVxjcOVJ3uHaZ+15KDM+D+uEZyCbs77csJDqqZunCuIlv2R3nOfe4bzkPzVB7UB+bvNJ9XY4b72Qgw1P/cj283mc3f8jCgdbxnYEg2ReS/qQ9l26BM1HsHymyZffYQPiXfmHKmrlRNnNJYta9okTLyyFzl/3S5osUWWwnOOpqihgePXch8PPsb3yqqqV2oJKgBTUDaAx/NBCQ2meXq328kxKGysGj+SGNSrd1z7u/qaXaM7f+rzCd676A0zaEkx0jMB4DA8veN5/0zQz8+x8mr51U8ank7ZNYftrMWPdZ91YZRtk81QpDlH8CkARnle1XLd3RCLn08pQ3MAjK3i83HvAwS4VZej09/at7HRwP1TAPY/P1OoPKOwbjsQ99jRgtt/q0dlLwmQtFN76LwXADEzvXUYrHoXTmf34i5RT4mYFJAJYITknHx3XJCRrqX28HbJenr/06v4It8BiJMJj9WHTNzJ4dx4n1f91VIUCqwPKlspKEM5XrjXUhcP+wZUiDIMmTQN0aNvdT14NGvRQ1CR0WOShIgeCCivGhcRUBGHbDlCOVw5x93bN8/JL/AAD4otBgiOOZlhfn+w22POwE3BHsNzImfvezxyEDimkSa/FEidyGa1j1H2BdyMf5JFmTSd0cTUBwTH1wOBCcSwPnG3QRMRlN8BWWFo5QiQ/dqQtJiuRAMIIfltjz6PWV7RWp2Kb1xFTSmTNQkgeba3Rwp0yERWI3HBg2YIcL+wphR4klgWWnEGfvIj1J5dgEUXHSoG+fNADLplIInZ7ryoS wj4+9lsF zLi3fjSfIQOvohfUdBCtNz9tlDVlV4fw6f3/9z8eP2AMuYWCoJLMrmVGbgC3297cprioQ7bnE+XDay01IeNyCOXBpasf/FGDzgW5l79LlodduOlkLpg5bGUlmlTwWenMLsarkn1PZYuZZFJnObcb6kIbrLMavvDzF8DWDhXpxn/pDZ5eSeal2GizUKUDQY2it2Abg2fHR9u+HxelyhUSy0SyweIOm/zuvc07s3ndRzediQUODHy+UnRRj0MyVhH8SZYSv 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 11/04/2024 16:00, David Hildenbrand wrote: > On 11.04.24 16:54, Ryan Roberts wrote: >> 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? > > Because in my case calling code does > > nr = folio_pte_batch(folio, addr, src_pte, pte, max_nr, flags, >              &any_writable); > > ... > > if (any_writable) >     pte = pte_mkwrite(pte, src_vma); > > ... > > and later checks in another function pte_write(). > > So if the common pattern is that the original PTE will be used for checks, then > it doesn't make sense to unnecessary checks+setting for the first PTE. Yep understood. And I think adopting your semantics for any_shared actually simplifies the code in patch 4 too; I've just commented that.