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 1E3E0C25B4F for ; Fri, 3 May 2024 09:41:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 89DCB6B0098; Fri, 3 May 2024 05:41:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 84E326B0099; Fri, 3 May 2024 05:41:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 73C7D6B009A; Fri, 3 May 2024 05:41:40 -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 557C16B0098 for ; Fri, 3 May 2024 05:41:40 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id F3665810B0 for ; Fri, 3 May 2024 09:41:39 +0000 (UTC) X-FDA: 82076592318.12.FC51645 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf13.hostedemail.com (Postfix) with ESMTP id AD9D22000A for ; Fri, 3 May 2024 09:41:31 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=none; spf=pass (imf13.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=1714729291; 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=9JGwgH37E9mqU96qVAbD+wncP1baKjwSMbUen5o9Bzg=; b=tK0j9Pqe3sBtqharAEFF79YDVWjhlxdwCNik2TorJFUg5hMSUQxS+DfzyFtKsSojOLjJDK fezHHRq0sjIygg5rlJ64p9KMYp6uhSjOuCzmdRzPJmQ1MAWrxgp0fORXAfq1/w/2cv/2+0 4Kf2pfkZHOKw1zCrKmN/UNAaUscfeWo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714729291; a=rsa-sha256; cv=none; b=VYr1RowPNcnv1lfahldYxEab+XxsQy2Nw5l9ttOgChGZpxdVh9jp5QLCBHd4AgEfH7Ttwr Ja4JKGmPWynre6lBdA5A5Tge2lGmnuLMkwppS/LHLt3VHDL9LBmwVmTzRpnyHzeQy1j3Sd l4MjvWiujpF9BQQirOSWQANs/coQYaQ= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; spf=pass (imf13.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 1AB31339; Fri, 3 May 2024 02:41:56 -0700 (PDT) Received: from [10.57.67.51] (unknown [10.57.67.51]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 490343F73F; Fri, 3 May 2024 02:41:28 -0700 (PDT) Message-ID: <7548e30c-d56a-4a57-ab87-86c9c8e523b1@arm.com> Date: Fri, 3 May 2024 10:41:26 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 3/6] mm: introduce pte_move_swp_offset() helper which can move offset bidirectionally 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, linux-kernel@vger.kernel.org, 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 References: <20240503005023.174597-1-21cnbao@gmail.com> <20240503005023.174597-4-21cnbao@gmail.com> From: Ryan Roberts In-Reply-To: <20240503005023.174597-4-21cnbao@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspam-User: X-Stat-Signature: 5qg98yydjd78dk9tsdqb8ijcy6tfh5ta X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: AD9D22000A X-HE-Tag: 1714729291-178215 X-HE-Meta: U2FsdGVkX19m4rEfdRecwN5Oe2oaw4CrwOHwhV1wOK5Bo/7DF1TUwdMz/0ou6juoWEb4wCGjL0ICGT1GWT34AIKiscEOGv83wjl1YJrw0FS6Xch656LDJfDi/t24zNnIfi/ORv8tvIx/o0iqV1DJ//7Lqtfa1o5FRv0Z72tdK/oIfb0z/XvKSXSBbcNBvMMtjNi3wKzOJvcBo7C7FQcJMX+bQRew/JTsPVwHqcCK/PrtGeespQiSlDaiTbiYFnGqxDM/Yf61JwO04zn8/A9jYBwkP5zxCzwRo7Mh0ZwG0aYy2ZAskjc8KhN27i8L6MFzqXEPa+pMlhdUm9E364bEprvNt5isT/vihelXco2dbnDGaIRsI9lHWyVfmxOp+G9/tTnzFnC8vg/AHUEPip3XKbf5cI80cGaZY480DtJeYs5TFckfnP7l6DI2PI4ss936iF9U80P03xSWfOYHx/aInvM58IAEuxKijFPvQC1PnO7l265bP+PChd4bGvb5nGKJochU2rcBhvRIofJtT4BjS47eOyY8IIuAJa2sRxNnfP7aKJswgiKqk9qEw4mUOo1vmEYmhPicKTdUFFevZwrjbBObSVxbfpnTuk6TZSpJsIiOSbtA6/IfZGKja1ylH0ETaZlTdUWMTThMkVYO9luqh6CbaCOXFznf4ncU+zD3tma5MT4Zev4VUogMzH2k5BYTlLnd5eNVJG59Byo6HQW8wCKxqsYiHJlGhnIQkHwn2XEj+ymKjkO+Ez+K2be1WeCyL3EVZLyBjhKW10Tgxeuuq4AIRLNX2SA8tKQ/zzRrW5yuW8eO2s142TjtG76UHBWtTYLxGaPInKnLpjsSKY/otM4yhKy285JaLodKWc/jqehBkVt5HDsvk9aBCNWzymwvjnoneIAI5e4fGrw1xusjQjBxVMLZPoeam7tCD+hH9Wv3s/nPKZ9b/cv2RUuRFo5vO5sX8fHlpzNaVAURDTP JIrau0cv jcpgTnrrbdy4Eydrxn6eVo1p8VdZYWU9IlofcjG53sQqgHnTr3t+r5mZO2+9LC8a/2Bixj+XW+w1tycr6XB/2FrzdzUF3ee6S/hOf1kvzJ7NgwBuw+CEnILYvf0JVgeK4bRrgv7U7E2hEPX3c/WtSTvWRd1QGjCJDPBGqpSaQxwzE9yuIyUwSZDaQfLVxF5jfo3Ec9a6YzX0PoH15VMdgfAtYolyIMSd7ZWnnjWqt+kllohrj8RXakWME+SMB90ue7xtOw5XEZi6g78nkIGxElwJRwY9B/nwjBxuR1L3NLnlFwh5AA/Dp3jSSf9GbBmCL8t92CLAfaTXQdjzj8rRCiaFdtQ== 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 03/05/2024 01:50, Barry Song wrote: > From: Barry Song > > There could arise a necessity to obtain the first pte_t from a swap > pte_t located in the middle. For instance, this may occur within the > context of do_swap_page(), where a page fault can potentially occur in > any PTE of a large folio. To address this, the following patch introduces > pte_move_swp_offset(), a function capable of bidirectional movement by > a specified delta argument. Consequently, pte_increment_swp_offset() You mean pte_next_swp_offset()? > will directly invoke it with delta = 1. > > Suggested-by: "Huang, Ying" > Signed-off-by: Barry Song > --- > mm/internal.h | 25 +++++++++++++++++++++---- > 1 file changed, 21 insertions(+), 4 deletions(-) > > diff --git a/mm/internal.h b/mm/internal.h > index c5552d35d995..cfe4aed66a5c 100644 > --- a/mm/internal.h > +++ b/mm/internal.h > @@ -211,18 +211,21 @@ static inline int folio_pte_batch(struct folio *folio, unsigned long addr, > } > > /** > - * pte_next_swp_offset - Increment the swap entry offset field of a swap pte. > + * pte_move_swp_offset - Move the swap entry offset field of a swap pte > + * forward or backward by delta > * @pte: The initial pte state; is_swap_pte(pte) must be true and > * non_swap_entry() must be false. > + * @delta: The direction and the offset we are moving; forward if delta > + * is positive; backward if delta is negative > * > - * Increments the swap offset, while maintaining all other fields, including > + * Moves the swap offset, while maintaining all other fields, including > * swap type, and any swp pte bits. The resulting pte is returned. > */ > -static inline pte_t pte_next_swp_offset(pte_t pte) > +static inline pte_t pte_move_swp_offset(pte_t pte, long delta) We have equivalent functions for pfn: pte_next_pfn() pte_advance_pfn() Although the latter takes an unsigned long and only moves forward currently. I wonder if it makes sense to have their naming and semantics match? i.e. change pte_advance_pfn() to pte_move_pfn() and let it move backwards too. I guess we don't have a need for that and it adds more churn. Anyway: Reviewed-by: Ryan Roberts > { > swp_entry_t entry = pte_to_swp_entry(pte); > pte_t new = __swp_entry_to_pte(__swp_entry(swp_type(entry), > - (swp_offset(entry) + 1))); > + (swp_offset(entry) + delta))); > > if (pte_swp_soft_dirty(pte)) > new = pte_swp_mksoft_dirty(new); > @@ -234,6 +237,20 @@ static inline pte_t pte_next_swp_offset(pte_t pte) > return new; > } > > + > +/** > + * pte_next_swp_offset - Increment the swap entry offset field of a swap pte. > + * @pte: The initial pte state; is_swap_pte(pte) must be true and > + * non_swap_entry() must be false. > + * > + * Increments the swap offset, while maintaining all other fields, including > + * swap type, and any swp pte bits. The resulting pte is returned. > + */ > +static inline pte_t pte_next_swp_offset(pte_t pte) > +{ > + return pte_move_swp_offset(pte, 1); > +} > + > /** > * swap_pte_batch - detect a PTE batch for a set of contiguous swap entries > * @start_ptep: Page table pointer for the first entry.