e2fsprogs: Limit number of reserved gdt blocks on small fs
PATCH v2 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 case that it would not fit in the journal transaction by default. 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 | 31 ++++++++++++- misc/mke2fs.c | 27 ++++++++++++ tests/d_loaddump/script | 2 +- 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_resize_inode/expect | 96 ++++++++++++++++++++--------------------- 10 files changed, 154 insertions(+), 100 deletions(-)
lib/ext2fs/initialize.c +29 -2
@@ -59,18 +59,45 @@ static unsigned int calc_reserved_gdt_blocks(ext2_filsys fs)unsigned long max_blocks =0xffffffff ;unsigned long rsv_groups;unsigned int rsv_gdb; +__u64 blocks_count; +int journal_blocks, credits; + + blocks_count =ext2fs_blocks_count (sb); + journal_blocks =ext2fs_default_journal_size (blocks_count);/* We set it at 1024x the current filesystem size, or * the upper block count limit (2^32), whichever is lower. */ -if (ext2fs_blocks_count (sb) < max_blocks /1024 ) - max_blocks =ext2fs_blocks_count (sb) *1024 ; +if (blocks_count < max_blocks /1024 ) + max_blocks = blocks_count *1024 ;/* * ext2fs_div64_ceil() is unnecessary because max_blocks is * max _GDT_ blocks, which is limited to 32 bits. */ 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 sure that the number of +* 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. +* +* journal_blocks / 8 is the maximum amount of credits we're allowed +* to use in a single transaction. +* +*/ + credits = (1 << fs->super->s_log_groups_per_flex) *4 + rsv_gdb; +if (journal_blocks >0 && credits > journal_blocks /8 ) + rsv_gdb = (journal_blocks /8 ) - + (1 << fs->super->s_log_groups_per_flex) *4 ; +if (rsv_gdb >EXT2_ADDR_PER_BLOCK (sb)) rsv_gdb =EXT2_ADDR_PER_BLOCK (sb);#ifdef RES_GDT_DEBUG
misc/mke2fs.c +27 -0
@@ -3076,6 +3076,33 @@ 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 +*/ + credits = (1 << fs_param.s_log_groups_per_flex) *4 + + fs->super->s_reserved_gdt_blocks; +if (credits > journal_blocks /8 ) { +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/d_loaddump/script +1 -1
@@ -13,7 +13,7 @@ dd if=/dev/zero of=$TMPFILE bs=1k count=512 > /dev/null 2>&1 echo "mke2fs -Fq -b 1024 test.img 512" >> $OUT -$MKE2FS -Fq $TMPFILE 512 > /dev/null 2>&1 +$MKE2FS -Fq $TMPFILE 512 status=$? echo Exit status is $status >> $OUT
tests/f_desc_size_bad/expect.1 +1 -1
@@ -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), 405/2048 blocks Exit status is 1
tests/f_desc_size_bad/expect.2 +1 -1
@@ -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), 405/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
@@ -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
@@ -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
@@ -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_resize_inode/expect +48 -48
163 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Quoted 3 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.
So, I'll get to the patch review if I need to, but this all seemed a little odd; this is a regression, so do we really need to restrict things at mkfs time?
On the userspace side, things were ok until:
9f6ba88 resize2fs: add support for new in-kernel online resize ioctl
and even with that, on the kernelspace side, things were ok until:
8f7d89f jbd2: transaction reservation support
I guess I'm trying to understand why that jbd2 commit regressed this. I've not been paying enough attention to ext4 lately. ;)
I mean, the threshold got chopped in half:
- if (nblocks > journal->j_max_transaction_buffers) {
+ /*
+ * 1/2 of transaction can be reserved so we can practically handle
+ * only 1/2 of maximum transaction size per operation
+ */
+ if (WARN_ON(blocks > journal->j_max_transaction_buffers / 2)) {
printk(KERN_ERR "JBD2: %s wants too many credits (%d > %d)\n",
- current->comm, nblocks,
- journal->j_max_transaction_buffers);
+ current->comm, blocks,
+ journal->j_max_transaction_buffers / 2);
return -ENOSPC;
}so it's clear why the behavior changed, I guess, but it feels like I must be missing something here.
The reproducer, for those playing along at home, is something like:
mkfs.ext4 /dev/sda 20M
mount /dev/sda /mnt/test
resize2fs /dev/sda 200M
-Eric
Quoted 36 lines · Eric Sandeen
Quoted 3 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.
So, I'll get to the patch review if I need to, but this all seemed a little odd; this is a regression, so do we really need to restrict things at mkfs time?
On the userspace side, things were ok until:
9f6ba88 resize2fs: add support for new in-kernel online resize ioctl
and even with that, on the kernelspace side, things were ok until:
8f7d89f jbd2: transaction reservation support
I guess I'm trying to understand why that jbd2 commit regressed this. I've not been paying enough attention to ext4 lately. ;)
I mean, the threshold got chopped in half:
(quoted diff) +7
-3- if (nblocks > journal->j_max_transaction_buffers) { + /* + * 1/2 of transaction can be reserved so we can practically handle + * only 1/2 of maximum transaction size per operation + */ + if (WARN_ON(blocks > journal->j_max_transaction_buffers / 2)) { printk(KERN_ERR "JBD2: %s wants too many credits (%d > %d)\n", - current->comm, nblocks, - journal->j_max_transaction_buffers); + current->comm, blocks, + journal->j_max_transaction_buffers / 2); return -ENOSPC; }
Quoted 2 lines
so it's clear why the behavior changed, I guess, but it feels like I must be missing something here.
Is there some way to reserve these journal blocks only in the case of delalloc usage? This has caused a performance regression with Lustre servers on 3.10 kernels because the journal commits twice as often. We've worked around this for now by doubling the journal size, but it seems a bit of a hack since we can never use the whole journal anymore.
Quoted 6 lines
The reproducer, for those playing along at home, is something like:
mkfs.ext4
/dev/sda20M
mount/dev/sda/mnt/test
resize2fs/dev/sda200M
Quoted 7 lines
-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
Cheers, Andreas
Jan Kara
reviewerQuoted 37 lines · Andreas Dilger
Quoted 36 lines · Eric Sandeen
Quoted 3 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.
So, I'll get to the patch review if I need to, but this all seemed a little odd; this is a regression, so do we really need to restrict things at mkfs time?
On the userspace side, things were ok until:
9f6ba88 resize2fs: add support for new in-kernel online resize ioctl
and even with that, on the kernelspace side, things were ok until:
8f7d89f jbd2: transaction reservation support
I guess I'm trying to understand why that jbd2 commit regressed this. I've not been paying enough attention to ext4 lately. ;)
I mean, the threshold got chopped in half:
(quoted diff) +7
-3- if (nblocks > journal->j_max_transaction_buffers) { + /* + * 1/2 of transaction can be reserved so we can practically handle + * only 1/2 of maximum transaction size per operation + */ + if (WARN_ON(blocks > journal->j_max_transaction_buffers / 2)) { printk(KERN_ERR "JBD2: %s wants too many credits (%d > %d)\n", - current->comm, nblocks, - journal->j_max_transaction_buffers); + current->comm, blocks, + journal->j_max_transaction_buffers / 2); return -ENOSPC; }
Quoted 8 lines
Quoted 2 lines
so it's clear why the behavior changed, I guess, but it feels like I must be missing something here.
Is there some way to reserve these journal blocks only in the case of delalloc usage? This has caused a performance regression with Lustre servers on 3.10 kernels because the journal commits twice as often. We've worked around this for now by doubling the journal size, but it seems a bit of a hack since we can never use the whole journal anymore.
Hum, so the above hunk only limits maximum number of credits used by a
single handle. Multiple handles can still consume upto maximum transaction size buffers (at least that's the intention :). So I don't see how that can cause the problem you describe. What can happen though is that there are quite a few outstanding reserved handles and so we have to reserve space for them in the running transaction. Do you use dioread_nolock option? That enables the use of reserved handles in ext4 for conversion of unwritten extents...
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 46 lines · Jan Kara
Quoted 37 lines · Andreas Dilger
Quoted 36 lines · Eric Sandeen
Quoted 3 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.
So, I'll get to the patch review if I need to, but this all seemed a little odd; this is a regression, so do we really need to restrict things at mkfs time?
On the userspace side, things were ok until:
9f6ba88 resize2fs: add support for new in-kernel online resize ioctl
and even with that, on the kernelspace side, things were ok until:
8f7d89f jbd2: transaction reservation support
I guess I'm trying to understand why that jbd2 commit regressed this. I've not been paying enough attention to ext4 lately. ;)
I mean, the threshold got chopped in half:
(quoted diff) +7
-3- if (nblocks > journal->j_max_transaction_buffers) { + /* + * 1/2 of transaction can be reserved so we can practically handle + * only 1/2 of maximum transaction size per operation + */ + if (WARN_ON(blocks > journal->j_max_transaction_buffers / 2)) { printk(KERN_ERR "JBD2: %s wants too many credits (%d > %d)\n", - current->comm, nblocks, - journal->j_max_transaction_buffers); + current->comm, blocks, + journal->j_max_transaction_buffers / 2); return -ENOSPC; }Quoted 8 lines
Quoted 2 lines
so it's clear why the behavior changed, I guess, but it feels like I must be missing something here.
Is there some way to reserve these journal blocks only in the case of delalloc usage? This has caused a performance regression with Lustre servers on 3.10 kernels because the journal commits twice as often. We've worked around this for now by doubling the journal size, but it seems a bit of a hack since we can never use the whole journal anymore.
Quoted 8 lines
Hum, so the above hunk only limits maximum number of credits used by a
single handle. Multiple handles can still consume upto maximum transaction size buffers (at least that's the intention :). So I don't see how that can cause the problem you describe. What can happen though is that there are quite a few outstanding reserved handles and so we have to reserve space for them in the running transaction. Do you usedioread_nolockoption? That enables the use of reserved handles in ext4 for conversion of unwritten extents...
You're probably asking Andreas, but just in case, for my testcase, it's all defaults & standard options.
i.e. just this fails, after the above commit, whereas it worked before.
mkfs.ext4 /dev/sda 20M
mount /dev/sda /mnt/test
resize2fs /dev/sda 200M
-Eric
Jan Kara
reviewerQuoted 56 lines · Eric Sandeen
Quoted 46 lines · Jan Kara
Quoted 37 lines · Andreas Dilger
Quoted 36 lines · Eric Sandeen
Quoted 3 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.
So, I'll get to the patch review if I need to, but this all seemed a little odd; this is a regression, so do we really need to restrict things at mkfs time?
On the userspace side, things were ok until:
9f6ba88 resize2fs: add support for new in-kernel online resize ioctl
and even with that, on the kernelspace side, things were ok until:
8f7d89f jbd2: transaction reservation support
I guess I'm trying to understand why that jbd2 commit regressed this. I've not been paying enough attention to ext4 lately. ;)
I mean, the threshold got chopped in half:
(quoted diff) +7
-3- if (nblocks > journal->j_max_transaction_buffers) { + /* + * 1/2 of transaction can be reserved so we can practically handle + * only 1/2 of maximum transaction size per operation + */ + if (WARN_ON(blocks > journal->j_max_transaction_buffers / 2)) { printk(KERN_ERR "JBD2: %s wants too many credits (%d > %d)\n", - current->comm, nblocks, - journal->j_max_transaction_buffers); + current->comm, blocks, + journal->j_max_transaction_buffers / 2); return -ENOSPC; }Quoted 8 lines
Quoted 2 lines
so it's clear why the behavior changed, I guess, but it feels like I must be missing something here.
Is there some way to reserve these journal blocks only in the case of delalloc usage? This has caused a performance regression with Lustre servers on 3.10 kernels because the journal commits twice as often. We've worked around this for now by doubling the journal size, but it seems a bit of a hack since we can never use the whole journal anymore.
Quoted 8 lines
Hum, so the above hunk only limits maximum number of credits used by a
single handle. Multiple handles can still consume upto maximum transaction size buffers (at least that's the intention :). So I don't see how that can cause the problem you describe. What can happen though is that there are quite a few outstanding reserved handles and so we have to reserve space for them in the running transaction. Do you usedioread_nolockoption? That enables the use of reserved handles in ext4 for conversion of unwritten extents...
Quoted 8 lines
You're probably asking Andreas, but just in case, for my testcase, it's all defaults & standard options.
i.e. just this fails, after the above commit, whereas it worked before.
mkfs.ext4
/dev/sda20M
mount/dev/sda/mnt/test
resize2fs/dev/sda200M
Yeah, I understand your failure - transaction reservation has reduced
max transaction size to a half. After that your fs resize exceeds max transaction size and we are in trouble. I'd prefer solution for that to be in resize code though because it's really a corner case and I wouldn't like to slow down the common transaction start path for it...
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 70 lines · Jan Kara
Date: Tue, 28 Apr 2015 14:21:02 +0200
From: Jan Kara <[email protected]>
To: Eric Sandeen <[email protected]>
Cc: Jan Kara <[email protected]>, Andreas Dilger <[email protected]>,
Lukas Czerner <[email protected]>, [email protected]
Subject: Re: [PATCH v2] e2fsprogs: Limit number of reserved gdt blocks on
small fsQuoted 61 lines · Eric Sandeen
Quoted 46 lines · Jan Kara
Quoted 37 lines · Andreas Dilger
Quoted 36 lines · Eric Sandeen
Quoted 3 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.
So, I'll get to the patch review if I need to, but this all seemed a little odd; this is a regression, so do we really need to restrict things at mkfs time?
On the userspace side, things were ok until:
9f6ba88 resize2fs: add support for new in-kernel online resize ioctl
and even with that, on the kernelspace side, things were ok until:
8f7d89f jbd2: transaction reservation support
I guess I'm trying to understand why that jbd2 commit regressed this. I've not been paying enough attention to ext4 lately. ;)
I mean, the threshold got chopped in half:
(quoted diff) +7
-3- if (nblocks > journal->j_max_transaction_buffers) { + /* + * 1/2 of transaction can be reserved so we can practically handle + * only 1/2 of maximum transaction size per operation + */ + if (WARN_ON(blocks > journal->j_max_transaction_buffers / 2)) { printk(KERN_ERR "JBD2: %s wants too many credits (%d > %d)\n", - current->comm, nblocks, - journal->j_max_transaction_buffers); + current->comm, blocks, + journal->j_max_transaction_buffers / 2); return -ENOSPC; }Quoted 8 lines
Quoted 2 lines
so it's clear why the behavior changed, I guess, but it feels like I must be missing something here.
Is there some way to reserve these journal blocks only in the case of delalloc usage? This has caused a performance regression with Lustre servers on 3.10 kernels because the journal commits twice as often. We've worked around this for now by doubling the journal size, but it seems a bit of a hack since we can never use the whole journal anymore.
Quoted 8 lines
Hum, so the above hunk only limits maximum number of credits used by a
single handle. Multiple handles can still consume upto maximum transaction size buffers (at least that's the intention :). So I don't see how that can cause the problem you describe. What can happen though is that there are quite a few outstanding reserved handles and so we have to reserve space for them in the running transaction. Do you usedioread_nolockoption? That enables the use of reserved handles in ext4 for conversion of unwritten extents...You're probably asking Andreas, but just in case, for my testcase, it's all defaults & standard options.
i.e. just this fails, after the above commit, whereas it worked before.
Quoted 8 lines
Quoted 3 lines
mkfs.ext4
/dev/sda20M
mount/dev/sda/mnt/test
resize2fs/dev/sda200MYeah, I understand your failure - transaction reservation has reduced
max transaction size to a half. After that your fs resize exceeds max transaction size and we are in trouble. I'd prefer solution for that to be in resize code though because it's really a corner case and I wouldn't like to slow down the common transaction start path for it...
Hi Jan,
if you have not already, please see the patch which started the discussion.
Also I think that aside from the userspace fix, I need to add some safety to the kernel as well so that people who do run into this know what's going on.
Thanks!
-Lukas
Quoted 3 lines
Honza
Quoted 81 lines · Lukáš Czerner
Quoted 70 lines · Jan Kara
Date: Tue, 28 Apr 2015 14:21:02 +0200
From: Jan Kara <[email protected]>
To: Eric Sandeen <[email protected]>
Cc: Jan Kara <[email protected]>, Andreas Dilger <[email protected]>,
Lukas Czerner <[email protected]>, [email protected]
Subject: Re: [PATCH v2] e2fsprogs: Limit number of reserved gdt blocks on
small fsQuoted 61 lines · Eric Sandeen
Quoted 46 lines · Jan Kara
Quoted 37 lines · Andreas Dilger
Quoted 36 lines · Eric Sandeen
Quoted 3 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.
So, I'll get to the patch review if I need to, but this all seemed a little odd; this is a regression, so do we really need to restrict things at mkfs time?
On the userspace side, things were ok until:
9f6ba88 resize2fs: add support for new in-kernel online resize ioctl
and even with that, on the kernelspace side, things were ok until:
8f7d89f jbd2: transaction reservation support
I guess I'm trying to understand why that jbd2 commit regressed this. I've not been paying enough attention to ext4 lately. ;)
I mean, the threshold got chopped in half:
(quoted diff) +7
-3- if (nblocks > journal->j_max_transaction_buffers) { + /* + * 1/2 of transaction can be reserved so we can practically handle + * only 1/2 of maximum transaction size per operation + */ + if (WARN_ON(blocks > journal->j_max_transaction_buffers / 2)) { printk(KERN_ERR "JBD2: %s wants too many credits (%d > %d)\n", - current->comm, nblocks, - journal->j_max_transaction_buffers); + current->comm, blocks, + journal->j_max_transaction_buffers / 2); return -ENOSPC; }Quoted 8 lines
Quoted 2 lines
so it's clear why the behavior changed, I guess, but it feels like I must be missing something here.
Is there some way to reserve these journal blocks only in the case of delalloc usage? This has caused a performance regression with Lustre servers on 3.10 kernels because the journal commits twice as often. We've worked around this for now by doubling the journal size, but it seems a bit of a hack since we can never use the whole journal anymore.
Quoted 8 lines
Hum, so the above hunk only limits maximum number of credits used by a
single handle. Multiple handles can still consume upto maximum transaction size buffers (at least that's the intention :). So I don't see how that can cause the problem you describe. What can happen though is that there are quite a few outstanding reserved handles and so we have to reserve space for them in the running transaction. Do you usedioread_nolockoption? That enables the use of reserved handles in ext4 for conversion of unwritten extents...You're probably asking Andreas, but just in case, for my testcase, it's all defaults & standard options.
i.e. just this fails, after the above commit, whereas it worked before.
Quoted 8 lines
Quoted 3 lines
mkfs.ext4
/dev/sda20M
mount/dev/sda/mnt/test
resize2fs/dev/sda200MYeah, I understand your failure - transaction reservation has reduced
max transaction size to a half. After that your fs resize exceeds max transaction size and we are in trouble. I'd prefer solution for that to be in resize code though because it's really a corner case and I wouldn't like to slow down the common transaction start path for it...
Quoted 4 lines
Hi Jan,
if you have not already, please see the patch which started the discussion.
It just doesn't feel right to me to place limits on fs geometry for this reason. We could, but it seems like a stopgap. Can we modify the resize code so that it doesn't need such a large transaction?
In the "old" resize world, I think we played tricks with restarting transactions, because until the resize was complete and superblocks were updated, it was ok if we lost updates to new block groups (or something like that...) i.e. we didn't need one giant atomic update of the filesystem.
Maybe we can do something similar here? I've kind of lost track of how resize is working now, TBH.
-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
Jan Kara
reviewerQuoted 91 lines · Eric Sandeen
Quoted 81 lines · Lukáš Czerner
Quoted 70 lines · Jan Kara
Date: Tue, 28 Apr 2015 14:21:02 +0200
From: Jan Kara <[email protected]>
To: Eric Sandeen <[email protected]>
Cc: Jan Kara <[email protected]>, Andreas Dilger <[email protected]>,
Lukas Czerner <[email protected]>, [email protected]
Subject: Re: [PATCH v2] e2fsprogs: Limit number of reserved gdt blocks on
small fsQuoted 61 lines · Eric Sandeen
Quoted 46 lines · Jan Kara
Quoted 37 lines · Andreas Dilger
Quoted 36 lines · Eric Sandeen
Quoted 3 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.
So, I'll get to the patch review if I need to, but this all seemed a little odd; this is a regression, so do we really need to restrict things at mkfs time?
On the userspace side, things were ok until:
9f6ba88 resize2fs: add support for new in-kernel online resize ioctl
and even with that, on the kernelspace side, things were ok until:
8f7d89f jbd2: transaction reservation support
I guess I'm trying to understand why that jbd2 commit regressed this. I've not been paying enough attention to ext4 lately. ;)
I mean, the threshold got chopped in half:
(quoted diff) +7
-3- if (nblocks > journal->j_max_transaction_buffers) { + /* + * 1/2 of transaction can be reserved so we can practically handle + * only 1/2 of maximum transaction size per operation + */ + if (WARN_ON(blocks > journal->j_max_transaction_buffers / 2)) { printk(KERN_ERR "JBD2: %s wants too many credits (%d > %d)\n", - current->comm, nblocks, - journal->j_max_transaction_buffers); + current->comm, blocks, + journal->j_max_transaction_buffers / 2); return -ENOSPC; }Quoted 8 lines
Quoted 2 lines
so it's clear why the behavior changed, I guess, but it feels like I must be missing something here.
Is there some way to reserve these journal blocks only in the case of delalloc usage? This has caused a performance regression with Lustre servers on 3.10 kernels because the journal commits twice as often. We've worked around this for now by doubling the journal size, but it seems a bit of a hack since we can never use the whole journal anymore.
Quoted 8 lines
Hum, so the above hunk only limits maximum number of credits used by a
single handle. Multiple handles can still consume upto maximum transaction size buffers (at least that's the intention :). So I don't see how that can cause the problem you describe. What can happen though is that there are quite a few outstanding reserved handles and so we have to reserve space for them in the running transaction. Do you usedioread_nolockoption? That enables the use of reserved handles in ext4 for conversion of unwritten extents...You're probably asking Andreas, but just in case, for my testcase, it's all defaults & standard options.
i.e. just this fails, after the above commit, whereas it worked before.
Quoted 8 lines
Quoted 3 lines
mkfs.ext4
/dev/sda20M
mount/dev/sda/mnt/test
resize2fs/dev/sda200MYeah, I understand your failure - transaction reservation has reduced
max transaction size to a half. After that your fs resize exceeds max transaction size and we are in trouble. I'd prefer solution for that to be in resize code though because it's really a corner case and I wouldn't like to slow down the common transaction start path for it...Quoted 4 lines
Hi Jan,
if you have not already, please see the patch which started the discussion.
It just doesn't feel right to me to place limits on fs geometry for this reason. We could, but it seems like a stopgap. Can we modify the resize code so that it doesn't need such a large transaction?
Quoted 7 lines
In the "old" resize world, I think we played tricks with restarting transactions, because until the resize was complete and superblocks were updated, it was ok if we lost updates to new block groups (or something like that...) i.e. we didn't need one giant atomic update of the filesystem.
Maybe we can do something similar here? I've kind of lost track of how resize is working now, TBH.
Well, the fact is we have to limit some fs parameters so that code can be
reasonably simple. IMO already supporting 20 MB filesystem with a journal is a stretch and choice of number of reserved blocks looks arbitrary but I guess we shouldn't regress if possible.
So 20 MB filesystem will get 1 MB journal. That means j_max_transaction_size 256 and thus we allow at most 128 credits in a single handle. The filesystem has 79 reserved GDT blocks and flex group size 16 so when resizing to 200 MB when adding full flex group, the resize code in ext4_flex_group_add() wants a handle with 4*16 + 79 credits which is too much (143).
That being said the calculation in ext4_flex_group_add() looks too pessimistic (in the flex_gd->count * 4 part). Sure we need to modify resize inode and its dindirect block but that's common for all the groups, similarly for superblock so we can change that to (3 + flex_gd->count) and even that is too pessimistic since we have EXT4_DESC_PER_BLOCK(sb) descriptors in one block. So we could shrink it to (3 + 1 + (flex_gd->count + EXT4_DESC_PER_BLOCK(sb) - 1) / EXT4_DESC_PER_BLOCK(sb)). That will shrink the total credit estimate down to 84 for that filesystem.
The attached patch fixes the issue for me. Thoughts?
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 1 line
From
37ecb96f1ab1e57bc5c1663c1662d658df2f84fdMon Sep 17 00:00:00 2001
From: Jan Kara <[email protected]>
Date: Wed, 29 Apr 2015 11:46:31 +0200
Subject: [PATCH] ext4: Fix growing of tiny filesystems
The estimate of necessary transaction credits in ext4_flex_group_add() is too pessimistic. It reserves credit for sb, resize inode, and resize inode dindirect block for each group added in a flex group although they are always the same block and thus it is enough to account them only once. Also the number of modified GDT block is overestimated since we fit EXT4_DESC_PER_BLOCK(sb) descriptors in one block.
Make the estimation more precise. That reduces number of requested credits enough that we can grow 20 MB filesystem (which has 1 MB journal, 79 reserved GDT blocks, and flex group size 16 by default).
--- fs/ext4/resize.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
fs/ext4/resize.c +5 -2
@@ -1432,12 +1432,15 @@ static int ext4_flex_group_add(struct super_block *sb, goto exit;/* * We will always be modifying at least the superblock and GDT -* block. If we are adding a group past the last current GDT block, +* blocks. If we are adding a group past the last current GDT block, * we will also modify the inode and the dindirect block. If we * are adding a group with superblock/GDT backups we will also * modify each of the reserved GDT dindirect blocks. */ - credit = flex_gd->count *4 + reserved_gdb; + credit =3 ;/* sb, resize inode, resize inode dindirect */ + credit +=1 + (flex_gd->count +EXT4_DESC_PER_BLOCK (sb) -1 ) / +EXT4_DESC_PER_BLOCK (sb);/* GDT blocks */ + credit += reserved_gdb;/* Reserved GDT dindirect blocks */ handle =ext4_journal_start_sb (sb,EXT4_HT_RESIZE , credit);if (IS_ERR (handle)) { err =PTR_ERR (handle);
Signature · 1 line
2.1.4
Quoted 1 line · Jan Kara
On Tue 28-04-15 10:46:12, Eric Sandeen wrote:
...
Quoted 7 lines
Quoted 2 lines
Maybe we can do something similar here? I've kind of lost track of how resize is working now, TBH.
Well, the fact is we have to limit some fs parameters so that code can be
reasonably simple. IMO already supporting 20 MB filesystem with a journal is a stretch and choice of number of reserved blocks looks arbitrary but I guess we shouldn't regress if possible.
Quoted 6 lines
So 20 MB filesystem will get 1 MB journal. That means
j_max_transaction_size256 and thus we allow at most 128 credits in a single handle. The filesystem has 79 reserved GDT blocks and flex group size 16 so when resizing to 200 MB when adding full flex group, the resize code inext4_flex_group_add()wants a handle with 4*16 + 79 credits which is too much (143).
*nod*
Quoted 9 lines
That being said the calculation in
ext4_flex_group_add()looks too pessimistic (in theflex_gd->count* 4 part). Sure we need to modify resize inode and its dindirect block but that's common for all the groups, similarly for superblock so we can change that to (3 +flex_gd->count) and even that is too pessimistic since we haveEXT4_DESC_PER_BLOCK(sb)descriptors in one block. So we could shrink it to (3 + 1 + (flex_gd->count+EXT4_DESC_PER_BLOCK(sb)- 1) /EXT4_DESC_PER_BLOCK(sb)). That will shrink the total credit estimate down to 84 for that filesystem.
Quoted 3 lines
The attached patch fixes the issue for me. Thoughts?
Honza
I think I'm glad you understand it better than me. :) I was surprised at the large reservation but hadn't worked out why it was a problem.
Quoted 27 lines
From
37ecb96f1ab1e57bc5c1663c1662d658df2f84fdMon Sep 17 00:00:00 2001
From: Jan Kara <[email protected]>
Date: Wed, 29 Apr 2015 11:46:31 +0200
Subject: [PATCH] ext4: Fix growing of tiny filesystemsThe estimate of necessary transaction credits in
ext4_flex_group_add()is too pessimistic. It reserves credit for sb, resize inode, and resize inode dindirect block for each group added in a flex group although they are always the same block and thus it is enough to account them only once. Also the number of modified GDT block is overestimated since we fitEXT4_DESC_PER_BLOCK(sb)descriptors in one block.Make the estimation more precise. That reduces number of requested credits enough that we can grow 20 MB filesystem (which has 1 MB journal, 79 reserved GDT blocks, and flex group size 16 by default).
Signed-off-by Jan Kara <[email protected]>--- fs/ext4/resize.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)fs/ext4/resize.c +0
-0@@ -1432,12 +1432,15 @@ static int ext4_flex_group_add(struct super_block *sb, goto exit;
fs/ext4/resize.c static int ext4_flex_group_add(struct super_block *sb, · line 1440
Quoted 10 lines
fs/ext4/resize.c +2
-2/* * We will always be modifying at least the superblock and GDT -* block. If we are adding a group past the last current GDT block, +* blocks. If we are adding a group past the last current GDT block, * we will also modify the inode and the dindirect block. If we * are adding a group with superblock/GDT backups we will also * modify each of the reserved GDT dindirect blocks. */ - credit = flex_gd->count *4 + reserved_gdb; + credit =3 ;/* sb, resize inode, resize inode dindirect */
yay for excellent comments :)
fs/ext4/resize.c static int ext4_flex_group_add(struct super_block *sb, · line 1442
Quoted 2 lines
fs/ext4/resize.c +2
-0+ credit +=1 + (flex_gd->count +EXT4_DESC_PER_BLOCK (sb) -1 ) / +EXT4_DESC_PER_BLOCK (sb);/* GDT blocks */
maybe credit += 1 + DIV_ROUND_UP(flex_gd->count, EXT4_DESC_PER_BLOCK(sb)) ?
fs/ext4/resize.c static int ext4_flex_group_add(struct super_block *sb, · line 1446
Quoted 4 lines
fs/ext4/resize.c +1
-0+ credit += reserved_gdb;/* Reserved GDT dindirect blocks */ handle =ext4_journal_start_sb (sb,EXT4_HT_RESIZE , credit);if (IS_ERR (handle)) { err =PTR_ERR (handle);
Thanks!
-Eric