From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Aditya Sharma <adi.sharma@zohomail.in>, linux-mm@kvack.org
Cc: akpm@linux-foundation.org, ljs@kernel.org,
Liam.Howlett@oracle.com, vbabka@kernel.org, rppt@kernel.org,
surenb@google.com, mhocko@suse.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm: update stale locking comment in do_anonymous_page()
Date: Wed, 1 Apr 2026 12:52:17 +0200 [thread overview]
Message-ID: <db246b9b-2cc4-4aff-b92b-537ca27c47c0@kernel.org> (raw)
In-Reply-To: <20260331142936.229667-1-adi.sharma@zohomail.in>
On 3/31/26 16:29, Aditya Sharma wrote:
> The comment above do_anonymous_page() dates back to 2005 and describes
> the pre-per-VMA-lock world where mmap_lock was always held on entry.
> Since CONFIG_PER_VMA_LOCK was introduced (6.4), the fault handler now
> has a fast path that enters holding only a per-VMA read lock, with
> mmap_lock not held at all.
>
> Update the comment to describe both entry contexts accurately.
>
> Signed-off-by: Aditya Sharma <adi.sharma@zohomail.in>
> ---
> mm/memory.c | 22 +++++++++++++++++++---
> 1 file changed, 19 insertions(+), 3 deletions(-)
>
> diff --git a/mm/memory.c b/mm/memory.c
> index c65e82c86..cc8dbbaea 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -5210,9 +5210,25 @@ static struct folio *alloc_anon_folio(struct vm_fault *vmf)
> }
>
> /*
> - * We enter with non-exclusive mmap_lock (to exclude vma changes,
> - * but allow concurrent faults), and pte mapped but not yet locked.
> - * We return with mmap_lock still held, but pte unmapped and unlocked.
> + * We enter in one of two locking contexts:
> + *
> + * 1) VMA lock path (FAULT_FLAG_VMA_LOCK set):
> + * Entered holding a read lock on the faulting VMA (vma_start_read),
> + * but NOT holding mmap_lock. This is the fast path introduced with
> + * per-VMA locking (CONFIG_PER_VMA_LOCK). If this function cannot
> + * complete the fault (e.g. needs to wait on I/O or encounters a
> + * condition requiring the mm lock), it must return VM_FAULT_RETRY
> + * and the caller will fall back to the mmap_lock path below.
> + *
> + * 2) mmap_lock path (FAULT_FLAG_VMA_LOCK not set):
> + * Entered holding a non-exclusive (read) lock on mmap_lock, which
> + * excludes VMA tree modifications but allows concurrent faults on
> + * other VMAs. No per-VMA lock is held.
> + *
> + * In both cases, on entry the pte is mapped but not yet locked.
> + * On return, the pte is unmapped and unlocked, and whichever of
> + * the above locks was held on entry is still held (mmap_lock is
> + * not dropped, VMA read lock is not dropped, rather, the caller releases it).
> */
> static vm_fault_t do_anonymous_page(struct vm_fault *vmf)
> {
Was this AI generated?
I don't think we want to have such a wall of text for each and every
function that can be called with VMA lock or mmap lock in read mode.
--
Cheers,
David
next prev parent reply other threads:[~2026-04-01 10:52 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-31 14:29 [PATCH] mm: update stale locking comment in do_anonymous_page() Aditya Sharma
2026-04-01 10:52 ` David Hildenbrand (Arm) [this message]
2026-04-01 16:42 ` Aditya Sharma
2026-04-01 18:47 ` David Hildenbrand (Arm)
2026-04-05 17:18 ` [PATCH v2] mm/memory: update stale locking comments for fault handlers Aditya Sharma
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=db246b9b-2cc4-4aff-b92b-537ca27c47c0@kernel.org \
--to=david@kernel.org \
--cc=Liam.Howlett@oracle.com \
--cc=adi.sharma@zohomail.in \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=rppt@kernel.org \
--cc=surenb@google.com \
--cc=vbabka@kernel.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