From: Andrew Morton <akpm@linux-foundation.org>
To: Dev Jain <dev.jain@arm.com>
Cc: Liam.Howlett@oracle.com, lorenzo.stoakes@oracle.com,
vbabka@suse.cz, jannh@google.com, pfalcato@suse.de,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
david@redhat.com, peterx@redhat.com, ryan.roberts@arm.com,
mingo@kernel.org, libang.li@antgroup.com, maobibo@loongson.cn,
zhengqi.arch@bytedance.com, baohua@kernel.org,
anshuman.khandual@arm.com, willy@infradead.org,
ioworker0@gmail.com, yang@os.amperecomputing.com,
baolin.wang@linux.alibaba.com, ziy@nvidia.com, hughd@google.com
Subject: Re: [PATCH v2 2/2] mm: Optimize mremap() by PTE batching
Date: Wed, 7 May 2025 18:37:03 -0700 [thread overview]
Message-ID: <20250507183703.43d7b53d5e2e263566cfe80a@linux-foundation.org> (raw)
In-Reply-To: <20250507060256.78278-3-dev.jain@arm.com>
On Wed, 7 May 2025 11:32:56 +0530 Dev Jain <dev.jain@arm.com> wrote:
> To use PTE batching, we want to determine whether the folio mapped by
> the PTE is large, thus requiring the use of vm_normal_folio(). We want
> to avoid the cost of vm_normal_folio() if the code path doesn't already
> require the folio. For arm64, pte_batch_hint() does the job. To generalize
> this hint, add a helper which will determine whether two consecutive PTEs
> point to consecutive PFNs, in which case there is a high probability that
> the underlying folio is large.
> Next, use folio_pte_batch() to optimize move_ptes(). On arm64, if the ptes
> are painted with the contig bit, then ptep_get() will iterate through all 16
> entries to collect a/d bits. Hence this optimization will result in a 16x
> reduction in the number of ptep_get() calls. Next, ptep_get_and_clear()
> will eventually call contpte_try_unfold() on every contig block, thus
> flushing the TLB for the complete large folio range. Instead, use
> get_and_clear_full_ptes() so as to elide TLBIs on each contig block, and only
> do them on the starting and ending contig block.
>
> ...
>
> --- a/include/linux/pgtable.h
> +++ b/include/linux/pgtable.h
> @@ -369,6 +369,35 @@ static inline pgd_t pgdp_get(pgd_t *pgdp)
> }
> #endif
>
> +/**
> + * maybe_contiguous_pte_pfns - Hint whether the page mapped by the pte belongs
> + * to a large folio.
> + * @ptep: Pointer to the page table entry.
> + * @pte: The page table entry.
> + *
> + * This helper is invoked when the caller wants to batch over a set of ptes
> + * mapping a large folio, but the concerned code path does not already have
> + * the folio. We want to avoid the cost of vm_normal_folio() only to find that
> + * the underlying folio was small; i.e keep the small folio case as fast as
> + * possible.
> + *
> + * The caller must ensure that ptep + 1 exists.
> + */
Gee, that isn't the prettiest interface we've ever invented.
Is there any prospect that this function will get another caller? If
not then it's probably better to just open-code all this in the caller
and fill it up with comments.
Anyway, review of this series is scanty. I'd normally enter
wait-and-see mode, but this:
> the average execution time reduces from 1.9 to
> 1.2 seconds, giving a 37% performance optimization, on Apple M3 (arm64).
prompts me into push-it-along mode.
next prev parent reply other threads:[~2025-05-08 1:37 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-07 6:02 [PATCH v2 0/2] Optimize mremap() for large folios Dev Jain
2025-05-07 6:02 ` [PATCH v2 1/2] mm: Call pointers to ptes as ptep Dev Jain
2025-05-08 1:05 ` Barry Song
2025-05-08 6:21 ` Anshuman Khandual
2025-05-08 9:21 ` Lorenzo Stoakes
2025-05-07 6:02 ` [PATCH v2 2/2] mm: Optimize mremap() by PTE batching Dev Jain
2025-05-08 1:37 ` Andrew Morton [this message]
2025-05-08 4:53 ` Lorenzo Stoakes
2025-05-08 2:00 ` Zi Yan
2025-05-08 4:01 ` Dev Jain
2025-05-08 6:31 ` Anshuman Khandual
2025-05-08 7:16 ` Anshuman Khandual
2025-05-08 8:05 ` Dev Jain
2025-05-08 9:40 ` Lorenzo Stoakes
2025-05-08 10:04 ` Lorenzo Stoakes
2025-05-08 18:01 ` David Hildenbrand
2025-05-18 8:17 ` Dev Jain
2025-05-19 9:04 ` Lorenzo Stoakes
2025-05-20 9:21 ` Dev Jain
2025-05-08 18:35 ` [PATCH v2 0/2] Optimize mremap() for large folios Lorenzo Stoakes
2025-05-09 5:27 ` Dev Jain
2025-05-09 8:44 ` Lorenzo Stoakes
2025-05-09 9:26 ` 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=20250507183703.43d7b53d5e2e263566cfe80a@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=Liam.Howlett@oracle.com \
--cc=anshuman.khandual@arm.com \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=david@redhat.com \
--cc=dev.jain@arm.com \
--cc=hughd@google.com \
--cc=ioworker0@gmail.com \
--cc=jannh@google.com \
--cc=libang.li@antgroup.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=maobibo@loongson.cn \
--cc=mingo@kernel.org \
--cc=peterx@redhat.com \
--cc=pfalcato@suse.de \
--cc=ryan.roberts@arm.com \
--cc=vbabka@suse.cz \
--cc=willy@infradead.org \
--cc=yang@os.amperecomputing.com \
--cc=zhengqi.arch@bytedance.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