aboutsummaryrefslogtreecommitdiffstats
path: root/mm/swapfile.c
diff options
context:
space:
mode:
Diffstat (limited to 'mm/swapfile.c')
-rw-r--r--mm/swapfile.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 296e0bbf7836..510f0039b000 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -401,8 +401,6 @@ void free_swap_and_cache(swp_entry_t entry)
401 * No need to decide whether this PTE shares the swap entry with others, 401 * No need to decide whether this PTE shares the swap entry with others,
402 * just let do_wp_page work it out if a write is requested later - to 402 * just let do_wp_page work it out if a write is requested later - to
403 * force COW, vm_page_prot omits write permission from any private vma. 403 * force COW, vm_page_prot omits write permission from any private vma.
404 *
405 * vma->vm_mm->page_table_lock is held.
406 */ 404 */
407static void unuse_pte(struct vm_area_struct *vma, pte_t *pte, 405static void unuse_pte(struct vm_area_struct *vma, pte_t *pte,
408 unsigned long addr, swp_entry_t entry, struct page *page) 406 unsigned long addr, swp_entry_t entry, struct page *page)
@@ -424,23 +422,25 @@ static int unuse_pte_range(struct vm_area_struct *vma, pmd_t *pmd,
424 unsigned long addr, unsigned long end, 422 unsigned long addr, unsigned long end,
425 swp_entry_t entry, struct page *page) 423 swp_entry_t entry, struct page *page)
426{ 424{
427 pte_t *pte;
428 pte_t swp_pte = swp_entry_to_pte(entry); 425 pte_t swp_pte = swp_entry_to_pte(entry);
426 pte_t *pte;
427 spinlock_t *ptl;
428 int found = 0;
429 429
430 pte = pte_offset_map(pmd, addr); 430 pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl);
431 do { 431 do {
432 /* 432 /*
433 * swapoff spends a _lot_ of time in this loop! 433 * swapoff spends a _lot_ of time in this loop!
434 * Test inline before going to call unuse_pte. 434 * Test inline before going to call unuse_pte.
435 */ 435 */
436 if (unlikely(pte_same(*pte, swp_pte))) { 436 if (unlikely(pte_same(*pte, swp_pte))) {
437 unuse_pte(vma, pte, addr, entry, page); 437 unuse_pte(vma, pte++, addr, entry, page);
438 pte_unmap(pte); 438 found = 1;
439 return 1; 439 break;
440 } 440 }
441 } while (pte++, addr += PAGE_SIZE, addr != end); 441 } while (pte++, addr += PAGE_SIZE, addr != end);
442 pte_unmap(pte - 1); 442 pte_unmap_unlock(pte - 1, ptl);
443 return 0; 443 return found;
444} 444}
445 445
446static inline int unuse_pmd_range(struct vm_area_struct *vma, pud_t *pud, 446static inline int unuse_pmd_range(struct vm_area_struct *vma, pud_t *pud,
@@ -522,12 +522,10 @@ static int unuse_mm(struct mm_struct *mm,
522 down_read(&mm->mmap_sem); 522 down_read(&mm->mmap_sem);
523 lock_page(page); 523 lock_page(page);
524 } 524 }
525 spin_lock(&mm->page_table_lock);
526 for (vma = mm->mmap; vma; vma = vma->vm_next) { 525 for (vma = mm->mmap; vma; vma = vma->vm_next) {
527 if (vma->anon_vma && unuse_vma(vma, entry, page)) 526 if (vma->anon_vma && unuse_vma(vma, entry, page))
528 break; 527 break;
529 } 528 }
530 spin_unlock(&mm->page_table_lock);
531 up_read(&mm->mmap_sem); 529 up_read(&mm->mmap_sem);
532 /* 530 /*
533 * Currently unuse_mm cannot fail, but leave error handling 531 * Currently unuse_mm cannot fail, but leave error handling