The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH v3 0/3] mm/ksm: fix ksm_zero_pages accounting on fork
@ 2026-11-23  3:41 Xu Xin (vivo)
  2026-11-23  3:43 ` [PATCH v3 1/3] mm/ksm: do not inherit ksm_zero_pages counter or PTE markers " Xu Xin (vivo)
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Xu Xin (vivo) @ 2026-11-23  3:41 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: akpm, chengming.zhou, linux-mm, stable, xu.xin, linux-kernel,
	donettom

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 v3:
- Rename might_clear_ksm_zero_pte() to ksm_fork_pte() and refactor the
  PTE marker check and comments (David Hildenbrand).

- Add Tested-by tag from Karl Mehltretter to patch 1/3.

- Refine exit status handling and add ksm_pause() in patch 2/3 and patch
  3/3 to prevent races and 8-bit truncation (Sashiko AI).

Changes in v2:
- Encapsulate zero-page PTE marker clearing into a dedicated helper and document ksm_zero_pages fork behavior (David).
- Fix compilation error for !CONFIG_KSM and address initial KSM fork selftest bug fixes.

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                           | 22 +++++++--
 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, 85 insertions(+), 14 deletions(-)

-- 
2.34.1


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

end of thread, other threads:[~2026-11-23 16:49 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23  3:41 [PATCH v3 0/3] mm/ksm: fix ksm_zero_pages accounting on fork Xu Xin (vivo)
2026-11-23  3:43 ` [PATCH v3 1/3] mm/ksm: do not inherit ksm_zero_pages counter or PTE markers " Xu Xin (vivo)
2026-11-23  3:43 ` Xu Xin (vivo)
2026-11-23 16:38   ` David Hildenbrand (Arm)
2026-11-23  3:45 ` [PATCH v3 2/3] selftests/mm: fix false-positive and racy KSM fork test Xu Xin (vivo)
2026-11-23 16:43   ` David Hildenbrand (Arm)
2026-11-23  3:45 ` [PATCH v3 3/3] selftests/mm: verify ksm_zero_pages is not inherited on fork Xu Xin (vivo)
2026-11-23 16:49   ` David Hildenbrand (Arm)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox