2018-04-05 12:29:23

by Claudio Imbrenda

[permalink] [raw]
Subject: [PATCH v1 1/1] mm/ksm: 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")

Signed-off-by: Claudio Imbrenda <[email protected]>
---
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



2018-04-05 13:52:04

by Greg KH

[permalink] [raw]
Subject: Re: [PATCH v1 1/1] mm/ksm: fix inconsistent accounting of zero pages

On Thu, Apr 05, 2018 at 02:27:54PM +0200, Claudio Imbrenda wrote:
> 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 <[email protected]>
> ---
> mm/ksm.c | 7 +++++++
> 1 file changed, 7 insertions(+)

<formletter>

This is not the correct way to submit patches for inclusion in the
stable kernel tree. Please read:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.

</formletter>

2018-04-09 03:43:20

by Sasha Levin

[permalink] [raw]
Subject: Re: [PATCH v1 1/1] mm/ksm: fix inconsistent accounting of zero pages

Hi,

[This is an automated email]

This commit has been processed because it contains a "Fixes:" tag,
fixing commit: e86c59b1b12d mm/ksm: improve deduplication of zero pages with colouring.

The bot has also determined it's probably a bug fixing patch. (score: 20.2626)

The bot has tested the following trees: v4.16, v4.15.15, v4.14.32.

v4.16: Build OK!
v4.15.15: Build OK!
v4.14.32: Build OK!

--
Thanks,
Sasha