Re: [PATCH V4 1/2] vfio dma_map/unmap: optimized for hugetlbfs pages

From: Matthew Wilcox
Date: Wed Sep 09 2020 - 13:12:30 EST


On Wed, Sep 09, 2020 at 03:29:41PM +0100, Christoph Hellwig wrote:
> On Wed, Sep 09, 2020 at 10:05:18AM -0300, Jason Gunthorpe wrote:
> > How to use? The VMAs can have mixed page sizes so the caller would
> > have to somehow switch and call twice? Not sure this is faster.
>
> We can find out the page size based on the page. Right now it is
> rather cumbersome, but one of willys pending series has a nicer helper
> for that.

Actually already merged. There's page_size() which went into 5.4, and
is the one you'd want to use (also page_shift() and compound_nr()).
The thp_* equivalents (merged in 5.9) compile away to nothing if you
don't have CONFIG_TRANSPARENT_HUGEPAGE enabled, but since there are
many ways of getting a compound page mapped into userspace, page_size()
is the helper to use for VFIO.