From nobody Tue Oct 7 05:19:41 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C4C91D63E6 for ; Mon, 14 Jul 2025 09:39:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752485982; cv=none; b=V0KrtLa96xSQ3HTb7bbGhqV4ac32Rx0KrO+xO/8Qoi7e4Pefp3hESxnshhhdTqHlKIgdaMVTYYDPc5fv2D0SFWaIf++OkUyh3YIClLfXr1M6y9ok3tp2ZzVCvQPJorBsu7VfbxgmP8vaM/KypZ7KiV1Ui7plg64CHEEQu8+7Awk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752485982; c=relaxed/simple; bh=cQ0TpDO9ZCOEo8C3OLkJivTCTe9XM5S/iXQQdJiXaQ4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Jpagr+dj2PedLrMb5FPXlrkGO2aA2ZjeBGCAZ2bS2MfqtMUNYFQoCqANAis8q24CMUzv4DCbwUvwarMQe+JTewib+2lKDoq5DcQy8bAEkgeg/cQJyMBcddl98kPQblf80AFmKvYKEqBQquEbmJ/rvwhVmRfGhs8GxoetdVlcUDQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lg9+S2UT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lg9+S2UT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 955BFC4CEED; Mon, 14 Jul 2025 09:39:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1752485982; bh=cQ0TpDO9ZCOEo8C3OLkJivTCTe9XM5S/iXQQdJiXaQ4=; h=From:To:Cc:Subject:Date:From; b=lg9+S2UTu8r1DfSFfWgiSttKR4mGPbsogToufb1yH4UYTqHgfmYM9qgSiH/PSlm6a dkCWpi/Hkc5RN8oOgA5LDiLXurN5oe7L2XLFhjfF/Wt5B5sE0ugbs/pulsTSpigeGV YGLu3ncijh/24AMqk6fR9eZkG4V5u3qqKPXrWzSmEIhX8i5QD59VEsUONHEEcbZwHt lV20tOG4xqyargOpayFDiH9RU2RbcpQt099Q1P0VPDUc5dogsnXlgGw1M28G1tN/Rc ZAM3bjysKI88DmYLq/kWCZyyoSD5ajtARtVl6eqgtA9GSC8L/XbzthdoYxbyO3S8wB J4l92Nm7UfOEw== From: Chao Yu To: xiang@kernel.org Cc: linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org, Yue Hu , Jeffle Xu , Sandeep Dhavale , Hongbo Li , Chao Yu Subject: [PATCH v3] erofs: support to readahead dirent blocks in erofs_readdir() Date: Mon, 14 Jul 2025 17:39:35 +0800 Message-ID: <20250714093935.200749-1-chao@kernel.org> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This patch supports to readahead more blocks in erofs_readdir(), it can enhance readdir performance in large direcotry. readdir test in a large directory which contains 12000 sub-files. files_per_second Before: 926385.54 After: 2380435.562 Meanwhile, let's introduces a new sysfs entry to control readahead bytes to provide more flexible policy for readahead of readdir(). - location: /sys/fs/erofs//dir_ra_bytes - default value: 16384 - disable readahead: set the value to 0 Signed-off-by: Chao Yu --- v3: - add EROFS prefix for macro - update new sysfs interface to 1) use bytes instead of pages 2) remove upper boundary limitation - fix bug of pageidx calculation Documentation/ABI/testing/sysfs-fs-erofs | 8 ++++++++ fs/erofs/dir.c | 13 +++++++++++++ fs/erofs/internal.h | 4 ++++ fs/erofs/super.c | 2 ++ fs/erofs/sysfs.c | 2 ++ 5 files changed, 29 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-fs-erofs b/Documentation/ABI/t= esting/sysfs-fs-erofs index bf3b6299c15e..85fa56ca092c 100644 --- a/Documentation/ABI/testing/sysfs-fs-erofs +++ b/Documentation/ABI/testing/sysfs-fs-erofs @@ -35,3 +35,11 @@ Description: Used to set or show hardware accelerators i= n effect and multiple accelerators are separated by '\n'. Supported accelerator(s): qat_deflate. Disable all accelerators with an empty string (echo > accel). + +What: /sys/fs/erofs//dir_ra_bytes +Date: July 2025 +Contact: "Chao Yu" +Description: Used to set or show readahead bytes during readdir(), by + default the value is 16384. + + - 0: disable readahead. diff --git a/fs/erofs/dir.c b/fs/erofs/dir.c index 3e4b38bec0aa..950d6b0046f4 100644 --- a/fs/erofs/dir.c +++ b/fs/erofs/dir.c @@ -47,8 +47,10 @@ static int erofs_readdir(struct file *f, struct dir_cont= ext *ctx) struct inode *dir =3D file_inode(f); struct erofs_buf buf =3D __EROFS_BUF_INITIALIZER; struct super_block *sb =3D dir->i_sb; + struct file_ra_state *ra =3D &f->f_ra; unsigned long bsz =3D sb->s_blocksize; unsigned int ofs =3D erofs_blkoff(sb, ctx->pos); + unsigned long nr_pages =3D DIV_ROUND_UP_POW2(dir->i_size, PAGE_SIZE); int err =3D 0; bool initial =3D true; =20 @@ -63,6 +65,17 @@ static int erofs_readdir(struct file *f, struct dir_cont= ext *ctx) break; } =20 + /* readahead blocks to enhance performance in large directory */ + if (EROFS_I_SB(dir)->dir_ra_bytes) { + unsigned long idx =3D DIV_ROUND_UP(ctx->pos, PAGE_SIZE); + pgoff_t ra_pages =3D DIV_ROUND_UP( + EROFS_I_SB(dir)->dir_ra_bytes, PAGE_SIZE); + + if (nr_pages - idx > 1 && !ra_has_index(ra, idx)) + page_cache_sync_readahead(dir->i_mapping, ra, + f, idx, min(nr_pages - idx, ra_pages)); + } + de =3D 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 0d19bde8c094..4399b9332307 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -157,6 +157,7 @@ struct erofs_sb_info { /* sysfs support */ struct kobject s_kobj; /* /sys/fs/erofs/ */ struct completion s_kobj_unregister; + erofs_off_t dir_ra_bytes; =20 /* fscache support */ struct fscache_volume *volume; @@ -238,6 +239,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) =20 +/* default readahead size of directory */ +#define EROFS_DIR_RA_BYTES 16384 + struct erofs_inode { erofs_nid_t nid; =20 diff --git a/fs/erofs/super.c b/fs/erofs/super.c index e1e9f06e8342..38fc4813a896 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -715,6 +715,8 @@ static int erofs_fc_fill_super(struct super_block *sb, = struct fs_context *fc) if (err) return err; =20 + sbi->dir_ra_bytes =3D EROFS_DIR_RA_BYTES; + erofs_info(sb, "mounted with root inode @ nid %llu.", sbi->root_nid); return 0; } diff --git a/fs/erofs/sysfs.c b/fs/erofs/sysfs.c index eed8797a193f..9d9f820a5621 100644 --- a/fs/erofs/sysfs.c +++ b/fs/erofs/sysfs.c @@ -65,12 +65,14 @@ EROFS_ATTR_FUNC(drop_caches, 0200); #ifdef CONFIG_EROFS_FS_ZIP_ACCEL EROFS_ATTR_FUNC(accel, 0644); #endif +EROFS_ATTR_RW_UI(dir_ra_bytes, erofs_sb_info); =20 static struct attribute *erofs_sb_attrs[] =3D { #ifdef CONFIG_EROFS_FS_ZIP ATTR_LIST(sync_decompress), ATTR_LIST(drop_caches), #endif + ATTR_LIST(dir_ra_bytes), NULL, }; ATTRIBUTE_GROUPS(erofs_sb); --=20 2.49.0