From: lizhe.67@bytedance.com
To: alex.williamson@redhat.com
Cc: david@redhat.com, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org, lizhe.67@bytedance.com,
muchun.song@linux.dev, peterx@redhat.com
Subject: Re: [PATCH v4] vfio/type1: optimize vfio_pin_pages_remote() for large folio
Date: Mon, 26 May 2025 11:37:37 +0800 [thread overview]
Message-ID: <20250526033737.7657-1-lizhe.67@bytedance.com> (raw)
In-Reply-To: <20250523085415.6f316c84.alex.williamson@redhat.com>
On Fri, 23 May 2025 08:54:15 -0600, alex.williamson@redhat.com wrote:
> > > +static long vpfn_pages(struct vfio_dma *dma,
> > > + dma_addr_t iova_start, long nr_pages)
> > > +{
> > > + dma_addr_t iova_end = iova_start + (nr_pages << PAGE_SHIFT);
> > > + struct vfio_pfn *vpfn;
> > > + long count = 0;
> > > +
> > > + do {
> > > + vpfn = vfio_find_vpfn_range(dma, iova_start, iova_end);
> >
> > I am somehow confused here. Function vfio_find_vpfn_range()is designed
> > to find, through the rbtree, the node that is closest to the root node
> > and satisfies the condition within the range [iova_start, iova_end),
> > rather than the node closest to iova_start? Or perhaps I have
> > misunderstood something?
>
> Sorry, that's an oversight on my part. We might forego the _range
> version and just do an inline walk of the tree counting the number of
> already accounted pfns within the range. Thanks,
>
> Alex
>
> > > + if (likely(!vpfn))
> > > + break;
> > > +
> > > + count++;
> > > + iova_start = vpfn->iova + PAGE_SIZE;
> > > + } while (iova_start < iova_end);
> > > +
> > > + return count;
> > > +}
The utilization of the function vpfn_pages() is undoubtedly a
good idea. It can swiftly determine the num of vpfn pages
within a specified range, which will evidently expedite the
process of vfio_pin_pages_remote(). Given that the function
vfio_find_vpfn_range() returns the "top" node in the rb tree
that satisfies the condition within the range
[iova_start, iova_end), might we consider implementing the
functionality of vpfn_pages() using the following approach?
+static long _vpfn_pages(struct vfio_pfn *vpfn,
+ dma_addr_t iova_start, dma_addr_t iova_end)
+{
+ struct vfio_pfn *left;
+ struct vfio_pfn *right;
+
+ if (!vpfn)
+ return 0;
+
+ left = vpfn->node.rb_left ?
+ rb_entry(vpfn->node.rb_left, struct vfio_pfn, node) : NULL;
+ right = vpfn->node.rb_right ?
+ rb_entry(vpfn->node.rb_right, struct vfio_pfn, node) : NULL;
+
+ if ((vpfn->iova >= iova_start) && (vpfn->iova < iova_end))
+ return 1 + _vpfn_pages(left, iova_start, iova_end) +
+ _vpfn_pages(right, iova_start, iova_end);
+
+ if (vpfn->iova >= iova_end)
+ return _vpfn_pages(left, iova_start, iova_end);
+
+ return _vpfn_pages(right, iova_start, iova_end);
+}
+
+static long vpfn_pages(struct vfio_dma *dma,
+ dma_addr_t iova_start, long nr_pages)
+{
+ dma_addr_t iova_end = iova_start + (nr_pages << PAGE_SHIFT);
+ struct vfio_pfn *top = vfio_find_vpfn_range(dma, iova_start, iova_end);
+
+ return _vpfn_pages(top, iova_start, iova_end);
+}
Thanks,
Zhe
next prev parent reply other threads:[~2025-05-26 3:37 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-21 4:25 [PATCH v4] vfio/type1: optimize vfio_pin_pages_remote() for large folios lizhe.67
2025-05-21 6:36 ` David Hildenbrand
2025-05-21 19:17 ` Alex Williamson
2025-05-22 3:49 ` [PATCH v4] vfio/type1: optimize vfio_pin_pages_remote() for large folio lizhe.67
2025-05-22 7:22 ` David Hildenbrand
2025-05-22 8:25 ` lizhe.67
2025-05-22 20:52 ` Alex Williamson
2025-05-23 3:42 ` lizhe.67
2025-05-23 14:54 ` Alex Williamson
2025-05-26 3:37 ` lizhe.67 [this message]
2025-05-27 19:14 ` Alex Williamson
2025-05-28 4:21 ` lizhe.67
2025-05-28 20:11 ` Alex Williamson
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=20250526033737.7657-1-lizhe.67@bytedance.com \
--to=lizhe.67@bytedance.com \
--cc=alex.williamson@redhat.com \
--cc=david@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=muchun.song@linux.dev \
--cc=peterx@redhat.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
all inboxes | Powered by JetHome®