[PATCH RFC 0/3] mm/ksm: scan with per-VMA locks

From: Longlong Xia

Date: Sat Sep 12 2026 - 04:32:08 EST


From: Longlong Xia <xialonglong@xxxxxxxxxx>

This work was developed independently before I saw the above series.
After comparing the two implementations, I found that the approaches
overlap, so I am posting this draft version as an alternative
implementation and would be happy to combine the useful parts.

The main differences are:

- use per-VMA locking in the ksmd VMA scanner;
- revalidate the mmap-lock sequence before skipping the fallback walk;
- avoid repeating a completed VMA traversal when no candidate page is
found.

Benchmark (QEMU q35, TCG multi-thread, 4 vCPUs, 8 GiB, x86_64 guest on
Ubuntu 24.04, 7.3-rc2 base, CONFIG_KSM=y + CONFIG_PER_VMA_LOCK=y;
victim: 32 MiB anon, 2048 unique pages x4 duplicates,
pages_to_scan=100000, sleep_millisecs=0, 3 runs each; churners: 4
threads mmap/munmaping 256 MiB in the same mm. Microbenchmark as
posted in [3]; relative numbers only, TCG is not native hardware):

0 churners 4 churners (mean)
7.3-rc2 1.21-1.41 s 90.9 s
+ patch 2/3 1.41 s 48.7 s (-46%)
+ patch 2/3 + 3/3 1.21-1.41 s 30.1 s (-67%)


1. mm/pagewalk: allow folio_walk_start() under a vma read lock

2. mm/ksm: use the VMA lock when looking up mergeable pages

3. mm/ksm: scan VMAs with per-VMA locks

Link:https://lore.kernel.org/all/5cd47bc3-bc3d-473c-80d0-8be8b7b79881@xxxxxxx/

Longlong Xia (3):
mm/pagewalk: allow folio_walk_start() under a vma read lock
mm/ksm: use the VMA lock when looking up mergeable pages
mm/ksm: scan VMAs with per-VMA locks

include/linux/pagewalk.h | 3 +
mm/ksm.c | 166 ++++++++++++++++++++++++++++++++++++---
mm/pagewalk.c | 11 ++-
3 files changed, 166 insertions(+), 14 deletions(-)

base-commit: df2908090cda368b01ff43709f51890076c56157
--
2.43.0