ksm: use a folio in replace_page()
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Fri, 2 Sep 2022 19:46:41 +0000 (20:46 +0100)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 3 Oct 2022 21:02:53 +0000 (14:02 -0700)
Replace three calls to compound_head() with one.

Link: https://lkml.kernel.org/r/20220902194653.1739778-46-willy@infradead.org
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/ksm.c

index c3edb5836a4419f56154a085a919e888ae422def..c19fcca9bc03dcd9511486000c6cadb11d724c29 100644 (file)
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -1110,6 +1110,7 @@ static int replace_page(struct vm_area_struct *vma, struct page *page,
                        struct page *kpage, pte_t orig_pte)
 {
        struct mm_struct *mm = vma->vm_mm;
+       struct folio *folio;
        pmd_t *pmd;
        pmd_t pmde;
        pte_t *ptep;
@@ -1178,10 +1179,11 @@ static int replace_page(struct vm_area_struct *vma, struct page *page,
        ptep_clear_flush(vma, addr, ptep);
        set_pte_at_notify(mm, addr, ptep, newpte);
 
+       folio = page_folio(page);
        page_remove_rmap(page, vma, false);
-       if (!page_mapped(page))
-               try_to_free_swap(page);
-       put_page(page);
+       if (!folio_mapped(folio))
+               folio_free_swap(folio);
+       folio_put(folio);
 
        pte_unmap_unlock(ptep, ptl);
        err = 0;