From: Jyun-An Chen <jun930436@gmail.com>
To: Theodore Ts'o <tytso@mit.edu>, linux-ext4@vger.kernel.org
Cc: Andreas Dilger <adilger.kernel@dilger.ca>,
Jan Kara <jack@suse.cz>, Baokun Li <libaokun@linux.alibaba.com>,
Ojaswin Mujoo <ojaswin@linux.ibm.com>,
Ritesh Harjani <ritesh.list@gmail.com>,
Zhang Yi <yi.zhang@huawei.com>,
Jyun-An Chen <jun930436@gmail.com>
Subject: [PATCH] ext4: stop walking the whole fsmap meta_list for every extent
Date: Fri, 4 Dec 2026 21:29:15 +0800 [thread overview]
Message-ID: <20261204132915.73095-1-jun930436@gmail.com> (raw)
ext4_getfsmap_datadev_helper() is called once per free extent and
ext4_getfsmap_meta_helper() once per block group that starts with used
blocks. Both walk the entire remaining gfi_meta_list on every call,
although the list is sorted by fmr_physical (list_sort() in
ext4_getfsmap_find_fixed_metadata(), and entries are only ever removed
afterwards). A GETFSMAP query therefore costs
O(free extents * fixed metadata extents).
For example, a 4 TiB filesystem (default mkfs, flex_bg=16) has 6210
merged fixed metadata extents; with 200k free-space fragments near the
start of the device, a single GETFSMAP call returns 408k records.
GETFSMAP needs no privileges.
Stop each walk at the first extent that starts beyond both the current
range (fsb for the free-extent case, fs_end for the metadata case) and
gfi_next_fsblk. Because the list is sorted, no later extent can satisfy
either branch, and since neither branch runs again, gfi_next_fsblk and
the local fsb cannot change for the rest of the walk. The output is
therefore unchanged.
Time for one GETFSMAP call returning all records, measured in QEMU
(TCG, arm64) with and without this patch:
image before after
4 TiB, 200k free fragments near start 92.7 s 3.6 s
1 TiB, 200k free fragments near start 3.6 s 0.94 s
4 TiB, mostly allocated (meta_helper) 17.2 s 13.0 s
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Jyun-An Chen <jun930436@gmail.com>
---
fs/ext4/fsmap.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/fs/ext4/fsmap.c b/fs/ext4/fsmap.c
index f41c2298d196..914661240177 100644
--- a/fs/ext4/fsmap.c
+++ b/fs/ext4/fsmap.c
@@ -208,6 +208,9 @@ static int ext4_getfsmap_meta_helper(struct super_block *sb,
* partially/fully overlap with the query range
*/
list_for_each_entry_safe(p, tmp, &info->gfi_meta_list, fmr_list) {
+ if (p->fmr_physical > fs_end &&
+ p->fmr_physical > info->gfi_next_fsblk)
+ break;
if (p->fmr_physical + p->fmr_length <= info->gfi_next_fsblk) {
list_del(&p->fmr_list);
kfree(p);
@@ -278,6 +281,9 @@ static int ext4_getfsmap_datadev_helper(struct super_block *sb,
/* Merge in any relevant extents from the meta_list */
list_for_each_entry_safe(p, tmp, &info->gfi_meta_list, fmr_list) {
+ if (p->fmr_physical >= fsb &&
+ p->fmr_physical > info->gfi_next_fsblk)
+ break;
if (p->fmr_physical + p->fmr_length <= info->gfi_next_fsblk) {
list_del(&p->fmr_list);
kfree(p);
base-commit: aceadbccd428fb8e6593b27a3091d961f80225d1
next reply other threads:[~2026-12-04 13:29 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 13:29 Jyun-An Chen [this message]
2026-12-04 13:42 ` [PATCH] ext4: stop walking the whole fsmap meta_list for every extent sashiko-bot
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=20261204132915.73095-1-jun930436@gmail.com \
--to=jun930436@gmail.com \
--cc=adilger.kernel@dilger.ca \
--cc=jack@suse.cz \
--cc=libaokun@linux.alibaba.com \
--cc=linux-ext4@vger.kernel.org \
--cc=ojaswin@linux.ibm.com \
--cc=ritesh.list@gmail.com \
--cc=tytso@mit.edu \
--cc=yi.zhang@huawei.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.