[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAGsJ_4x1RbQ+GKKc1rrTaNA8Xd+W8K-Zu6-kwVYNKzB0OWiowQ@mail.gmail.com>
Date: Sat, 7 Jun 2025 16:53:02 +1200
From: Barry Song <21cnbao@...il.com>
To: Matthew Wilcox <willy@...radead.org>
Cc: akpm@...ux-foundation.org, linux-mm@...ck.org,
linux-kernel@...r.kernel.org, Barry Song <v-songbaohua@...o.com>,
"Liam R. Howlett" <Liam.Howlett@...cle.com>, Lorenzo Stoakes <lorenzo.stoakes@...cle.com>,
David Hildenbrand <david@...hat.com>, Vlastimil Babka <vbabka@...e.cz>, Jann Horn <jannh@...gle.com>,
Suren Baghdasaryan <surenb@...gle.com>, Lokesh Gidra <lokeshgidra@...gle.com>,
Tangquan Zheng <zhengtangquan@...o.com>, Qi Zheng <zhengqi.arch@...edance.com>
Subject: Re: [PATCH v3] mm: use per_vma lock for MADV_DONTNEED
On Sat, Jun 7, 2025 at 4:05 PM Matthew Wilcox <willy@...radead.org> wrote:
>
> On Sat, Jun 07, 2025 at 12:46:23PM +1200, Barry Song wrote:
> > To simplify handling, the implementation falls back to the standard
> > mmap_lock if userfaultfd is enabled on the VMA, avoiding the complexity of
> > userfaultfd_remove().
>
> This feels too complex to me. Why do we defer grabbing the vma lock
> so late, instead of grabbing it at the start like the fault handler does?
Hi Matthew,
It looks like you missed the spot where your comment should have gone:
https://lore.kernel.org/all/0b96ce61-a52c-4036-b5b6-5c50783db51f@lucifer.local/
So I believe Lorenzo is the best person to respond to your concern.
In both v1 and v2 [1][2], we did try to fall back as early as possible:
[1] https://lore.kernel.org/linux-mm/20250527044145.13153-1-21cnbao@gmail.com/
[2] https://lore.kernel.org/all/20250530104439.64841-1-21cnbao@gmail.com/
But that approach had its own problems:
* It's not extensible to other madvise operations.
* It's not easy to adapt to vector_madvise.
I also initially found the new approach too complex and tried a few
alternatives, but each had its own problems. In the end, Lorenzo's
solution still seems to be the cleanest among them.
I even forgot to move the code below back to visit() from
madvise_vma_behavior(). I had changed it while exploring an
alternative and should have reverted it.
+ if (madv_behavior && madv_behavior->lock_mode ==
MADVISE_VMA_READ_LOCK) {
+ vma = try_vma_read_lock(mm, madv_behavior, start, end);
+ if (vma) {
+ error = madvise_vma_behavior(vma, &prev, start, end,
+ madv_behavior); /* better to be visit() */
+ vma_end_read(vma);
+ return error;
+ }
+ }
Thanks
Barry
Powered by blists - more mailing lists