diff --git a/mm/filemap.c b/mm/filemap.c index 4263d9775998..6bf0b540ef19 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3434,8 +3434,13 @@ static struct file *do_async_mmap_readahead(struct vm_fault *vmf, * Don't touch the mmap_miss counter to avoid decreasing it multiple * times for a single folio and break the balance with mmap_miss * increase in do_sync_mmap_readahead(). + * + * VM_SEQ_READ mappings skip the mmap_miss increment in + * do_sync_mmap_readahead(), so skip the decrement here as well to + * keep the counter symmetric. */ - if (likely(!folio_test_locked(folio))) { + if (likely(!folio_test_locked(folio)) && + !(vmf->vma->vm_flags & VM_SEQ_READ)) { mmap_miss = READ_ONCE(ra->mmap_miss); if (mmap_miss) WRITE_ONCE(ra->mmap_miss, --mmap_miss); @@ -3936,10 +3941,15 @@ vm_fault_t filemap_map_pages(struct vm_fault *vmf, * In such situation, read-ahead is only a waste of IO. * Don't decrease mmap_miss in this scenario to make sure * we can stop read-ahead. + * + * VM_SEQ_READ mappings skip the mmap_miss increment in + * do_sync_mmap_readahead(), so skip the decrement here as + * well to keep the counter symmetric. */ if ((map_ret & VM_FAULT_NOPAGE) && !(vmf->flags & FAULT_FLAG_TRIED) && - !folio_test_workingset(folio)) { + !folio_test_workingset(folio) && + !(vma->vm_flags & VM_SEQ_READ)) { unsigned short mmap_miss; mmap_miss = READ_ONCE(file->f_ra.mmap_miss);