From: Ridong Chen scan_folios() walks a gen list from the tail under lru_lock. Isolating a folio unlinks it, which writes the lru pointers of its neighbour, and the next iteration then reads that neighbour's flags. Both miss in the cache when many CPUs reclaim from the same lruvec, and the misses are taken while other CPUs wait for the lock. isolate_lru_folios() prefetches the previous folio for the same reason, and inc_min_seq() prefetches the next one as it walks its list from the head. Do the same in scan_folios(), which walks from the tail like isolate_lru_folios(). Tested on an i7-13700HX (8P+8E cores, 24 threads), turbo off and the performance governor. 24 files of 128MiB on ext4 on brd, all threads in one memcg with memory.max=1G, random 4K pread(), so nearly every read refaults and every thread ends up in direct reclaim. Reads per second per CPU, mean of 2 runs, with and without this change in one kernel and the runs interleaved: CPUs base patched 1 426681 425912 -0.2% 2 387442 392010 +1.2% 4 360312 365538 +1.5% 8 314549 322524 +2.5% 12 235058 245057 +4.3% 16 184086 200956 +9.2% 24 124478 145011 +16.5% Signed-off-by: Ridong Chen --- mm/vmscan.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/vmscan.c b/mm/vmscan.c index 9dbdcda04f13..14f75c6fc4a8 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4814,6 +4814,8 @@ static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec, struct folio *folio = lru_to_folio(head); int delta = folio_nr_pages(folio); + prefetchw_prev_lru_folio(folio, head); + VM_WARN_ON_ONCE_FOLIO(folio_test_unevictable(folio), folio); VM_WARN_ON_ONCE_FOLIO(folio_test_active(folio), folio); VM_WARN_ON_ONCE_FOLIO(folio_is_file_lru(folio) != type, folio); -- 2.34.1