From: Barry Song <21cnbao@gmail.com>
To: Lance Yang <ioworker0@gmail.com>
Cc: David Hildenbrand <david@redhat.com>,
Ryan Roberts <ryan.roberts@arm.com>,
akpm@linux-foundation.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, Barry Song <v-songbaohua@oppo.com>,
Yin Fengwei <fengwei.yin@intel.com>
Subject: Re: [PATCH] mm: export folio_pte_batch as a couple of modules might need it
Date: Tue, 27 Feb 2024 23:38:14 +1300 [thread overview]
Message-ID: <CAGsJ_4xOi0=rQjcv=S6HvHg8r9s_m4+tTimAK+bX-p4C4sDGGA@mail.gmail.com> (raw)
In-Reply-To: <CAK1f24mOc+Y_UCA2nSC7VbNQMy0DahULz-6JsEPMqTyoAA+MoA@mail.gmail.com>
On Tue, Feb 27, 2024 at 11:22 PM Lance Yang <ioworker0@gmail.com> wrote:
>
> On Tue, Feb 27, 2024 at 5:14 PM David Hildenbrand <david@redhat.com> wrote:
> >
> > On 27.02.24 10:07, Ryan Roberts wrote:
> > > On 27/02/2024 02:40, Barry Song wrote:
> > >> From: Barry Song <v-songbaohua@oppo.com>
> > >>
> > >> madvise and some others might need folio_pte_batch to check if a range
> > >> of PTEs are completely mapped to a large folio with contiguous physcial
> > >> addresses. Let's export it for others to use.
> > >>
> > >> Cc: Lance Yang <ioworker0@gmail.com>
> > >> Cc: Ryan Roberts <ryan.roberts@arm.com>
> > >> Cc: David Hildenbrand <david@redhat.com>
> > >> Cc: Yin Fengwei <fengwei.yin@intel.com>
> > >> Signed-off-by: Barry Song <v-songbaohua@oppo.com>
> > >> ---
> > >> -v1:
> > >> at least two jobs madv_free and madv_pageout depend on it. To avoid
> > >> conflicts and dependencies, after discussing with Lance, we prefer
> > >> this one can land earlier.
> > >
> > > I think this will also ultimately be useful for mprotect too, though I haven't
> > > looked at it properly yet.
> > >
> >
> > Yes, I think we briefly discussed that.
> >
> > >>
> > >> mm/internal.h | 13 +++++++++++++
> > >> mm/memory.c | 11 +----------
> > >> 2 files changed, 14 insertions(+), 10 deletions(-)
> > >>
> > >> diff --git a/mm/internal.h b/mm/internal.h
> > >> index 13b59d384845..8e2bc304f671 100644
> > >> --- a/mm/internal.h
> > >> +++ b/mm/internal.h
> > >> @@ -83,6 +83,19 @@ static inline void *folio_raw_mapping(struct folio *folio)
> > >> return (void *)(mapping & ~PAGE_MAPPING_FLAGS);
> > >> }
> > >>
> > >> +/* Flags for folio_pte_batch(). */
> > >> +typedef int __bitwise fpb_t;
> > >> +
> > >> +/* Compare PTEs after pte_mkclean(), ignoring the dirty bit. */
> > >> +#define FPB_IGNORE_DIRTY ((__force fpb_t)BIT(0))
> > >> +
> > >> +/* Compare PTEs after pte_clear_soft_dirty(), ignoring the soft-dirty bit. */
> > >> +#define FPB_IGNORE_SOFT_DIRTY ((__force fpb_t)BIT(1))
> > >> +
> > >> +extern int folio_pte_batch(struct folio *folio, unsigned long addr,
> > >> + pte_t *start_ptep, pte_t pte, int max_nr, fpb_t flags,
> > >> + bool *any_writable);
> > >> +
> > >> void __acct_reclaim_writeback(pg_data_t *pgdat, struct folio *folio,
> > >> int nr_throttled);
> > >> static inline void acct_reclaim_writeback(struct folio *folio)
> > >> diff --git a/mm/memory.c b/mm/memory.c
> > >> index 1c45b6a42a1b..319b3be05e75 100644
> > >> --- a/mm/memory.c
> > >> +++ b/mm/memory.c
> > >> @@ -953,15 +953,6 @@ static __always_inline void __copy_present_ptes(struct vm_area_struct *dst_vma,
> > >> set_ptes(dst_vma->vm_mm, addr, dst_pte, pte, nr);
> > >> }
> > >>
> > >> -/* Flags for folio_pte_batch(). */
> > >> -typedef int __bitwise fpb_t;
> > >> -
> > >> -/* Compare PTEs after pte_mkclean(), ignoring the dirty bit. */
> > >> -#define FPB_IGNORE_DIRTY ((__force fpb_t)BIT(0))
> > >> -
> > >> -/* Compare PTEs after pte_clear_soft_dirty(), ignoring the soft-dirty bit. */
> > >> -#define FPB_IGNORE_SOFT_DIRTY ((__force fpb_t)BIT(1))
> > >> -
> > >> static inline pte_t __pte_batch_clear_ignored(pte_t pte, fpb_t flags)
> > >> {
> > >> if (flags & FPB_IGNORE_DIRTY)
> > >> @@ -982,7 +973,7 @@ static inline pte_t __pte_batch_clear_ignored(pte_t pte, fpb_t flags)
> > >> * If "any_writable" is set, it will indicate if any other PTE besides the
> > >> * first (given) PTE is writable.
> > >> */
> > >
> > > David was talking in Lance's patch thread, about improving the docs for this
> > > function now that its exported. Might be worth syncing on that.
> >
> > Here is my take:
> >
> > Signed-off-by: David Hildenbrand <david@redhat.com>
> > ---
> > mm/memory.c | 22 ++++++++++++++++++----
> > 1 file changed, 18 insertions(+), 4 deletions(-)
> >
> > diff --git a/mm/memory.c b/mm/memory.c
> > index d0b855a1837a8..098356b8805ae 100644
> > --- a/mm/memory.c
> > +++ b/mm/memory.c
> > @@ -971,16 +971,28 @@ static inline pte_t __pte_batch_clear_ignored(pte_t pte, fpb_t flags)
> > return pte_wrprotect(pte_mkold(pte));
> > }
> >
> > -/*
> > +/**
> > + * folio_pte_batch - detect a PTE batch for a large folio
> > + * @folio: The large folio to detect a PTE batch for.
> > + * @addr: The user virtual address the first page is mapped at.
> > + * @start_ptep: Page table pointer for the first entry.
> > + * @pte: Page table entry for the first page.
>
> Nit:
>
> - * @pte: Page table entry for the first page.
> + * @pte: Page table entry for the first page that must be the first subpage of
> + * the folio excluding arm64 for now.
>
> IIUC, pte_batch_hint is always 1 excluding arm64 for now.
> I'm not sure if this modification will be helpful?
I don't understand how this will be different for arm64 and others.
It seems pte_batch_hint with one value > 1 only helps move the
PTE pointer faster to finish the call.
Thanks
Barry
next prev parent reply other threads:[~2024-02-27 10:38 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-27 2:40 Barry Song
2024-02-27 3:18 ` Barry Song
2024-02-27 9:11 ` Ryan Roberts
2024-02-27 9:07 ` Ryan Roberts
2024-02-27 9:14 ` David Hildenbrand
2024-02-27 9:20 ` Ryan Roberts
2024-02-27 9:27 ` Barry Song
2024-02-27 9:36 ` David Hildenbrand
2024-02-27 9:51 ` Lance Yang
2024-02-27 9:53 ` David Hildenbrand
2024-02-27 9:57 ` Lance Yang
2024-02-27 10:21 ` Lance Yang
2024-02-27 10:30 ` David Hildenbrand
2024-02-27 10:53 ` Ryan Roberts
2024-02-27 10:55 ` Lance Yang
2024-02-27 10:38 ` Barry Song [this message]
2024-02-27 9:18 ` David Hildenbrand
2024-02-27 16:00 ` Christoph Hellwig
2024-02-27 19:01 ` Barry Song
2024-02-28 1:46 ` Lance Yang
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='CAGsJ_4xOi0=rQjcv=S6HvHg8r9s_m4+tTimAK+bX-p4C4sDGGA@mail.gmail.com' \
--to=21cnbao@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=fengwei.yin@intel.com \
--cc=ioworker0@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ryan.roberts@arm.com \
--cc=v-songbaohua@oppo.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