From: David Hildenbrand <david@redhat.com>
To: Zi Yan <ziy@nvidia.com>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
Andrew Morton <akpm@linux-foundation.org>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>,
Lorenzo Stoakes <lorenzo.stoakes@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>,
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 4/4] mm: remove boolean output parameters from folio_pte_batch_ext()
Date: Wed, 2 Jul 2025 11:09:41 +0200 [thread overview]
Message-ID: <09c356c3-5874-43ac-93e5-4374a386df98@redhat.com> (raw)
In-Reply-To: <d58f8ab8-55da-447a-9fd6-93bebe27f23e@redhat.com>
On 02.07.25 11:08, David Hildenbrand wrote:
> On 30.06.25 19:59, Zi Yan wrote:
>> On 27 Jun 2025, at 7:55, David Hildenbrand wrote:
>>
>>> Instead, let's just allow for specifying through flags whether we want
>>> to have bits merged into the original PTE.
>>>
>>> For the madvise() case, simplify by having only a single parameter for
>>> merging young+dirty. For madvise_cold_or_pageout_pte_range() merging the
>>> dirty bit is not required, but also not harmful. This code is not that
>>> performance critical after all to really force all micro-optimizations.
>>>
>>> As we now have two pte_t * parameters, use PageTable() to make sure we
>>> are actually given a pointer at a copy of the PTE, not a pointer into
>>> an actual page table.
>>>
>>> Signed-off-by: David Hildenbrand <david@redhat.com>
>>> ---
>>> mm/internal.h | 58 +++++++++++++++++++++++++++++++--------------------
>>> mm/madvise.c | 26 +++++------------------
>>> mm/memory.c | 8 ++-----
>>> mm/util.c | 2 +-
>>> 4 files changed, 43 insertions(+), 51 deletions(-)
>>>
>>> diff --git a/mm/internal.h b/mm/internal.h
>>> index 6000b683f68ee..fe69e21b34a24 100644
>>> --- a/mm/internal.h
>>> +++ b/mm/internal.h
>>> @@ -208,6 +208,18 @@ typedef int __bitwise fpb_t;
>>> /* Compare PTEs honoring the soft-dirty bit. */
>>> #define FPB_HONOR_SOFT_DIRTY ((__force fpb_t)BIT(1))
>>>
>>> +/*
>>> + * Merge PTE write bits: if any PTE in the batch is writable, modify the
>>> + * PTE at @ptentp to be writable.
>>> + */
>>> +#define FPB_MERGE_WRITE ((__force fpb_t)BIT(2))
>>> +
>>> +/*
>>> + * Merge PTE young and dirty bits: if any PTE in the batch is young or dirty,
>>> + * modify the PTE at @ptentp to be young or dirty, respectively.
>>> + */
>>> +#define FPB_MERGE_YOUNG_DIRTY ((__force fpb_t)BIT(3))
>>> +
>>> static inline pte_t __pte_batch_clear_ignored(pte_t pte, fpb_t flags)
>>> {
>>> if (!(flags & FPB_HONOR_DIRTY))
>>> @@ -220,16 +232,11 @@ static inline pte_t __pte_batch_clear_ignored(pte_t pte, fpb_t flags)
>>> /**
>>> * folio_pte_batch_ext - detect a PTE batch for a large folio
>>> * @folio: The large folio to detect a PTE batch for.
>>> + * @vma: The VMA. Only relevant with FPB_MERGE_WRITE, otherwise can be NULL.
>>> * @ptep: Page table pointer for the first entry.
>>> - * @pte: Page table entry for the first page.
>>> + * @ptentp: Pointer at a copy of the first page table entry.
>>> * @max_nr: The maximum number of table entries to consider.
>>> * @flags: Flags to modify the PTE batch semantics.
>>> - * @any_writable: Optional pointer to indicate whether any entry except the
>>> - * first one is writable.
>>> - * @any_young: Optional pointer to indicate whether any entry except the
>>> - * first one is young.
>>> - * @any_dirty: Optional pointer to indicate whether any entry except the
>>> - * first one is dirty.
>>> *
>>> * Detect a PTE batch: consecutive (present) PTEs that map consecutive
>>> * pages of the same large folio in a single VMA and a single page table.
>>> @@ -242,28 +249,26 @@ static inline pte_t __pte_batch_clear_ignored(pte_t pte, fpb_t flags)
>>> * must be limited by the caller so scanning cannot exceed a single VMA and
>>> * a single page table.
>>> *
>>> + * Depending on the FPB_MERGE_* flags, the pte stored at @ptentp will
>>> + * be modified.
>>> + *
>>> * This function will be inlined to optimize based on the input parameters;
>>> * consider using folio_pte_batch() instead if applicable.
>>> *
>>> * Return: the number of table entries in the batch.
>>> */
>>> static inline unsigned int folio_pte_batch_ext(struct folio *folio,
>>> - pte_t *ptep, pte_t pte, unsigned int max_nr, fpb_t flags,
>>> - bool *any_writable, bool *any_young, bool *any_dirty)
>>> + struct vm_area_struct *vma, pte_t *ptep, pte_t *ptentp,
>>> + unsigned int max_nr, fpb_t flags)
>>> {
>>> + bool any_writable = false, any_young = false, any_dirty = false;
>>> + pte_t expected_pte, pte = *ptentp;
>>> unsigned int nr, cur_nr;
>>> - pte_t expected_pte;
>>> -
>>> - if (any_writable)
>>> - *any_writable = false;
>>> - if (any_young)
>>> - *any_young = false;
>>> - if (any_dirty)
>>> - *any_dirty = false;
>>>
>>> VM_WARN_ON_FOLIO(!pte_present(pte), folio);
>>> VM_WARN_ON_FOLIO(!folio_test_large(folio) || max_nr < 1, folio);
>>> VM_WARN_ON_FOLIO(page_folio(pfn_to_page(pte_pfn(pte))) != folio, folio);
>>> + VM_WARN_ON(virt_addr_valid(ptentp) && PageTable(virt_to_page(ptentp)));
>>
>> Why not just VM_WARN_ON(!pte_same(*ptep, *ptentp)) ?
>>
>> ptep points to the first page table entry and ptentp points to the copy of it.
>> I assume ptep should point to a valid page table entry to begin with.
>
> That would also work, only miss the case where someone would by accident
> flip both pointers :)
... or pass the same pointer twice.
--
Cheers,
David / dhildenb
prev parent reply other threads:[~2025-07-02 9:09 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-27 11:55 [PATCH v1 0/4] mm: folio_pte_batch() improvements 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
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 [this message]
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=09c356c3-5874-43ac-93e5-4374a386df98@redhat.com \
--to=david@redhat.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=apopple@nvidia.com \
--cc=byungchul@sk.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=lorenzo.stoakes@oracle.com \
--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