@@ -986,13 +986,13 @@ int copy_page_range(struct mm_struct *dst_mm, struct mm_struct *src_mm,
986986static unsigned long zap_pte_range (struct mmu_gather * tlb ,
987987 struct vm_area_struct * vma , pmd_t * pmd ,
988988 unsigned long addr , unsigned long end ,
989- long * zap_work , struct zap_details * details )
989+ struct zap_details * details )
990990{
991991 struct mm_struct * mm = tlb -> mm ;
992992 int force_flush = 0 ;
993- pte_t * pte ;
994- spinlock_t * ptl ;
995993 int rss [NR_MM_COUNTERS ];
994+ spinlock_t * ptl ;
995+ pte_t * pte ;
996996
997997again :
998998 init_rss_vec (rss );
@@ -1001,12 +1001,9 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb,
10011001 do {
10021002 pte_t ptent = * pte ;
10031003 if (pte_none (ptent )) {
1004- (* zap_work )-- ;
10051004 continue ;
10061005 }
10071006
1008- (* zap_work ) -= PAGE_SIZE ;
1009-
10101007 if (pte_present (ptent )) {
10111008 struct page * page ;
10121009
@@ -1075,7 +1072,7 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb,
10751072 print_bad_pte (vma , addr , ptent , NULL );
10761073 }
10771074 pte_clear_not_present_full (mm , addr , pte , tlb -> fullmm );
1078- } while (pte ++ , addr += PAGE_SIZE , ( addr != end && * zap_work > 0 ) );
1075+ } while (pte ++ , addr += PAGE_SIZE , addr != end );
10791076
10801077 add_mm_rss_vec (mm , rss );
10811078 arch_leave_lazy_mmu_mode ();
@@ -1099,7 +1096,7 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb,
10991096static inline unsigned long zap_pmd_range (struct mmu_gather * tlb ,
11001097 struct vm_area_struct * vma , pud_t * pud ,
11011098 unsigned long addr , unsigned long end ,
1102- long * zap_work , struct zap_details * details )
1099+ struct zap_details * details )
11031100{
11041101 pmd_t * pmd ;
11051102 unsigned long next ;
@@ -1111,49 +1108,42 @@ static inline unsigned long zap_pmd_range(struct mmu_gather *tlb,
11111108 if (next - addr != HPAGE_PMD_SIZE ) {
11121109 VM_BUG_ON (!rwsem_is_locked (& tlb -> mm -> mmap_sem ));
11131110 split_huge_page_pmd (vma -> vm_mm , pmd );
1114- } else if (zap_huge_pmd (tlb , vma , pmd )) {
1115- (* zap_work )-- ;
1111+ } else if (zap_huge_pmd (tlb , vma , pmd ))
11161112 continue ;
1117- }
11181113 /* fall through */
11191114 }
1120- if (pmd_none_or_clear_bad (pmd )) {
1121- (* zap_work )-- ;
1115+ if (pmd_none_or_clear_bad (pmd ))
11221116 continue ;
1123- }
1124- next = zap_pte_range (tlb , vma , pmd , addr , next ,
1125- zap_work , details );
1126- } while (pmd ++ , addr = next , (addr != end && * zap_work > 0 ));
1117+ next = zap_pte_range (tlb , vma , pmd , addr , next , details );
1118+ cond_resched ();
1119+ } while (pmd ++ , addr = next , addr != end );
11271120
11281121 return addr ;
11291122}
11301123
11311124static inline unsigned long zap_pud_range (struct mmu_gather * tlb ,
11321125 struct vm_area_struct * vma , pgd_t * pgd ,
11331126 unsigned long addr , unsigned long end ,
1134- long * zap_work , struct zap_details * details )
1127+ struct zap_details * details )
11351128{
11361129 pud_t * pud ;
11371130 unsigned long next ;
11381131
11391132 pud = pud_offset (pgd , addr );
11401133 do {
11411134 next = pud_addr_end (addr , end );
1142- if (pud_none_or_clear_bad (pud )) {
1143- (* zap_work )-- ;
1135+ if (pud_none_or_clear_bad (pud ))
11441136 continue ;
1145- }
1146- next = zap_pmd_range (tlb , vma , pud , addr , next ,
1147- zap_work , details );
1148- } while (pud ++ , addr = next , (addr != end && * zap_work > 0 ));
1137+ next = zap_pmd_range (tlb , vma , pud , addr , next , details );
1138+ } while (pud ++ , addr = next , addr != end );
11491139
11501140 return addr ;
11511141}
11521142
11531143static unsigned long unmap_page_range (struct mmu_gather * tlb ,
11541144 struct vm_area_struct * vma ,
11551145 unsigned long addr , unsigned long end ,
1156- long * zap_work , struct zap_details * details )
1146+ struct zap_details * details )
11571147{
11581148 pgd_t * pgd ;
11591149 unsigned long next ;
@@ -1167,13 +1157,10 @@ static unsigned long unmap_page_range(struct mmu_gather *tlb,
11671157 pgd = pgd_offset (vma -> vm_mm , addr );
11681158 do {
11691159 next = pgd_addr_end (addr , end );
1170- if (pgd_none_or_clear_bad (pgd )) {
1171- (* zap_work )-- ;
1160+ if (pgd_none_or_clear_bad (pgd ))
11721161 continue ;
1173- }
1174- next = zap_pud_range (tlb , vma , pgd , addr , next ,
1175- zap_work , details );
1176- } while (pgd ++ , addr = next , (addr != end && * zap_work > 0 ));
1162+ next = zap_pud_range (tlb , vma , pgd , addr , next , details );
1163+ } while (pgd ++ , addr = next , addr != end );
11771164 tlb_end_vma (tlb , vma );
11781165 mem_cgroup_uncharge_end ();
11791166
@@ -1218,9 +1205,7 @@ unsigned long unmap_vmas(struct mmu_gather *tlb,
12181205 unsigned long end_addr , unsigned long * nr_accounted ,
12191206 struct zap_details * details )
12201207{
1221- long zap_work = ZAP_BLOCK_SIZE ;
12221208 unsigned long start = start_addr ;
1223- spinlock_t * i_mmap_lock = details ? details -> i_mmap_lock : NULL ;
12241209 struct mm_struct * mm = vma -> vm_mm ;
12251210
12261211 mmu_notifier_invalidate_range_start (mm , start_addr , end_addr );
@@ -1253,33 +1238,15 @@ unsigned long unmap_vmas(struct mmu_gather *tlb,
12531238 * Since no pte has actually been setup, it is
12541239 * safe to do nothing in this case.
12551240 */
1256- if (vma -> vm_file ) {
1241+ if (vma -> vm_file )
12571242 unmap_hugepage_range (vma , start , end , NULL );
1258- zap_work -= (end - start ) /
1259- pages_per_huge_page (hstate_vma (vma ));
1260- }
12611243
12621244 start = end ;
12631245 } else
1264- start = unmap_page_range (tlb , vma ,
1265- start , end , & zap_work , details );
1266-
1267- if (zap_work > 0 ) {
1268- BUG_ON (start != end );
1269- break ;
1270- }
1271-
1272- if (need_resched () ||
1273- (i_mmap_lock && spin_needbreak (i_mmap_lock ))) {
1274- if (i_mmap_lock )
1275- goto out ;
1276- cond_resched ();
1277- }
1278-
1279- zap_work = ZAP_BLOCK_SIZE ;
1246+ start = unmap_page_range (tlb , vma , start , end , details );
12801247 }
12811248 }
1282- out :
1249+
12831250 mmu_notifier_invalidate_range_end (mm , start_addr , end_addr );
12841251 return start ; /* which is now the end (or restart) address */
12851252}
@@ -2612,96 +2579,11 @@ static int do_wp_page(struct mm_struct *mm, struct vm_area_struct *vma,
26122579 return ret ;
26132580}
26142581
2615- /*
2616- * Helper functions for unmap_mapping_range().
2617- *
2618- * __ Notes on dropping i_mmap_lock to reduce latency while unmapping __
2619- *
2620- * We have to restart searching the prio_tree whenever we drop the lock,
2621- * since the iterator is only valid while the lock is held, and anyway
2622- * a later vma might be split and reinserted earlier while lock dropped.
2623- *
2624- * The list of nonlinear vmas could be handled more efficiently, using
2625- * a placeholder, but handle it in the same way until a need is shown.
2626- * It is important to search the prio_tree before nonlinear list: a vma
2627- * may become nonlinear and be shifted from prio_tree to nonlinear list
2628- * while the lock is dropped; but never shifted from list to prio_tree.
2629- *
2630- * In order to make forward progress despite restarting the search,
2631- * vm_truncate_count is used to mark a vma as now dealt with, so we can
2632- * quickly skip it next time around. Since the prio_tree search only
2633- * shows us those vmas affected by unmapping the range in question, we
2634- * can't efficiently keep all vmas in step with mapping->truncate_count:
2635- * so instead reset them all whenever it wraps back to 0 (then go to 1).
2636- * mapping->truncate_count and vma->vm_truncate_count are protected by
2637- * i_mmap_lock.
2638- *
2639- * In order to make forward progress despite repeatedly restarting some
2640- * large vma, note the restart_addr from unmap_vmas when it breaks out:
2641- * and restart from that address when we reach that vma again. It might
2642- * have been split or merged, shrunk or extended, but never shifted: so
2643- * restart_addr remains valid so long as it remains in the vma's range.
2644- * unmap_mapping_range forces truncate_count to leap over page-aligned
2645- * values so we can save vma's restart_addr in its truncate_count field.
2646- */
2647- #define is_restart_addr (truncate_count ) (!((truncate_count) & ~PAGE_MASK))
2648-
2649- static void reset_vma_truncate_counts (struct address_space * mapping )
2650- {
2651- struct vm_area_struct * vma ;
2652- struct prio_tree_iter iter ;
2653-
2654- vma_prio_tree_foreach (vma , & iter , & mapping -> i_mmap , 0 , ULONG_MAX )
2655- vma -> vm_truncate_count = 0 ;
2656- list_for_each_entry (vma , & mapping -> i_mmap_nonlinear , shared .vm_set .list )
2657- vma -> vm_truncate_count = 0 ;
2658- }
2659-
2660- static int unmap_mapping_range_vma (struct vm_area_struct * vma ,
2582+ static void unmap_mapping_range_vma (struct vm_area_struct * vma ,
26612583 unsigned long start_addr , unsigned long end_addr ,
26622584 struct zap_details * details )
26632585{
2664- unsigned long restart_addr ;
2665- int need_break ;
2666-
2667- /*
2668- * files that support invalidating or truncating portions of the
2669- * file from under mmaped areas must have their ->fault function
2670- * return a locked page (and set VM_FAULT_LOCKED in the return).
2671- * This provides synchronisation against concurrent unmapping here.
2672- */
2673-
2674- again :
2675- restart_addr = vma -> vm_truncate_count ;
2676- if (is_restart_addr (restart_addr ) && start_addr < restart_addr ) {
2677- start_addr = restart_addr ;
2678- if (start_addr >= end_addr ) {
2679- /* Top of vma has been split off since last time */
2680- vma -> vm_truncate_count = details -> truncate_count ;
2681- return 0 ;
2682- }
2683- }
2684-
2685- restart_addr = zap_page_range (vma , start_addr ,
2686- end_addr - start_addr , details );
2687- need_break = need_resched () || spin_needbreak (details -> i_mmap_lock );
2688-
2689- if (restart_addr >= end_addr ) {
2690- /* We have now completed this vma: mark it so */
2691- vma -> vm_truncate_count = details -> truncate_count ;
2692- if (!need_break )
2693- return 0 ;
2694- } else {
2695- /* Note restart_addr in vma's truncate_count field */
2696- vma -> vm_truncate_count = restart_addr ;
2697- if (!need_break )
2698- goto again ;
2699- }
2700-
2701- spin_unlock (details -> i_mmap_lock );
2702- cond_resched ();
2703- spin_lock (details -> i_mmap_lock );
2704- return - EINTR ;
2586+ zap_page_range (vma , start_addr , end_addr - start_addr , details );
27052587}
27062588
27072589static inline void unmap_mapping_range_tree (struct prio_tree_root * root ,
@@ -2711,12 +2593,8 @@ static inline void unmap_mapping_range_tree(struct prio_tree_root *root,
27112593 struct prio_tree_iter iter ;
27122594 pgoff_t vba , vea , zba , zea ;
27132595
2714- restart :
27152596 vma_prio_tree_foreach (vma , & iter , root ,
27162597 details -> first_index , details -> last_index ) {
2717- /* Skip quickly over those we have already dealt with */
2718- if (vma -> vm_truncate_count == details -> truncate_count )
2719- continue ;
27202598
27212599 vba = vma -> vm_pgoff ;
27222600 vea = vba + ((vma -> vm_end - vma -> vm_start ) >> PAGE_SHIFT ) - 1 ;
@@ -2728,11 +2606,10 @@ static inline void unmap_mapping_range_tree(struct prio_tree_root *root,
27282606 if (zea > vea )
27292607 zea = vea ;
27302608
2731- if ( unmap_mapping_range_vma (vma ,
2609+ unmap_mapping_range_vma (vma ,
27322610 ((zba - vba ) << PAGE_SHIFT ) + vma -> vm_start ,
27332611 ((zea - vba + 1 ) << PAGE_SHIFT ) + vma -> vm_start ,
2734- details ) < 0 )
2735- goto restart ;
2612+ details );
27362613 }
27372614}
27382615
@@ -2747,15 +2624,9 @@ static inline void unmap_mapping_range_list(struct list_head *head,
27472624 * across *all* the pages in each nonlinear VMA, not just the pages
27482625 * whose virtual address lies outside the file truncation point.
27492626 */
2750- restart :
27512627 list_for_each_entry (vma , head , shared .vm_set .list ) {
2752- /* Skip quickly over those we have already dealt with */
2753- if (vma -> vm_truncate_count == details -> truncate_count )
2754- continue ;
27552628 details -> nonlinear_vma = vma ;
2756- if (unmap_mapping_range_vma (vma , vma -> vm_start ,
2757- vma -> vm_end , details ) < 0 )
2758- goto restart ;
2629+ unmap_mapping_range_vma (vma , vma -> vm_start , vma -> vm_end , details );
27592630 }
27602631}
27612632
@@ -2794,26 +2665,14 @@ void unmap_mapping_range(struct address_space *mapping,
27942665 details .last_index = hba + hlen - 1 ;
27952666 if (details .last_index < details .first_index )
27962667 details .last_index = ULONG_MAX ;
2797- details .i_mmap_lock = & mapping -> i_mmap_lock ;
27982668
2799- mutex_lock (& mapping -> unmap_mutex );
2800- spin_lock (& mapping -> i_mmap_lock );
2801-
2802- /* Protect against endless unmapping loops */
2803- mapping -> truncate_count ++ ;
2804- if (unlikely (is_restart_addr (mapping -> truncate_count ))) {
2805- if (mapping -> truncate_count == 0 )
2806- reset_vma_truncate_counts (mapping );
2807- mapping -> truncate_count ++ ;
2808- }
2809- details .truncate_count = mapping -> truncate_count ;
28102669
2670+ spin_lock (& mapping -> i_mmap_lock );
28112671 if (unlikely (!prio_tree_empty (& mapping -> i_mmap )))
28122672 unmap_mapping_range_tree (& mapping -> i_mmap , & details );
28132673 if (unlikely (!list_empty (& mapping -> i_mmap_nonlinear )))
28142674 unmap_mapping_range_list (& mapping -> i_mmap_nonlinear , & details );
28152675 spin_unlock (& mapping -> i_mmap_lock );
2816- mutex_unlock (& mapping -> unmap_mutex );
28172676}
28182677EXPORT_SYMBOL (unmap_mapping_range );
28192678
0 commit comments