Re: [PATCH v1 06/11] mm: support GUP-triggered unsharing via FAULT_FLAG_UNSHARE (!hugetlb)

From: Matthew Wilcox
Date: Sun Dec 19 2021 - 06:30:38 EST


On Sun, Dec 19, 2021 at 12:01:59AM -0800, John Hubbard wrote:
> On 12/18/21 22:02, Nadav Amit wrote:
> > I found my old messy code for the software-PTE thing.
> >
> > I see that eventually I decided to hold a pointer to the “extra PTEs”
> > of each page in the PMD-page-struct. [ I also implemented the 2-adjacent
> > pages approach but this code is long gone. ]
>
> a) The PMD-page-struct approach won't help as much, because (assuming
> that we're using it in an attempt to get a true, perfect pin count), you
> are combining the pin counts of a PMD's worth of pages. OTOH...maybe
> that actually *is* OK, assuming you don't overflow--except that you can
> only answer the "is it dma-pinned?" question at a PMD level. That's a
> contradiction of your stated desire above to have very granular control.
>
> Also, because of not having bit 0 available in page._pt_pad_1, I think
> the count would have to be implemented as adding and subtracting 2,
> instead of 1 (in order to keep the value even), further reducing the
> counter range.

I think you misunderstood Nadav's approach. He's talking about making
an extra side-allocation per PMD if you're using uffd, and storing
extra information in it. I think it's a worthwile approach.