All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] mm/ksm: fix ksm_zero_pages accounting on fork
@ 2026-11-20  7:42 Xu Xin (vivo)
  2026-11-20  7:43 ` [PATCH v2 1/3] mm/ksm: do not inherit ksm_zero_pages counter or PTE markers " Xu Xin (vivo)
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Xu Xin (vivo) @ 2026-11-20  7:42 UTC (permalink / raw)
  To: david
  Cc: akpm, chengming.zhou, donettom, linux-kernel, linux-mm, stable,
	xu.xin

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 a false-positive bug in the existing KSM fork selftest by
removing a redundant init_global_file_handles() call in the child.

Patch 3 extends the selftest to verify that ksm_zero_pages is not
inherited across fork().

---
Changes in v2:
- Encapsulate zero-page PTE marker clearing into a dedicated
  might_clear_ksm_zero_pte() helper and simplify the code comment. (David)

- Fix compilation error by adding stub implementation of
  might_clear_ksm_zero_pte() for !CONFIG_KSM. (kernel test robot)

- Document the fork() interaction and MADV_UNMERGEABLE behavior for
  ksm_zero_pages in Documentation/admin-guide/mm/ksm.rst. (David)

- Fix a false-positive bug in the KSM fork selftest (patch 2/3) and
  extend it to verify ksm_zero_pages is not inherited on fork (patch 3/3).

Xu Xin (vivo) (3):
  mm/ksm: do not inherit ksm_zero_pages counter or PTE markers on fork
  selftests/mm: fix false-positive KSM fork test by dropping
    init_global_file_handles()
  selftests/mm: verify ksm_zero_pages is not inherited on fork

 Documentation/admin-guide/mm/ksm.rst          |  7 +++-
 include/linux/ksm.h                           | 18 ++++++++--
 mm/memory.c                                   |  2 ++
 .../selftests/mm/ksm_functional_tests.c       | 35 ++++++++++++++-----
 4 files changed, 49 insertions(+), 13 deletions(-)

-- 
2.34.1


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

end of thread, other threads:[~2026-11-20  7:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20  7:42 [PATCH v2 0/3] mm/ksm: fix ksm_zero_pages accounting on fork Xu Xin (vivo)
2026-11-20  7:43 ` [PATCH v2 1/3] mm/ksm: do not inherit ksm_zero_pages counter or PTE markers " Xu Xin (vivo)
2026-11-20  7:44 ` [PATCH v2 2/3] selftests/mm: fix false-positive KSM fork test by dropping init_global_file_handles() Xu Xin (vivo)
2026-11-20  7:44 ` [PATCH v2 3/3] selftests/mm: verify ksm_zero_pages is not inherited on fork Xu Xin (vivo)

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.