From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C408367B80 for ; Tue, 19 May 2026 17:01:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779210117; cv=none; b=lK3nLHSDWekVIMe4DT460TW1z0So0Egz3x0M/iNWTR65LbmkdiScXyw38ptw0kFp6QQdCQCYujChLu5yF+EnnbMOMEhqn0rNmXG3PccYkR8nZwKF/xBoLdMVCD2f3qVyY0mqhIby7/PrTb8cJOpXDNHF+c8h6IcpLXSRRC93rFY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779210117; c=relaxed/simple; bh=Cy/D7M3r9Gy98bOyegXLfNg7rkuz/ohcygE5dOo+HPQ=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=vElMd2J3NyqXBc2yaVTG/we7P8eUTBgKuCOPHboKwL91AJ9o1t3+HiyLb3DBpu2d2gvHUoN80BhEZNKl/a2COw5mvA/O9Th2Q8mVS6MackOuG1PrGvtbRl1L6f3IjnkaUhLnSNzGurS+w2Hn5T81xAgb9hy5kdzO5nUxQweugJ4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=e6nV9Gpf; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="e6nV9Gpf" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B437CC2BCFA; Tue, 19 May 2026 17:01:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1779210117; bh=Cy/D7M3r9Gy98bOyegXLfNg7rkuz/ohcygE5dOo+HPQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=e6nV9GpfNstBdXq6ZdsifSX+niJrrOXZl12ydNb3DF/WfXaGAtFI7yoqe2zVJ8NRR YpdqqA+LAOQP3cxAnOzxgE0qm03+DNHWn4hmI42t/HUXFBji5yQmTuX5WxtgsEPJp0 eGE4DycP5JbWZc63g1bO7iONJzCvzbELkvLRp0ug= Date: Tue, 19 May 2026 10:01:56 -0700 From: Andrew Morton To: Cc: , , , , , , , Subject: Re: [PATCH v5 0/5] KSM: performance optimizations for rmap_walk_ksm Message-Id: <20260519100156.05043f9d043889a5f60e22d3@linux-foundation.org> In-Reply-To: <20260519220536792dMIKRMurt3vZ5lXC5pwh8@zte.com.cn> References: <20260519220536792dMIKRMurt3vZ5lXC5pwh8@zte.com.cn> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On Tue, 19 May 2026 22:05:36 +0800 (CST) wrote: > From: xu xin > > 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?