From: Andrew Morton <akpm@linux-foundation.org>
To: <xu.xin16@zte.com.cn>
Cc: <david@kernel.org>, <ljs@kernel.org>, <hughd@google.com>,
<linux-mm@kvack.org>, <linux-kernel@vger.kernel.org>,
<michel@lespinasse.org>, <corbet@lwn.net>,
<wang.yaxin@zte.com.cn>
Subject: Re: [PATCH v5 0/5] KSM: performance optimizations for rmap_walk_ksm
Date: Tue, 19 May 2026 10:01:56 -0700 [thread overview]
Message-ID: <20260519100156.05043f9d043889a5f60e22d3@linux-foundation.org> (raw)
In-Reply-To: <20260519220536792dMIKRMurt3vZ5lXC5pwh8@zte.com.cn>
On Tue, 19 May 2026 22:05:36 +0800 (CST) <xu.xin16@zte.com.cn> wrote:
> From: xu xin <xu.xin16@zte.com.cn>
>
> When available memory is extremely tight, causing KSM pages to be swapped
> out, or when there is significant memory fragmentation and THP triggers
> memory compaction, the system will invoke the rmap_walk_ksm function to
> perform reverse mapping. However, we observed that this function becomes
> particularly time-consuming when a large number of VMAs (e.g., 20,000)
> share the same anon_vma. Through debug trace analysis, we found that most
> of the latency occurs within anon_vma_interval_tree_foreach, leading to an
> excessively long hold time on the anon_vma lock (even reaching 500ms or
> more), which in turn causes upper-layer applications (waiting for the
> anon_vma lock) to be blocked for extended periods.
>
> This series fixes a severe KSM reverse-mapping performance problem
> that can freeze applications for hundreds of milliseconds under
> memory pressure especially when a lot of unrelated VMAs sharing a
> single anon_vma.
That would be good to fix.
> Two key highlights:
>
> 1. Lock hold time drops from >500ms to <2ms
> - In our benchmark (20,000 VMAs sharing an anon_vma), worst-case
> anon_vma lock hold time during KSM rmap walk went from 705ms
> down to 1.67ms (max) and 1.44ms (avg).
How real-worldish is that benchmark?
How much effect are our users likely to see from this patchset in their
real-world workloads?
> 2. Real user impact
> - The anon_vma lock is also acquired by page faults, reclaim,
> migration, compaction, mlock, exit_mmap, and cgroup accounting.
>
> - A long hold due to inefficient rmap walks stalls application
> threads, causing latency spikes, reduced throughput, or even
> container timeouts.
>
> - The problem occurs even without fork() – VMA splitting (e.g.,
> via mprotect or madvise over time) can create tens of thousands
> of VMAs all attached to the same anon_vma.
>
> ...
>
> Changes in v5:
> - Patch 1: replaced local_clock() with tracepoints – no overhead
> when tracepoints are disabled.
Thanks for that change.
> - Patch 3: switched from vm_pgoff (unstable after VMA split) to a
> linear page offset.
> - Patch 4: adapted to the linear page offset; added user-impact
> description (real workloads, lock contention examples,
> VMA splitting scenario).
> - Patch 5: simplified to a single process with 32 pages (instead
> of multi-process), as suggested by David.
>
> MAINTAINERS | 3 +
I don't recall seeing any discussion about you becoming an rmap
M:aintainer, perhaps I missed it. Thanks for the interest, but it
probably would be better to propose this as a standalone patch,
separated from this series.
> include/trace/events/rmap.h | 73 ++++
> mm/ksm.c | 48 ++-
> mm/rmap.c | 9 +
> tools/testing/rmap/Makefile | 11 +
> tools/testing/rmap/rmap_benchmark.c | 529 +++++++++++++++++++++++++++
> tools/testing/selftests/mm/rmap.c | 76 ++++
> tools/testing/selftests/mm/vm_util.c | 38 ++
> tools/testing/selftests/mm/vm_util.h | 2 +
> 9 files changed, 781 insertions(+), 8 deletions(-)
> create mode 100644 include/trace/events/rmap.h
> create mode 100644 tools/testing/rmap/Makefile
> create mode 100644 tools/testing/rmap/rmap_benchmark.c
AI review was only partial, for unclear reasons:
https://sashiko.dev/#/patchset/20260519220536792dMIKRMurt3vZ5lXC5pwh8@zte.com.cn
Please take a look, see if there's anything useful there?
next prev parent reply other threads:[~2026-05-19 17:01 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-19 14:05 xu.xin16
2026-05-19 14:09 ` [PATCH v5 1/5] mm/rmap: add tracepoint for rmap_walk xu.xin16
2026-05-19 14:11 ` [PATCH v5 2/5] tools/testing: add rmap walk latency benchmark xu.xin16
2026-05-19 14:12 ` [PATCH v5 3/5] ksm: add pgoff into ksm_rmap_item xu.xin16
2026-05-19 14:14 ` [PATCH v5 4/5] ksm: Optimize rmap_walk_ksm by passing a suitable pgoff xu.xin16
2026-05-19 14:18 ` [PATCH v5 5/5] ksm: add mremap selftests for ksm_rmap_walk xu.xin16
2026-05-19 17:01 ` Andrew Morton [this message]
2026-05-20 6:26 ` [PATCH v5 0/5] KSM: performance optimizations for rmap_walk_ksm xu.xin16
2026-05-20 6:37 ` xu.xin16
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=20260519100156.05043f9d043889a5f60e22d3@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=corbet@lwn.net \
--cc=david@kernel.org \
--cc=hughd@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=michel@lespinasse.org \
--cc=wang.yaxin@zte.com.cn \
--cc=xu.xin16@zte.com.cn \
/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
all inboxes | Powered by JetHome®