From: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
To: David Hildenbrand <david@redhat.com>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
Andrew Morton <akpm@linux-foundation.org>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>,
Vlastimil Babka <vbabka@suse.cz>, Jann Horn <jannh@google.com>,
Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>, Zi Yan <ziy@nvidia.com>,
Matthew Brost <matthew.brost@intel.com>,
Joshua Hahn <joshua.hahnjy@gmail.com>,
Rakie Kim <rakie.kim@sk.com>, Byungchul Park <byungchul@sk.com>,
Gregory Price <gourry@gourry.net>,
Ying Huang <ying.huang@linux.alibaba.com>,
Alistair Popple <apopple@nvidia.com>,
Pedro Falcato <pfalcato@suse.de>, Rik van Riel <riel@surriel.com>,
Harry Yoo <harry.yoo@oracle.com>
Subject: Re: [PATCH v1 2/4] mm: smaller folio_pte_batch() improvements
Date: Fri, 27 Jun 2025 17:51:50 +0100 [thread overview]
Message-ID: <ea03a9a8-6e2d-4576-b15b-cf8fca1ebcfe@lucifer.local> (raw)
In-Reply-To: <20250627115510.3273675-3-david@redhat.com>
On Fri, Jun 27, 2025 at 01:55:08PM +0200, David Hildenbrand wrote:
> Let's clean up a bit:
>
> (1) No need for start_ptep vs. ptep anymore, we can simply use ptep
>
> (2) Let's switch to "unsigned int" for everything
>
> (3) We can simplify the code by leaving the pte unchanged after the
> pte_same() check.
>
> (4) Clarify that we should never exceed a single VMA; it indicates a
> problem in the caller.
>
> No functional change intended.
>
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
> mm/internal.h | 37 +++++++++++++++----------------------
> 1 file changed, 15 insertions(+), 22 deletions(-)
>
> diff --git a/mm/internal.h b/mm/internal.h
> index 9690c75063881..ca6590c6d9eab 100644
> --- a/mm/internal.h
> +++ b/mm/internal.h
> @@ -221,7 +221,7 @@ static inline pte_t __pte_batch_clear_ignored(pte_t pte, fpb_t flags)
> * 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.
> + * @ptep: Page table pointer for the first entry.
> * @pte: Page table entry for the first page.
> * @max_nr: The maximum number of table entries to consider.
> * @flags: Flags to modify the PTE batch semantics.
> @@ -233,24 +233,24 @@ static inline pte_t __pte_batch_clear_ignored(pte_t pte, fpb_t flags)
> * first one is dirty.
> *
> * Detect a PTE batch: consecutive (present) PTEs that map consecutive
> - * pages of the same large folio.
> + * pages of the same large folio in a single VMA and a single page table.
> *
> * All PTEs inside a PTE batch have the same PTE bits set, excluding the PFN,
> * the accessed bit, writable bit, dirty bit (unless FPB_HONOR_DIRTY is set) and
> * soft-dirty bit (unless FPB_HONOR_SOFT_DIRTY is set).
> *
> - * start_ptep must map any page of the folio. max_nr must be at least one and
> - * must be limited by the caller so scanning cannot exceed a single page table.
> + * @ptep must map any page of the folio. max_nr must be at least one and
> + * must be limited by the caller so scanning cannot exceed a single VMA and
> + * a single page table.
> *
> * Return: the number of table entries in the batch.
> */
> -static inline int folio_pte_batch(struct folio *folio, unsigned long addr,
> - pte_t *start_ptep, pte_t pte, int max_nr, fpb_t flags,
> +static inline unsigned int folio_pte_batch(struct folio *folio, unsigned long addr,
Do we need to worry about propagating this type change?
mremap_folio_pte_batch() and zap_present_ptes() return the value as an int for example.
I mean I doubt we're going to be seeing an overflow here :) but maybe worth
propagating this everywhere.
> + pte_t *ptep, pte_t pte, unsigned int max_nr, fpb_t flags,
> bool *any_writable, bool *any_young, bool *any_dirty)
> {
> - pte_t expected_pte, *ptep;
> - bool writable, young, dirty;
> - int nr, cur_nr;
> + unsigned int nr, cur_nr;
> + pte_t expected_pte;
>
> if (any_writable)
> *any_writable = false;
> @@ -267,29 +267,22 @@ static inline int folio_pte_batch(struct folio *folio, unsigned long addr,
> max_nr = min_t(unsigned long, max_nr,
> folio_pfn(folio) + folio_nr_pages(folio) - pte_pfn(pte));
>
> - nr = pte_batch_hint(start_ptep, pte);
> + nr = pte_batch_hint(ptep, pte);
> expected_pte = __pte_batch_clear_ignored(pte_advance_pfn(pte, nr), flags);
> - ptep = start_ptep + nr;
> + ptep = ptep + nr;
>
> while (nr < max_nr) {
> pte = ptep_get(ptep);
> - if (any_writable)
> - writable = !!pte_write(pte);
> - if (any_young)
> - young = !!pte_young(pte);
> - if (any_dirty)
> - dirty = !!pte_dirty(pte);
> - pte = __pte_batch_clear_ignored(pte, flags);
>
> - if (!pte_same(pte, expected_pte))
> + if (!pte_same(__pte_batch_clear_ignored(pte, flags), expected_pte))
Doing this here will change the output of any_writable, any_young:
static inline pte_t __pte_batch_clear_ignored(pte_t pte, fpb_t flags)
{
...
return pte_wrprotect(pte_mkold(pte));
}
So we probably need to get these values earlier?
> break;
>
> if (any_writable)
> - *any_writable |= writable;
> + *any_writable |= pte_write(pte);
> if (any_young)
> - *any_young |= young;
> + *any_young |= pte_young(pte);
> if (any_dirty)
> - *any_dirty |= dirty;
> + *any_dirty |= pte_dirty(pte);
>
> cur_nr = pte_batch_hint(ptep, pte);
> expected_pte = pte_advance_pfn(expected_pte, cur_nr);
> --
> 2.49.0
>
next prev parent reply other threads:[~2025-06-27 16:52 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-27 11:55 [PATCH v1 0/4] mm: " David Hildenbrand
2025-06-27 11:55 ` [PATCH v1 1/4] mm: convert FPB_IGNORE_* into FPB_HONOR_* David Hildenbrand
2025-06-27 13:40 ` Lance Yang
2025-06-27 16:28 ` Lorenzo Stoakes
2025-06-27 16:30 ` David Hildenbrand
2025-06-27 16:33 ` Lorenzo Stoakes
2025-06-29 8:59 ` Mike Rapoport
2025-06-30 13:47 ` David Hildenbrand
2025-06-28 3:37 ` Dev Jain
2025-06-28 21:00 ` David Hildenbrand
2025-06-30 3:34 ` Dev Jain
2025-06-30 9:04 ` Ryan Roberts
2025-06-30 9:08 ` David Hildenbrand
2025-06-30 9:18 ` Ryan Roberts
2025-06-30 9:24 ` David Hildenbrand
2025-06-30 10:57 ` Ryan Roberts
2025-06-30 11:01 ` David Hildenbrand
2025-06-30 14:35 ` Zi Yan
2025-07-02 8:31 ` Oscar Salvador
2025-06-27 11:55 ` [PATCH v1 2/4] mm: smaller folio_pte_batch() improvements David Hildenbrand
2025-06-27 13:58 ` Lance Yang
2025-06-27 16:51 ` Lorenzo Stoakes [this message]
2025-06-27 17:02 ` David Hildenbrand
2025-06-27 18:39 ` Lorenzo Stoakes
2025-06-30 17:40 ` Zi Yan
2025-07-02 8:42 ` Oscar Salvador
2025-07-02 8:48 ` David Hildenbrand
2025-07-02 8:51 ` Lorenzo Stoakes
2025-07-02 9:00 ` David Hildenbrand
2025-07-02 9:08 ` Lorenzo Stoakes
2025-07-02 9:11 ` David Hildenbrand
2025-06-27 11:55 ` [PATCH v1 3/4] mm: split folio_pte_batch() into folio_pte_batch() and folio_pte_batch_ext() David Hildenbrand
2025-06-27 14:19 ` Lance Yang
2025-06-27 15:09 ` David Hildenbrand
2025-06-27 15:45 ` Lance Yang
2025-06-27 18:48 ` Lorenzo Stoakes
2025-06-30 9:19 ` David Hildenbrand
2025-06-30 10:41 ` Lorenzo Stoakes
2025-06-30 10:54 ` David Hildenbrand
2025-06-30 17:45 ` Zi Yan
2025-07-02 9:02 ` Oscar Salvador
2025-07-02 9:05 ` David Hildenbrand
2025-07-02 9:07 ` Oscar Salvador
2025-07-02 9:11 ` David Hildenbrand
2025-07-02 9:09 ` Oscar Salvador
2025-06-27 11:55 ` [PATCH v1 4/4] mm: remove boolean output parameters from folio_pte_batch_ext() David Hildenbrand
2025-06-27 14:34 ` Lance Yang
2025-06-27 15:11 ` David Hildenbrand
2025-06-27 15:40 ` Lance Yang
2025-06-27 19:04 ` Lorenzo Stoakes
2025-06-30 9:32 ` David Hildenbrand
2025-06-30 11:08 ` Lorenzo Stoakes
2025-06-30 11:16 ` David Hildenbrand
2025-06-30 11:18 ` Lorenzo Stoakes
2025-06-30 11:21 ` David Hildenbrand
2025-06-30 17:59 ` Zi Yan
2025-07-02 9:08 ` David Hildenbrand
2025-07-02 9:09 ` David Hildenbrand
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=ea03a9a8-6e2d-4576-b15b-cf8fca1ebcfe@lucifer.local \
--to=lorenzo.stoakes@oracle.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=apopple@nvidia.com \
--cc=byungchul@sk.com \
--cc=david@redhat.com \
--cc=gourry@gourry.net \
--cc=harry.yoo@oracle.com \
--cc=jannh@google.com \
--cc=joshua.hahnjy@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=matthew.brost@intel.com \
--cc=mhocko@suse.com \
--cc=pfalcato@suse.de \
--cc=rakie.kim@sk.com \
--cc=riel@surriel.com \
--cc=rppt@kernel.org \
--cc=surenb@google.com \
--cc=vbabka@suse.cz \
--cc=ying.huang@linux.alibaba.com \
--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