From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753027AbbJSG32 (ORCPT ); Mon, 19 Oct 2015 02:29:28 -0400 Received: from LGEAMRELO12.lge.com ([156.147.23.52]:46243 "EHLO lgeamrelo12.lge.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751933AbbJSG2l (ORCPT ); Mon, 19 Oct 2015 02:28:41 -0400 X-Original-SENDERIP: 156.147.1.125 X-Original-MAILFROM: minchan@kernel.org X-Original-SENDERIP: 10.177.223.161 X-Original-MAILFROM: minchan@kernel.org From: Minchan Kim To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Hugh Dickins , Rik van Riel , Mel Gorman , Michal Hocko , Johannes Weiner , "Kirill A. Shutemov" , Vlastimil Babka , Minchan Kim Subject: [PATCH 5/5] mm: mark stable page dirty in KSM Date: Mon, 19 Oct 2015 15:31:47 +0900 Message-Id: <1445236307-895-6-git-send-email-minchan@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1445236307-895-1-git-send-email-minchan@kernel.org> References: <1445236307-895-1-git-send-email-minchan@kernel.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Minchan Kim --- 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