Commit 063e60d8 authored by Matthew Wilcox (Oracle)'s avatar Matthew Wilcox (Oracle) Committed by Andrew Morton

mm: handle faults that merely update the accessed bit under the VMA lock

Move FAULT_FLAG_VMA_LOCK check out of handle_pte_fault().  This should
have a significant performance improvement for mmaped files.  Write faults
(on read-only shared pages) still take the mmap lock as we do not want to
audit all the implementations of ->pfn_mkwrite() and ->page_mkwrite(). 
However write-faults on private mappings are handled under the VMA lock.

[willy@infradead.org: address "suspicious RCU usage" warning]
  Link: https://lkml.kernel.org/r/ZMK7jwpI4uD6tKrF@casper.infradead.org
Link: https://lkml.kernel.org/r/20230724185410.1124082-11-willy@infradead.orgSigned-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Cc: Arjun Roy <arjunroy@google.com>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Punit Agrawal <punit.agrawal@bytedance.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 4c2f803a
...@@ -3268,6 +3268,11 @@ static vm_fault_t wp_pfn_shared(struct vm_fault *vmf) ...@@ -3268,6 +3268,11 @@ static vm_fault_t wp_pfn_shared(struct vm_fault *vmf)
vm_fault_t ret; vm_fault_t ret;
pte_unmap_unlock(vmf->pte, vmf->ptl); pte_unmap_unlock(vmf->pte, vmf->ptl);
if (vmf->flags & FAULT_FLAG_VMA_LOCK) {
vma_end_read(vmf->vma);
return VM_FAULT_RETRY;
}
vmf->flags |= FAULT_FLAG_MKWRITE; vmf->flags |= FAULT_FLAG_MKWRITE;
ret = vma->vm_ops->pfn_mkwrite(vmf); ret = vma->vm_ops->pfn_mkwrite(vmf);
if (ret & (VM_FAULT_ERROR | VM_FAULT_NOPAGE)) if (ret & (VM_FAULT_ERROR | VM_FAULT_NOPAGE))
...@@ -3290,6 +3295,12 @@ static vm_fault_t wp_page_shared(struct vm_fault *vmf, struct folio *folio) ...@@ -3290,6 +3295,12 @@ static vm_fault_t wp_page_shared(struct vm_fault *vmf, struct folio *folio)
vm_fault_t tmp; vm_fault_t tmp;
pte_unmap_unlock(vmf->pte, vmf->ptl); pte_unmap_unlock(vmf->pte, vmf->ptl);
if (vmf->flags & FAULT_FLAG_VMA_LOCK) {
folio_put(folio);
vma_end_read(vmf->vma);
return VM_FAULT_RETRY;
}
tmp = do_page_mkwrite(vmf, folio); tmp = do_page_mkwrite(vmf, folio);
if (unlikely(!tmp || (tmp & if (unlikely(!tmp || (tmp &
(VM_FAULT_ERROR | VM_FAULT_NOPAGE)))) { (VM_FAULT_ERROR | VM_FAULT_NOPAGE)))) {
...@@ -3431,6 +3442,12 @@ static vm_fault_t do_wp_page(struct vm_fault *vmf) ...@@ -3431,6 +3442,12 @@ static vm_fault_t do_wp_page(struct vm_fault *vmf)
return 0; return 0;
} }
copy: copy:
if ((vmf->flags & FAULT_FLAG_VMA_LOCK) && !vma->anon_vma) {
pte_unmap_unlock(vmf->pte, vmf->ptl);
vma_end_read(vmf->vma);
return VM_FAULT_RETRY;
}
/* /*
* Ok, we need to copy. Oh, well.. * Ok, we need to copy. Oh, well..
*/ */
...@@ -4985,12 +5002,6 @@ static vm_fault_t handle_pte_fault(struct vm_fault *vmf) ...@@ -4985,12 +5002,6 @@ static vm_fault_t handle_pte_fault(struct vm_fault *vmf)
if (pte_protnone(vmf->orig_pte) && vma_is_accessible(vmf->vma)) if (pte_protnone(vmf->orig_pte) && vma_is_accessible(vmf->vma))
return do_numa_page(vmf); return do_numa_page(vmf);
if ((vmf->flags & FAULT_FLAG_VMA_LOCK) && !vma_is_anonymous(vmf->vma)) {
pte_unmap(vmf->pte);
vma_end_read(vmf->vma);
return VM_FAULT_RETRY;
}
spin_lock(vmf->ptl); spin_lock(vmf->ptl);
entry = vmf->orig_pte; entry = vmf->orig_pte;
if (unlikely(!pte_same(ptep_get(vmf->pte), entry))) { if (unlikely(!pte_same(ptep_get(vmf->pte), entry))) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment