[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250703040443.36566-1-lizhe.67@bytedance.com>
Date: Thu, 3 Jul 2025 12:04:43 +0800
From: lizhe.67@...edance.com
To: jgg@...dia.com
Cc: alex.williamson@...hat.com,
david@...hat.com,
kvm@...r.kernel.org,
linux-kernel@...r.kernel.org,
lizhe.67@...edance.com,
peterx@...hat.com
Subject: Re: [PATCH 0/4] vfio/type1: optimize vfio_pin_pages_remote() and vfio_unpin_pages_remote() for large folio
> On Wed, 2 Jul 2025 09:47:56 -0300, jgg@...dia.com wrote:
>
> On Wed, Jul 02, 2025 at 11:57:08AM +0200, David Hildenbrand wrote:
> > On 02.07.25 11:38, lizhe.67@...edance.com wrote:
> > > On Wed, 2 Jul 2025 10:15:29 +0200, david@...hat.com wrote:
> > >
> > > > Jason mentioned in reply to the other series that, ideally, vfio
> > > > shouldn't be messing with folios at all.
> > > >
> > > > While we now do that on the unpin side, we still do it at the pin side.
> > >
> > > Yes.
> > >
> > > > Which makes me wonder if we can avoid folios in patch #1 in
> > > > contig_pages(), and simply collect pages that correspond to consecutive
> > > > PFNs.
> > >
> > > In my opinion, comparing whether the pfns of two pages are contiguous
> > > is relatively inefficient. Using folios might be a more efficient
> > > solution.
> >
> > buffer[i + 1] == nth_page(buffer[i], 1)
> >
> > Is extremely efficient, except on
>
> sg_alloc_append_table_from_pages() is using the
>
> next_pfn = (sg_phys(sgt_append->prv) + prv_len) / PAGE_SIZE;
> last_pg = pfn_to_page(next_pfn - 1);
>
> Approach to evaluate contiguity.
>
> iommufd is also using very similar in batch_from_pages():
>
> if (!batch_add_pfn(batch, page_to_pfn(*pages)))
I'm not particularly familiar with this section of the code, so I
can't say for certain. Regarding the two locations mentioned earlier,
if it's possible to determine the contiguity of physical memory by
passing in an array of page pointers, then we could adopt the
approach suggested by David. I've made a preliminary implementation
here[1]. Is that helper function okay with you?
> So we should not be trying to optimize this only in VFIO, I would drop
> that from this series.
>
> If it can be optimized we should try to have some kind of generic
> helper for building a physical contiguous range from a struct page
> list.
Thanks,
Zhe
[1]: https://lore.kernel.org/all/20250703035425.36124-1-lizhe.67@bytedance.com/
Powered by blists - more mailing lists