From: Longlong Xia <xialonglong2025@163.com>
To: xu.xin16@zte.com.cn
Cc: akpm@linux-foundation.org, baohua@kernel.org,
baolin.wang@linux.alibaba.com, borntraeger@linux.ibm.com,
chengming.zhou@linux.dev, david@kernel.org, dev.jain@arm.com,
gourry@gourry.net, harry@kernel.org, lance.yang@linux.dev,
liam@infradead.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, nico.pache@linux.dev, peterz@infradead.org,
rppt@kernel.org, surenb@google.com, usama.arif@linux.dev,
vbabka@kernel.org, ziy@nvidia.com, ljs@kernel.org,
Longlong Xia <xialonglong@kylinos.cn>
Subject: [PATCH RFC 1/3] mm/pagewalk: allow folio_walk_start() under a vma read lock
Date: Sat, 12 Sep 2026 16:24:05 +0800 [thread overview]
Message-ID: <20260912082407.75875-2-xialonglong2025@163.com> (raw)
In-Reply-To: <20260912082407.75875-1-xialonglong2025@163.com>
From: Longlong Xia <xialonglong@kylinos.cn>
Allow folio_walk_start() to use a vma read lock by replacing
mmap_assert_locked() with vma_assert_locked(). This lets KSM look
up pages without taking the mmap read lock.
The vma lock stabilizes the mapping, while page table locks serialize
entry updates. Callers walking another mm under the vma lock must
also hold an mm_users reference to prevent exit_mmap() from freeing
the page tables.
Assisted-by: Zcode:GLM-5.3
Signed-off-by: Longlong Xia <xialonglong@kylinos.cn>
---
include/linux/pagewalk.h | 3 +++
mm/pagewalk.c | 11 +++++++++--
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/include/linux/pagewalk.h b/include/linux/pagewalk.h
index b41d7265c01b..cafd7b15f480 100644
--- a/include/linux/pagewalk.h
+++ b/include/linux/pagewalk.h
@@ -151,6 +151,9 @@ typedef int __bitwise folio_walk_flags_t;
/* Walk shared zeropages (small + huge) as well. */
#define FW_ZEROPAGE ((__force folio_walk_flags_t)BIT(0))
+/* The caller holds the VMA read lock instead of the mmap lock. */
+#define FW_VMA_LOCKED ((__force folio_walk_flags_t)BIT(1))
+
enum folio_walk_level {
FW_LEVEL_PTE,
FW_LEVEL_PMD,
diff --git a/mm/pagewalk.c b/mm/pagewalk.c
index cc07fcf50e87..57ffaf2a85b8 100644
--- a/mm/pagewalk.c
+++ b/mm/pagewalk.c
@@ -894,7 +894,11 @@ int walk_page_mapping(struct address_space *mapping, pgoff_t first_index,
* huge_ptep_set_*, ...). Note that the page table entry stored in @fw might
* not correspond to the first physical entry of a logical hugetlb entry.
*
- * The mmap lock must be held in read mode.
+ * The mmap lock must be held in read mode. Alternatively, with
+ * CONFIG_PER_VMA_LOCK and @FW_VMA_LOCKED, the vma lock may be held in read mode: the
+ * page tables of a read-locked vma cannot be torn down while the mm has
+ * users, so a caller that walks an mm other than its own must also hold a
+ * mm_users reference for the duration of the walk.
*
* Return: folio pointer on success, otherwise NULL.
*/
@@ -912,7 +916,10 @@ struct folio *folio_walk_start(struct folio_walk *fw,
pgd_t *pgdp;
p4d_t *p4dp;
- mmap_assert_locked(vma->vm_mm);
+ if (flags & FW_VMA_LOCKED)
+ vma_assert_locked(vma);
+ else
+ mmap_assert_locked(vma->vm_mm);
vma_pgtable_walk_begin(vma);
if (WARN_ON_ONCE(addr < vma->vm_start || addr >= vma->vm_end))
--
2.43.0
next prev parent reply other threads:[~2026-09-12 8:25 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-11 8:04 [PATCH 0/4] mm/ksm: use per-VMA locking for find_mergeable_vma() 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-11 8:47 ` [PATCH 0/4] mm/ksm: use per-VMA locking for find_mergeable_vma() Jinjiang Tu
2026-09-13 4:17 ` xu.xin16
2026-09-12 8:24 ` [PATCH RFC 0/3] mm/ksm: scan with per-VMA locks Longlong Xia
2026-09-12 8:24 ` Longlong Xia [this message]
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=20260912082407.75875-2-xialonglong2025@163.com \
--to=xialonglong2025@163.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=ljs@kernel.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=xialonglong@kylinos.cn \
--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