From: Lorenzo Stoakes <ljs@kernel.org>
To: xu.xin16@zte.com.cn
Cc: david@kernel.org, akpm@linux-foundation.org, hughd@google.com,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
michel@lespinasse.org
Subject: Re: [PATCH v4 4/5] ksm: Optimize rmap_walk_ksm by passing a suitable address range
Date: Fri, 15 May 2026 13:28:28 +0100 [thread overview]
Message-ID: <agcL72kTdIc__PGD@lucifer> (raw)
In-Reply-To: <20260515151344118ESEm1fT7x-Gd6kodR8VVq@zte.com.cn>
On Fri, May 15, 2026 at 03:13:44PM +0800, xu.xin16@zte.com.cn wrote:
> > > diff --git a/mm/ksm.c b/mm/ksm.c
> > > index 0299a53ba7c9..a13184d00759 100644
> > > --- a/mm/ksm.c
> > > +++ b/mm/ksm.c
> > > @@ -3200,6 +3200,7 @@ void rmap_walk_ksm(struct folio *folio, struct rmap_walk_control *rwc)
> > > hlist_for_each_entry(rmap_item, &stable_node->hlist, hlist) {
> > > /* Ignore the stable/unstable/sqnr flags */
> > > const unsigned long addr = rmap_item->address & PAGE_MASK;
> > > + const unsigned long vm_pgoff = rmap_item->vm_pgoff;
> > > struct anon_vma *anon_vma = rmap_item->anon_vma;
> > > struct anon_vma_chain *vmac;
> > > struct vm_area_struct *vma;
> > > @@ -3213,8 +3214,12 @@ void rmap_walk_ksm(struct folio *folio, struct rmap_walk_control *rwc)
> > > anon_vma_lock_read(anon_vma);
> > > }
> > >
> > > + /*
> > > + * Currently KSM folios are order-0 normal pages, so pgoff_end
> > > + * should be the same as pgoff_start.
> > > + */
> > > anon_vma_interval_tree_foreach(vmac, &anon_vma->rb_root,
> > > - 0, ULONG_MAX) {
> > > + vm_pgoff, vm_pgoff) {
> >
> > But vm_pgoff would just correspond to the start of the VMA, not where the page
> > is actually mapped?
> >
> > I'd assume you really want the linear page index of the original page?
>
> Right. I've reconsidered and realized that using vm_pgoff is indeed unstable.
Your email client is inserting (kinda) HTML :) & apos ; -> ' please tell it to
behave :P
>
> My initial idea was: as long as we can find the VMA that maps this page,
> it's sufficient for anon_vma_interval_tree_foreach() to check whether
> "vm_pgoff <= pgoff of the original page <= (vm_pgoff + vma_pages(v) - 1)".
>
> However, the flaw here is that the VMA may be split(e.g., due to madvise or mprotect),
> causing vma_pages(v) to change, thereby making this condition no longer satisfied.
>
> Indeed, it's better to use the linear page index of the original page.
Yup :)
Partially mapped large folios would cause weirdness also but KSM uses order-0
right? So probably not a thing.
>
> I'll send v5 to correct this.
>
> >
> > --
> > Cheers,
> >
> > David
> >
Cheers, Lorenzo
next prev parent reply other threads:[~2026-05-15 12:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-15 7:13 [PATCH v4 4/5] ksm: Optimize rmap_walk_ksm by passing a suitable address range xu.xin16
2026-05-15 12:28 ` Lorenzo Stoakes [this message]
-- strict thread matches above, loose matches on Subject: below --
2026-05-03 12:35 [PATCH v4 0/5] KSM: Optimizations for rmap_walk_ksm xu.xin16
2026-05-03 12:50 ` [PATCH v4 4/5] ksm: Optimize rmap_walk_ksm by passing a suitable address range xu.xin16
2026-05-13 12:10 ` David Hildenbrand (Arm)
2026-05-15 7:15 ` 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=agcL72kTdIc__PGD@lucifer \
--to=ljs@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=hughd@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=michel@lespinasse.org \
--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