Revert "mm, thp: Do not make pmd/pud dirty without a reason"
authorLinus Torvalds <torvalds@linux-foundation.org>
Wed, 29 Nov 2017 17:01:01 +0000 (09:01 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 29 Nov 2017 17:01:01 +0000 (09:01 -0800)
This reverts commit 152e93af3cfe2d29d8136cc0a02a8612507136ee.

It was a nice cleanup in theory, but as Nicolai Stange points out, we do
need to make the page dirty for the copy-on-write case even when we
didn't end up making it writable, since the dirty bit is what we use to
check that we've gone through a COW cycle.

Reported-by: Michal Hocko <mhocko@kernel.org>
Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/huge_memory.c
mm/internal.h
mm/khugepaged.c
mm/memory.c
mm/migrate.c

index f22401fd83b5cd53da62498a76d75e96a69317b8..0e7ded98d114d184877d2fc9bd0f02c3187f2ed5 100644 (file)
@@ -474,13 +474,10 @@ out:
 }
 __setup("transparent_hugepage=", setup_transparent_hugepage);
 
-pmd_t maybe_pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma, bool dirty)
+pmd_t maybe_pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma)
 {
-       if (likely(vma->vm_flags & VM_WRITE)) {
+       if (likely(vma->vm_flags & VM_WRITE))
                pmd = pmd_mkwrite(pmd);
-               if (dirty)
-                       pmd = pmd_mkdirty(pmd);
-       }
        return pmd;
 }
 
@@ -602,7 +599,7 @@ static int __do_huge_pmd_anonymous_page(struct vm_fault *vmf, struct page *page,
                }
 
                entry = mk_huge_pmd(page, vma->vm_page_prot);
-               entry = maybe_pmd_mkwrite(entry, vma, true);
+               entry = maybe_pmd_mkwrite(pmd_mkdirty(entry), vma);
                page_add_new_anon_rmap(page, vma, haddr, true);
                mem_cgroup_commit_charge(page, memcg, false, true);
                lru_cache_add_active_or_unevictable(page, vma);
@@ -744,8 +741,8 @@ static void insert_pfn_pmd(struct vm_area_struct *vma, unsigned long addr,
        if (pfn_t_devmap(pfn))
                entry = pmd_mkdevmap(entry);
        if (write) {
-               entry = pmd_mkyoung(entry);
-               entry = maybe_pmd_mkwrite(entry, vma, true);
+               entry = pmd_mkyoung(pmd_mkdirty(entry));
+               entry = maybe_pmd_mkwrite(entry, vma);
        }
 
        if (pgtable) {
@@ -791,14 +788,10 @@ int vmf_insert_pfn_pmd(struct vm_area_struct *vma, unsigned long addr,
 EXPORT_SYMBOL_GPL(vmf_insert_pfn_pmd);
 
 #ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD
-static pud_t maybe_pud_mkwrite(pud_t pud, struct vm_area_struct *vma,
-               bool dirty)
+static pud_t maybe_pud_mkwrite(pud_t pud, struct vm_area_struct *vma)
 {
-       if (likely(vma->vm_flags & VM_WRITE)) {
+       if (likely(vma->vm_flags & VM_WRITE))
                pud = pud_mkwrite(pud);
-               if (dirty)
-                       pud = pud_mkdirty(pud);
-       }
        return pud;
 }
 
@@ -814,8 +807,8 @@ static void insert_pfn_pud(struct vm_area_struct *vma, unsigned long addr,
        if (pfn_t_devmap(pfn))
                entry = pud_mkdevmap(entry);
        if (write) {
-               entry = pud_mkyoung(entry);
-               entry = maybe_pud_mkwrite(entry, vma, true);
+               entry = pud_mkyoung(pud_mkdirty(entry));
+               entry = maybe_pud_mkwrite(entry, vma);
        }
        set_pud_at(mm, addr, pud, entry);
        update_mmu_cache_pud(vma, addr, pud);
@@ -1286,7 +1279,7 @@ int do_huge_pmd_wp_page(struct vm_fault *vmf, pmd_t orig_pmd)
        if (reuse_swap_page(page, NULL)) {
                pmd_t entry;
                entry = pmd_mkyoung(orig_pmd);
-               entry = maybe_pmd_mkwrite(entry, vma, true);
+               entry = maybe_pmd_mkwrite(pmd_mkdirty(entry), vma);
                if (pmdp_set_access_flags(vma, haddr, vmf->pmd, entry,  1))
                        update_mmu_cache_pmd(vma, vmf->address, vmf->pmd);
                ret |= VM_FAULT_WRITE;
@@ -1356,7 +1349,7 @@ alloc:
        } else {
                pmd_t entry;
                entry = mk_huge_pmd(new_page, vma->vm_page_prot);
-               entry = maybe_pmd_mkwrite(entry, vma, true);
+               entry = maybe_pmd_mkwrite(pmd_mkdirty(entry), vma);
                pmdp_huge_clear_flush_notify(vma, haddr, vmf->pmd);
                page_add_new_anon_rmap(new_page, vma, haddr, true);
                mem_cgroup_commit_charge(new_page, memcg, false, true);
@@ -2935,7 +2928,7 @@ void remove_migration_pmd(struct page_vma_mapped_walk *pvmw, struct page *new)
        if (pmd_swp_soft_dirty(*pvmw->pmd))
                pmde = pmd_mksoft_dirty(pmde);
        if (is_write_migration_entry(entry))
-               pmde = maybe_pmd_mkwrite(pmde, vma, false);
+               pmde = maybe_pmd_mkwrite(pmde, vma);
 
        flush_cache_range(vma, mmun_start, mmun_start + HPAGE_PMD_SIZE);
        page_add_anon_rmap(new, vma, mmun_start, true);
index b35cdebda0cef459ed55bb559b0412f7c0a53ddb..e6bd35182daee1226b684464fd202df86762c636 100644 (file)
@@ -328,8 +328,7 @@ static inline void mlock_migrate_page(struct page *newpage, struct page *page)
        }
 }
 
-extern pmd_t maybe_pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma,
-               bool dirty);
+extern pmd_t maybe_pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma);
 
 /*
  * At what user virtual address is page expected in @vma?
index db43dc8a8ae619c0fc58f8efeecf7d2c99654938..ea4ff259b67195b32d3335795d4de80c4e6e5bcf 100644 (file)
@@ -1057,7 +1057,7 @@ static void collapse_huge_page(struct mm_struct *mm,
        pgtable = pmd_pgtable(_pmd);
 
        _pmd = mk_huge_pmd(new_page, vma->vm_page_prot);
-       _pmd = maybe_pmd_mkwrite(_pmd, vma, false);
+       _pmd = maybe_pmd_mkwrite(pmd_mkdirty(_pmd), vma);
 
        /*
         * spin_lock() below is not the equivalent of smp_wmb(), so
index b10c1d26f675be98aca602142084cdf35621719a..85e7a87da79fe4a5487e1f3f6216e61b9827515c 100644 (file)
@@ -3335,7 +3335,7 @@ static int do_set_pmd(struct vm_fault *vmf, struct page *page)
 
        entry = mk_huge_pmd(page, vma->vm_page_prot);
        if (write)
-               entry = maybe_pmd_mkwrite(entry, vma, true);
+               entry = maybe_pmd_mkwrite(pmd_mkdirty(entry), vma);
 
        add_mm_counter(vma->vm_mm, MM_FILEPAGES, HPAGE_PMD_NR);
        page_add_file_rmap(page, true);
index 57865fc8cfe332282f35b25770bb72f75d7152f0..4d0be47a322a8a33491c94072100ebcec829becd 100644 (file)
@@ -2068,7 +2068,7 @@ int migrate_misplaced_transhuge_page(struct mm_struct *mm,
        }
 
        entry = mk_huge_pmd(new_page, vma->vm_page_prot);
-       entry = maybe_pmd_mkwrite(entry, vma, false);
+       entry = maybe_pmd_mkwrite(pmd_mkdirty(entry), vma);
 
        /*
         * Clear the old entry under pagetable lock and establish the new PTE.