linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Liam R. Howlett" <Liam.Howlett@oracle.com>
To: Mateusz Guzik <mjguzik@gmail.com>
Cc: Suren Baghdasaryan <surenb@google.com>,
	linux-mm <linux-mm@kvack.org>,
	Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
	Matthew Wilcox <willy@infradead.org>
Subject: Re: not issuing vma_start_write() in dup_mmap() if the caller is single-threaded
Date: Mon, 31 Mar 2025 12:43:40 -0400	[thread overview]
Message-ID: <ygc6bdufwp3gbiwhuketiydwoblpacwfbgaupffkyegkr7wfco@2pq545tkvg5m> (raw)
In-Reply-To: <CAGudoHGFX-6dgYXe0f1HxL3gm5GC-v62mPp4phFje6sUy5B0vg@mail.gmail.com>

* Mateusz Guzik <mjguzik@gmail.com> [250330 15:43]:
> On Sun, Mar 30, 2025 at 9:23 PM Suren Baghdasaryan <surenb@google.com> wrote:
> > > However, the good news is that mm_count tends to be 1. If both
> > > mm_count and mm_users are 1, then there is no usefaultfd in use and
> > > nobody to add it either.
> >
> > I'm not sure... IIUC new_userfaultfd() does not take mmap_lock while
> > calling mmgrab(), therefore I think it can race with the code checking
> > its value.
> >

Considering the mm struct isn't the only way to find the vmas and there
are users who use other locks to ensure the mm and vma don't go away
(rmap, for example).  It is reasonable to think that other users may use
the vma lock to avoid mm_struct accesses racing.

Although I don't know of a way this is unsafe today, we are complicating
the locking story of the mm with this change and no data has been given
on the benefit.  I don't recall any regression caused by the addition of
per-vma locking?

> 
> It issues:
> ctx->mm = current->mm;
> ...
> mmgrab(ctx->mm);
> 
> Thus I claim if mm_count is 1 *and* mm_users is 1 *and* we are in
> dup_mmap(), nobody has a userfaultfd for our mm and there is nobody to
> create it either and the optimization is saved.

mm_count is lazy, so I am not entirely sure we can trust what it says.
But maybe that's only true of mmgrab_lazy_tlb() now?

Thanks,
Liam


  reply	other threads:[~2025-03-31 16:44 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-27  5:46 Mateusz Guzik
2025-03-29  0:56 ` Suren Baghdasaryan
2025-03-29  1:15   ` Mateusz Guzik
2025-03-29  1:35     ` Suren Baghdasaryan
2025-03-29  1:51       ` Mateusz Guzik
2025-03-30 19:23         ` Suren Baghdasaryan
2025-03-30 19:25           ` Suren Baghdasaryan
2025-03-30 19:43           ` Mateusz Guzik
2025-03-31 16:43             ` Liam R. Howlett [this message]
2025-03-31 17:50               ` Mateusz Guzik
2025-03-31 18:42                 ` Suren Baghdasaryan
2025-03-31 19:24                 ` Liam R. Howlett
2025-03-31 20:27                   ` Mateusz Guzik

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=ygc6bdufwp3gbiwhuketiydwoblpacwfbgaupffkyegkr7wfco@2pq545tkvg5m \
    --to=liam.howlett@oracle.com \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=mjguzik@gmail.com \
    --cc=surenb@google.com \
    --cc=willy@infradead.org \
    /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