LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH v1 1/1] mm/ksm: fix inconsistent accounting of zero pages
@ 2018-04-05 12:27 Claudio Imbrenda
  2018-04-05 13:50 ` Greg KH
  2018-04-09  3:37 ` Sasha Levin
  0 siblings, 2 replies; 3+ messages in thread
From: Claudio Imbrenda @ 2018-04-05 12:27 UTC (permalink / raw)
  To: linux-kernel
  Cc: akpm, aarcange, minchan, kirill.shutemov, linux-mm, hughd,
	borntraeger, gerald.schaefer, stable

When using KSM with use_zero_pages, we replace anonymous pages
containing only zeroes with actual zero pages, which are not anonymous.
We need to do proper accounting of the mm counters, otherwise we will
get wrong values in /proc and a BUG message in dmesg when tearing down
the mm.

Fixes: e86c59b1b1 ("mm/ksm: improve deduplication of zero pages with colouring")

Signed-off-by: Claudio Imbrenda <imbrenda@linux.vnet.ibm.com>
---
 mm/ksm.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/mm/ksm.c b/mm/ksm.c
index 293721f..2d6b352 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -1131,6 +1131,13 @@ static int replace_page(struct vm_area_struct *vma, struct page *page,
 	} else {
 		newpte = pte_mkspecial(pfn_pte(page_to_pfn(kpage),
 					       vma->vm_page_prot));
+		/*
+		 * We're replacing an anonymous page with a zero page, which is
+		 * not anonymous. We need to do proper accounting otherwise we
+		 * will get wrong values in /proc, and a BUG message in dmesg
+		 * when tearing down the mm.
+		 */
+		dec_mm_counter(mm, MM_ANONPAGES);
 	}
 
 	flush_cache_page(vma, addr, pte_pfn(*ptep));
-- 
2.7.4

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-04-09  3:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-05 12:27 [PATCH v1 1/1] mm/ksm: fix inconsistent accounting of zero pages Claudio Imbrenda
2018-04-05 13:50 ` Greg KH
2018-04-09  3:37 ` Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).