From: Mike Rapoport <rppt@kernel.org>
To: Lokesh Gidra <lokeshgidra@google.com>
Cc: Peter Xu <peterx@redhat.com>,
David Hildenbrand <david@redhat.com>,
Andrea Arcangeli <aarcange@redhat.com>,
Suren Baghdasaryan <surenb@google.com>,
"open list:MEMORY MANAGEMENT" <linux-mm@kvack.org>
Subject: Re: Synchronization around mmap_changing in userfaultfd
Date: Thu, 25 Jan 2024 11:19:10 +0200 [thread overview]
Message-ID: <ZbInjmxnMSw_v1rf@kernel.org> (raw)
In-Reply-To: <CA+EESO6AZ493P+3Wo=97F3WRJpzwqj2pQomvGd8wd3-kMi8_wQ@mail.gmail.com>
Hi,
On Thu, Jan 11, 2024 at 03:32:20PM -0800, Lokesh Gidra wrote:
> Hi,
>
> We have been seeing mmap_lock contention issues while using
> userfaultfd for GC in Android. But now that per-vma locks are being
> used in the kernel, we were hoping to use it in userfaultfd code to
> pin the VMA in COPY/MOVE/ZEROPAGE etc. operations. But while going
> through the code, I noticed that mmap_changing is implicitly protected
> by mmap_lock:
>
> 1) All increments to it (except for userfault_remove) are done with
> mmap_lock in write-mode
> 2) All reads (in copy/move/zeropage etc) are done with mmap_lock in read-mode
>
> I wanted to understand if that's just out of convenience, and
> therefore would it be ok to introduce a read-write semaphore in
> userfaultfd_ctx to achieve the same synchronization:
>
> 1) All increments are done with this semaphore in write-mode
> 2) All operations (copy/move/zeropage etc) are done within the
> critical section of this semaphore in read-mode and checking that
> mmap_changing is 0.
mmap_changing was added to the existing critical sections that were already
protected with mmap_lock, so I didn't see a reason for additional lock to
protect mmap_changing.
With per-vma locks, your proposal makes perfect sense to me.
> If this is wrong, then kindly explain why mmap_changing needs to be
> protected with mmap_lock.
>
>
> Thanks,
> Lokesh
>
--
Sincerely yours,
Mike.
next prev parent reply other threads:[~2024-01-25 9:19 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-11 23:32 Lokesh Gidra
2024-01-25 9:19 ` Mike Rapoport [this message]
2024-01-25 15:23 ` Lokesh Gidra
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=ZbInjmxnMSw_v1rf@kernel.org \
--to=rppt@kernel.org \
--cc=aarcange@redhat.com \
--cc=david@redhat.com \
--cc=linux-mm@kvack.org \
--cc=lokeshgidra@google.com \
--cc=peterx@redhat.com \
--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