@@ -821,15 +821,25 @@ static bool folio_referenced_one(struct folio *folio,
821
821
}
822
822
823
823
if (pvmw .pte ) {
824
- if (lru_gen_enabled () &&
825
- pte_young ( ptep_get ( pvmw . pte ))) {
824
+ if (lru_gen_enabled () && pte_young ( ptep_get ( pvmw . pte )) &&
825
+ !( vma -> vm_flags & ( VM_SEQ_READ | VM_RAND_READ ))) {
826
826
lru_gen_look_around (& pvmw );
827
827
referenced ++ ;
828
828
}
829
829
830
830
if (ptep_clear_flush_young_notify (vma , address ,
831
- pvmw .pte ))
832
- referenced ++ ;
831
+ pvmw .pte )) {
832
+ /*
833
+ * Don't treat a reference through
834
+ * a sequentially read mapping as such.
835
+ * If the folio has been used in another mapping,
836
+ * we will catch it; if this other mapping is
837
+ * already gone, the unmap path will have set
838
+ * the referenced flag or activated the folio.
839
+ */
840
+ if (likely (!(vma -> vm_flags & VM_SEQ_READ )))
841
+ referenced ++ ;
842
+ }
833
843
} else if (IS_ENABLED (CONFIG_TRANSPARENT_HUGEPAGE )) {
834
844
if (pmdp_clear_flush_young_notify (vma , address ,
835
845
pvmw .pmd ))
@@ -863,20 +873,7 @@ static bool invalid_folio_referenced_vma(struct vm_area_struct *vma, void *arg)
863
873
struct folio_referenced_arg * pra = arg ;
864
874
struct mem_cgroup * memcg = pra -> memcg ;
865
875
866
- /*
867
- * Ignore references from this mapping if it has no recency. If the
868
- * folio has been used in another mapping, we will catch it; if this
869
- * other mapping is already gone, the unmap path will have set the
870
- * referenced flag or activated the folio in zap_pte_range().
871
- */
872
- if (!vma_has_recency (vma ))
873
- return true;
874
-
875
- /*
876
- * If we are reclaiming on behalf of a cgroup, skip counting on behalf
877
- * of references from different cgroups.
878
- */
879
- if (memcg && !mm_match_cgroup (vma -> vm_mm , memcg ))
876
+ if (!mm_match_cgroup (vma -> vm_mm , memcg ))
880
877
return true;
881
878
882
879
return false;
@@ -907,7 +904,6 @@ int folio_referenced(struct folio *folio, int is_locked,
907
904
.arg = (void * )& pra ,
908
905
.anon_lock = folio_lock_anon_vma_read ,
909
906
.try_lock = true,
910
- .invalid_vma = invalid_folio_referenced_vma ,
911
907
};
912
908
913
909
* vm_flags = 0 ;
@@ -923,6 +919,15 @@ int folio_referenced(struct folio *folio, int is_locked,
923
919
return 1 ;
924
920
}
925
921
922
+ /*
923
+ * If we are reclaiming on behalf of a cgroup, skip
924
+ * counting on behalf of references from different
925
+ * cgroups
926
+ */
927
+ if (memcg ) {
928
+ rwc .invalid_vma = invalid_folio_referenced_vma ;
929
+ }
930
+
926
931
rmap_walk (folio , & rwc );
927
932
* vm_flags = pra .vm_flags ;
928
933
0 commit comments