@@ -821,15 +821,25 @@ static bool folio_referenced_one(struct folio *folio,
821821 }
822822
823823 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 ))) {
826826 lru_gen_look_around (& pvmw );
827827 referenced ++ ;
828828 }
829829
830830 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+ }
833843 } else if (IS_ENABLED (CONFIG_TRANSPARENT_HUGEPAGE )) {
834844 if (pmdp_clear_flush_young_notify (vma , address ,
835845 pvmw .pmd ))
@@ -863,20 +873,7 @@ static bool invalid_folio_referenced_vma(struct vm_area_struct *vma, void *arg)
863873 struct folio_referenced_arg * pra = arg ;
864874 struct mem_cgroup * memcg = pra -> memcg ;
865875
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 ))
880877 return true;
881878
882879 return false;
@@ -907,7 +904,6 @@ int folio_referenced(struct folio *folio, int is_locked,
907904 .arg = (void * )& pra ,
908905 .anon_lock = folio_lock_anon_vma_read ,
909906 .try_lock = true,
910- .invalid_vma = invalid_folio_referenced_vma ,
911907 };
912908
913909 * vm_flags = 0 ;
@@ -923,6 +919,15 @@ int folio_referenced(struct folio *folio, int is_locked,
923919 return 1 ;
924920 }
925921
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+
926931 rmap_walk (folio , & rwc );
927932 * vm_flags = pra .vm_flags ;
928933
0 commit comments