mm/rmap: move SetPageAnonExclusive() out of page_move_anon_rmap()
authorDavid Hildenbrand <david@redhat.com>
Mon, 2 Oct 2023 14:29:47 +0000 (16:29 +0200)
committerAndrew Morton <akpm@linux-foundation.org>
Wed, 18 Oct 2023 21:34:14 +0000 (14:34 -0700)
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>
mm/huge_memory.c
mm/hugetlb.c
mm/memory.c
mm/rmap.c

index aa0224556132611bed08aa322d31cc38ca1cbf4f..76ead290f1c82be897258c0cca189f05c837eafb 100644 (file)
@@ -1377,6 +1377,7 @@ vm_fault_t do_huge_pmd_wp_page(struct vm_fault *vmf)
                pmd_t entry;
 
                page_move_anon_rmap(page, vma);
+               SetPageAnonExclusive(page);
                folio_unlock(folio);
 reuse:
                if (unlikely(unshare)) {
index 2878e0e6bac5c8bcf9a6b1df3efd31f9b677a3e7..35d924f7497231f611ae1c9346e3b02327e121fc 100644 (file)
@@ -5652,8 +5652,10 @@ retry_avoidcopy:
         * owner and can reuse this page.
         */
        if (folio_mapcount(old_folio) == 1 && folio_test_anon(old_folio)) {
-               if (!PageAnonExclusive(&old_folio->page))
+               if (!PageAnonExclusive(&old_folio->page)) {
                        page_move_anon_rmap(&old_folio->page, vma);
+                       SetPageAnonExclusive(&old_folio->page);
+               }
                if (likely(!unshare))
                        set_huge_ptep_writable(vma, haddr, ptep);
 
index ceffe96f2a0e335e4441ff75877bbc3893851fa4..21fba1c9a6c730d9283bf2cd4117f14e172ff026 100644 (file)
@@ -3481,6 +3481,7 @@ static vm_fault_t do_wp_page(struct vm_fault *vmf)
                 * sunglasses. Hit it.
                 */
                page_move_anon_rmap(vmf->page, vma);
+               SetPageAnonExclusive(vmf->page);
                folio_unlock(folio);
 reuse:
                if (unlikely(unshare)) {
index c6bb2339e35b260001c8559d818926c3810a94ea..6f1ea1491118c5ca0622cba3a0c0c832ce333418 100644 (file)
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -1152,7 +1152,6 @@ void page_move_anon_rmap(struct page *page, struct vm_area_struct *vma)
         * folio_test_anon()) will not see one without the other.
         */
        WRITE_ONCE(folio->mapping, anon_vma);
-       SetPageAnonExclusive(page);
 }
 
 /**