]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commit
mm/ksm: fix ksm_zero_pages accounting
authorChengming Zhou <chengming.zhou@linux.dev>
Tue, 28 May 2024 05:15:22 +0000 (13:15 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 6 Jun 2024 02:19:26 +0000 (19:19 -0700)
commitc2dc78b86e0821ecf9a9d0c35dba2618279a5bb6
treeb023d4ec8ba10a50829dae578c56b2edf698f4ee
parent730cdc2c72c6905a2eda2fccbbf67dcef1206590
mm/ksm: fix ksm_zero_pages accounting

We normally ksm_zero_pages++ in ksmd when page is merged with zero page,
but ksm_zero_pages-- is done from page tables side, where there is no any
accessing protection of ksm_zero_pages.

So we can read very exceptional value of ksm_zero_pages in rare cases,
such as -1, which is very confusing to users.

Fix it by changing to use atomic_long_t, and the same case with the
mm->ksm_zero_pages.

Link: https://lkml.kernel.org/r/20240528-b4-ksm-counters-v3-2-34bb358fdc13@linux.dev
Fixes: e2942062e01d ("ksm: count all zero pages placed by KSM")
Fixes: 6080d19f0704 ("ksm: add ksm zero pages for each process")
Signed-off-by: Chengming Zhou <chengming.zhou@linux.dev>
Acked-by: David Hildenbrand <david@redhat.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Ran Xiaokai <ran.xiaokai@zte.com.cn>
Cc: Stefan Roesch <shr@devkernel.io>
Cc: xu xin <xu.xin16@zte.com.cn>
Cc: Yang Yang <yang.yang29@zte.com.cn>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
fs/proc/base.c
include/linux/ksm.h
include/linux/mm_types.h
mm/ksm.c