From: Jason Gunthorpe <jgg@nvidia.com>
To: Aaron Lewis <aaronlewis@google.com>
Cc: alex.williamson@redhat.com, dmatlack@google.com,
kvm@vger.kernel.org, seanjc@google.com
Subject: Re: [RFC PATCH 1/2] vfio: Improve DMA mapping performance for huge pages
Date: Tue, 23 Dec 2025 22:10:54 -0400 [thread overview]
Message-ID: <aUtLrp2smpXZPpBO@nvidia.com> (raw)
In-Reply-To: <20251223230044.2617028-2-aaronlewis@google.com>
On Tue, Dec 23, 2025 at 11:00:43PM +0000, Aaron Lewis wrote:
> More effort will be needed to see what kind of speed ups can be achieved
> by optimizing iommufd. Sample profiler results (below) show that it
> isn't the GUP calls that are slowing it down like they were in the
> "vfio_type1_iommu" case. The majority of the slowdown is coming from
> batch_from_pages(), and the majority of that time is being spent in
> batch_add_pfn_num().
This is probably because vfio is now using num_pages_contiguous()
which seems to be a little bit faster than batch_add_pfn()
Since that is pretty new maybe it explains the discrepancy in reports.
> @@ -598,7 +600,18 @@ static long vaddr_get_pfns(struct mm_struct *mm, unsigned long vaddr,
> ret = pin_user_pages_remote(mm, vaddr, pin_pages, flags | FOLL_LONGTERM,
> batch->pages, NULL);
> if (ret > 0) {
> + unsigned long nr_pages = compound_nr(batch->pages[0]);
> + bool override_size = false;
> +
> + if (PageHead(batch->pages[0]) && nr_pages > pin_pages &&
> + ret == pin_pages) {
> + override_size = true;
> + ret = nr_pages;
> + page_ref_add(batch->pages[0], nr_pages - pin_pages);
> + }
This isn't right, num_pages_contiguous() is the best we can do for
lists returns by pin_user_pages(). In a VMA context you cannot blindly
assume the whole folio was mapped contiguously. Indeed I seem to
recall this was already proposed and rejected and that is how we ended
up with num_pages_contiguous().
Again, use the memfd path which supports this optimization already.
Jason
next prev parent reply other threads:[~2025-12-24 2:10 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-23 23:00 [RFC PATCH 0/2] vfio: Improve DMA mapping performance for huge pages Aaron Lewis
2025-12-23 23:00 ` [RFC PATCH 1/2] " Aaron Lewis
2025-12-24 2:10 ` Jason Gunthorpe [this message]
2025-12-29 21:40 ` Aaron Lewis
2025-12-30 1:12 ` Jason Gunthorpe
2026-01-05 18:31 ` David Matlack
2026-01-05 19:01 ` Jason Gunthorpe
2026-01-05 19:36 ` David Matlack
2025-12-23 23:00 ` [RFC PATCH 2/2] vfio: selftest: Add vfio_dma_mapping_perf_test Aaron Lewis
2025-12-24 2:04 ` [RFC PATCH 0/2] vfio: Improve DMA mapping performance for huge pages Jason Gunthorpe
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=aUtLrp2smpXZPpBO@nvidia.com \
--to=jgg@nvidia.com \
--cc=aaronlewis@google.com \
--cc=alex.williamson@redhat.com \
--cc=dmatlack@google.com \
--cc=kvm@vger.kernel.org \
--cc=seanjc@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.