The patch titled Subject: mm: set pte writable while pte_soft_dirty() is true in do_swap_page() has been added to the -mm mm-unstable branch. Its filename is mm-set-pte-writable-while-pte_soft_dirty-is-true-in-do_swap_page.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-set-pte-writable-while-pte_soft_dirty-is-true-in-do_swap_page.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 the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Barry Song <v-songbaohua@xxxxxxxx> Subject: mm: set pte writable while pte_soft_dirty() is true in do_swap_page() Date: Sat, 8 Jun 2024 09:13:58 +1200 This patch leverages the new pte_needs_soft_dirty_wp() helper to optimize a scenario where softdirty is enabled, but the softdirty flag has already been set in do_swap_page(). In this situation, we can use pte_mkwrite instead of applying write-protection since we don't depend on write faults. Link: https://lkml.kernel.org/r/20240607211358.4660-3-21cnbao@xxxxxxxxx Signed-off-by: Barry Song <v-songbaohua@xxxxxxxx> Suggested-by: David Hildenbrand <david@xxxxxxxxxx> Cc: Chris Li <chrisl@xxxxxxxxxx> Cc: Kairui Song <kasong@xxxxxxxxxxx> Cc: Matthew Wilcox (Oracle) <willy@xxxxxxxxxxxxx> Cc: Minchan Kim <minchan@xxxxxxxxxx> Cc: Ryan Roberts <ryan.roberts@xxxxxxx> Cc: Suren Baghdasaryan <surenb@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/mm/memory.c~mm-set-pte-writable-while-pte_soft_dirty-is-true-in-do_swap_page +++ a/mm/memory.c @@ -4322,7 +4322,7 @@ check_folio: if (!folio_test_ksm(folio) && (exclusive || folio_ref_count(folio) == 1)) { if ((vma->vm_flags & VM_WRITE) && !userfaultfd_pte_wp(vma, pte) && - !vma_soft_dirty_enabled(vma)) { + !pte_needs_soft_dirty_wp(vma, pte)) { pte = pte_mkwrite(pte, vma); if (vmf->flags & FAULT_FLAG_WRITE) { pte = pte_mkdirty(pte); _ Patches currently in -mm which might be from v-songbaohua@xxxxxxxx are mm-remove-the-implementation-of-swap_free-and-always-use-swap_free_nr.patch mm-introduce-pte_move_swp_offset-helper-which-can-move-offset-bidirectionally.patch mm-introduce-arch_do_swap_page_nr-which-allows-restore-metadata-for-nr-pages.patch mm-swap-reuse-exclusive-folio-directly-instead-of-wp-page-faults.patch mm-introduce-pmdpte_needs_soft_dirty_wp-helpers-for-softdirty-write-protect.patch mm-set-pte-writable-while-pte_soft_dirty-is-true-in-do_swap_page.patch