Re: [PATCH v7 2/6] tools/testing: add rmap walk latency benchmark

From: David Hildenbrand (Arm)

Date: Fri Jun 05 2026 - 12:03:41 EST


On 5/30/26 11:04, xu.xin16@xxxxxxxxxx wrote:
> From: xu xin <xu.xin16@xxxxxxxxxx>
>
> Add a benchmark to measure rmap_walk latency for KSM, anonymous,
> and file-backed pages under high sharing.
>
> For KSM, the sysfs file "max_page_sharing" is set as 256 to make
> sure that every KSM page can be shared by 256 original pages. A
> large region is split into 20000 VMAs via mprotect then merged by
> KSM, whose purpose is to construct a lot of unrelated VMAs
> sharing its anon_vma to reproduce the issue proposed at
> https://lore.kernel.org/all/20260503205013850sym7UO0jvKJzyRiTYmO8V@xxxxxxxxxx/.
>
> For anon and file pages, 256 (equal to KSM's max_page_sharing)
> child processes are forked to share a single physical page (COW
> not broken). The benchmark uses move_pages() to trigger migration,
> collects rmap_walk_start/end trace events, and reports max/average
> latency. The tool also saves/restores KSM config and filters trace
> events by PID to avoid noise.
>
> For each test, the program prints the number of captured events and
> the maximum / average latency in milliseconds.
>
> This benchmark helps developers evaluate optimizations in the reverse
> mapping code, such as limiting max_page_sharing or improving tree
> traversal efficiency.
>
> Usage (must be run as root):
> '# cd tools/testing/rmap/ && make
> ’# sudo ./rmap_benchmark
> KSM rmap_walk latency (Shared by 256 VMAs via mprotect and KSM merge):
> Max: 839.00 ms (838998 us)
> Avg: 605.80 ms (605799 us)
> Count: 4 events
> Anonymous page rmap_walk latency (Shared by 256 VMAs via fork, COW not broken):
> Max: 4.05 ms (4055 us)
> Avg: 2.86 ms (2858 us)
> Count: 2 events
> File page rmap_walk latency (Shared by 256 VMAs via fork, MAP_SHARED):
> Max: 2.57 ms (2572 us)
> Avg: 1.25 ms (1250 us)
> Count: 4 events
>
> Signed-off-by: xu xin <xu.xin16@xxxxxxxxxx>
> ---

And that benchmark would then also have to be carried OOT I guess.

--
Cheers,

David