[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20240427094118.51194ffe@x390.bzzz77.ru>
Date: Sat, 27 Apr 2024 09:41:18 +0300
From: Alexey Zhuravlev <bzzz@...mcloud.com>
To: linux-ext4@...r.kernel.org
Subject: shrink extent tree when possible
Hi,
Please, consider for inclusion the patch attempting to shrink extent tree after successful extent merging.
Thanks, Alex
>From 72a8dda0cb490fdb7fbcd0be2c19dbb3e2973b23 Mon Sep 17 00:00:00 2001
From: Alex Zhuravlev <bzzz@...mcloud.com>
Date: Thu, 25 Jan 2024 21:24:08 +0300
Subject: [PATCH 2/2] Shrink extent's tree if the next level is presented by a single node and all entries can fit the root.
after successful extent merging a 1st level index can collapse enough to fit the root.
Signed-off-by: Alex Zhuravlev <bzzz@...mcloud.com>
---
fs/ext4/extents.c | 29 +++++++++++++++++++++++++----
1 file changed, 25 insertions(+), 4 deletions(-)
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index a2de6b863df1..d7ad0cd92dfe 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -2025,10 +2025,31 @@ static int ext4_ext_merge_blocks(handle_t *handle,
}
}
- /*
- * TODO: given we've got two paths, it should be possible to
- * collapse those two blocks into the root one in some cases
- */
+ /* move the next level into the root if possible */
+ k = le16_to_cpu(path[1].p_hdr->eh_entries);
+ if (depth > 2 && le16_to_cpu(path[0].p_hdr->eh_entries == 1) &&
+ path[1].p_hdr == npath[1].p_hdr &&
+ k <= le16_to_cpu(path[0].p_hdr->eh_max)) {
+
+ next = ext4_idx_pblock(path[0].p_idx);
+
+ err = ext4_ext_get_access(handle, inode, path + 0);
+ if (err)
+ return err;
+ memcpy(EXT_FIRST_INDEX(path[0].p_hdr),
+ EXT_FIRST_INDEX(path[1].p_hdr),
+ k * sizeof(struct ext4_extent_idx));
+ path[0].p_hdr->eh_entries = cpu_to_le16(k);
+ le16_add_cpu(&path[0].p_hdr->eh_depth, -1);
+ err = ext4_ext_dirty(handle, inode, path + 0);
+ if (err)
+ return err;
+
+ ext4_free_blocks(handle, inode, NULL, next, 1,
+ EXT4_FREE_BLOCKS_METADATA |
+ EXT4_FREE_BLOCKS_FORGET);
+ }
+
return 1;
}
--
2.44.0
Powered by blists - more mailing lists