[PATCH 1/4] Lock the new THP when collapsing pages

From: Hidetoshi Seto
Date: Wed Mar 16 2011 - 22:31:48 EST

When collapsing pages, if the new THP is poisoned before it is
mapped to the APL, memory_failure() can do nothing except setting
the poison flag to the new THP, because it is not locked and not
mapped yet.

So lock the new THP to make sure that memory_failure() could
run after the poisoned new THP is mapped to APL successfully.
This can make sure the poisoned THP will give the smallest impact
to the system by killing the APL instead of panicking the system.

Signed-off-by: Hidetoshi Seto <seto.hidetoshi@xxxxxxxxxxxxxx>
Signed-off-by: Jin Dongming <jin.dongming@xxxxxxxxxxxxxxxxxx>
mm/huge_memory.c | 7 +++++++
1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 113e35c..e02f687 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -1869,6 +1869,12 @@ static void collapse_huge_page(struct mm_struct *mm,

+ /*
+ * Lock the new THP to block memory_failure until it is
+ * mapped to the process.
+ */
+ lock_page_nosync(new_page);
__collapse_huge_page_copy(pte, new_page, vma, address, ptl);
@@ -1900,6 +1906,7 @@ static void collapse_huge_page(struct mm_struct *mm,
*hpage = NULL;
+ unlock_page(new_page);

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/