Skip to content

Commit 14ddee4

Browse files
Matthew Wilcox (Oracle)akpm00
authored andcommitted
mm: use a folio in copy_present_pte()
We still have to keep the page around because we need to know which page in the folio we're copying, but we can replace five implict calls to compound_head() with one. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> Reviewed-by: Zi Yan <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent edf5047 commit 14ddee4

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

mm/memory.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -906,25 +906,28 @@ copy_present_pte(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma,
906906
unsigned long vm_flags = src_vma->vm_flags;
907907
pte_t pte = *src_pte;
908908
struct page *page;
909+
struct folio *folio;
909910

910911
page = vm_normal_page(src_vma, addr, pte);
911-
if (page && PageAnon(page)) {
912+
if (page)
913+
folio = page_folio(page);
914+
if (page && folio_test_anon(folio)) {
912915
/*
913916
* If this page may have been pinned by the parent process,
914917
* copy the page immediately for the child so that we'll always
915918
* guarantee the pinned page won't be randomly replaced in the
916919
* future.
917920
*/
918-
get_page(page);
921+
folio_get(folio);
919922
if (unlikely(page_try_dup_anon_rmap(page, false, src_vma))) {
920-
/* Page maybe pinned, we have to copy. */
921-
put_page(page);
923+
/* Page may be pinned, we have to copy. */
924+
folio_put(folio);
922925
return copy_present_page(dst_vma, src_vma, dst_pte, src_pte,
923926
addr, rss, prealloc, page);
924927
}
925928
rss[MM_ANONPAGES]++;
926929
} else if (page) {
927-
get_page(page);
930+
folio_get(folio);
928931
page_dup_file_rmap(page, false);
929932
rss[mm_counter_file(page)]++;
930933
}
@@ -937,7 +940,7 @@ copy_present_pte(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma,
937940
ptep_set_wrprotect(src_mm, addr, src_pte);
938941
pte = pte_wrprotect(pte);
939942
}
940-
VM_BUG_ON(page && PageAnon(page) && PageAnonExclusive(page));
943+
VM_BUG_ON(page && folio_test_anon(folio) && PageAnonExclusive(page));
941944

942945
/*
943946
* If it's a shared mapping, mark it clean in

0 commit comments

Comments
 (0)