From: Qiliang Yuan <qiliang.yuan@linux.dev>
To: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
Jan Kara <jack@suse.cz>,
Andrew Morton <akpm@linux-foundation.org>,
Vishal Moola <vishal.moola@gmail.com>,
fujunjie <fujunjie1@qq.com>
Cc: Roman Gushchin <roman.gushchin@linux.dev>,
Usama Arif <usama.arif@linux.dev>,
linux-fsdevel@vger.kernel.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org,
Qiliang Yuan <qiliang.yuan@linux.dev>
Subject: [PATCH v2 3/3] mm/filemap: extend VM_SEQ_READ readahead below descending faults
Date: Mon, 09 Nov 2026 05:34:13 -0500 [thread overview]
Message-ID: <20261109-bug-mm-mmap-readahead-descending-v2-3-abac52890a9c@linux.dev> (raw)
In-Reply-To: <20261109-bug-mm-mmap-readahead-descending-v2-0-abac52890a9c@linux.dev>
On a VM_SEQ_READ mapping, a synchronous fault reads ahead from the
faulting page towards higher offsets through page_cache_sync_ra().
A reader that moves towards lower offsets, such as memmove() copying
backwards out of a mapping, finds the pages above the fault already
cached, so each of its faults reads a single new page.
page_cache_sync_ra() also looks for a stream only below the fault and
takes it for a small random read.
When the page above the fault is already cached, read the window of
ra_pages that ends at the faulting page instead, without a readahead
mark. Reading one byte from each page of a 2 GiB file, last page first,
in a MADV_SEQUENTIAL mapping with a cold page cache, read_ahead_kb 8192:
before after
time 50.92 s 0.96 s
major faults 524289 258
Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev>
---
mm/filemap.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/mm/filemap.c b/mm/filemap.c
index e445279cc561f..be587f8d0e8e6 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -3405,7 +3405,19 @@ static struct file *do_sync_mmap_readahead(struct vm_fault *vmf)
if (vm_flags & VM_SEQ_READ) {
fpin = maybe_unlock_mmap_for_io(vmf, fpin);
- page_cache_sync_ra(&ractl, ra->ra_pages);
+ if (!filemap_descending(mapping, vmf->pgoff, 1)) {
+ page_cache_sync_ra(&ractl, ra->ra_pages);
+ return fpin;
+ }
+ /* Read the window that ends at the faulting page */
+ ra->start = vmf->pgoff + 1 -
+ min_t(unsigned long, ra->ra_pages,
+ vmf->pgoff + 1);
+ ra->size = vmf->pgoff + 1 - ra->start;
+ ra->async_size = 0;
+ ra->order = 0;
+ ractl._index = ra->start;
+ page_cache_ra_order(&ractl, ra);
return fpin;
}
}
--
2.43.0
prev parent reply other threads:[~2026-11-09 10:35 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-09 10:34 [PATCH v2 0/3] mm/filemap: read ahead for mmap readers that move backwards Qiliang Yuan
2026-11-09 10:34 ` [PATCH v2 1/3] mm/filemap: move the mmap hit check of filemap_map_pages() into helpers Qiliang Yuan
2026-11-09 10:34 ` [PATCH v2 2/3] mm/filemap: read ahead downwards on descending VM_HUGEPAGE faults Qiliang Yuan
2026-11-09 10:34 ` Qiliang Yuan [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261109-bug-mm-mmap-readahead-descending-v2-3-abac52890a9c@linux.dev \
--to=qiliang.yuan@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=fujunjie1@qq.com \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=roman.gushchin@linux.dev \
--cc=usama.arif@linux.dev \
--cc=vishal.moola@gmail.com \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®