diff --git a/mm/memory.c b/mm/memory.c index 20869d0cd5a102f2141b38847b909b0866467a2d..f580b9c542471cacfc76dfb17e1d76692022c989 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3397,6 +3397,8 @@ void unmap_mapping_range(struct address_space *mapping, } EXPORT_SYMBOL(unmap_mapping_range); +static DECLARE_WAIT_QUEUE_HEAD(swapcache_wq); + /* * We enter with non-exclusive mmap_lock (to exclude vma changes, * but allow concurrent faults), and pte mapped but not yet locked. @@ -3408,6 +3410,7 @@ EXPORT_SYMBOL(unmap_mapping_range); vm_fault_t do_swap_page(struct vm_fault *vmf) { struct vm_area_struct *vma = vmf->vma; + DECLARE_WAITQUEUE(wait, current); struct page *page = NULL, *swapcache; struct swap_info_struct *si = NULL; bool need_clear_cache = false; @@ -3475,7 +3478,9 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) */ if (swapcache_prepare(entry)) { /* Relax a bit to prevent rapid repeated page faults */ + add_wait_queue(&swapcache_wq, &wait); schedule_timeout_uninterruptible(1); + remove_wait_queue(&swapcache_wq, &wait); goto out; } need_clear_cache = true; @@ -3650,8 +3655,11 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) pte_unmap_unlock(vmf->pte, vmf->ptl); out: /* Clear the swap cache pin for direct swapin after PTL unlock */ - if (need_clear_cache) + if (need_clear_cache) { swapcache_clear(si, entry); + if (waitqueue_active(&swapcache_wq)) + wake_up(&swapcache_wq); + } if (si) put_swap_device(si); return ret; @@ -3665,8 +3673,11 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) unlock_page(swapcache); put_page(swapcache); } - if (need_clear_cache) + if (need_clear_cache) { swapcache_clear(si, entry); + if (waitqueue_active(&swapcache_wq)) + wake_up(&swapcache_wq); + } if (si) put_swap_device(si); return ret;