Re: [RFC v10 PATCH 0/3] mm: zap pages with read mmap_sem in munmap for large mapping

From: Matthew Wilcox
Date: Tue Sep 18 2018 - 06:38:07 EST


On Mon, Sep 17, 2018 at 01:00:58PM -0700, Yang Shi wrote:
> On 9/15/18 3:10 AM, Matthew Wilcox wrote:
> > Something I've been wondering about for a while is whether we should "sort"
> > the readers together. ie if the acquirers look like this:
> >
> > A write
> > B read
> > C read
> > D write
> > E read
> > F read
> > G write
> >
> > then we should grant the lock to A, BCEF, D, G rather than A, BC, D, EF, G.
>
> I'm not sure how much this can help to the real world workload.
>
> Typically, there are multi threads to contend for one mmap_sem. So, they are
> trying to read/write the same address space. There might be dependency or
> synchronization among them. Sorting read together might break the
> dependency?

I don't think that's true for the mmap_sem. If one thread is trying to
get the sem for read then it's a page fault. Another thread trying to
get the sem for write is trying to modify the address space. If an
application depends on the ordering of an mmap vs a page fault, it has
to have its own synchronisation.