mm-rmap-split-page_dup_rmap-into-page_dup_file_rmap-and-page_try_dup_anon_rmap.patch removed from -mm tree
The quilt patch titled
Subject: mm/rmap: split page_dup_rmap() into page_dup_file_rmap() and page_try_dup_anon_rmap()
has been removed from the -mm tree. Its filename was
mm-rmap-split-page_dup_rmap-into-page_dup_file_rmap-and-page_try_dup_anon_rmap.patch
This patch was dropped because it was merged into mm-stable
------------------------------------------------------
From: David Hildenbrand <[email protected]>
Subject: mm/rmap: split page_dup_rmap() into page_dup_file_rmap() and page_try_dup_anon_rmap()
... and move the special check for pinned pages into page_try_dup_anon_rmap() to prepare for tracking exclusive anonymous pages via a new pageflag, clearing it only after making sure that there are no GUP pins on the anonymous page.
We really only care about pins on anonymous pages, because they are prone to getting replaced in the COW handler once mapped R/O. For !anon pages in cow-mappings (!VM_SHARED && VM_MAYWRITE) we shouldn't really care about that, at least not that I could come up with an example.
Let's drop the is_cow_mapping() check from page_needs_cow_for_dma(), as we know we're dealing with anonymous pages. Also, drop the handling of pinned pages from copy_huge_pud() and add a comment if ever supporting anonymous pages on the PUD level.
This is a preparation for tracking exclusivity of anonymous pages in the rmap code, and disallowing marking a page shared (-> failing to duplicate) if there are GUP pins on a page.
---
include/linux/mm.h | 5 ---- include/linux/rmap.h | 49 ++++++++++++++++++++++++++++++++++++++++- mm/huge_memory.c | 27 ++++++---------------- mm/hugetlb.c | 16 +++++++------ mm/memory.c | 17 ++++++++++---- mm/migrate.c | 2 - 6 files changed, 79 insertions(+), 37 deletions(-)
include/linux/mm.h renamed from include/linux/mm.h~mm-rmap-split-page_dup_rmap-into-page_dup_file_rmap-and-page_try_dup_anon_rmap +1 -4
@@ -1575,16 +1575,13 @@ static inline bool page_maybe_dma_pinned/* * This should most likely only be called during fork() to see whether we -* should break the cow immediately for a page on the src mm. +* should break the cow immediately for an anon page on the src mm. * * The caller has to hold the PT lock and the vma->vm_mm->->write_protect_seq. */ static inline bool page_needs_cow_for_dma (struct vm_area_struct *vma,struct page *page) { -if (!is_cow_mapping (vma->vm_flags)) -return false; -VM_BUG_ON (!(raw_read_seqcount (&vma->vm_mm->write_protect_seq) &1 ));if (!test_bit (MMF_HAS_PINNED , &vma->vm_mm->flags))
include/linux/rmap.h renamed from include/linux/rmap.h~mm-rmap-split-page_dup_rmap-into-page_dup_file_rmap-and-page_try_dup_anon_rmap +48 -1
65 lines not on this page · raw message
mm/huge_memory.c renamed from mm/huge_memory.c~mm-rmap-split-page_dup_rmap-into-page_dup_file_rmap-and-page_try_dup_anon_rmap +8 -19
@@ -1097,23 +1097,16 @@ int copy_huge_pmd(struct mm_struct *dst_ src_page =pmd_page (pmd);VM_BUG_ON_PAGE (!PageHead (src_page), src_page); -/* -* If this page is a potentially pinned page, split and retry the fault -* with smaller page size. Normally this should not happen because the -* userspace should use MADV_DONTFORK upon pinned regions. This is a -* best effort that the pinned pages won't be replaced by another -* random page during the coming copy-on-write. -*/ -if (unlikely (page_needs_cow_for_dma (src_vma, src_page))) { +get_page (src_page); +if (unlikely (page_try_dup_anon_rmap (src_page, true, src_vma))) { +/* Page maybe pinned: split and retry the fault on PTEs. */ +put_page (src_page);pte_free (dst_mm, pgtable);spin_unlock (src_ptl);spin_unlock (dst_ptl);__split_huge_pmd (src_vma, src_pmd, addr, false,NULL );return -EAGAIN ; } - -get_page (src_page); -page_dup_rmap (src_page, true);add_mm_counter (dst_mm,MM_ANONPAGES ,HPAGE_PMD_NR ); out_zero_page:mm_inc_nr_ptes (dst_mm);
@@ -1217,14 +1210,10 @@ int copy_huge_pud(struct mm_struct *dst_/* No huge zero pud yet */ } -/* Please refer to comments in copy_huge_pmd() */ -if (unlikely (page_needs_cow_for_dma (vma,pud_page (pud)))) { -spin_unlock (src_ptl); -spin_unlock (dst_ptl); -__split_huge_pud (vma, src_pud, addr); -return -EAGAIN ; - } - +/* +* TODO: once we support anonymous pages, use page_try_dup_anon_rmap() +* and split if duplicating fails. +*/ pudp_set_wrprotect (src_mm, addr, src_pud); pud =pud_mkold (pud_wrprotect (pud));set_pud_at (dst_mm, addr, dst_pud, pud);
mm/hugetlb.c renamed from mm/hugetlb.c~mm-rmap-split-page_dup_rmap-into-page_dup_file_rmap-and-page_try_dup_anon_rmap +9 -7
@@ -4806,15 +4806,18 @@ again:get_page (ptepage);/* -* This is a rare case where we see pinned hugetlb -* pages while they're prone to COW. We need to do the -* COW earlier during fork. +* Failing to duplicate the anon rmap is a rare case +* where we see pinned hugetlb pages while they're +* prone to COW. We need to do the COW earlier during +* fork. * * When pre-allocating the page or copying data, we * need to be without the pgtable locks since we could * sleep during the process. */ -if (unlikely (page_needs_cow_for_dma (vma, ptepage))) { +if (!PageAnon (ptepage)) { +page_dup_file_rmap (ptepage, true); + }else if (page_try_dup_anon_rmap (ptepage, true, vma)) {pte_t src_pte_old = entry;struct page *new;
@@ -4861,7 +4864,6 @@ again: entry =huge_pte_wrprotect (entry); } -page_dup_rmap (ptepage, true);set_huge_pte_at (dst, addr, dst_pte, entry);hugetlb_count_add (npages, dst); }
@@ -5541,7 +5543,7 @@ retry:ClearHPageRestoreReserve (page);hugepage_add_new_anon_rmap (page, vma, haddr); }else -page_dup_rmap (page, true); +page_dup_file_rmap (page, true); new_pte =make_huge_pte (vma, page, ((vma->vm_flags &VM_WRITE ) && (vma->vm_flags &VM_SHARED )));set_huge_pte_at (mm, haddr, ptep, new_pte);
@@ -5902,7 +5904,7 @@ int hugetlb_mcopy_atomic_pte(struct mm_s goto out_release_unlock;if (vm_shared) { -page_dup_rmap (page, true); +page_dup_file_rmap (page, true); }else {ClearHPageRestoreReserve (page);hugepage_add_new_anon_rmap (page, dst_vma, dst_addr);
mm/memory.c renamed from mm/memory.c~mm-rmap-split-page_dup_rmap-into-page_dup_file_rmap-and-page_try_dup_anon_rmap +12 -5
@@ -825,7 +825,8 @@ copy_nonpresent_pte(struct mm_struct *ds*/ get_page (page); rss[mm_counter (page)]++; -page_dup_rmap (page, false); +/* Cannot fail as these pages cannot get pinned. */ +BUG_ON (page_try_dup_anon_rmap (page, false, src_vma));/* * We do not preserve soft-dirty information, because so
@@ -921,18 +922,24 @@ copy_present_pte(struct vm_area_struct *struct page *page; page =vm_normal_page (src_vma, addr, pte); -if (page &&unlikely (page_needs_cow_for_dma (src_vma, page))) { +if (page &&PageAnon (page)) {/* * If this page may have been pinned by the parent process, * copy the page immediately for the child so that we'll always * guarantee the pinned page won't be randomly replaced in the * future. */ -return copy_present_page (dst_vma, src_vma, dst_pte, src_pte, - addr, rss, prealloc, page); +get_page (page); +if (unlikely (page_try_dup_anon_rmap (page, false, src_vma))) { +/* Page maybe pinned, we have to copy. */ +put_page (page); +return copy_present_page (dst_vma, src_vma, dst_pte, src_pte, + addr, rss, prealloc, page); + } + rss[mm_counter (page)]++; }else if (page) {get_page (page); -page_dup_rmap (page, false); +page_dup_file_rmap (page, false); rss[mm_counter (page)]++; }
mm/migrate.c renamed from mm/migrate.c~mm-rmap-split-page_dup_rmap-into-page_dup_file_rmap-and-page_try_dup_anon_rmap +1 -1
@@ -234,7 +234,7 @@ static bool remove_migration_pte(structif (folio_test_anon (folio))hugepage_add_anon_rmap (new, vma, pvmw.address);else -page_dup_rmap (new, true); +page_dup_file_rmap (new, true);set_huge_pte_at (vma->vm_mm, pvmw.address, pvmw.pte, pte); } else#endif
_
Patches currently in -mm which might be from [email protected] are