Linux-ext4 Archive mirror
 help / color / mirror / Atom feed
* [PATCH -V2 1/2] ext4: reduce computation of overhead during resize
@ 2022-07-20  4:26 Kiselev, Oleg
  2022-07-22 13:58 ` Theodore Ts'o
  0 siblings, 1 reply; 2+ messages in thread
From: Kiselev, Oleg @ 2022-07-20  4:26 UTC (permalink / raw
  To: linux-ext4@vger.kernel.org; +Cc: Theodore Ts'o, Jan Kara

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>
---
v2:
  - changed static function's name to be more descriptive
  - removed useless cast
---
 fs/ext4/resize.c | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

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

+static void ext4_add_overhead(struct super_block *sb,
+                              const ext4_fsblk_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(sbi->s_overhead);
+       smp_wmb();
+}
+
 /*
  * ext4_update_super() updates the super block so that the newly added
  * groups can be seen by the filesystem.
@@ -1481,9 +1492,17 @@ static void ext4_update_super(struct super_block *sb,
 	}

 	/*
-	 * Update the fs overhead information
+	 * Update the fs overhead information.
+	 *
+	 * For bigalloc, if the superblock already has a properly calculated
+	 * overhead, update it with 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_add_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.34.3


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH -V2 1/2] ext4: reduce computation of overhead during resize
  2022-07-20  4:26 [PATCH -V2 1/2] ext4: reduce computation of overhead during resize Kiselev, Oleg
@ 2022-07-22 13:58 ` Theodore Ts'o
  0 siblings, 0 replies; 2+ messages in thread
From: Theodore Ts'o @ 2022-07-22 13:58 UTC (permalink / raw
  To: linux-ext4, okiselev; +Cc: Theodore Ts'o, Jan Kara

On Wed, 20 Jul 2022 04:26:22 +0000, Kiselev, Oleg wrote:
> 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).
> 
> [...]

Applied, thanks!  (Some slight adjustments were needed to resolve a
merge conflict.)

[1/2] ext4: reduce computation of overhead during resize
      commit: d985f3d81c0be1c673ac0462b26727b2a1aeb0d6

Best regards,
-- 
Theodore Ts'o <tytso@mit.edu>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-07-22 13:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-20  4:26 [PATCH -V2 1/2] ext4: reduce computation of overhead during resize Kiselev, Oleg
2022-07-22 13:58 ` Theodore Ts'o

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).