linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Suren Baghdasaryan <surenb@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>, linux-mm@kvack.org
Subject: Re: [PATCH 2/6] mm: Call wp_page_copy() under the VMA lock
Date: Thu, 28 Sep 2023 06:18:48 +0100	[thread overview]
Message-ID: <ZRUMuDwlxQJqWixk@casper.infradead.org> (raw)
In-Reply-To: <CAJuCfpG0MnUaR5HgYTWkcBrT=CmDFtXj8+dFXCWVoAAL8SoXVw@mail.gmail.com>

On Wed, Sep 27, 2023 at 03:38:38PM -0700, Suren Baghdasaryan wrote:
> On Tue, Sep 26, 2023 at 10:25 PM Matthew Wilcox (Oracle)
> <willy@infradead.org> wrote:
> > It is usually safe to call wp_page_copy() under the VMA lock.  The only
> > unsafe situation is when no anon_vma has been allocated for this VMA,
> > and we have to look at adjacent VMAs to determine if their anon_vma can
> > be shared.  Since this happens only for the first COW of a page in this
> > VMA, the majority of calls to wp_page_copy() do not need to fall back
> > to the mmap_sem.
> >
> > Add vmf_anon_prepare() as an alternative to anon_vma_prepare() which
> > will return RETRY if we currently hold the VMA lock and need to allocate
> > an anon_vma.  This lets us drop the check in do_wp_page().
> >
> > Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> > ---
> >  mm/memory.c | 39 ++++++++++++++++++++++++++-------------
> >  1 file changed, 26 insertions(+), 13 deletions(-)
> >
> > diff --git a/mm/memory.c b/mm/memory.c
> > index 97f860d6cd2a..cff78c496728 100644
> > --- a/mm/memory.c
> > +++ b/mm/memory.c
> > @@ -3042,6 +3042,21 @@ static inline void wp_page_reuse(struct vm_fault *vmf)
> >         count_vm_event(PGREUSE);
> >  }
> >
> > +static vm_fault_t vmf_anon_prepare(struct vm_fault *vmf)
> > +{
> > +       struct vm_area_struct *vma = vmf->vma;
> > +
> > +       if (likely(vma->anon_vma))
> > +               return 0;
> > +       if (vmf->flags & FAULT_FLAG_VMA_LOCK) {
> 
> I don't think the above condition will happen today because
> lock_vma_under_rcu() returns NULL and do_page_fault() falls back to
> taking mmap_lock when !vma->anon_vma
> (https://elixir.bootlin.com/linux/v6.6-rc3/source/mm/memory.c#L5428).
> We would need to narrow down that check in lock_vma_under_rcu() to
> make this work here.

That's only for anon VMAs.  For file-backed VMAs, we can get here ...

handle_pte_fault()
        if (vmf->flags & (FAULT_FLAG_WRITE|FAULT_FLAG_UNSHARE)) {
                if (!pte_write(entry))
                        return do_wp_page(vmf);

ie we we have a MAP_PRIVATE of a file, first take a read-fault on it,
then write to it.  That causes us to allocate an anon page in this
file-backed VMA, so we need an anon_vma to exist.


  reply	other threads:[~2023-09-28  5:18 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-27  5:24 [PATCH 0/6] Handle more faults " Matthew Wilcox (Oracle)
2023-09-27  5:24 ` [PATCH 1/6] mm: Make lock_folio_maybe_drop_mmap() VMA lock aware Matthew Wilcox (Oracle)
2023-09-27  5:25 ` [PATCH 2/6] mm: Call wp_page_copy() under the VMA lock Matthew Wilcox (Oracle)
2023-09-27 22:38   ` Suren Baghdasaryan
2023-09-28  5:18     ` Matthew Wilcox [this message]
2023-09-28 14:57       ` Suren Baghdasaryan
2023-09-27  5:25 ` [PATCH 3/6] mm: Handle shared faults " Matthew Wilcox (Oracle)
2023-09-28  0:46   ` Suren Baghdasaryan
2023-09-28  1:02     ` Suren Baghdasaryan
2023-09-28  5:33       ` Matthew Wilcox
2023-09-28 15:02         ` Suren Baghdasaryan
2023-09-27  5:25 ` [PATCH 4/6] mm: Handle COW " Matthew Wilcox (Oracle)
2023-09-28  0:53   ` Suren Baghdasaryan
2023-09-27  5:25 ` [PATCH 5/6] mm: Handle read " Matthew Wilcox (Oracle)
2023-09-27  5:25 ` [PATCH 6/6] mm: Handle write faults to RO pages " Matthew Wilcox (Oracle)
2023-09-27 22:18 ` [PATCH 0/6] Handle more faults " Suren Baghdasaryan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZRUMuDwlxQJqWixk@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=linux-mm@kvack.org \
    --cc=surenb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox