From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7748D3E3141 for ; Thu, 13 Aug 2026 18:55:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786647306; cv=none; b=R7K/1OtQXQvDFJNu/xW0cMEo43QwowYU0oaJsbvFh0lexmzbsmH53MYBn+found6eE+Mv9k27cK/g9cSNJVkIhUAjDsLLNwfBf0dVHD4Z6N1pBus+YJJP6uSR1tMS8SWyxiuBLWIQ1Dd7xyvdbiZCQ/aVn47N+JDinIRLxGyCoo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786647306; c=relaxed/simple; bh=XMuChUdN+cS7qdelWxUcjcTqWV/eMrjCVbQy3cElUIM=; h=Date:To:From:Subject:Message-Id; b=dlSdV3LgShE36Zb+6LZEVMi1cd1i4uh/PJVzmp4YgpOhy/rksbM7X3Y8T661q/a/u6xQwQ5RjqhTTt/jpqTGT6tDPARwadUX9f5GWFkOgUj6F/SbuPMU6vPh30zAaoLh4lB52EMQUZ14gozG6mpzEk2giHGdVghMzRxNoKRTQgQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=InlFurtz; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="InlFurtz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4BA6B1F00A3A; Thu, 13 Aug 2026 18:55:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1786647304; bh=BAMNOuONmtODjGROSqGR7SL/tD43nXiacSadS/3L9Ag=; h=Date:To:From:Subject; b=InlFurtzvo+X6FiDO8Hrlo+PpWNq0lLBpuh6YIwgB7VQcgRp6CAaMRhGWDtXGOB4x FeGbH9YVOrejZhQYyGvUhaErUwZjuvRCPcm8/jLsR5/5Scc1jklQuTgcxItyHtt6/h efSEdz2DE6eCpcIPuhxVNWz2VYEv51FNz/ncZSns= Date: Thu, 13 Aug 2026 11:55:03 -0700 To: mm-commits@vger.kernel.org,ljs@kernel.org,akpm@linux-foundation.org From: Andrew Morton Subject: + mm-migrate-calculate-large-folio-page-index-using-pfn.patch added to mm-unstable branch Message-Id: <20260813185504.4BA6B1F00A3A@smtp.kernel.org> Precedence: bulk X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: The patch titled Subject: mm/migrate: calculate large folio page index using PFN has been added to the -mm mm-unstable branch. Its filename is mm-migrate-calculate-large-folio-page-index-using-pfn.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-migrate-calculate-large-folio-page-index-using-pfn.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there most days ------------------------------------------------------ From: "Lorenzo Stoakes (ARM)" Subject: mm/migrate: calculate large folio page index using PFN Date: Thu, 13 Aug 2026 18:32:30 +0100 Rather than having to figure out the page index to use using linear_page_index(), calculate it using PFN. This is a more natural fit as the linear page index is immaterial to determining the folio page index. Derive the page index from the offset between migration entry PFN and folio PFN - pvmw.pfn (set via DEFINE_FOLIO_VMA_WALK() which uses folio_pfn() to obtain it). Additionally remove a not so useful comment and clean the code layout up. No functional change intended. Link: https://lore.kernel.org/20260813-b4-scalable-cow-virt-pgoff-v5-13-c21581c0c3c8@kernel.org Signed-off-by: Lorenzo Stoakes (ARM) Suggested-by: David Hildenbrand (Arm) Acked-by: David Hildenbrand (Arm) Cc: Adrian Hunter Cc: Alexander Deucher Cc: Alexander Gordeev Cc: Alexander Shishkin Cc: Alistair Popple Cc: Arnaldo Carvalho de Melo Cc: Arnd Bergmann Cc: Baolin Wang Cc: Baoquan He Cc: Barry Song Cc: Boris Brezillon Cc: Byungchul Park Cc: Chengming Zhou Cc: Chris Li Cc: Christan König Cc: Christian Borntraeger Cc: Claudio Imbrenda Cc: Dave Airlie Cc: Dev Jain Cc: Gerald Schaefer Cc: Greg Kroah-Hartman Cc: Gregory Price (Meta) Cc: Harry Yoo Cc: Heiko Carstens Cc: Huang Ray Cc: "Huang, Ying" Cc: Ian Rogers Cc: Ingo Molnar Cc: James Clark Cc: Jan Kara Cc: Jann Horn Cc: Janosch Frank Cc: Jason Gunthorpe Cc: Jiri Olsa Cc: John Hubbard Cc: Joshua Hahn Cc: Kairui Song Cc: Kees Cook Cc: Kemeng Shi Cc: Lance Yang Cc: Liam R. Howlett Cc: Liviu Dudau Cc: Maarten Lankhorst Cc: Marc Rutland Cc: "Masami Hiramatsu (Google)" Cc: Matthew Auld Cc: Matthew Brost Cc: Matthew Wilcox (Oracle) Cc: Maxime Ripard Cc: Miaohe Lin Cc: Michal Hocko Cc: Mike Rapoport Cc: Muchun Song Cc: Namhyung kim Cc: Naoya Horiguchi Cc: Nhat Pham Cc: Nico Pache Cc: Oleg Nesterov Cc: Oscar Salvador Cc: Pedro Falcato Cc: Peter Xu Cc: Peter Zijlstra Cc: Rakie Kim Cc: Rik van Riel Cc: Rodrigo Vivi Cc: Ryan Roberts Cc: Steven Price Cc: Suren Baghdasaryan Cc: Sven Schnelle Cc: Thomas Hellström Cc: Thomas Zimemrmann Cc: Vasily Gorbik Cc: Vlastimil Babka Cc: xu xin Cc: Zi Yan Signed-off-by: Andrew Morton --- mm/migrate.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) --- a/mm/migrate.c~mm-migrate-calculate-large-folio-page-index-using-pfn +++ a/mm/migrate.c @@ -356,16 +356,11 @@ static bool remove_migration_pte(struct while (page_vma_mapped_walk(&pvmw)) { rmap_t rmap_flags = RMAP_NONE; - pte_t old_pte; - pte_t pte; + unsigned long idx = 0; softleaf_t entry; struct page *new; - unsigned long idx = 0; - - /* pgoff is invalid for ksm pages, but they are never large */ - if (folio_test_large(folio) && !folio_test_hugetlb(folio)) - idx = linear_page_index(vma, pvmw.address) - pvmw.pgoff; - new = folio_page(folio, idx); + pte_t old_pte; + pte_t pte; #ifdef CONFIG_ARCH_HAS_PMD_SOFTLEAVES /* PMD-mapped THP migration entry */ @@ -381,14 +376,18 @@ static bool remove_migration_pte(struct pvmw.pte); else old_pte = ptep_get(pvmw.pte); + + entry = softleaf_from_pte(old_pte); + if (folio_test_large(folio) && !folio_test_hugetlb(folio)) + idx = softleaf_to_pfn(entry) - pvmw.pfn; + if (rmap_walk_arg->map_unused_to_zeropage && try_to_map_unused_to_zeropage(&pvmw, folio, old_pte, idx)) continue; folio_get(folio); + new = folio_page(folio, idx); pte = mk_pte(new, READ_ONCE(vma->vm_page_prot)); - - entry = softleaf_from_pte(old_pte); if (!softleaf_is_migration_young(entry)) pte = pte_mkold(pte); if (folio_test_dirty(folio) && softleaf_is_migration_dirty(entry)) _ Patches currently in -mm which might be from ljs@kernel.org are mm-vma-introduce-vma-anon-page-offset-field-and-add-helpers.patch mm-provide-vma_is_cow_mapping-and-remove-is_cow_mapping.patch mm-introduce-linear_anon_page_index.patch mm-abstract-vma_address-and-introduce-vma_anon_address.patch mm-update-print_bad_page_map-to-show-anon-index-if-appropriate.patch mm-introduce-and-use-vma_filebacked_address.patch mm-vma-fix-self-merge-check-in-copy_vma.patch tools-testing-vma-add-tests-for-copy_vma-self-merge.patch mm-propagate-vma-anonymous-page-offset-on-map-remap-split-merge.patch mm-rmap-track-whether-the-page-vma-mapped-pgoff-is-anonymous.patch mm-clean-up-vma_address_end.patch mm-huge_memory-update-remove_migration_pmd-to-accept-a-folio.patch mm-migrate-calculate-large-folio-page-index-using-pfn.patch mm-rmap-use-anon-pgoff-to-track-map_private-file-backed-anon-folios.patch tools-testing-vma-expand-vma-merge-tests-to-assert-anon-pgoff.patch tools-testing-selftests-mm-test-anonymous-page-offset-merge-behaviour.patch mm-add-some-missing-includes-to-mm-local-headers.patch maintainers-add-drivers-char-memc-to-mm-misc-memory-mapping-sections.patch