From: Chao Yu <chao@kernel.org>
To: xiang@kernel.org
Cc: linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org,
Yue Hu <zbestahu@gmail.com>,
Jeffle Xu <jefflexu@linux.alibaba.com>,
Sandeep Dhavale <dhavale@google.com>,
Hongbo Li <lihongbo22@huawei.com>, Chao Yu <chao@kernel.org>
Subject: [PATCH 2/2] erofs: support to readahead dirent blocks in erofs_readdir()
Date: Thu, 10 Jul 2025 15:36:19 +0800 [thread overview]
Message-ID: <20250710073619.4083422-2-chao@kernel.org> (raw)
In-Reply-To: <20250710073619.4083422-1-chao@kernel.org>
This patch supports to readahead more blocks in erofs_readdir(),
it can enhance performance in large direcotry.
readdir test in a large directory which contains 12000 sub-files.
files_per_second
Before: 926385.54
After: 2380435.562
Signed-off-by: Chao Yu <chao@kernel.org>
---
fs/erofs/dir.c | 8 ++++++++
fs/erofs/internal.h | 3 +++
2 files changed, 11 insertions(+)
diff --git a/fs/erofs/dir.c b/fs/erofs/dir.c
index cff61c5a172b..04113851fc0f 100644
--- a/fs/erofs/dir.c
+++ b/fs/erofs/dir.c
@@ -47,8 +47,10 @@ static int erofs_readdir(struct file *f, struct dir_context *ctx)
struct inode *dir = file_inode(f);
struct erofs_buf buf = __EROFS_BUF_INITIALIZER;
struct super_block *sb = dir->i_sb;
+ struct file_ra_state *ra = &f->f_ra;
unsigned long bsz = sb->s_blocksize;
unsigned int ofs = erofs_blkoff(sb, ctx->pos);
+ unsigned long nr_pages = DIV_ROUND_UP_POW2(dir->i_size, PAGE_SIZE);
int err = 0;
bool initial = true;
@@ -65,6 +67,12 @@ static int erofs_readdir(struct file *f, struct dir_context *ctx)
}
cond_resched();
+ /* readahead blocks to enhance performance in large directory */
+ if (nr_pages - dbstart > 1 && !ra_has_index(ra, dbstart))
+ page_cache_sync_readahead(dir->i_mapping, ra, f,
+ dbstart, min(nr_pages - dbstart,
+ (pgoff_t)MAX_DIR_RA_PAGES));
+
de = erofs_bread(&buf, dbstart, true);
if (IS_ERR(de)) {
erofs_err(sb, "failed to readdir of logical block %llu of nid %llu",
diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
index a32c03a80c70..ef9d1ee8c688 100644
--- a/fs/erofs/internal.h
+++ b/fs/erofs/internal.h
@@ -238,6 +238,9 @@ EROFS_FEATURE_FUNCS(xattr_filter, compat, COMPAT_XATTR_FILTER)
#define EROFS_I_BL_XATTR_BIT (BITS_PER_LONG - 1)
#define EROFS_I_BL_Z_BIT (BITS_PER_LONG - 2)
+/* maximum readahead pages of directory */
+#define MAX_DIR_RA_PAGES 4
+
struct erofs_inode {
erofs_nid_t nid;
--
2.49.0
next prev parent reply other threads:[~2025-07-10 7:36 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-10 7:36 [PATCH 1/2] erofs: allow readdir() to be interrupted Chao Yu
2025-07-10 7:36 ` Chao Yu [this message]
2025-07-10 7:46 ` [PATCH 2/2] erofs: support to readahead dirent blocks in erofs_readdir() Gao Xiang
2025-07-10 7:59 ` Chao Yu
2025-07-10 8:04 ` Gao Xiang
2025-07-10 13:15 ` Chao Yu
2025-07-10 7:41 ` [PATCH 1/2] erofs: allow readdir() to be interrupted Gao Xiang
2025-07-10 7:57 ` Chao Yu
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=20250710073619.4083422-2-chao@kernel.org \
--to=chao@kernel.org \
--cc=dhavale@google.com \
--cc=jefflexu@linux.alibaba.com \
--cc=lihongbo22@huawei.com \
--cc=linux-erofs@lists.ozlabs.org \
--cc=linux-kernel@vger.kernel.org \
--cc=xiang@kernel.org \
--cc=zbestahu@gmail.com \
/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®