* [PATCH] erofs: enable buffered RWF_DONTCACHE reads
@ 2026-11-19 3:52 Wenjie Qi
2026-11-19 21:17 ` Gao Xiang
0 siblings, 1 reply; 2+ messages in thread
From: Wenjie Qi @ 2026-11-19 3:52 UTC (permalink / raw)
To: xiang, chao
Cc: linux-erofs, linux-fsdevel, shengyong1, yangyongpeng, qiwenjie,
qwjhust
From: Wenjie Qi <qiwenjie@xiaomi.com>
EROFS uses filemap_read() for buffered reads, including the inode-sharing
path, which preserves request flags when cloning the kiocb.
Advertise FOP_DONTCACHE in both file operation tables so preadv2() callers
can request that newly instantiated file-cache folios be dropped after
consumption. This is useful for one-pass reads that need not retain data
in the page cache.
For compressed reads, retain trailing readmore and propagate dropbehind
to the single-folio neighbor lookup. Readahead expansion already marks
new folios through readahead_control. Suppress prefix readmore so it
cannot refill pages already consumed and evicted. Ordinary readmore is
unchanged.
Tested sequential reads of 1-GiB files with 1-MiB requests on NVMe-backed
LZ4 and Zstd EROFS images in x86-64 QEMU/KVM with two vCPUs and 2 GiB RAM.
Each reader ran with memory.max=255852544 (244 MiB) and
memory.swap.max=0. Normal and dontcache ran in ten paired rounds per
layout, alternating their order and using a fresh guest for each run.
Results are arithmetic means of ten runs. Memory values average the
run-level time-weighted memory.current means. Percentage changes are
relative to normal reads:
MiB/s Mean memory, MiB
Layout normal/dontcache change normal/dontcache change
LZ4 2513.57/6350.61 +152.65% 169.53/17.39 -89.74%
Zstd 2535.57/4066.49 +60.38% 179.01/18.17 -89.85%
In this test, dontcache reduced average cgroup memory by about 90%,
left no consumed file pages resident and recorded no memcg reclaim
scans or steals. Both layouts were faster in all ten pairs. This
offers a smaller cache footprint for one-pass reads on memory-constrained
systems.
Signed-off-by: Wenjie Qi <qiwenjie@xiaomi.com>
Signed-off-by: Sheng Yong <shengyong1@xiaomi.com>
Reviewed-by: Yongpeng Yang <yangyongpeng@xiaomi.com>
---
fs/erofs/data.c | 1 +
fs/erofs/internal.h | 5 +++--
fs/erofs/ishare.c | 1 +
fs/erofs/zdata.c | 10 +++++++++-
4 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/fs/erofs/data.c b/fs/erofs/data.c
index 968303afd..db0bac732 100644
--- a/fs/erofs/data.c
+++ b/fs/erofs/data.c
@@ -537,4 +537,5 @@ const struct file_operations erofs_file_fops = {
.get_unmapped_area = thp_get_unmapped_area,
.splice_read = filemap_splice_read,
.setlease = generic_setlease,
+ .fop_flags = FOP_DONTCACHE,
};
diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
index 8363c0c05..cbe58576b 100644
--- a/fs/erofs/internal.h
+++ b/fs/erofs/internal.h
@@ -321,10 +321,11 @@ static inline unsigned int erofs_inode_datalayout(unsigned int ifmt)
/* reclaiming is never triggered when allocating new folios. */
static inline struct folio *erofs_grab_folio_nowait(struct address_space *as,
- pgoff_t index)
+ pgoff_t index, bool dropbehind)
{
return __filemap_get_folio(as, index,
- FGP_LOCK|FGP_CREAT|FGP_NOFS|FGP_NOWAIT,
+ FGP_LOCK | FGP_CREAT | FGP_NOFS | FGP_NOWAIT |
+ (dropbehind ? FGP_DONTCACHE : 0),
readahead_gfp_mask(as) & ~__GFP_RECLAIM);
}
diff --git a/fs/erofs/ishare.c b/fs/erofs/ishare.c
index ea146fa8a..585bf4614 100644
--- a/fs/erofs/ishare.c
+++ b/fs/erofs/ishare.c
@@ -190,6 +190,7 @@ const struct file_operations erofs_ishare_fops = {
.get_unmapped_area = thp_get_unmapped_area,
.splice_read = erofs_ishare_splice_read,
.fadvise = erofs_ishare_fadvise,
+ .fop_flags = FOP_DONTCACHE,
};
struct inode *erofs_real_inode(struct inode *inode, bool *need_iput)
diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c
index e981e371d..19e6051f5 100644
--- a/fs/erofs/zdata.c
+++ b/fs/erofs/zdata.c
@@ -512,6 +512,7 @@ struct z_erofs_frontend {
struct page *candidate_bvpage;
struct z_erofs_pcluster *pcl, *head;
enum z_erofs_pclustermode mode;
+ bool dropbehind;
erofs_off_t headoffset;
@@ -1807,6 +1808,10 @@ static void z_erofs_pcluster_readmore(struct z_erofs_frontend *f,
erofs_off_t cur, end, headoffset = f->headoffset;
int err;
+ /* Avoid repopulating a prefix that dropbehind has already evicted. */
+ if (f->dropbehind && !backmost)
+ return;
+
if (backmost) {
if (rac)
end = headoffset + readahead_length(rac) - 1;
@@ -1836,7 +1841,8 @@ static void z_erofs_pcluster_readmore(struct z_erofs_frontend *f,
pgoff_t index = cur >> PAGE_SHIFT;
struct folio *folio;
- folio = erofs_grab_folio_nowait(f->sharedinode->i_mapping, index);
+ folio = erofs_grab_folio_nowait(f->sharedinode->i_mapping, index,
+ f->dropbehind);
if (!IS_ERR_OR_NULL(folio)) {
if (folio_test_uptodate(folio))
folio_unlock(folio);
@@ -1860,6 +1866,7 @@ static int z_erofs_read_folio(struct file *file, struct folio *folio)
int err;
trace_erofs_read_folio(realinode, folio, false);
+ f.dropbehind = folio_test_dropbehind(folio);
z_erofs_pcluster_readmore(&f, NULL, true);
err = z_erofs_scan_folio(&f, folio, false);
z_erofs_pcluster_readmore(&f, NULL, false);
@@ -1890,6 +1897,7 @@ static void z_erofs_readahead(struct readahead_control *rac)
int err;
trace_erofs_readahead(realinode, readahead_index(rac), nrpages, false);
+ f.dropbehind = rac->dropbehind;
z_erofs_pcluster_readmore(&f, rac, true);
/* traverse from last to first for best metadata I/O performance */
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] erofs: enable buffered RWF_DONTCACHE reads
2026-11-19 3:52 [PATCH] erofs: enable buffered RWF_DONTCACHE reads Wenjie Qi
@ 2026-11-19 21:17 ` Gao Xiang
0 siblings, 0 replies; 2+ messages in thread
From: Gao Xiang @ 2026-11-19 21:17 UTC (permalink / raw)
To: Wenjie Qi
Cc: xiang, chao, linux-erofs, linux-fsdevel, shengyong1, yangyongpeng,
qiwenjie
On Thu, Nov 19, 2026 at 11:52:50AM +0800, Wenjie Qi wrote:
> From: Wenjie Qi <qiwenjie@xiaomi.com>
>
> EROFS uses filemap_read() for buffered reads, including the inode-sharing
> path, which preserves request flags when cloning the kiocb.
>
> Advertise FOP_DONTCACHE in both file operation tables so preadv2() callers
> can request that newly instantiated file-cache folios be dropped after
> consumption. This is useful for one-pass reads that need not retain data
> in the page cache.
>
> For compressed reads, retain trailing readmore and propagate dropbehind
> to the single-folio neighbor lookup. Readahead expansion already marks
> new folios through readahead_control. Suppress prefix readmore so it
> cannot refill pages already consumed and evicted. Ordinary readmore is
> unchanged.
>
> Tested sequential reads of 1-GiB files with 1-MiB requests on NVMe-backed
> LZ4 and Zstd EROFS images in x86-64 QEMU/KVM with two vCPUs and 2 GiB RAM.
> Each reader ran with memory.max=255852544 (244 MiB) and
> memory.swap.max=0. Normal and dontcache ran in ten paired rounds per
> layout, alternating their order and using a fresh guest for each run.
>
> Results are arithmetic means of ten runs. Memory values average the
> run-level time-weighted memory.current means. Percentage changes are
> relative to normal reads:
>
> MiB/s Mean memory, MiB
> Layout normal/dontcache change normal/dontcache change
> LZ4 2513.57/6350.61 +152.65% 169.53/17.39 -89.74%
> Zstd 2535.57/4066.49 +60.38% 179.01/18.17 -89.85%
>
> In this test, dontcache reduced average cgroup memory by about 90%,
> left no consumed file pages resident and recorded no memcg reclaim
> scans or steals. Both layouts were faster in all ten pairs. This
> offers a smaller cache footprint for one-pass reads on memory-constrained
> systems.
>
> Signed-off-by: Wenjie Qi <qiwenjie@xiaomi.com>
> Signed-off-by: Sheng Yong <shengyong1@xiaomi.com>
> Reviewed-by: Yongpeng Yang <yangyongpeng@xiaomi.com>
Yeah, that was in my own plan too but I never find a slot, thank you.
It would be useful for one-time load on large files like AI models
and these numbers are impressive:
Reviewed-by: Gao Xiang <xiang@kernel.org>
Thanks,
Gao Xiang
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-19 21:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 3:52 [PATCH] erofs: enable buffered RWF_DONTCACHE reads Wenjie Qi
2026-11-19 21:17 ` Gao Xiang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox