* [PATCH] ext4: stop walking the whole fsmap meta_list for every extent
@ 2026-12-04 13:29 Jyun-An Chen
2026-12-04 13:42 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Jyun-An Chen @ 2026-12-04 13:29 UTC (permalink / raw)
To: Theodore Ts'o, linux-ext4
Cc: Andreas Dilger, Jan Kara, Baokun Li, Ojaswin Mujoo,
Ritesh Harjani, Zhang Yi, Jyun-An Chen
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ext4: stop walking the whole fsmap meta_list for every extent
2026-12-04 13:29 [PATCH] ext4: stop walking the whole fsmap meta_list for every extent Jyun-An Chen
@ 2026-12-04 13:42 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-04 13:42 UTC (permalink / raw)
To: Jyun-An Chen, linux-ext4; +Cc: tytso
> 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>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204132915.73095-1-jun930436@gmail.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-04 13:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 13:29 [PATCH] ext4: stop walking the whole fsmap meta_list for every extent Jyun-An Chen
2026-12-04 13:42 ` sashiko-bot
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.