thp: support file pages in zap_huge_pmd()
authorKirill A. Shutemov <kirill.shutemov@linux.intel.com>
Tue, 26 Jul 2016 22:25:34 +0000 (15:25 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 26 Jul 2016 23:19:19 +0000 (16:19 -0700)
split_huge_pmd() for file mappings (and DAX too) is implemented by just
clearing pmd entry as we can re-fill this area from page cache on pte
level later.

This means we don't need deposit page tables when file THP is mapped.
Therefore we shouldn't try to withdraw a page table on zap_huge_pmd()
file THP PMD.

Link: http://lkml.kernel.org/r/1466021202-61880-14-git-send-email-kirill.shutemov@linux.intel.com
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/huge_memory.c

index 5bc058ad12c2bad1dac8b58e706da5c0361e70e0..d8ccd245947d982e397f7819eef660fbac2ce850 100644 (file)
@@ -1689,10 +1689,16 @@ int zap_huge_pmd(struct mmu_gather *tlb, struct vm_area_struct *vma,
                struct page *page = pmd_page(orig_pmd);
                page_remove_rmap(page, true);
                VM_BUG_ON_PAGE(page_mapcount(page) < 0, page);
-               add_mm_counter(tlb->mm, MM_ANONPAGES, -HPAGE_PMD_NR);
                VM_BUG_ON_PAGE(!PageHead(page), page);
-               pte_free(tlb->mm, pgtable_trans_huge_withdraw(tlb->mm, pmd));
-               atomic_long_dec(&tlb->mm->nr_ptes);
+               if (PageAnon(page)) {
+                       pgtable_t pgtable;
+                       pgtable = pgtable_trans_huge_withdraw(tlb->mm, pmd);
+                       pte_free(tlb->mm, pgtable);
+                       atomic_long_dec(&tlb->mm->nr_ptes);
+                       add_mm_counter(tlb->mm, MM_ANONPAGES, -HPAGE_PMD_NR);
+               } else {
+                       add_mm_counter(tlb->mm, MM_FILEPAGES, -HPAGE_PMD_NR);
+               }
                spin_unlock(ptl);
                tlb_remove_page_size(tlb, page, HPAGE_PMD_SIZE);
        }