From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
To: xu.xin16@zte.com.cn
Cc: akpm@linux-foundation.org, david@kernel.org, surenb@google.com,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
chengming.zhou@linux.dev
Subject: Re: [PATCH 3/4] mm/ksm: make break_ksm() more scalable
Date: Fri, 11 Sep 2026 10:04:26 +0100 [thread overview]
Message-ID: <aqPCapAzJPqDUh-f@gremlin> (raw)
In-Reply-To: <20260911161210082WKOqK1dumByDY7jeEOdPF@zte.com.cn>
On Fri, Sep 11, 2026 at 04:12:10PM +0800, xu.xin16@zte.com.cn wrote:
> From: Xu Xin (ZTE) <xu.xin@linux.dev>
>
> Currently the last argument 'walk_lock' of break_ksm() is used to
> indicate whether the page_walk is protected by mmap_read_lock or
> mmap_write_lock. If 'walk_lock' is true, we suppose its context to
> be under mmap_write_lock() protection, then mark it PGWALK_WRLOCK and
> make its vma be write-locked during the walk; If 'walk_lock' is
> false, we suppose its context to be mmap_read_lock(), then mark it
> PGWALK_RDLOCK.
I thnk this whole block is unnecessary. You're basically writing what the code
does in English
>
> This change is prepared for the latter patch to enable VMA
Latter -> later.
And it's the patch I'm not cc'd on so I don't see unless I go do a bunch of
stuff to try to download it... great :)
> read-locking where break_ksm() might be under the third new proctecion
> way: VMA read-locking, so we have to replace the boolean variable to
> the enum 'page_walk_lock', but without any function changed.
You don't, this is just horrible.
>
> No functional change intended.
>
> Signed-off-by: Xu Xin (ZTE) <xu.xin@linux.dev>
> ---
> mm/ksm.c | 21 ++++++++-------------
> 1 file changed, 8 insertions(+), 13 deletions(-)
>
> diff --git a/mm/ksm.c b/mm/ksm.c
> index 8df66b4e5de0..dda105681d7f 100644
> --- a/mm/ksm.c
> +++ b/mm/ksm.c
> @@ -660,16 +660,11 @@ static int break_ksm_pmd_entry(pmd_t *pmdp, unsigned long addr, unsigned long en
> return found;
> }
>
> -static const struct mm_walk_ops break_ksm_ops = {
> +static struct mm_walk_ops break_ksm_ops = {
> .pmd_entry = break_ksm_pmd_entry,
> .walk_lock = PGWALK_RDLOCK,
> };
>
> -static const struct mm_walk_ops break_ksm_lock_vma_ops = {
> - .pmd_entry = break_ksm_pmd_entry,
> - .walk_lock = PGWALK_WRLOCK,
> -};
> -
> /*
> * Though it's very tempting to unmerge rmap_items from stable tree rather
> * than check every pte of a given vma, the locking doesn't quite work for
> @@ -696,11 +691,11 @@ static const struct mm_walk_ops break_ksm_lock_vma_ops = {
> * protection keys here anyway.
> */
> static int break_ksm(struct vm_area_struct *vma, unsigned long addr,
> - unsigned long end, bool lock_vma)
> + unsigned long end, enum page_walk_lock walk_lock)
Ugh yuck this is horrible, you're exposing internal page walker state here as a
parameter...?
And then this commit makes it possible for any walk_lock to be passed but then
you change none of the code to handle it?
> {
> vm_fault_t ret = 0;
> - const struct mm_walk_ops *ops = lock_vma ?
> - &break_ksm_lock_vma_ops : &break_ksm_ops;
> + struct mm_walk_ops *ops = &break_ksm_ops;
> + ops->walk_lock = walk_lock;
Are you sure this can't be run concurrently by two walkers?
I didn't see any arguments about that in the commit message. Having a single,
static, struct where you change the walk_lock is gross.
What would be better is to have your own enum that lists ksm lock state or
express it some other way, then if possible have it on the stack otherwise
ensure that state can't be corrupted.
Again, if you'd sent me 4/4 too I could see the overall structure and give
advice but...
>
> do {
> int ksm_page;
> @@ -807,7 +802,7 @@ static void break_cow(struct ksm_rmap_item *rmap_item)
> mmap_read_lock(mm);
> vma = find_mergeable_vma(mm, addr);
> if (vma)
> - break_ksm(vma, addr, addr + PAGE_SIZE, false);
> + break_ksm(vma, addr, addr + PAGE_SIZE, PGWALK_RDLOCK);
> mmap_read_unlock(mm);
> }
>
> @@ -1245,7 +1240,7 @@ static int unmerge_and_remove_all_rmap_items(void)
> for_each_vma(vmi, vma) {
> if (!(vma->vm_flags & VM_MERGEABLE) || !vma->anon_vma)
> continue;
> - err = break_ksm(vma, vma->vm_start, vma->vm_end, false);
> + err = break_ksm(vma, vma->vm_start, vma->vm_end, PGWALK_RDLOCK);
> if (err)
> goto error;
> }
> @@ -2885,7 +2880,7 @@ static int __ksm_del_vma(struct vm_area_struct *vma)
> return 0;
>
> if (vma->anon_vma) {
> - err = break_ksm(vma, vma->vm_start, vma->vm_end, true);
> + err = break_ksm(vma, vma->vm_start, vma->vm_end, PGWALK_WRLOCK);
> if (err)
> return err;
> }
> @@ -3037,7 +3032,7 @@ int ksm_madvise(struct vm_area_struct *vma, unsigned long start,
> return 0; /* just ignore the advice */
>
> if (vma->anon_vma) {
> - err = break_ksm(vma, start, end, true);
> + err = break_ksm(vma, start, end, PGWALK_WRLOCK);
> if (err)
> return err;
> }
> --
> 2.25.1
--
Cheers, Lorenzo
next prev parent reply other threads:[~2026-09-11 9:04 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) [this message]
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 ` [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=aqPCapAzJPqDUh-f@gremlin \
--to=ljs@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=chengming.zhou@linux.dev \
--cc=david@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=surenb@google.com \
--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®