Commit e1f1b157 authored by Hugh Dickins's avatar Hugh Dickins Committed by Linus Torvalds

mm/huge_memory.c: fix data loss when splitting a file pmd

__split_huge_pmd_locked() must check if the cleared huge pmd was dirty,
and propagate that to PageDirty: otherwise, data may be lost when a huge
tmpfs page is modified then split then reclaimed.

How has this taken so long to be noticed?  Because there was no problem
when the huge page is written by a write system call (shmem_write_end()
calls set_page_dirty()), nor when the page is allocated for a write fault
(fault_dirty_shared_page() calls set_page_dirty()); but when allocated for
a read fault (which MAP_POPULATE simulates), no set_page_dirty().

Fixes: d21b9e57 ("thp: handle file pages in split_huge_pmd()")
Signed-off-by: default avatarHugh Dickins <>
Reported-by: default avatarAshwin Chaugule <>
Reviewed-by: default avatarYang Shi <>
Reviewed-by: default avatarKirill A. Shutemov <>
Cc: "Huang, Ying" <>
Cc: <>	[4.8+]
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent 35033ab9
......@@ -2084,6 +2084,8 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd,
if (vma_is_dax(vma))
page = pmd_page(_pmd);
if (!PageDirty(page) && pmd_dirty(_pmd))
if (!PageReferenced(page) && pmd_young(_pmd))
page_remove_rmap(page, true);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment