Re: [RFC PATCH 1/8] mm: mmap: unmap large mapping by section

From: Matthew Wilcox
Date: Thu Mar 22 2018 - 12:51:14 EST


On Thu, Mar 22, 2018 at 05:18:55PM +0100, Laurent Dufour wrote:
> > It's *really* rare to page-fault on a VMA which is in the middle of
> > being replaced. Why are you trying to optimise it?
>
> I was not trying to optimize it, but to not wait in the page fault handler.
> This could become tricky in the case the VMA is removed once mmap(MAP_FIXED) is
> done and before the waiting page fault got woken up. This means that the
> removed VMA structure will have to remain until all the waiters are woken up
> which implies ref_count or similar.

Yes, that's why we don't want an actual rwsem. What I had in mind was
a struct completion on the stack of the caller of munmap(), and a pointer
to it from the vma. The page fault handler grabs the VMA tree lock, walks
the VMA tree and finds a VMA. If the VMA is marked as locked, it waits
for the completion. Upon wakeup *it does not look at the VMA*, instead it
restarts the page fault.