All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: Alexey Zhuravlev <bzzz@whamcloud.com>
To: linux-ext4@vger.kernel.org
Subject: shrink extent tree when possible
Date: Sat, 27 Apr 2024 09:41:18 +0300	[thread overview]
Message-ID: <20240427094118.51194ffe@x390.bzzz77.ru> (raw)


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@whamcloud.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@whamcloud.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


                 reply	other threads:[~2024-04-27  7:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20240427094118.51194ffe@x390.bzzz77.ru \
    --to=bzzz@whamcloud.com \
    --cc=linux-ext4@vger.kernel.org \
    /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.