[PATCH v5 0/3] mm/ksm: fix ksm_zero_pages accounting on fork
From: xu . xin
Date: Tue Dec 01 2026 - 02:46:01 EST
From: "Xu Xin (vivo)" <xu.xin@xxxxxxxxx>
Currently, fork() wrongly inherits the parent's ksm_zero_pages counter
and keeps the KSM dirty-bit marker on zero-page PTEs, inflating both the
child's per-mm counter and the global ksm_zero_pages counter.
Patch 1 fixes this by resetting the child's mm->ksm_zero_pages to 0 in
ksm_fork() and clearing the KSM zero-page marker when copying present
PTEs, and documents the behavior.
Patch 2 fixes false-positive and racy bugs in the existing KSM fork
selftest by dropping init_global_file_handles() in the child, avoiding
8-bit exit status truncation, and pausing ksmd before fork().
Patch 3 extends the selftest to verify that neither ksm_merging_pages
nor ksm_zero_pages is inherited across fork().
---
Changes in v5:
- patch #1: Rename ksm_fork_pte() to ksm_fork_zero_pte() (David)
- patch #2: Add Fixes tag.
v4: https://lore.kernel.org/linux-mm/20261124130143.128411-1-xu.xin@xxxxxxxxx
Xu Xin (vivo) (3):
mm/ksm: do not inherit ksm_zero_pages counter or PTE markers on fork
selftests/mm: fix false-positive and racy KSM fork test
selftests/mm: verify ksm_zero_pages is not inherited on fork
Documentation/admin-guide/mm/ksm.rst | 7 ++-
include/linux/ksm.h | 24 ++++++++--
mm/memory.c | 5 +-
.../selftests/mm/ksm_functional_tests.c | 48 +++++++++++++++----
tools/testing/selftests/mm/vm_util.c | 16 +++++++
tools/testing/selftests/mm/vm_util.h | 1 +
6 files changed, 87 insertions(+), 14 deletions(-)
--
2.34.1