Skip to content

Commit d8a28dd

Browse files
davidhildenbrandSENSEIIIII
authored andcommitted
BACKPORT: mm/rmap: move SetPageAnonExclusive() out of page_move_anon_rmap()
Patch series "mm/rmap: convert page_move_anon_rmap() to folio_move_anon_rmap()". Convert page_move_anon_rmap() to folio_move_anon_rmap(), letting the callers handle PageAnonExclusive. I'm including cleanup patch #3 because it fits into the picture and can be done cleaner by the conversion. This patch (of 3): Let's move it into the caller: there is a difference between whether an anon folio can only be mapped by one process (e.g., into one VMA), and whether it is truly exclusive (e.g., no references -- including GUP -- from other processes). Further, for large folios the page might not actually be pointing at the head page of the folio, so it better be handled in the caller. This is a preparation for converting page_move_anon_rmap() to consume a folio. Link: https://lkml.kernel.org/r/20231002142949.235104-1-david@redhat.com Link: https://lkml.kernel.org/r/20231002142949.235104-2-david@redhat.com Signed-off-by: David Hildenbrand <david@redhat.com> Reviewed-by: Suren Baghdasaryan <surenb@google.com> Reviewed-by: Vishal Moola (Oracle) <vishal.moola@gmail.com> Cc: Mike Kravetz <mike.kravetz@oracle.com> Cc: Muchun Song <muchun.song@linux.dev> Cc: Matthew Wilcox <willy@infradead.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Conflicts: 1. mm/hugetlb.c [Due to page_mapcount() instead of folio_mapcount() and folio_test_anon() instead of PageAnon()] (cherry picked from commit 5ca432896a4ce6d69fffc3298b24c0dd9bdb871f) Bug: 413428616 Bug: 313807618 Change-Id: Ibd29fec4d2a521d5ffc0782effd855cde9687a78 Signed-off-by: Suren Baghdasaryan <surenb@google.com> Signed-off-by: Lokesh Gidra <lokeshgidra@google.com>
1 parent 6a8cf13 commit d8a28dd

4 files changed

Lines changed: 5 additions & 2 deletions

File tree

mm/huge_memory.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,6 +1372,7 @@ vm_fault_t do_huge_pmd_wp_page(struct vm_fault *vmf)
13721372
pmd_t entry;
13731373

13741374
page_move_anon_rmap(page, vma);
1375+
SetPageAnonExclusive(page);
13751376
folio_unlock(folio);
13761377
reuse:
13771378
if (unlikely(unshare)) {

mm/hugetlb.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5581,8 +5581,10 @@ static vm_fault_t hugetlb_wp(struct mm_struct *mm, struct vm_area_struct *vma,
55815581
* owner and can reuse this page.
55825582
*/
55835583
if (page_mapcount(old_page) == 1 && PageAnon(old_page)) {
5584-
if (!PageAnonExclusive(old_page))
5584+
if (!PageAnonExclusive(old_page)) {
55855585
page_move_anon_rmap(old_page, vma);
5586+
SetPageAnonExclusive(old_page);
5587+
}
55865588
if (likely(!unshare))
55875589
set_huge_ptep_writable(vma, haddr, ptep);
55885590

mm/memory.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3561,6 +3561,7 @@ static vm_fault_t do_wp_page(struct vm_fault *vmf)
35613561
* sunglasses. Hit it.
35623562
*/
35633563
page_move_anon_rmap(vmf->page, vma);
3564+
SetPageAnonExclusive(vmf->page);
35643565
folio_unlock(folio);
35653566
reuse:
35663567
if (unlikely(unshare)) {

mm/rmap.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,6 @@ void page_move_anon_rmap(struct page *page, struct vm_area_struct *vma)
11401140
* folio_test_anon()) will not see one without the other.
11411141
*/
11421142
WRITE_ONCE(folio->mapping, anon_vma);
1143-
SetPageAnonExclusive(page);
11441143
}
11451144

11461145
/**

0 commit comments

Comments
 (0)