mm: drop mmap_sem before calling balance_dirty_pages() in write fault
[linux-2.6-microblaze.git] / mm / internal.h
index 0d5f720..7dd7fbb 100644 (file)
@@ -362,6 +362,27 @@ vma_address(struct page *page, struct vm_area_struct *vma)
        return max(start, vma->vm_start);
 }
 
+static inline struct file *maybe_unlock_mmap_for_io(struct vm_fault *vmf,
+                                                   struct file *fpin)
+{
+       int flags = vmf->flags;
+
+       if (fpin)
+               return fpin;
+
+       /*
+        * FAULT_FLAG_RETRY_NOWAIT means we don't want to wait on page locks or
+        * anything, so we only pin the file and drop the mmap_sem if only
+        * FAULT_FLAG_ALLOW_RETRY is set.
+        */
+       if ((flags & (FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_RETRY_NOWAIT)) ==
+           FAULT_FLAG_ALLOW_RETRY) {
+               fpin = get_file(vmf->vma->vm_file);
+               up_read(&vmf->vma->vm_mm->mmap_sem);
+       }
+       return fpin;
+}
+
 #else /* !CONFIG_MMU */
 static inline void clear_page_mlock(struct page *page) { }
 static inline void mlock_vma_page(struct page *page) { }