From: David Hildenbrand <david@redhat.com>
To: Zhang Qilong <zhangqilong3@huawei.com>,
akpm@linux-foundation.org, lorenzo.stoakes@oracle.com,
Liam.Howlett@oracle.com, vbabka@suse.cz, rppt@kernel.org,
surenb@google.com, mhocko@suse.com, jannh@google.com,
pfalcato@suse.de
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
wangkefeng.wang@huawei.com, sunnanyong@huawei.com
Subject: Re: [RFC PATCH 3/3] mm/mremap: Use can_pte_batch_count() instead of folio_pte_batch() for pte batch
Date: Mon, 27 Oct 2025 20:41:03 +0100 [thread overview]
Message-ID: <13945f06-f862-4f80-904a-f2a4ccff3e4b@redhat.com> (raw)
In-Reply-To: <20251027140315.907864-4-zhangqilong3@huawei.com>
On 27.10.25 15:03, Zhang Qilong wrote:
> In current mremap_folio_pte_batch(), 1) pte_batch_hint() always
> return one pte in non-ARM64 machine, it is not efficient. 2) Next,
> it need to acquire a folio to call the folio_pte_batch().
>
> Due to new added can_pte_batch_count(), we just call it instead of
> folio_pte_batch(). And then rename mremap_folio_pte_batch() to
> mremap_pte_batch().
>
> Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
> ---
> mm/mremap.c | 16 +++-------------
> 1 file changed, 3 insertions(+), 13 deletions(-)
>
> diff --git a/mm/mremap.c b/mm/mremap.c
> index bd7314898ec5..d11f93f1622f 100644
> --- a/mm/mremap.c
> +++ b/mm/mremap.c
> @@ -169,27 +169,17 @@ static pte_t move_soft_dirty_pte(pte_t pte)
> pte = pte_swp_mksoft_dirty(pte);
> #endif
> return pte;
> }
>
> -static int mremap_folio_pte_batch(struct vm_area_struct *vma, unsigned long addr,
> +static int mremap_pte_batch(struct vm_area_struct *vma, unsigned long addr,
> pte_t *ptep, pte_t pte, int max_nr)
> {
> - struct folio *folio;
> -
> if (max_nr == 1)
> return 1;
>
> - /* Avoid expensive folio lookup if we stand no chance of benefit. */
> - if (pte_batch_hint(ptep, pte) == 1)
> - return 1;
> -
> - folio = vm_normal_folio(vma, addr, pte);
> - if (!folio || !folio_test_large(folio))
> - return 1;
> -
> - return folio_pte_batch(folio, ptep, pte, max_nr);
> + return can_pte_batch_count(vma, ptep, &pte, max_nr, 0);
> }
>
> static int move_ptes(struct pagetable_move_control *pmc,
> unsigned long extent, pmd_t *old_pmd, pmd_t *new_pmd)
> {
> @@ -278,11 +268,11 @@ static int move_ptes(struct pagetable_move_control *pmc,
> * make sure the physical page stays valid until
> * the TLB entry for the old mapping has been
> * flushed.
> */
> if (pte_present(old_pte)) {
> - nr_ptes = mremap_folio_pte_batch(vma, old_addr, old_ptep,
> + nr_ptes = mremap_pte_batch(vma, old_addr, old_ptep,
> old_pte, max_nr_ptes);
> force_flush = true;
> }
> pte = get_and_clear_ptes(mm, old_addr, old_ptep, nr_ptes);
get_and_clear_ptes() documents: "Clear present PTEs that map consecutive
pages of the same folio, collecting dirty/accessed bits."
And as can_pte_batch_count() will merge access/dirty bits, you would
silently set ptes dirty/accessed that belong to other folios, which
sounds very wrong.
Staring at the code, I wonder if there is also a problem with the write
bit, have to dig into that.
--
Cheers
David / dhildenb
next prev parent reply other threads:[~2025-10-27 19:41 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-27 14:03 [RFC PATCH 0/3] mm: PTEs batch optimization in mincore and mremap Zhang Qilong
2025-10-27 14:03 ` [RFC PATCH 1/3] mm: Introduce can_pte_batch_count() for PTEs batch optimization Zhang Qilong
2025-10-27 19:24 ` David Hildenbrand
2025-10-27 19:51 ` Lorenzo Stoakes
2025-10-27 20:21 ` Ryan Roberts
2025-10-27 14:03 ` [RFC PATCH 2/3] mm/mincore: Use can_pte_batch_count() in mincore_pte_range() for pte batch mincore_pte_range() Zhang Qilong
2025-10-27 19:27 ` David Hildenbrand
2025-10-27 19:34 ` Lorenzo Stoakes
2025-10-27 14:03 ` [RFC PATCH 3/3] mm/mremap: Use can_pte_batch_count() instead of folio_pte_batch() for pte batch Zhang Qilong
2025-10-27 19:41 ` David Hildenbrand [this message]
2025-10-27 19:57 ` Lorenzo Stoakes
2025-10-28 13:01 zhangqilong
2025-10-28 13:27 zhangqilong
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=13945f06-f862-4f80-904a-f2a4ccff3e4b@redhat.com \
--to=david@redhat.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=jannh@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=mhocko@suse.com \
--cc=pfalcato@suse.de \
--cc=rppt@kernel.org \
--cc=sunnanyong@huawei.com \
--cc=surenb@google.com \
--cc=vbabka@suse.cz \
--cc=wangkefeng.wang@huawei.com \
--cc=zhangqilong3@huawei.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