Skip to contentSkip to conversation

meta_bg online resize patches

PATCH Superseded Theodore Ts'o 1 participant 7 messages Sep 2, 2012 – Sep 3, 2012 ext4 file system

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Theodore Ts'o

author maintainer
#0 lore raw

cover meta_bg online resize patches

This patch series is based on a set of patches from Yongqiang Yang, with some bug fixes. In particular, we have to grow certain arrays which are allocated at mount time. Originally, they were allocated to be big enough to cover the largest possible size they could be given the number of reserved gdt blocks. This wasted memory and doesn't work in the meta_bg scheme, since there is no limit imposed at mkfs time.

Theodore Ts'o (2):
ext4: grow the s_flex_groups array as needed when resizing
ext4: grow the s_group_info array as needed

Yongqiang Yang (3):
ext4: when resizing, do not copy gdt blocks for groups that do not
have them
ext4: avoid duplicate writes of the backup bg descriptor blocks
ext4: add online resizing support for meta_bg and bit64

 fs/ext4/ext4.h    |   6 ++
 fs/ext4/ioctl.c   |  15 ----
 fs/ext4/mballoc.c |  79 +++++++++--------
 fs/ext4/resize.c  | 249 ++++++++++++++++++++++++++++++++++++++++--------------
 fs/ext4/super.c   |  48 ++++++++---
 5 files changed, 267 insertions(+), 130 deletions(-)
Signature · 1 line
1.7.12.rc0.22.gcdd159b
author maintainer
#1 lore raw

PATCH 1/5 ext4: when resizing, do not copy gdt blocks for groups that do not have them

From: Yongqiang Yang <[email protected]>

The resize code was copying blocks at the beginning of each block group in order to copy the superblock and block group descriptor table (gdt) blocks. This was, unfortunately, being done even for block groups that did not have super blocks or gdt blocks. This is a complete waste of perfectly good I/O bandwidth, to skip writing those blocks for sparse bg's.

---
 fs/ext4/resize.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/ext4/resize.c +4 -0
index 41f6ef6..724e250 100644
@@ -451,6 +451,9 @@ static int setup_new_flex_group_blocks(struct super_block *sb,
 		gdblocks = ext4_bg_num_gdb(sb, group);
 		start = ext4_group_first_block_no(sb, group);
 
+		if (!ext4_bg_has_super(sb, group))
+			goto handle_itb;
+
 		/* Copy all of the GDT blocks into the backup in this group */
 		for (j = 0, block = start + 1; j < gdblocks; j++, block++) {
 			struct buffer_head *gdb;
@@ -493,6 +496,7 @@ static int setup_new_flex_group_blocks(struct super_block *sb,
 				goto out;
 		}
 
+handle_itb:
 		/* Initialize group tables of the grop @group */
 		if (!(bg_flags[i] & EXT4_BG_INODE_ZEROED))
 			goto handle_bb;
Signature · 1 line
1.7.12.rc0.22.gcdd159b
author maintainer
#2 lore raw

PATCH 2/5 ext4: avoid duplicate writes of the backup bg descriptor blocks

In reply to Theodore Ts'o

From: Yongqiang Yang <[email protected]>

The resize code was needlessly writing the backup block group descriptor blocks multiple times (once per block group) during an online resize.

---
 fs/ext4/resize.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
fs/ext4/resize.c +6 -4
index 724e250..e3f5f53 100644
@@ -1353,13 +1353,15 @@ exit_journal:
 		err = err2;
 
 	if (!err) {
-		int i;
+		int gdb_num = group / EXT4_DESC_PER_BLOCK(sb);
+		int gdb_num_end = ((group + flex_gd->count - 1) /
+				   EXT4_DESC_PER_BLOCK(sb));
+
 		update_backups(sb, sbi->s_sbh->b_blocknr, (char *)es,
 			       sizeof(struct ext4_super_block));
-		for (i = 0; i < flex_gd->count; i++, group++) {
+		for (; gdb_num <= gdb_num_end; gdb_num++) {
 			struct buffer_head *gdb_bh;
-			int gdb_num;
-			gdb_num = group / EXT4_BLOCKS_PER_GROUP(sb);
+
 			gdb_bh = sbi->s_group_desc[gdb_num];
 			update_backups(sb, gdb_bh->b_blocknr, gdb_bh->b_data,
 				       gdb_bh->b_size);
Signature · 1 line
1.7.12.rc0.22.gcdd159b
author maintainer
#3 lore raw

PATCH 3/5 ext4: grow the s_flex_groups array as needed when resizing

In reply to Theodore Ts'o

Previously, we allocated the s_flex_groups array to the maximum size that the file system could be resized. There was two problems with this approach. First, it wasted memory in the common case where the file system was not resized. Secondly, once we start allowing online resizing using the meta_bg scheme, there is no maximum size that the file system can be resized. So instead, we need to grow the s_flex_groups at inline resize time.

---
 fs/ext4/ext4.h   |  3 +++
 fs/ext4/resize.c | 14 +++++++++-----
 fs/ext4/super.c  | 48 +++++++++++++++++++++++++++++++++++-------------
 3 files changed, 47 insertions(+), 18 deletions(-)
fs/ext4/ext4.h +3 -0
index 0df5ee1..464cff7 100644
@@ -1276,6 +1276,7 @@ struct ext4_sb_info {
 
 	unsigned int s_log_groups_per_flex;
 	struct flex_groups *s_flex_groups;
+	ext4_group_t s_flex_groups_allocated;
 
 	/* workqueue for dio unwritten */
 	struct workqueue_struct *dio_unwritten_wq;
@@ -2055,6 +2056,8 @@ extern void ext4_superblock_csum_set(struct super_block *sb,
 extern void *ext4_kvmalloc(size_t size, gfp_t flags);
 extern void *ext4_kvzalloc(size_t size, gfp_t flags);
 extern void ext4_kvfree(void *ptr);
+extern int ext4_alloc_flex_bg_array(struct super_block *sb,
+				    ext4_group_t ngroup);
 extern __printf(4, 5)
 void __ext4_error(struct super_block *, const char *, unsigned int,
 		  const char *, ...);
fs/ext4/resize.c +9 -5
index e3f5f53..2ec7ece 100644
@@ -1498,6 +1498,10 @@ int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input)
 	if (err)
 		goto out;
 
+	err = ext4_alloc_flex_bg_array(sb, input->group + 1);
+	if (err)
+		return err;
+
 	flex_gd.count = 1;
 	flex_gd.groups = input;
 	flex_gd.bg_flags = &bg_flags;
@@ -1657,7 +1661,7 @@ int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count)
 	unsigned long n_desc_blocks;
 	unsigned long o_desc_blocks;
 	unsigned long desc_blocks;
-	int err = 0, flexbg_size = 1;
+	int err = 0, flexbg_size = 1 << sbi->s_log_groups_per_flex;
 
 	o_blocks_count = ext4_blocks_count(es);
 
@@ -1716,14 +1720,14 @@ int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count)
 			goto out;
 	}
 
-	if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FLEX_BG) &&
-	    es->s_log_groups_per_flex)
-		flexbg_size = 1 << es->s_log_groups_per_flex;
-
 	o_blocks_count = ext4_blocks_count(es);
 	if (o_blocks_count == n_blocks_count)
 		goto out;
 
+	err = ext4_alloc_flex_bg_array(sb, n_group + 1);
+	if (err)
+		return err;
+
 	flex_gd = alloc_flex_gd(flexbg_size);
 	if (flex_gd == NULL) {
 		err = -ENOMEM;
fs/ext4/super.c +35 -13

67 lines not on this page · raw message

Signature · 1 line
1.7.12.rc0.22.gcdd159b
author maintainer
#4 lore raw

PATCH 4/5 ext4: grow the s_group_info array as needed

In reply to Theodore Ts'o

Previously we allocated the s_group_info array with enough space for any future possible growth of the file system via online resize. This is unfortunate because it wastes memory, and it doesn't work for the meta_bg scheme, since there is no limit based on the number of reserved gdt blocks. So add the code to grow the s_group_info array as needed.

---
 fs/ext4/ext4.h    |  3 +++
 fs/ext4/mballoc.c | 79 +++++++++++++++++++++++++++----------------------------
 fs/ext4/resize.c  |  8 ++++++
 3 files changed, 50 insertions(+), 40 deletions(-)
fs/ext4/ext4.h +3 -0
index 464cff7..8b6902c 100644
@@ -1233,6 +1233,7 @@ struct ext4_sb_info {
 	spinlock_t s_md_lock;
 	unsigned short *s_mb_offsets;
 	unsigned int *s_mb_maxs;
+	unsigned int s_group_info_size;
 
 	/* tunables */
 	unsigned long s_stripe;
@@ -1971,6 +1972,8 @@ extern void ext4_exit_mballoc(void);
 extern void ext4_free_blocks(handle_t *handle, struct inode *inode,
 			     struct buffer_head *bh, ext4_fsblk_t block,
 			     unsigned long count, int flags);
+extern int ext4_mb_alloc_groupinfo(struct super_block *sb,
+				   ext4_group_t ngroups);
 extern int ext4_mb_add_groupinfo(struct super_block *sb,
 		ext4_group_t i, struct ext4_group_desc *desc);
 extern int ext4_group_add_blocks(handle_t *handle, struct super_block *sb,
fs/ext4/mballoc.c +39 -40

107 lines not on this page · raw message

fs/ext4/resize.c +8 -0
index 2ec7ece..39ff8ee 100644
@@ -1502,6 +1502,10 @@ int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input)
 	if (err)
 		return err;
 
+	err = ext4_mb_alloc_groupinfo(sb, input->group + 1);
+	if (err)
+		goto out;
+
 	flex_gd.count = 1;
 	flex_gd.groups = input;
 	flex_gd.bg_flags = &bg_flags;
@@ -1728,6 +1732,10 @@ int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count)
 	if (err)
 		return err;
 
+	err = ext4_mb_alloc_groupinfo(sb, n_group + 1);
+	if (err)
+		goto out;
+
 	flex_gd = alloc_flex_gd(flexbg_size);
 	if (flex_gd == NULL) {
 		err = -ENOMEM;
Signature · 1 line
1.7.12.rc0.22.gcdd159b
author maintainer
#5 lore raw

PATCH 5/5 ext4: add online resizing support for meta_bg and bit64

In reply to Theodore Ts'o

From: Yongqiang Yang <[email protected]>

This patch adds support for resizing file systems with the meta_bg and 64bit features.

---
 fs/ext4/ioctl.c  |  15 ----
 fs/ext4/resize.c | 215 +++++++++++++++++++++++++++++++++++++++++--------------
 2 files changed, 161 insertions(+), 69 deletions(-)
fs/ext4/ioctl.c +0 -15
index 7f7dad7..8b84fe2 100644
@@ -365,26 +365,11 @@ group_add_out:
 			return -EOPNOTSUPP;
 		}
 
-		if (EXT4_HAS_INCOMPAT_FEATURE(sb,
-			       EXT4_FEATURE_INCOMPAT_META_BG)) {
-			ext4_msg(sb, KERN_ERR,
-				 "Online resizing not (yet) supported with meta_bg");
-			return -EOPNOTSUPP;
-		}
-
 		if (copy_from_user(&n_blocks_count, (__u64 __user *)arg,
 				   sizeof(__u64))) {
 			return -EFAULT;
 		}
 
-		if (n_blocks_count > MAX_32_NUM &&
-		    !EXT4_HAS_INCOMPAT_FEATURE(sb,
-					       EXT4_FEATURE_INCOMPAT_64BIT)) {
-			ext4_msg(sb, KERN_ERR,
-				 "File system only supports 32-bit block numbers");
-			return -EOPNOTSUPP;
-		}
-
 		err = ext4_resize_begin(sb);
 		if (err)
 			return err;
fs/ext4/resize.c +159 -52

389 lines not on this page · raw message

author maintainer
#6 lore raw

PATCH 5/5 ext4: add online resizing support for meta_bg and 64-bit file systems

From: Yongqiang Yang <[email protected]>

This patch adds support for resizing file systems with the meta_bg and 64bit features.

[ Added a fix by tytso to fix a divide by zero when resizing a
filesystem from 14 TB to 18TB. Also fixed overhead accounting for meta_bg file systems.]

---
 fs/ext4/ioctl.c  |  15 ----
 fs/ext4/resize.c | 215 ++++++++++++++++++++++++++++++++++++++++++-------------
 2 files changed, 165 insertions(+), 65 deletions(-)
fs/ext4/ioctl.c +0 -15
index 7f7dad7..8b84fe2 100644
@@ -365,26 +365,11 @@ group_add_out:
 			return -EOPNOTSUPP;
 		}
 
-		if (EXT4_HAS_INCOMPAT_FEATURE(sb,
-			       EXT4_FEATURE_INCOMPAT_META_BG)) {
-			ext4_msg(sb, KERN_ERR,
-				 "Online resizing not (yet) supported with meta_bg");
-			return -EOPNOTSUPP;
-		}
-
 		if (copy_from_user(&n_blocks_count, (__u64 __user *)arg,
 				   sizeof(__u64))) {
 			return -EFAULT;
 		}
 
-		if (n_blocks_count > MAX_32_NUM &&
-		    !EXT4_HAS_INCOMPAT_FEATURE(sb,
-					       EXT4_FEATURE_INCOMPAT_64BIT)) {
-			ext4_msg(sb, KERN_ERR,
-				 "File system only supports 32-bit block numbers");
-			return -EOPNOTSUPP;
-		}
-
 		err = ext4_resize_begin(sb);
 		if (err)
 			return err;
fs/ext4/resize.c +163 -48

400 lines not on this page · raw message