From: Jinjiang Tu <tujinjiang@huawei.com>
To: <xu.xin16@zte.com.cn>, <akpm@linux-foundation.org>,
<david@kernel.org>, <liam@infradead.org>, <surenb@google.com>,
<rppt@kernel.org>, <ziy@nvidia.com>,
<baolin.wang@linux.alibaba.com>, <nico.pache@linux.dev>,
<dev.jain@arm.com>, <baohua@kernel.org>, <lance.yang@linux.dev>,
<chengming.zhou@linux.dev>, <usama.arif@linux.dev>,
<gourry@gourry.net>, <harry@kernel.org>, <vbabka@kernel.org>,
<peterz@infradead.org>, <borntraeger@linux.ibm.com>
Cc: <linux-kernel@vger.kernel.org>, <linux-mm@kvack.org>
Subject: Re: [PATCH 0/4] mm/ksm: use per-VMA locking for find_mergeable_vma()
Date: Fri, 11 Sep 2026 16:47:22 +0800 [thread overview]
Message-ID: <40c0c081-d636-407b-898e-f40f3d5d38cb@huawei.com> (raw)
In-Reply-To: <20260911160421076_KNXun8Mpp9Xj7fxHG0i7@zte.com.cn>
在 2026/9/11 16:04, xu.xin16@zte.com.cn 写道:
> From: Xu Xin (ZTE) <xu.xin@linux.dev>
>
> KSM scans VM_MERGEABLE VMAs and currently protects each scan with
> mmap_read_lock(). Per-VMA locking allows KSM to read-lock only the VMA
> it is actually interested in, so that unrelated mmap()/munmap() activity
> in the same mm no longer blocks ksmd.
>
> This series is organized as follows:
>
> Patch 1 removes an unused 'vma' member from struct folio_walk. It has
> never been used since its introduction and is pure cleanup.
>
> Patch 2 adds a 'walk_lock' member to struct folio_walk and extends
> folio_walk_start() to assert the required locking mode. Existing
> callers are converted to pass PGWALK_RDLOCK, so there is no functional
> change. This prepares folio_walk_start() for callers that hold a
> per-VMA read lock instead of mmap_read_lock(), which is needed by the
> Patch 4. No functional change.
>
> Patch 3 tranforms the boolean 'lock_vma' into the enum 'page_walk_lock'
> without any behavior changed, which is prepared for the Patch 4 to use
> per-VMA locking. No functional change.
>
> Patch 4 introduces find_mergeable_vma_locked(), which uses the
> universal per-VMA locking helper vma_start_read_unlocked() to look up
> and read-lock a VM_MERGEABLE VMA without taking mmap_read_lock(). All
> KSM call sites that previously used find_mergeable_vma() under
> mmap_read_lock() are converted to the new helper, and the locking in
> get_mergeable_page() is switched to PGWALK_VMA_RDLOCK_VERIFY so that
> folio_walk_start() can verify the per-VMA lock is held.
>
> A microbenchmark was run to measure the time KSM takes to merge a
> victim region under mmap_lock contention. Under interference from 4 churner
> threads, the merge time of the per-VMA KSM-optimized kernel is
> significantly reduced by 50%.
Hi.
During task exiting, __ksm_exit() uses mmap_write_lock() to synchronize with ksmd.
see the comment of ksm_test_exit().
void __ksm_exit(struct mm_struct *mm)
{
...
if (easy_to_free) {
mm_slot_free(mm_slot_cache, mm_slot);
mm_flags_clear(MMF_VM_MERGE_ANY, mm);
mm_flags_clear(MMF_VM_MERGEABLE, mm);
mmdrop(mm);
} else if (mm_slot) {
mmap_write_lock(mm);
mmap_write_unlock(mm);
}
}
When ksmd currently is scanning the exiting mm, we should guarantee the mm pagetable
still valid (i.e., mm_users > 0). However, ksm_mm_slot only holds mm_count, which only
guarantees the mm_strcut isn't freed. So, __ksm_exit() uses mmap write lock to synchronize
with ksmd.
IIUC, vma_read_lock cannot be exclusive with mmap_write_lock().
>
> Xu Xin (4):
> mm/pagewalk: delete the unused member
> mm: make folio_walk_start()'s locking asserts scalable
> mm/ksm: make break_ksm() more scalable
> mm/ksm: add find_mergeable_vma_locked() to use per-VMA locking
>
> arch/s390/mm/fault.c | 4 +-
> include/linux/pagewalk.h | 2 +-
> kernel/events/uprobes.c | 4 +-
> mm/huge_memory.c | 4 +-
> mm/ksm.c | 85 ++++++++++++++++++++++++----------------
> mm/migrate.c | 8 +++-
> mm/pagewalk.c | 10 ++++-
> mm/rmap.c | 4 +-
> 8 files changed, 79 insertions(+), 42 deletions(-)
>
next prev parent reply other threads:[~2026-09-11 8:47 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-11 8:04 xu.xin16
2026-09-11 8:07 ` [PATCH 1/4] mm/pagewalk: delete the unused member xu.xin16
2026-09-11 8:56 ` Lorenzo Stoakes (ARM)
2026-09-11 9:07 ` xu.xin16
2026-09-11 8:09 ` [PATCH 2/4] mm: make folio_walk_start()'s locking asserts scalable xu.xin16
2026-09-11 9:14 ` xu.xin16
2026-09-11 8:12 ` [PATCH 3/4] mm/ksm: make break_ksm() more scalable xu.xin16
2026-09-11 9:04 ` Lorenzo Stoakes (ARM)
2026-09-13 4:42 ` Matthew Wilcox
2026-09-11 8:13 ` [PATCH 4/4] mm/ksm: add find_mergeable_vma_locked() to use per-VMA locking xu.xin16
2026-09-11 8:22 ` Test Case Code " xu.xin16
2026-09-11 9:12 ` xu.xin16
2026-09-14 2:09 ` Longlong Xia
2026-09-14 2:38 ` xu.xin16
2026-09-11 8:47 ` Jinjiang Tu [this message]
2026-09-13 4:17 ` [PATCH 0/4] mm/ksm: use per-VMA locking for find_mergeable_vma() xu.xin16
2026-09-14 3:03 ` Jinjiang Tu
2026-09-14 3:09 ` Jinjiang Tu
2026-09-24 3:40 ` xu.xin16
2026-09-17 9:59 ` David Hildenbrand (Arm)
2026-09-12 8:24 ` [PATCH RFC 0/3] mm/ksm: scan with per-VMA locks Longlong Xia
2026-09-12 8:24 ` [PATCH RFC 1/3] mm/pagewalk: allow folio_walk_start() under a vma read lock Longlong Xia
2026-09-12 8:24 ` [PATCH RFC 2/3] mm/ksm: use the VMA lock when looking up mergeable pages Longlong Xia
2026-09-12 8:24 ` [PATCH RFC 3/3] mm/ksm: scan VMAs with per-VMA locks Longlong Xia
2026-09-13 4:37 ` [PATCH RFC 0/3] mm/ksm: scan " 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=40c0c081-d636-407b-898e-f40f3d5d38cb@huawei.com \
--to=tujinjiang@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=borntraeger@linux.ibm.com \
--cc=chengming.zhou@linux.dev \
--cc=david@kernel.org \
--cc=dev.jain@arm.com \
--cc=gourry@gourry.net \
--cc=harry@kernel.org \
--cc=lance.yang@linux.dev \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nico.pache@linux.dev \
--cc=peterz@infradead.org \
--cc=rppt@kernel.org \
--cc=surenb@google.com \
--cc=usama.arif@linux.dev \
--cc=vbabka@kernel.org \
--cc=xu.xin16@zte.com.cn \
--cc=ziy@nvidia.com \
/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®