public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
From: "Kiselev, Oleg" <okiselev@amazon.com>
To: "linux-ext4@vger.kernel.org" <linux-ext4@vger.kernel.org>
Cc: Theodore Ts'o <tytso@mit.edu>
Subject: [PATCH 1/2] ext4: reduce computation of overhead during resize
Date: Thu, 30 Jun 2022 02:17:21 +0000	[thread overview]
Message-ID: <D03FEE2D-DCAE-44A7-B0D3-0047808426BB@amazon.com> (raw)

This patch avoids doing an O(n**2)-complexity walk through every flex group.
Instead, it uses the already computed overhead information for the newly
allocated space, and simply adds it to the previously calculated
overhead stored in the superblock.  This drastically reduces the time
taken to resize very large bigalloc filesystems (from 3+ hours for a
64TB fs down to milliseconds).

Signed-off-by: Oleg Kiselev <okiselev@amazon.com>
---
 fs/ext4/resize.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
index 8b70a4701293..2acc9fca99ea 100644
--- a/fs/ext4/resize.c
+++ b/fs/ext4/resize.c
@@ -1380,6 +1380,16 @@ static int ext4_setup_new_descs(handle_t *handle, struct super_block *sb,
 	return err;
 }

+static void ext4_set_overhead(struct super_block *sb,
+                             const ext4_grpblk_t overhead)
+{
+       struct ext4_sb_info *sbi = EXT4_SB(sb);
+       struct ext4_super_block *es = sbi->s_es;
+       sbi->s_overhead += overhead;
+       es->s_overhead_clusters = cpu_to_le32((unsigned long) sbi->s_overhead);
+       smp_wmb();
+}
+
 /*
  * ext4_update_super() updates the super block so that the newly added
  * groups can be seen by the filesystem.
@@ -1482,8 +1492,16 @@ static void ext4_update_super(struct super_block *sb,

 	/*
 	 * Update the fs overhead information
+	 *
+	 * For bigalloc, if the superblock already has a properly calculated
+	 * overhead, update it wth a value based on numbers already computed
+	 * above for the newly allocated capacity.
 	 */
-	ext4_calculate_overhead(sb);
+	if (ext4_has_feature_bigalloc(sb) && (sbi->s_overhead != 0))
+		ext4_set_overhead(sb,
+			EXT4_NUM_B2C(sbi, blocks_count - free_blocks));
+	else
+		ext4_calculate_overhead(sb);

 	if (test_opt(sb, DEBUG))
 		printk(KERN_DEBUG "EXT4-fs: added group %u:"
--
2.32.0


             reply	other threads:[~2022-06-30  2:17 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-30  2:17 Kiselev, Oleg [this message]
2022-07-14 13:46 ` [PATCH 1/2] ext4: reduce computation of overhead during resize Jan Kara
2022-07-14 19:53   ` Kiselev, Oleg
2022-07-15  9:27     ` Jan Kara
2022-07-15 23:52       ` Kiselev, Oleg

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=D03FEE2D-DCAE-44A7-B0D3-0047808426BB@amazon.com \
    --to=okiselev@amazon.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=tytso@mit.edu \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox