The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: xu.xin@linux.dev
To: david@kernel.org
Cc: akpm@linux-foundation.org, chengming.zhou@linux.dev,
	donettom@linux.ibm.com, kmehltretter@gmail.com,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	stable@vger.kernel.org, xu.xin@linux.dev
Subject: [PATCH v5 0/3] mm/ksm: fix ksm_zero_pages accounting on fork
Date: Tue,  1 Dec 2026 15:45:24 +0800	[thread overview]
Message-ID: <20261201074524.539495-1-xu.xin@linux.dev> (raw)

From: "Xu Xin (vivo)" <xu.xin@linux.dev>

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@linux.dev


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


             reply	other threads:[~2026-12-01  7:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  7:45 xu.xin [this message]
2026-12-01  7:46 ` [PATCH v5 1/3] mm/ksm: do not inherit ksm_zero_pages counter or PTE markers on fork xu.xin
2026-12-01  7:48 ` [PATCH v5 2/3] selftests/mm: fix false-positive and racy KSM fork test xu.xin
2026-12-01  7:48 ` [PATCH v5 3/3] selftests/mm: verify ksm_zero_pages is not inherited on fork xu.xin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201074524.539495-1-xu.xin@linux.dev \
    --to=xu.xin@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=chengming.zhou@linux.dev \
    --cc=david@kernel.org \
    --cc=donettom@linux.ibm.com \
    --cc=kmehltretter@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox