public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	Andrew Morton <akpm@linux-foundation.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Lokesh Gidra <lokeshgidra@google.com>,
	"Liam R . Howlett" <Liam.Howlett@oracle.com>,
	Alistair Popple <apopple@nvidia.com>
Subject: Re: [PATCH] mm: Always sanity check anon_vma first for per-vma locks
Date: Wed, 10 Apr 2024 16:43:51 -0400	[thread overview]
Message-ID: <Zhb6B8UsidEEbFu3@x1n> (raw)
In-Reply-To: <Zhb2BWntckP3ZhDc@casper.infradead.org>

On Wed, Apr 10, 2024 at 09:26:45PM +0100, Matthew Wilcox wrote:
> On Wed, Apr 10, 2024 at 01:06:21PM -0400, Peter Xu wrote:
> > anon_vma is a tricky object in the context of per-vma lock, because it's
> > racy to modify it in that context and mmap lock is needed if it's not
> > stable yet.
> 
> I object to this commit message.  First, it's not a "sanity check".  It's
> a check to see if we already have an anon VMA.  Second, it's not "racy
> to modify it" at all.  The problem is that we need to look at other
> VMAs, for which we do not hold the lock.

For that "do not hold locks" part, isn't that "racy"?

When it's racy in that case, can I still word it as "racy to modify"?  We
can't modify it because it's racy to read the other vmas.

For "sanity check".. well, that falls into this category for me but I'm not
a native speaker. So I am open to any rewords for any of above.

> 
> > So the trivial side effect of such patch is:
> > 
> >   - We may do slightly better on the first WRITE of a private file mapping,
> >   because we can retry earlier (in lock_vma_under_rcu(), rather than
> >   vmf_anon_prepare() later).
> > 
> >   - We may always use mmap lock for the initial READs on a private file
> >   mappings, while before this patch it _can_ (only when no WRITE ever
> >   happened... but it doesn't make much sense for a MAP_PRIVATE..) do the
> >   read fault with per-vma lock.
> 
> But that's a super common path!  Look at 'cat /proc/self/maps'.  All
> your program text (including libraries) is mapped PRIVATE, and never
> written to (except by ptrace, I guess).
> 
> NAK this patch.

We're talking about any vma that will first benefit from a per-vma lock
here, right?

I think it should be only relevant to some major VMA or bunch of VMAs that
an userspace maps explicitly, then iiuc the goal is we want to reduce the
cache bouncing of the lock when it used to be per-mm, by replacing it with
a finer lock.  It doesn't sound right that these libraries even fall into
this category as they should just get loaded soon enough when the program
starts.

IOW, my understanding is that per-vma lock doesn't benefit from such normal
vmas or simple programs that much; we take either per-vma read lock, or
mmap read lock, and I would expect similar performance when such cache
bouncing isn't heavy.

I can do some tests later today or tomorrow. Any suggestion you have on
amplifying such effect that you have concern with?

-- 
Peter Xu


  reply	other threads:[~2024-04-10 20:43 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-10 17:06 [PATCH] mm: Always sanity check anon_vma first for per-vma locks Peter Xu
2024-04-10 20:26 ` Matthew Wilcox
2024-04-10 20:43   ` Peter Xu [this message]
2024-04-10 21:10     ` Matthew Wilcox
2024-04-10 21:23       ` Peter Xu
2024-04-10 23:59         ` Matthew Wilcox
2024-04-11  0:20           ` Peter Xu
2024-04-11 14:50             ` Matthew Wilcox
2024-04-11 15:34               ` Peter Xu
2024-04-11 17:14                 ` Matthew Wilcox
2024-04-11 15:42   ` Suren Baghdasaryan
2024-04-11 17:13 ` Liam R. Howlett
2024-04-11 21:12   ` Peter Xu
2024-04-11 21:27     ` Matthew Wilcox
2024-04-11 21:46       ` Peter Xu
2024-04-11 22:02         ` Matthew Wilcox
2024-04-12  3:14           ` Matthew Wilcox
2024-04-12 12:38             ` Peter Xu
2024-04-12 13:06               ` Suren Baghdasaryan
2024-04-12 14:16                 ` Matthew Wilcox
     [not found]                   ` <CAJuCfpGGUD6ev-KFhON2D2RqQRZSgjxFXvkNqeux-LrJw4L+iw@mail.gmail.com>
2024-04-12 15:19                     ` Matthew Wilcox
2024-04-12 15:31                       ` Matthew Wilcox
2024-04-13 21:46                         ` Suren Baghdasaryan
2024-04-13 22:52                           ` Matthew Wilcox
2024-04-13 23:11                             ` Suren Baghdasaryan
2024-04-13 21:41                       ` Suren Baghdasaryan
2024-04-13 22:46                         ` Matthew Wilcox
2024-04-15 15:58                       ` Suren Baghdasaryan
2024-04-15 16:13                         ` Matthew Wilcox
2024-04-15 16:19                           ` Suren Baghdasaryan
2024-04-15 16:26                             ` Matthew Wilcox
2024-04-12 12:46             ` Suren Baghdasaryan
2024-04-12 13:32               ` Matthew Wilcox
2024-04-12 13:46                 ` Suren Baghdasaryan
2024-04-26 14:00             ` Matthew Wilcox
2024-04-26 15:07               ` Suren Baghdasaryan
2024-04-26 15:28                 ` Matthew Wilcox
2024-04-26 15:32                   ` Suren Baghdasaryan
2024-04-26 15:50                     ` Matthew Wilcox
2024-04-26 15:32                 ` Liam R. Howlett

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=Zhb6B8UsidEEbFu3@x1n \
    --to=peterx@redhat.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=apopple@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lokeshgidra@google.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