67c1a82
From patchwork Thu Mar 15 15:23:53 2018
67c1a82
Content-Type: text/plain; charset="utf-8"
67c1a82
MIME-Version: 1.0
67c1a82
Content-Transfer-Encoding: 7bit
67c1a82
Subject: mm/khugepaged: Convert VM_BUG_ON() to collapse fail
67c1a82
From: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
67c1a82
X-Patchwork-Id: 10284785
67c1a82
Message-Id: <20180315152353.27989-1-kirill.shutemov@linux.intel.com>
67c1a82
To: Andrew Morton <akpm@linux-foundation.org>
67c1a82
Cc: Laura Abbott <labbott@redhat.com>, linux-mm@kvack.org,
67c1a82
 linux-kernel@vger.kernel.org,
67c1a82
 "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
67c1a82
Date: Thu, 15 Mar 2018 18:23:53 +0300
67c1a82
67c1a82
khugepaged is not yet able to convert PTE-mapped huge pages back to PMD
67c1a82
mapped. We do not collapse such pages. See check khugepaged_scan_pmd().
67c1a82
67c1a82
But if between khugepaged_scan_pmd() and __collapse_huge_page_isolate()
67c1a82
somebody managed to instantiate THP in the range and then split the PMD
67c1a82
back to PTEs we would have a problem -- VM_BUG_ON_PAGE(PageCompound(page))
67c1a82
will get triggered.
67c1a82
67c1a82
It's possible since we drop mmap_sem during collapse to re-take for
67c1a82
write.
67c1a82
67c1a82
Replace the VM_BUG_ON() with graceful collapse fail.
67c1a82
67c1a82
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
67c1a82
Fixes: b1caa957ae6d ("khugepaged: ignore pmd tables with THP mapped with ptes")
67c1a82
---
67c1a82
 mm/khugepaged.c | 7 ++++++-
67c1a82
 1 file changed, 6 insertions(+), 1 deletion(-)
67c1a82
67c1a82
diff --git a/mm/khugepaged.c b/mm/khugepaged.c
67c1a82
index b7e2268dfc9a..c15da1ea7e63 100644
67c1a82
--- a/mm/khugepaged.c
67c1a82
+++ b/mm/khugepaged.c
67c1a82
@@ -530,7 +530,12 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma,
67c1a82
 			goto out;
67c1a82
 		}
67c1a82
 
67c1a82
-		VM_BUG_ON_PAGE(PageCompound(page), page);
67c1a82
+		/* TODO: teach khugepaged to collapse THP mapped with pte */
67c1a82
+		if (PageCompound(page)) {
67c1a82
+			result = SCAN_PAGE_COMPOUND;
67c1a82
+			goto out;
67c1a82
+		}
67c1a82
+
67c1a82
 		VM_BUG_ON_PAGE(!PageAnon(page), page);
67c1a82
 
67c1a82
 		/*