On Mon, Apr 15, 2024 at 5:24 PM Matthew Wilcox <willy@xxxxxxxxxxxxx> wrote: > It seems a shame to fallback if the mmap_lock is readily available. > It doesn't blow up immediately in my testing ... thoughts? Seems fine to me, since nothing below the trylocked mmap_lock does vma_start_*(). > >From 70833af858ce41a80b5f0669648ee9f59b149a03 Mon Sep 17 00:00:00 2001 > From: "Matthew Wilcox (Oracle)" <willy@xxxxxxxxxxxxx> > Date: Mon, 15 Apr 2024 11:13:41 -0400 > Subject: [PATCH] mm: Optimise vmf_anon_prepare() for VMAs without an anon_vma > > If the mmap_lock can be taken for read, there's no reason not to take > it so that we can call __anon_vma_prepare(). > > Signed-off-by: Matthew Wilcox (Oracle) <willy@xxxxxxxxxxxxx> Reviewed-by: Jann Horn <jannh@xxxxxxxxxx> > --- > mm/memory.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/mm/memory.c b/mm/memory.c > index b9c23393fa9b..7075fb7f74da 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -3219,11 +3219,15 @@ vm_fault_t vmf_anon_prepare(struct vm_fault *vmf) > if (likely(vma->anon_vma)) > return 0; > if (vmf->flags & FAULT_FLAG_VMA_LOCK) { > - vma_end_read(vma); > - return VM_FAULT_RETRY; > + if (!mmap_read_trylock(vma->vm_mm)) { > + vma_end_read(vma); > + return VM_FAULT_RETRY; > + } > } > if (__anon_vma_prepare(vma)) > return VM_FAULT_OOM; > + if (vmf->flags & FAULT_FLAG_VMA_LOCK) > + mmap_read_unlock(vma->vm_mm); > return 0; > } > > -- > 2.43.0