Re: 答复: [PATCH V3] vfio dma_map/unmap: optimized for hugetlbfs pages

From: Hugh Dickins
Date: Tue Sep 01 2020 - 13:52:06 EST


On Tue, 1 Sep 2020, Maoming (maoming, Cloud Infrastructure Service Product Dept.) wrote:
> >
> > > In the original process of dma_map/unmap pages for VFIO-devices, to
> > > make sure the pages are contiguous, we have to check them one by one.
> > > As a result, dma_map/unmap could spend a long time.
> > > Using the hugetlb pages, we can avoid this problem.
> > > All pages in hugetlb pages are contiguous.And the hugetlb page should
> > > not be split.So we can delete the for loops.
> >
> > I know nothing about VFIO, but I'm surprised that you're paying such attention
> > to PageHuge hugetlbfs pages, rather than to PageCompound
> > pages: which would also include Transparent Huge Pages, of the traditional
> > anonymous kind, or the huge tmpfs kind, or the more general (not necessarily
> > pmd-sized) kind that Matthew Wilcox is currently working on.
> >
> > It's true that hugetlbfs is peculiar enough that whatever you write for it may
> > need some tweaks to cover the THP case too, or vice versa; but wouldn't your
> > patch be a lot better for covering all cases?
> >
> > You mention above that "the hugetlb page should not be split":
> > perhaps you have been worried that a THP could be split beneath you?
> > That used to be a possibility some years ago, but nowadays a THP cannot be
> > split while anyone is pinning it with an extra reference.
> >
> > Hugh
> >
>
>
> Thanks for your suggestions.
> You mention that a THP cannot be split while anyone is pinning it.
> Do you mean the check of can_split_huge_page()(in split_huge_page_to_list())?

Partly, yes: but that's just a racy check to avoid doing wasted work in
common cases; the more important check comes later in page_ref_freeze(),
which either fails, or prevents anyone else taking a new reference to
the THP (head or tails) while all the work on splitting is being done.

> When we want to pin pages, vfio_pin_pages_remote() always gets a normal page first.
> In this case, a THP cannot be split because of the increased reference.
> Is this right?

Yes.

>
> Maybe I can optimize for hugetlb pages as a first step,
> and then cover all compound pages.

Okay. That's definitely a good way to start out - but you may find
that the second step leads you to rewrite every line you wrote before!

Hugh