[PATCH 5/5] mm: mark stable page dirty in KSM

From: Minchan Kim
Date: Mon Oct 19 2015 - 02:29:31 EST


Stable page could be shared by several processes and last process
could own the page among them after CoW or zapping for every process
except last process happens. Then, page table entry of the page
in last process can have no dirty bit and PG_dirty flag in page->flags.
In this case, MADV_FREE could discard the page wrongly.
For preventing it, we mark stable page dirty.

Cc: Hugh Dickins <hughd@xxxxxxxxxx>
Signed-off-by: Minchan Kim <minchan@xxxxxxxxxx>
---
mm/ksm.c | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff --git a/mm/ksm.c b/mm/ksm.c
index 8f0faf809bf5..659e2b5119c0 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -1050,6 +1050,18 @@ static int try_to_merge_one_page(struct vm_area_struct *vma,
*/
set_page_stable_node(page, NULL);
mark_page_accessed(page);
+ /*
+ * Stable page could be shared by several processes
+ * and last process could own the page among them after
+ * CoW or zapping for every process except last process
+ * happens. Then, page table entry of the page
+ * in last process can have no dirty bit.
+ * In this case, MADV_FREE could discard the page
+ * wrongly.
+ * For preventing it, we mark stable page dirty.
+ */
+ if (!PageDirty(page))
+ SetPageDirty(page);
err = 0;
} else if (pages_identical(page, kpage))
err = replace_page(vma, page, kpage, orig_pte);
--
1.9.1

--
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/