On Tue, Feb 07, 2023 at 11:27:17PM +0000, Matthew Wilcox wrote: > I've been thinking about this one, and I wonder if we can do it > without taking any pgtable locks. The locking environment we're in > is the page fault handler, so we have the mmap_lock for read (for now > anyway ...). We also hold the folio lock, so _if_ the folio is mapped, > those entries can't disappear under us. Could MADV_DONTNEED do that from another pgtable that we don't hold the pgtable lock? > They also can't appear under us. This seems right. > We hold the PTL on one PMD, but not necessarily on any other PMD we > examine. > > I appreciate that PTEs can _change_ under us if we do not hold the PTL, > but by virtue of holding the folio lock, they can't change from or to > our PFNs. I also think the PMD table cannot disappear under us > since we're holding the mmap_lock for read, and anyone removing page > tables has to take the mmap_lock for write. Seems right to me too. -- Peter Xu