thp: handle file pages in split_huge_pmd()
authorKirill A. Shutemov <kirill.shutemov@linux.intel.com>
Tue, 26 Jul 2016 22:25:37 +0000 (15:25 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 26 Jul 2016 23:19:19 +0000 (16:19 -0700)
Splitting THP PMD is simple: just unmap it as in DAX case.  This way we
can avoid memory overhead on page table allocation to deposit.

It's probably a good idea to try to allocation page table with
GFP_ATOMIC in __split_huge_pmd_locked() to avoid refaulting the area,
but clearing pmd should be good enough for now.

Unlike DAX, we also remove the page from rmap and drop reference.
pmd_young() is transfered to PageReferenced().

Link: http://lkml.kernel.org/r/1466021202-61880-15-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 d8ccd245947d982e397f7819eef660fbac2ce850..e6725c5c5a62161992e11ef5a584122bdf36c511 100644 (file)
@@ -2987,10 +2987,18 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd,
 
        count_vm_event(THP_SPLIT_PMD);
 
-       if (vma_is_dax(vma)) {
-               pmd_t _pmd = pmdp_huge_clear_flush_notify(vma, haddr, pmd);
+       if (!vma_is_anonymous(vma)) {
+               _pmd = pmdp_huge_clear_flush_notify(vma, haddr, pmd);
                if (is_huge_zero_pmd(_pmd))
                        put_huge_zero_page();
+               if (vma_is_dax(vma))
+                       return;
+               page = pmd_page(_pmd);
+               if (!PageReferenced(page) && pmd_young(_pmd))
+                       SetPageReferenced(page);
+               page_remove_rmap(page, true);
+               put_page(page);
+               add_mm_counter(mm, MM_FILEPAGES, -HPAGE_PMD_NR);
                return;
        } else if (is_huge_zero_pmd(*pmd)) {
                return __split_huge_zero_page_pmd(vma, haddr, pmd);