Skip to contentSkip to conversation

mm/ksm.c: fix inconsistent accounting of zero pages

PATCH New [email protected] 1 participant 1 message Apr 10, 2018

Subsystems (3)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 34/140 mm/ksm.c: fix inconsistent accounting of zero pages

From: Claudio Imbrenda <[email protected]>
Subject: mm/ksm.c: fix inconsistent accounting of zero pages

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")
Cc Andrea Arcangeli <[email protected]>
Cc Minchan Kim <[email protected]>
Cc Kirill A. Shutemov <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Christian Borntraeger <[email protected]>
Cc Gerald Schaefer <[email protected]>

---

 mm/ksm.c |    7 +++++++
 1 file changed, 7 insertions(+)
mm/ksm.c renamed from mm/ksm.c~mm-ksm-fix-inconsistent-accounting-of-zero-pages +7 -0
diff -puN mm/ksm.c~mm-ksm-fix-inconsistent-accounting-of-zero-pages mm/ksm.c
@@ -1131,6 +1131,13 @@ static int replace_page(struct vm_area_s
 	} 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));

_