summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUsama Arif <usama.arif@linux.dev>2026-05-25 07:57:51 -0700
committerAndrew Morton <akpm@linux-foundation.org>2026-06-04 14:45:06 -0700
commiteb4c458a9803c3c75ee27d567a3a2ff0cc66da98 (patch)
tree8614c05a0b1433adc5f8f31dbf973c373ae95fb0
parent6d536ed691485fa5aa6417252d357c65eb474b75 (diff)
downloadlinux-eb4c458a9803c3c75ee27d567a3a2ff0cc66da98.tar.gz
linux-eb4c458a9803c3c75ee27d567a3a2ff0cc66da98.zip
mm: make mmap_miss accounting symmetric for VM_SEQ_READ
do_sync_mmap_readahead() skips both the mmap_miss increment and the MMAP_LOTSAMISS check for VM_SEQ_READ mappings, since sequential access is non-speculative and should always read ahead. The two decrement sites in do_async_mmap_readahead() and filemap_map_pages() do not mirror this skip, so concurrent faults on a VM_SEQ_READ mapping can still drive ra->mmap_miss down to zero through the decrement paths even though nothing in the sync path ever increments it. The counter itself is per-file (file->f_ra.mmap_miss), so it can be moved by any VMA mapping the file, not just the one currently faulting. Skip the decrement for VM_SEQ_READ in both decrement sites so the counter only moves for mappings that also participate in the increment side. No functional change for VM_SEQ_READ users, since the increment-side gate already prevents the counter from being consulted on their behalf, but it stops a VM_SEQ_READ mapping from biasing the counter for other mappings of the same file. Link: https://lore.kernel.org/20260525145751.2671248-1-usama.arif@linux.dev Signed-off-by: Usama Arif <usama.arif@linux.dev> Closes: https://lore.kernel.org/all/8edc8cd0-f65c-4456-9b3f-362e744c9a96@linux.dev/ Reviewed-by: William Kucharski <william.kucharski@linux.dev> Reviewed-by: Jan Kara <jack@suse.cz> Cc: David Hildenbrand <david@kernel.org> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: Shakeel Butt <shakeel.butt@linux.dev> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
-rw-r--r--mm/filemap.c14
1 files changed, 12 insertions, 2 deletions
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);