Skip to contentSkip to conversation

e2fsprogs: Limit number of reserved gdt blocks on small fs

PATCH Superseded Lukas Czerner 2 participants 5 messages Feb 27, 2015 – Mar 2, 2015

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 e2fsprogs: Limit number of reserved gdt blocks on small fs

Currently we're unable to online resize very small (smaller than 32 MB) file systems with 1k block size because there is not enough space in the journal to put all the reserved gdt blocks.

I tried to find solution in kernel which does not require to reserve journal credits for all the gdt blocks, but it looks like we have to have them all in journal to make sure that we atomically either change them all, or none.

So it leaves us with fixing the root cause which is the fact that mke2fs is setup by default so that it creates so many gdt blocks that it can't fit into the journal transaction.

Fix it by limiting the default number of reserved gdt blocks in the specific case of 1k bs and fs size < 32M. Note that it's still possible to create such file system by specifying non-default options so I've added mke2fs message that would warn users that would try to create such file system, but will still allow them to do so.

We still need to address the kernel problem where such file system would generate scary kernel warning, but that's for a separate patch.

Also fix output of some tests, because this change slightly alters the file system layout (specifically number of free blocks and number of reserved gdt blocks) on very small file systems.

---
 lib/ext2fs/initialize.c         |  23 +++
 misc/mke2fs.c                   |  28 +++
 tests/f_create_symlinks/expect  |   8 +-
 tests/f_desc_size_bad/expect.1  |   2 +-
 tests/f_desc_size_bad/expect.2  |   2 +-
 tests/f_resize_inode/expect     |  44 ++---
 tests/m_mkfs_overhead/script    |   2 +-
 tests/r_fixup_lastbg/expect     |  22 +--
 tests/r_fixup_lastbg_big/expect |  26 +--
 tests/r_move_itable/expect      | 404 ++++++++++++++++++++--------------------
 tests/r_resize_inode/expect     |  96 +++++-----
 11 files changed, 354 insertions(+), 303 deletions(-)
lib/ext2fs/initialize.c +23 -0
index 75fbf8e..0ef0e94 100644
@@ -71,6 +71,29 @@ static unsigned int calc_reserved_gdt_blocks(ext2_filsys fs)
 	 */
 	rsv_groups = ext2fs_div_ceil(max_blocks - sb->s_first_data_block, bpg);
 	rsv_gdb = ext2fs_div_ceil(rsv_groups, gdpb) - fs->desc_blocks;
+
+	/*
+	 * In online resize we require a huge number of journal
+	 * credits mainly because of the reserved_gdt_blocks. The
+	 * exact number of journal credits needed is:
+	 * flex_gd->count * 4 + reserved_gdb
+	 *
+	 * In order to allow online resize on file system with tiny
+	 * journal (tiny fs) we have to make the sure we have to
+	 * make sure reserved_gdt_blocks is small enough. If the user
+	 * specifies non-default values he can still run into this issue
+	 * but we do not want to make that mistake by default.
+	 *
+	 * Magic numbers:
+	 * - At block count smaller than 32768, journal will be 1024 block
+	 *   blocks long which would not be enough by default.
+	 * - 64 reserved gtd blocks is maximum number we can fit into said
+	 *   journal by default (flex_bg_count * 4 + rsv_gdb)
+	 */
+	if ((fs->blocksize == 1024) && (ext2fs_blocks_count(sb) < 32768) &&
+	    (rsv_gdb > 64))
+		rsv_gdb = 64;
+
 	if (rsv_gdb > EXT2_ADDR_PER_BLOCK(sb))
 		rsv_gdb = EXT2_ADDR_PER_BLOCK(sb);
 #ifdef RES_GDT_DEBUG
misc/mke2fs.c +28 -0
index aeb852f..e9edd3b 100644
@@ -3076,6 +3076,34 @@ int main (int argc, char *argv[])
 		}
 		if (!quiet)
 			printf("%s", _("done\n"));
+
+		/*
+		 * In online resize we require a huge number of journal
+		 * credits mainly because of the reserved_gdt_blocks. The
+		 * exact number of journal credits needed is:
+		 * flex_gd->count * 4 + reserved_gdb
+		 *
+		 * Warn user if we will not have enough credits to resize
+		 * the file system online.
+		 */
+		if (fs_param.s_feature_compat & EXT2_FEATURE_COMPAT_RESIZE_INODE)
+		{
+			unsigned int credits;
+
+			/*
+			* This is the amount we're allowed to use for a
+			* single handle in a transaction
+			*/
+			journal_blocks /= 8;
+			credits = (1 << fs_param.s_log_groups_per_flex) * 4 +
+				  fs->super->s_reserved_gdt_blocks;
+			if (credits > journal_blocks) {
+				fprintf(stderr, "%s", _("Warning: Journal is "
+					"not big enough. In this configuration "
+					"the file system will not be able to "
+					"grow online!\n"));
+			}
+		}
 	}
 no_journal:
 	if (!super_only &&
tests/f_create_symlinks/expect +4 -4
index 096495c..e6c7bdd 100644
@@ -4,7 +4,7 @@ Pass 2: Checking directory structure
 Pass 3: Checking directory connectivity
 Pass 4: Checking reference counts
 Pass 5: Checking group summary information
-test_filesys: 11/128 files (0.0% non-contiguous), 441/1024 blocks
+test_filesys: 11/128 files (0.0% non-contiguous), 252/1024 blocks
 Exit status is 0
 debugfs -R "symlink /l_30 /xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" test.img
 debugfs -R "symlink /l_70 /xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" test.img
@@ -45,7 +45,7 @@ Links: 1   Blockcount: 2
 Fragment:  Address: 0    Number: 0    Size: 0
 Size of extra inode fields: 28
 EXTENTS:
-(0):153
+(0):90
 debugfs -R "stat /l_1023" test.img
 Inode: 15   Type: symlink    Mode:  0777   Flags: 0x80000
 Generation: 0    Version: 0x00000000:00000000
@@ -55,7 +55,7 @@ Links: 1   Blockcount: 2
 Fragment:  Address: 0    Number: 0    Size: 0
 Size of extra inode fields: 28
 EXTENTS:
-(0):154
+(0):91
 debugfs -R "stat /l_1024" test.img
 /l_1024: File not found by ext2_lookup 
 debugfs -R "stat /l_1500" test.img
@@ -65,5 +65,5 @@ Pass 2: Checking directory structure
 Pass 3: Checking directory connectivity
 Pass 4: Checking reference counts
 Pass 5: Checking group summary information
-test_filesys: 15/128 files (0.0% non-contiguous), 443/1024 blocks
+test_filesys: 15/128 files (0.0% non-contiguous), 254/1024 blocks
 Exit status is 0
tests/f_desc_size_bad/expect.1 +1 -1
index 009ee04..dd461a0 100644
@@ -7,5 +7,5 @@ Pass 4: Checking reference counts
 Pass 5: Checking group summary information
 
 test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
-test_filesys: 11/32 files (0.0% non-contiguous), 801/2048 blocks
+test_filesys: 11/32 files (0.0% non-contiguous), 225/2048 blocks
 Exit status is 1
tests/f_desc_size_bad/expect.2 +1 -1
index d1429fd..604869f 100644
@@ -3,5 +3,5 @@ Pass 2: Checking directory structure
 Pass 3: Checking directory connectivity
 Pass 4: Checking reference counts
 Pass 5: Checking group summary information
-test_filesys: 11/32 files (0.0% non-contiguous), 801/2048 blocks
+test_filesys: 11/32 files (0.0% non-contiguous), 225/2048 blocks
 Exit status is 0
tests/f_resize_inode/expect +22 -22

130 lines not on this page · raw message

tests/m_mkfs_overhead/script +1 -1
index c21da0c..e19e67e 100644
@@ -3,7 +3,7 @@ test_description="test bg overhead calculation"
 OUT=$test_name.log
 EXP=$test_dir/expect
 FS_SIZE=1024
-MKE2FS_OPTS="-b 1024 -m 0 -g 256 -N 3745"
+MKE2FS_OPTS="-b 1024 -m 0 -g 256 -N 4513"
 
 MKE2FS_SKIP_PROGRESS=true
 MKE2FS_SKIP_CHECK_MSG=true
tests/r_fixup_lastbg/expect +11 -11
index 96b154a..6514328 100644
@@ -8,16 +8,16 @@ Creating journal (1024 blocks): done
 Writing superblocks and filesystem accounting information:    done
 
 Group 2: (Blocks 16385-19999) [INODE_UNINIT, ITABLE_ZEROED]
-  Block bitmap at 83 (bg #0 + 82)
-  Inode bitmap at 86 (bg #0 + 85)
-  Inode table at 295-398 (bg #0 + 294)
+  Block bitmap at 69 (bg #0 + 68)
+  Inode bitmap at 72 (bg #0 + 71)
+  Inode table at 281-384 (bg #0 + 280)
   3615 free blocks, 416 free inodes, 0 directories, 416 unused inodes
   Free blocks: 16385-19999
   Free inodes: 833-1248
-Group 2: (Blocks 16385-19999)
-  Block bitmap at 83 (bg #0 + 82)
-  Inode bitmap at 86 (bg #0 + 85)
-  Inode table at 295-398 (bg #0 + 294)
+Group 2: (Blocks 16385-19999) (EXPECTED 0xe815)
+  Block bitmap at 69 (bg #0 + 68)
+  Inode bitmap at 72 (bg #0 + 71)
+  Inode table at 281-384 (bg #0 + 280)
   3615 free blocks, 416 free inodes, 0 directories
   Free blocks: 16385-19999
   Free inodes: 833-1248
@@ -25,9 +25,9 @@ Resizing the filesystem on test.img to 20004 (1k) blocks.
 The filesystem on test.img is now 20004 (1k) blocks long.
 
 Group 2: (Blocks 16385-20003) [INODE_UNINIT]
-  Block bitmap at 83 (bg #0 + 82)
-  Inode bitmap at 86 (bg #0 + 85)
-  Inode table at 295-398 (bg #0 + 294)
+  Block bitmap at 69 (bg #0 + 68)
+  Inode bitmap at 72 (bg #0 + 71)
+  Inode table at 281-384 (bg #0 + 280)
   3619 free blocks, 416 free inodes, 0 directories, 416 unused inodes
   Free blocks: 16385-20003
   Free inodes: 833-1248
@@ -36,4 +36,4 @@ Pass 2: Checking directory structure
 Pass 3: Checking directory connectivity
 Pass 4: Checking reference counts
 Pass 5: Checking group summary information
-test.img: 11/1248 files (0.0% non-contiguous), 1517/20004 blocks
+test.img: 11/1248 files (0.0% non-contiguous), 1489/20004 blocks
tests/r_fixup_lastbg_big/expect +13 -13
index edaabaf..3e87acf 100644
@@ -8,16 +8,16 @@ Creating journal (1024 blocks): done
 Writing superblocks and filesystem accounting information:    done
 
 Group 2: (Blocks 16385-19999) [INODE_UNINIT, ITABLE_ZEROED]
-  Block bitmap at 83 (bg #0 + 82)
-  Inode bitmap at 86 (bg #0 + 85)
-  Inode table at 295-398 (bg #0 + 294)
+  Block bitmap at 69 (bg #0 + 68)
+  Inode bitmap at 72 (bg #0 + 71)
+  Inode table at 281-384 (bg #0 + 280)
   3615 free blocks, 416 free inodes, 0 directories, 416 unused inodes
   Free blocks: 16385-19999
   Free inodes: 833-1248
-Group 2: (Blocks 16385-19999)
-  Block bitmap at 83 (bg #0 + 82)
-  Inode bitmap at 86 (bg #0 + 85)
-  Inode table at 295-398 (bg #0 + 294)
+Group 2: (Blocks 16385-19999) (EXPECTED 0xe815)
+  Block bitmap at 69 (bg #0 + 68)
+  Inode bitmap at 72 (bg #0 + 71)
+  Inode table at 281-384 (bg #0 + 280)
   3615 free blocks, 416 free inodes, 0 directories
   Free blocks: 16385-19999
   Free inodes: 833-1248
@@ -27,19 +27,19 @@ Extending the inode table     ----------------------------------------
 The filesystem on test.img is now 40000 (1k) blocks long.
 
 Group 2: (Blocks 16385-24576) [INODE_UNINIT, BLOCK_UNINIT]
-  Block bitmap at 83 (bg #0 + 82)
-  Inode bitmap at 86 (bg #0 + 85)
-  Inode table at 295-398 (bg #0 + 294)
+  Block bitmap at 69 (bg #0 + 68)
+  Inode bitmap at 72 (bg #0 + 71)
+  Inode table at 281-384 (bg #0 + 280)
   8192 free blocks, 416 free inodes, 0 directories, 416 unused inodes
   Free blocks: 16385-24576
   Free inodes: 833-1248
 Group 3: (Blocks 24577-32768) [INODE_UNINIT, ITABLE_ZEROED]
   Backup superblock at 24577, Group descriptors at 24578-24578
-  Reserved GDT blocks at 24579-24656
-  Block bitmap at 413 (bg #0 + 412)
+  Reserved GDT blocks at 24579-24642
+  Block bitmap at 399 (bg #0 + 398)
 Pass 1: Checking inodes, blocks, and sizes
 Pass 2: Checking directory structure
 Pass 3: Checking directory connectivity
 Pass 4: Checking reference counts
 Pass 5: Checking group summary information
-test.img: 11/2080 files (0.0% non-contiguous), 1809/40000 blocks
+test.img: 11/2080 files (0.0% non-contiguous), 1767/40000 blocks
tests/r_move_itable/expect +202 -202

684 lines not on this page · raw message

tests/r_resize_inode/expect +48 -48

163 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 49 lines · Lukas Czerner

Currently we're unable to online resize very small (smaller than 32 MB) file systems with 1k block size because there is not enough space in the journal to put all the reserved gdt blocks.

I tried to find solution in kernel which does not require to reserve journal credits for all the gdt blocks, but it looks like we have to have them all in journal to make sure that we atomically either change them all, or none.

So it leaves us with fixing the root cause which is the fact that mke2fs is setup by default so that it creates so many gdt blocks that it can't fit into the journal transaction.

Fix it by limiting the default number of reserved gdt blocks in the specific case of 1k bs and fs size < 32M. Note that it's still possible to create such file system by specifying non-default options so I've added mke2fs message that would warn users that would try to create such file system, but will still allow them to do so.

We still need to address the kernel problem where such file system would generate scary kernel warning, but that's for a separate patch.

Also fix output of some tests, because this change slightly alters the file system layout (specifically number of free blocks and number of reserved gdt blocks) on very small file systems.

---
 lib/ext2fs/initialize.c         |  23 +++
 misc/mke2fs.c                   |  28 +++
 tests/f_create_symlinks/expect  |   8 +-
 tests/f_desc_size_bad/expect.1  |   2 +-
 tests/f_desc_size_bad/expect.2  |   2 +-
 tests/f_resize_inode/expect     |  44 ++---
 tests/m_mkfs_overhead/script    |   2 +-
 tests/r_fixup_lastbg/expect     |  22 +--
 tests/r_fixup_lastbg_big/expect |  26 +--
 tests/r_move_itable/expect      | 404 ++++++++++++++++++++--------------------
 tests/r_resize_inode/expect     |  96 +++++-----
 11 files changed, 354 insertions(+), 303 deletions(-)
lib/ext2fs/initialize.c +0 -0
index 75fbf8e..0ef0e94 100644
@@ -71,6 +71,29 @@ static unsigned int calc_reserved_gdt_blocks(ext2_filsys fs)
 	 */
 	rsv_groups = ext2fs_div_ceil(max_blocks - sb->s_first_data_block, bpg);
 	rsv_gdb = ext2fs_div_ceil(rsv_groups, gdpb) - fs->desc_blocks;

lib/ext2fs/initialize.c static unsigned int calc_reserved_gdt_blocks(ext2_filsys fs) · line 83

Quoted 10 lines
lib/ext2fs/initialize.c +10 -0
+
+	/*
+	 * In online resize we require a huge number of journal
+	 * credits mainly because of the reserved_gdt_blocks. The
+	 * exact number of journal credits needed is:
+	 * flex_gd->count * 4 + reserved_gdb
+	 *
+	 * In order to allow online resize on file system with tiny
+	 * journal (tiny fs) we have to make the sure we have to
+	 * make sure

Some extra "making sure" in the above sentence. ;)

lib/ext2fs/initialize.c static unsigned int calc_reserved_gdt_blocks(ext2_filsys fs) · line 90

Quoted 8 lines
lib/ext2fs/initialize.c +7 -0
                   reserved_gdt_blocks is small enough. If the user
+	 * specifies non-default values he can still run into this issue
+	 * but we do not want to make that mistake by default.
+	 *
+	 * Magic numbers:
+	 * - At block count smaller than 32768, journal will be 1024 block
+	 *   blocks long which would not be enough by default.
+	 * - 64 reserved gtd blocks is maximum number we can fit into said

gtd? (gdt? gdb?)

lib/ext2fs/initialize.c static unsigned int calc_reserved_gdt_blocks(ext2_filsys fs) · line 91

Quoted 1 line
lib/ext2fs/initialize.c +1 -0
+	 *   journal by default (flex_bg_count * 4 + rsv_gdb)

This is a little confusing; "flex_bg_count" isn't a thing, and it seems to say that the reserved blocks depend on the number of reserved blocks?

I'm curious, why does this matter only for 1k blocks, and not, say 2k blocks?

Quoted 25 lines
lib/ext2fs/initialize.c +5 -0
+	 */
+	if ((fs->blocksize == 1024) && (ext2fs_blocks_count(sb) < 32768) &&
+	    (rsv_gdb > 64))
+		rsv_gdb = 64;
+
 	if (rsv_gdb > EXT2_ADDR_PER_BLOCK(sb))
 		rsv_gdb = EXT2_ADDR_PER_BLOCK(sb);

#ifdef RES_GDT_DEBUG

misc/mke2fs.c +9 -0
index aeb852f..e9edd3b 100644
@@ -3076,6 +3076,34 @@ int main (int argc, char *argv[])
 		}
 		if (!quiet)
 			printf("%s", _("done\n"));
+
+		/*
+		 * In online resize we require a huge number of journal
+		 * credits mainly because of the reserved_gdt_blocks. The
+		 * exact number of journal credits needed is:
+		 * flex_gd->count * 4 + reserved_gdb
+		 *
+		 * Warn user if we will not have enough credits to resize
+		 * the file system online.

misc/mke2fs.c int main (int argc, char *argv[]) · line 3097

Quoted 10 lines
misc/mke2fs.c +10 -0
+		 */
+		if (fs_param.s_feature_compat & EXT2_FEATURE_COMPAT_RESIZE_INODE)
+		{
+			unsigned int credits;
+
+			/*
+			* This is the amount we're allowed to use for a
+			* single handle in a transaction
+			*/
+			journal_blocks /= 8;

This seems a little dangerous; if someone decides to use journal_blocks later in the function, it might be unexpectedly smaller.

misc/mke2fs.c int main (int argc, char *argv[]) · line 3100

Quoted 3 lines
misc/mke2fs.c +3 -0
+			credits = (1 << fs_param.s_log_groups_per_flex) * 4 +
+				  fs->super->s_reserved_gdt_blocks;
+			if (credits > journal_blocks) {

so maybe just scale this by 8, i.e. "if (credits > journal_blocks/8)"

And actually, I find myself wondering if this same calculation can be used in calc_reserved_gdt_blocks, rather than using the magic numbers?

Thanks,
-Eric

Quoted 9 lines
misc/mke2fs.c +6 -0
+				fprintf(stderr, "%s", _("Warning: Journal is "
+					"not big enough. In this configuration "
+					"the file system will not be able to "
+					"grow online!\n"));
+			}
+		}
 	}
 no_journal:
 	if (!super_only &&
#2 lore raw
Quoted 60 lines · Eric Sandeen

Date: Mon, 02 Mar 2015 10:06:23 -0600
From: Eric Sandeen <[email protected]>
To: Lukas Czerner <[email protected]>, [email protected]
Subject: Re: [PATCH] e2fsprogs: Limit number of reserved gdt blocks on small
fs

Quoted 53 lines · Lukas Czerner

Currently we're unable to online resize very small (smaller than 32 MB) file systems with 1k block size because there is not enough space in the journal to put all the reserved gdt blocks.

I tried to find solution in kernel which does not require to reserve journal credits for all the gdt blocks, but it looks like we have to have them all in journal to make sure that we atomically either change them all, or none.

So it leaves us with fixing the root cause which is the fact that mke2fs is setup by default so that it creates so many gdt blocks that it can't fit into the journal transaction.

Fix it by limiting the default number of reserved gdt blocks in the specific case of 1k bs and fs size < 32M. Note that it's still possible to create such file system by specifying non-default options so I've added mke2fs message that would warn users that would try to create such file system, but will still allow them to do so.

We still need to address the kernel problem where such file system would generate scary kernel warning, but that's for a separate patch.

Also fix output of some tests, because this change slightly alters the file system layout (specifically number of free blocks and number of reserved gdt blocks) on very small file systems.

---
 lib/ext2fs/initialize.c         |  23 +++
 misc/mke2fs.c                   |  28 +++
 tests/f_create_symlinks/expect  |   8 +-
 tests/f_desc_size_bad/expect.1  |   2 +-
 tests/f_desc_size_bad/expect.2  |   2 +-
 tests/f_resize_inode/expect     |  44 ++---
 tests/m_mkfs_overhead/script    |   2 +-
 tests/r_fixup_lastbg/expect     |  22 +--
 tests/r_fixup_lastbg_big/expect |  26 +--
 tests/r_move_itable/expect      | 404 ++++++++++++++++++++--------------------
 tests/r_resize_inode/expect     |  96 +++++-----
 11 files changed, 354 insertions(+), 303 deletions(-)
lib/ext2fs/initialize.c +4 -0
index 75fbf8e..0ef0e94 100644
@@ -71,6 +71,29 @@ static unsigned int calc_reserved_gdt_blocks(ext2_filsys fs)
 	 */
 	rsv_groups = ext2fs_div_ceil(max_blocks - sb->s_first_data_block, bpg);
 	rsv_gdb = ext2fs_div_ceil(rsv_groups, gdpb) - fs->desc_blocks;
+
+	/*
+	 * In online resize we require a huge number of journal
+	 * credits mainly because of the reserved_gdt_blocks. The
Quoted 8 lines

lib/ext2fs/initialize.c static unsigned int calc_reserved_gdt_blocks(ext2_filsys fs)

Quoted 6 lines
lib/ext2fs/initialize.c +6 -0
+	 * exact number of journal credits needed is:
+	 * flex_gd->count * 4 + reserved_gdb
+	 *
+	 * In order to allow online resize on file system with tiny
+	 * journal (tiny fs) we have to make the sure we have to
+	 * make sure

Some extra "making sure" in the above sentence. ;)

Right, I'll fix that.

Quoted 11 lines

lib/ext2fs/initialize.c static unsigned int calc_reserved_gdt_blocks(ext2_filsys fs) · line 90

Quoted 9 lines
lib/ext2fs/initialize.c +7 -0
                   reserved_gdt_blocks is small enough. If the user
+	 * specifies non-default values he can still run into this issue
+	 * but we do not want to make that mistake by default.
+	 *
+	 * Magic numbers:
+	 * - At block count smaller than 32768, journal will be 1024 block
+	 *   blocks long which would not be enough by default.
+	 * - 64 reserved gtd blocks is maximum number we can fit into said

gtd? (gdt? gdb?)

Oh yes...

I'll try to use it consistently.

Quoted 5 lines

lib/ext2fs/initialize.c static unsigned int calc_reserved_gdt_blocks(ext2_filsys fs) · line 91

Quoted 2 lines
lib/ext2fs/initialize.c +1 -0
+	 *   journal by default (flex_bg_count * 4 + rsv_gdb)

This is a little confusing; "flex_bg_count" isn't a thing, and it seems to say that the reserved blocks depend on the number of reserved blocks?

Does it ? It says that number of journal credits depend on the number of reserved gdt blocks, or maybe I am missing something.

flex_bg_count is a number of groups in flex group, I'll try to come up with a better name.

Quoted 2 lines

I'm curious, why does this matter only for 1k blocks, and not, say 2k blocks?

That's because of the way we compute the number of reserved GDT blocks. The number of GDT blocks depends on the number of block groups, which depends on the number of blocks in the file system. And with 1k file system we have much more blocks. In fact we have:

- twice as many blocks as with 2k file system
- four times the block groups

And we can also fit only half of the number of group descriptors into a single block which means that we need twice as many blocks per block group.

Which means that with 1k file system we need 8 times as many gdt blocks as with 2k fs and 2048 times more gdt blocks as with 4k with the same setup.

Quoted 40 lines
Quoted 26 lines
lib/ext2fs/initialize.c +5 -0
+	 */
+	if ((fs->blocksize == 1024) && (ext2fs_blocks_count(sb) < 32768) &&
+	    (rsv_gdb > 64))
+		rsv_gdb = 64;
+
 	if (rsv_gdb > EXT2_ADDR_PER_BLOCK(sb))
 		rsv_gdb = EXT2_ADDR_PER_BLOCK(sb);

#ifdef RES_GDT_DEBUG

misc/mke2fs.c +9 -0
index aeb852f..e9edd3b 100644
@@ -3076,6 +3076,34 @@ int main (int argc, char *argv[])
 		}
 		if (!quiet)
 			printf("%s", _("done\n"));
+
+		/*
+		 * In online resize we require a huge number of journal
+		 * credits mainly because of the reserved_gdt_blocks. The
+		 * exact number of journal credits needed is:
+		 * flex_gd->count * 4 + reserved_gdb
+		 *
+		 * Warn user if we will not have enough credits to resize
+		 * the file system online.

misc/mke2fs.c int main (int argc, char *argv[]) · line 3097

Quoted 10 lines
misc/mke2fs.c +10 -0
+		 */
+		if (fs_param.s_feature_compat & EXT2_FEATURE_COMPAT_RESIZE_INODE)
+		{
+			unsigned int credits;
+
+			/*
+			* This is the amount we're allowed to use for a
+			* single handle in a transaction
+			*/
+			journal_blocks /= 8;

This seems a little dangerous; if someone decides to use journal_blocks later in the function, it might be unexpectedly smaller.

Quoted 5 lines

misc/mke2fs.c int main (int argc, char *argv[]) · line 3100

Quoted 3 lines
misc/mke2fs.c +3 -0
+			credits = (1 << fs_param.s_log_groups_per_flex) * 4 +
+				  fs->super->s_reserved_gdt_blocks;
+			if (credits > journal_blocks) {

so maybe just scale this by 8, i.e. "if (credits > journal_blocks/8)"

Fair enough, I'll change that.

Quoted 3 lines

And actually, I find myself wondering if this same calculation can be used in calc_reserved_gdt_blocks, rather than using the magic numbers?

Unfortunately it can not. At the time we're calculating number of gdt blocks we have no idea how big the journal will be.

And at the time we already know how big the journal will be we already have blocks allocated for the resize_inode so we can not just simply change s_reserved_gdt_blocks here.

Thanks!
-Lukas

Quoted 16 lines

Thanks,
-Eric

Quoted 9 lines
misc/mke2fs.c +6 -0
+				fprintf(stderr, "%s", _("Warning: Journal is "
+					"not big enough. In this configuration "
+					"the file system will not be able to "
+					"grow online!\n"));
+			}
+		}
 	}
 no_journal:
 	if (!super_only &&
#3 lore raw
Quoted 1 line · Lukáš Czerner

On Mon, 2 Mar 2015, Eric Sandeen wrote:

...

Quoted 16 lines
Quoted 1 line

Some extra "making sure" in the above sentence. ;)

Right, I'll fix that.

Quoted 11 lines

lib/ext2fs/initialize.c static unsigned int calc_reserved_gdt_blocks(ext2_filsys fs) · line 90

Quoted 9 lines

reserved_gdt_blocks is small enough. If the user

lib/ext2fs/initialize.c +7 -0
+	 * specifies non-default values he can still run into this issue
+	 * but we do not want to make that mistake by default.
+	 *
+	 * Magic numbers:
+	 * - At block count smaller than 32768, journal will be 1024 block
+	 *   blocks long which would not be enough by default.
+	 * - 64 reserved gtd blocks is maximum number we can fit into said

gtd? (gdt? gdb?)

Quoted 3 lines

Oh yes...

I'll try to use it consistently.

thanks :)

Quoted 11 lines
Quoted 5 lines

lib/ext2fs/initialize.c static unsigned int calc_reserved_gdt_blocks(ext2_filsys fs) · line 91

Quoted 2 lines
lib/ext2fs/initialize.c +1 -0
+	 *   journal by default (flex_bg_count * 4 + rsv_gdb)

This is a little confusing; "flex_bg_count" isn't a thing, and it seems to say that the reserved blocks depend on the number of reserved blocks?

Does it ? It says that number of journal credits depend on the number of reserved gdt blocks, or maybe I am missing something.

flex_bg_count is a number of groups in flex group, I'll try to come up with a better name.

It just looks like a variable name; it's one that doesn't exist, so it's not clear what you're talking about.

Quoted 71 lines
Quoted 2 lines

I'm curious, why does this matter only for 1k blocks, and not, say 2k blocks?

That's because of the way we compute the number of reserved GDT blocks. The number of GDT blocks depends on the number of block groups, which depends on the number of blocks in the file system. And with 1k file system we have much more blocks. In fact we have:

- twice as many blocks as with 2k file system
- four times the block groups

And we can also fit only half of the number of group descriptors into a single block which means that we need twice as many blocks per block group.

Which means that with 1k file system we need 8 times as many gdt blocks as with 2k fs and 2048 times more gdt blocks as with 4k with the same setup.

Quoted 40 lines
Quoted 26 lines
lib/ext2fs/initialize.c +5 -0
+	 */
+	if ((fs->blocksize == 1024) && (ext2fs_blocks_count(sb) < 32768) &&
+	    (rsv_gdb > 64))
+		rsv_gdb = 64;
+
 	if (rsv_gdb > EXT2_ADDR_PER_BLOCK(sb))
 		rsv_gdb = EXT2_ADDR_PER_BLOCK(sb);
 #ifdef RES_GDT_DEBUG
misc/mke2fs.c +9 -0
index aeb852f..e9edd3b 100644
@@ -3076,6 +3076,34 @@ int main (int argc, char *argv[])
 		}
 		if (!quiet)
 			printf("%s", _("done\n"));
+
+		/*
+		 * In online resize we require a huge number of journal
+		 * credits mainly because of the reserved_gdt_blocks. The
+		 * exact number of journal credits needed is:
+		 * flex_gd->count * 4 + reserved_gdb
+		 *
+		 * Warn user if we will not have enough credits to resize
+		 * the file system online.

misc/mke2fs.c int main (int argc, char *argv[]) · line 3097

Quoted 10 lines
misc/mke2fs.c +10 -0
+		 */
+		if (fs_param.s_feature_compat & EXT2_FEATURE_COMPAT_RESIZE_INODE)
+		{
+			unsigned int credits;
+
+			/*
+			* This is the amount we're allowed to use for a
+			* single handle in a transaction
+			*/
+			journal_blocks /= 8;

This seems a little dangerous; if someone decides to use journal_blocks later in the function, it might be unexpectedly smaller.

Quoted 5 lines

misc/mke2fs.c int main (int argc, char *argv[]) · line 3100

Quoted 3 lines
misc/mke2fs.c +3 -0
+			credits = (1 << fs_param.s_log_groups_per_flex) * 4 +
+				  fs->super->s_reserved_gdt_blocks;
+			if (credits > journal_blocks) {

so maybe just scale this by 8, i.e. "if (credits > journal_blocks/8)"

Fair enough, I'll change that.

Quoted 3 lines

And actually, I find myself wondering if this same calculation can be used in calc_reserved_gdt_blocks, rather than using the magic numbers?

Quoted 6 lines

Unfortunately it can not. At the time we're calculating number of gdt blocks we have no idea how big the journal will be.

And at the time we already know how big the journal will be we already have blocks allocated for the resize_inode so we can not just simply change s_reserved_gdt_blocks here.

Ugh. That sounds like a mess.

But it feels like we need centralized functions or macros that express the relationships between these values, rather than sprinkling "* 4" and "if 1024" around. It seems to have the potential to get out of sync, but I've only given it cursory thought...

-Eric
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
Quoted 127 lines · Eric Sandeen

Date: Mon, 02 Mar 2015 11:27:11 -0600
From: Eric Sandeen <[email protected]>
To: Lukáš Czerner <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH] e2fsprogs: Limit number of reserved gdt blocks on small
fs

Quoted 1 line · Lukáš Czerner

On Mon, 2 Mar 2015, Eric Sandeen wrote:

...

Quoted 16 lines
Quoted 1 line

Some extra "making sure" in the above sentence. ;)

Right, I'll fix that.

Quoted 11 lines

lib/ext2fs/initialize.c static unsigned int calc_reserved_gdt_blocks(ext2_filsys fs) · line 90

Quoted 9 lines

reserved_gdt_blocks is small enough. If the user

lib/ext2fs/initialize.c +7 -0
+	 * specifies non-default values he can still run into this issue
+	 * but we do not want to make that mistake by default.
+	 *
+	 * Magic numbers:
+	 * - At block count smaller than 32768, journal will be 1024 block
+	 *   blocks long which would not be enough by default.
+	 * - 64 reserved gtd blocks is maximum number we can fit into said

gtd? (gdt? gdb?)

Quoted 3 lines

Oh yes...

I'll try to use it consistently.

thanks :)

Quoted 11 lines
Quoted 5 lines

lib/ext2fs/initialize.c static unsigned int calc_reserved_gdt_blocks(ext2_filsys fs) · line 91

Quoted 2 lines
lib/ext2fs/initialize.c +1 -0
+	 *   journal by default (flex_bg_count * 4 + rsv_gdb)

This is a little confusing; "flex_bg_count" isn't a thing, and it seems to say that the reserved blocks depend on the number of reserved blocks?

Does it ? It says that number of journal credits depend on the number of reserved gdt blocks, or maybe I am missing something.

flex_bg_count is a number of groups in flex group, I'll try to come up with a better name.

It just looks like a variable name; it's one that doesn't exist, so it's not clear what you're talking about.

Quoted 71 lines
Quoted 2 lines

I'm curious, why does this matter only for 1k blocks, and not, say 2k blocks?

That's because of the way we compute the number of reserved GDT blocks. The number of GDT blocks depends on the number of block groups, which depends on the number of blocks in the file system. And with 1k file system we have much more blocks. In fact we have:

- twice as many blocks as with 2k file system
- four times the block groups

And we can also fit only half of the number of group descriptors into a single block which means that we need twice as many blocks per block group.

Which means that with 1k file system we need 8 times as many gdt blocks as with 2k fs and 2048 times more gdt blocks as with 4k with the same setup.

Quoted 40 lines
Quoted 26 lines
lib/ext2fs/initialize.c +5 -0
+	 */
+	if ((fs->blocksize == 1024) && (ext2fs_blocks_count(sb) < 32768) &&
+	    (rsv_gdb > 64))
+		rsv_gdb = 64;
+
 	if (rsv_gdb > EXT2_ADDR_PER_BLOCK(sb))
 		rsv_gdb = EXT2_ADDR_PER_BLOCK(sb);
 #ifdef RES_GDT_DEBUG
misc/mke2fs.c +9 -0
index aeb852f..e9edd3b 100644
@@ -3076,6 +3076,34 @@ int main (int argc, char *argv[])
 		}
 		if (!quiet)
 			printf("%s", _("done\n"));
+
+		/*
+		 * In online resize we require a huge number of journal
+		 * credits mainly because of the reserved_gdt_blocks. The
+		 * exact number of journal credits needed is:
+		 * flex_gd->count * 4 + reserved_gdb
+		 *
+		 * Warn user if we will not have enough credits to resize
+		 * the file system online.

misc/mke2fs.c int main (int argc, char *argv[]) · line 3097

Quoted 10 lines
misc/mke2fs.c +10 -0
+		 */
+		if (fs_param.s_feature_compat & EXT2_FEATURE_COMPAT_RESIZE_INODE)
+		{
+			unsigned int credits;
+
+			/*
+			* This is the amount we're allowed to use for a
+			* single handle in a transaction
+			*/
+			journal_blocks /= 8;

This seems a little dangerous; if someone decides to use journal_blocks later in the function, it might be unexpectedly smaller.

Quoted 5 lines

misc/mke2fs.c int main (int argc, char *argv[]) · line 3100

Quoted 3 lines
misc/mke2fs.c +3 -0
+			credits = (1 << fs_param.s_log_groups_per_flex) * 4 +
+				  fs->super->s_reserved_gdt_blocks;
+			if (credits > journal_blocks) {

so maybe just scale this by 8, i.e. "if (credits > journal_blocks/8)"

Fair enough, I'll change that.

Quoted 3 lines

And actually, I find myself wondering if this same calculation can be used in calc_reserved_gdt_blocks, rather than using the magic numbers?

Quoted 6 lines

Unfortunately it can not. At the time we're calculating number of gdt blocks we have no idea how big the journal will be.

And at the time we already know how big the journal will be we already have blocks allocated for the resize_inode so we can not just simply change s_reserved_gdt_blocks here.

Quoted 6 lines

Ugh. That sounds like a mess.

But it feels like we need centralized functions or macros that express the relationships between these values, rather than sprinkling "* 4" and "if 1024" around. It seems to have the potential to get out of sync, but I've only given it cursory thought...

Yes, but that would require huge amount of rewrite I think. Mostly we're trying to think of the dependencies between various file system features and/or parameters. I think it's mostly in main() and PRS() functions however this "dependency" is entirely unexpected.

I tried to think about a better way where to put it, but this is what I came with. However maybe we can determine the journal size by ext2fs_default_journal_size() and use the default journal size instead ?

-Lukas

Quoted 3 lines

-Eric