@@ -39,12 +39,25 @@ static inline void __clear_shadow_entry(struct address_space *mapping,
39
39
xas_store (& xas , NULL );
40
40
}
41
41
42
- static void clear_shadow_entry (struct address_space * mapping , pgoff_t index ,
43
- void * entry )
42
+ static void clear_shadow_entries (struct address_space * mapping ,
43
+ struct folio_batch * fbatch , pgoff_t * indices )
44
44
{
45
+ int i ;
46
+
47
+ /* Handled by shmem itself, or for DAX we do nothing. */
48
+ if (shmem_mapping (mapping ) || dax_mapping (mapping ))
49
+ return ;
50
+
45
51
spin_lock (& mapping -> host -> i_lock );
46
52
xa_lock_irq (& mapping -> i_pages );
47
- __clear_shadow_entry (mapping , index , entry );
53
+
54
+ for (i = 0 ; i < folio_batch_count (fbatch ); i ++ ) {
55
+ struct folio * folio = fbatch -> folios [i ];
56
+
57
+ if (xa_is_value (folio ))
58
+ __clear_shadow_entry (mapping , indices [i ], folio );
59
+ }
60
+
48
61
xa_unlock_irq (& mapping -> i_pages );
49
62
if (mapping_shrinkable (mapping ))
50
63
inode_add_lru (mapping -> host );
@@ -105,36 +118,6 @@ static void truncate_folio_batch_exceptionals(struct address_space *mapping,
105
118
fbatch -> nr = j ;
106
119
}
107
120
108
- /*
109
- * Invalidate exceptional entry if easily possible. This handles exceptional
110
- * entries for invalidate_inode_pages().
111
- */
112
- static int invalidate_exceptional_entry (struct address_space * mapping ,
113
- pgoff_t index , void * entry )
114
- {
115
- /* Handled by shmem itself, or for DAX we do nothing. */
116
- if (shmem_mapping (mapping ) || dax_mapping (mapping ))
117
- return 1 ;
118
- clear_shadow_entry (mapping , index , entry );
119
- return 1 ;
120
- }
121
-
122
- /*
123
- * Invalidate exceptional entry if clean. This handles exceptional entries for
124
- * invalidate_inode_pages2() so for DAX it evicts only clean entries.
125
- */
126
- static int invalidate_exceptional_entry2 (struct address_space * mapping ,
127
- pgoff_t index , void * entry )
128
- {
129
- /* Handled by shmem itself */
130
- if (shmem_mapping (mapping ))
131
- return 1 ;
132
- if (dax_mapping (mapping ))
133
- return dax_invalidate_mapping_entry_sync (mapping , index );
134
- clear_shadow_entry (mapping , index , entry );
135
- return 1 ;
136
- }
137
-
138
121
/**
139
122
* folio_invalidate - Invalidate part or all of a folio.
140
123
* @folio: The folio which is affected.
@@ -494,6 +477,7 @@ unsigned long mapping_try_invalidate(struct address_space *mapping,
494
477
unsigned long ret ;
495
478
unsigned long count = 0 ;
496
479
int i ;
480
+ bool xa_has_values = false;
497
481
498
482
folio_batch_init (& fbatch );
499
483
while (find_lock_entries (mapping , & index , end , & fbatch , indices )) {
@@ -503,8 +487,8 @@ unsigned long mapping_try_invalidate(struct address_space *mapping,
503
487
/* We rely upon deletion not changing folio->index */
504
488
505
489
if (xa_is_value (folio )) {
506
- count += invalidate_exceptional_entry ( mapping ,
507
- indices [ i ], folio ) ;
490
+ xa_has_values = true;
491
+ count ++ ;
508
492
continue ;
509
493
}
510
494
@@ -522,6 +506,10 @@ unsigned long mapping_try_invalidate(struct address_space *mapping,
522
506
}
523
507
count += ret ;
524
508
}
509
+
510
+ if (xa_has_values )
511
+ clear_shadow_entries (mapping , & fbatch , indices );
512
+
525
513
folio_batch_remove_exceptionals (& fbatch );
526
514
folio_batch_release (& fbatch );
527
515
cond_resched ();
@@ -616,6 +604,7 @@ int invalidate_inode_pages2_range(struct address_space *mapping,
616
604
int ret = 0 ;
617
605
int ret2 = 0 ;
618
606
int did_range_unmap = 0 ;
607
+ bool xa_has_values = false;
619
608
620
609
if (mapping_empty (mapping ))
621
610
return 0 ;
@@ -629,8 +618,9 @@ int invalidate_inode_pages2_range(struct address_space *mapping,
629
618
/* We rely upon deletion not changing folio->index */
630
619
631
620
if (xa_is_value (folio )) {
632
- if (!invalidate_exceptional_entry2 (mapping ,
633
- indices [i ], folio ))
621
+ xa_has_values = true;
622
+ if (dax_mapping (mapping ) &&
623
+ !dax_invalidate_mapping_entry_sync (mapping , indices [i ]))
634
624
ret = - EBUSY ;
635
625
continue ;
636
626
}
@@ -666,6 +656,10 @@ int invalidate_inode_pages2_range(struct address_space *mapping,
666
656
ret = ret2 ;
667
657
folio_unlock (folio );
668
658
}
659
+
660
+ if (xa_has_values )
661
+ clear_shadow_entries (mapping , & fbatch , indices );
662
+
669
663
folio_batch_remove_exceptionals (& fbatch );
670
664
folio_batch_release (& fbatch );
671
665
cond_resched ();
0 commit comments