ext4: fix online resize with mballoc
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/1 ext4: fix online resize with mballoc
From: Frederic Bohe <[email protected]>
Update group infos when updating a group's descriptor. Add group infos when adding a group's descriptor. Refresh cache pages used by mb_alloc when changes occur.
---
This patch apply on top of 2.6.26-rc6 + ext4-patch-queue-37b3e39765d8521ba2252bfec81bb91504fa35c8
It fixes oops when a filesystem is resized online while being mounted with mballoc. Two oops have been identified:
The first one occurs when unmounting the resized filesystem.
The second one happens when trying to write to a group added during the online resize.
This patch has been tested with:
- small (100MB) and large (5TB) filesystems.
- 1K blocks and 4K blocks filesystems.
- inode size=256 up to 1024.
Tests consist in :
- online resizing, filling all blocks of the fs, unmounting, fs check
- filling all blocks of the fs, online resizing, filling newly added groups, unmounting, fs check
- Concurrent file copy/online resize, unmounting, fs check.
Non regression tests :
- offline resizing.
- online resizing without mballoc.
ext4.h | 4 + mballoc.c | 207 ++++++++++++++++++++++++++++++++++++++++++++++---------------- resize.c | 40 +++++++++++ 3 files changed, 199 insertions(+), 52 deletions(-)
fs/ext4/ext4.h +4 -0
@@ -1115,6 +1115,10 @@ extern int __init init_ext4_mballoc(voidextern void exit_ext4_mballoc (void );extern void ext4_mb_free_blocks (handle_t *,struct inode *,unsigned long ,unsigned long ,int ,unsigned long *); +extern int ext4_mb_add_more_groupinfo (struct super_block *sb, +ext4_group_t i,struct ext4_group_desc *desc); +extern void ext4_mb_update_group_info (struct ext4_group_info *grp, +ext4_grpblk_t add);/* inode.c */
fs/ext4/mballoc.c +162 -54
245 lines not on this page · raw message
fs/ext4/resize.c +47 -1
72 lines not on this page · raw message
Quoted 5 lines · Fr�d�ric Boh�
From: Frederic Bohe <[email protected]>
Update group infos when updating a group's descriptor. Add group infos when adding a group's descriptor. Refresh cache pages used by
mb_allocwhen changes occur.
Excellent, thank you for fixing this issue. Minor comments below.
fs/ext4/mballoc.c ext4_mb_store_history(struct ext4_alloca · line 2243
Quoted 5 lines
fs/ext4/mballoc.c +5
-0+/* Create and initialize ext4_group_info data */ +/* for the given group. */ + +int ext4_mb_add_groupinfo (struct super_block *sb,ext4_group_t group, +struct ext4_group_desc *desc)
Please indent the continued line to match '(' on previous line.
fs/ext4/mballoc.c ext4_mb_store_history(struct ext4_alloca · line 2256
Quoted 3 lines
fs/ext4/mballoc.c +3
-0+if (group %EXT4_DESC_PER_BLOCK (sb) ==0 ) { + metalen =sizeof (*meta_group_info) + <<EXT4_DESC_PER_BLOCK_BITS (sb);
Please put operator "<<" at end of previous line.
fs/ext4/mballoc.c ext4_mb_store_history(struct ext4_alloca · line 2260
Quoted 4 lines
fs/ext4/mballoc.c +4
-0+ meta_group_info =kmalloc (metalen,GFP_KERNEL ); +if (meta_group_info ==NULL ) { +printk (KERN_ERR "EXT4-fs: can't allocate mem for a " +"buddy group\n" );
Indent continued line to '('
fs/ext4/mballoc.c ext4_mb_store_history(struct ext4_alloca · line 2264
Quoted 4 lines
fs/ext4/mballoc.c +4
-0+ goto exit_meta_group_info; + } + sbi->s_group_info[group >> +EXT4_DESC_PER_BLOCK_BITS (sb)] = meta_group_info;
Prefer keeping related operations on the same line, like:
sbi->s_group_info[group >> EXT4_DESC_PER_BLOCK_BITS(sb)] = meta_group_info;
fs/ext4/mballoc.c ext4_mb_store_history(struct ext4_alloca · line 2272
Quoted 6 lines
fs/ext4/mballoc.c +6
-0+/* +* calculate needed size. if change bb_counters size, +* don't forget about ext4_mb_generate_buddy() +*/ + len =sizeof (struct ext4_group_info ); + len +=sizeof (unsigned short ) * (sb->s_blocksize_bits +2 );
It would be good to use an actual structure and not "sizeof(unsigned short)" because if the structure changes then this calculation will be wrong. Something like the following is much safer and will always be correct:
len = offsetof(typeof(*meta_group_info), bb_counters[sb->s_blocksize_bits + 2]);
I see that your code is copied from ext4_mb_init_backend(), so fault is not yours, but it is still good to make the code safe against future bugs.
fs/ext4/mballoc.c ext4_mb_store_history(struct ext4_alloca · line 2296
Quoted 11 lines
fs/ext4/mballoc.c +11
-0+/* +* initialize bb_free to be able to skip +* empty groups without initialization +*/ +if (desc->bg_flags &cpu_to_le16 (EXT4_BG_BLOCK_UNINIT )) { + meta_group_info[i]->bb_free = +ext4_free_blocks_after_init (sb, group, desc); + }else { + meta_group_info[i]->bb_free = +le16_to_cpu (desc->bg_free_blocks_count); + }
Please indent continued lines.
Quoted 4 lines
fs/ext4/mballoc.c +4
-0+INIT_LIST_HEAD (&meta_group_info[i]->bb_prealloc_list); + +#ifdef DOUBLE_CHECK + {
fs/ext4/mballoc.c ext4_mb_store_history(struct ext4_alloca · line 2311
Quoted 10 lines
fs/ext4/mballoc.c +10
-0+struct buffer_head *bh; + meta_group_info[i]->bb_bitmap = +kmalloc (sb->s_blocksize,GFP_KERNEL ); +BUG_ON (meta_group_info[i]->bb_bitmap ==NULL ); + bh =ext4_read_block_bitmap (sb, group); +BUG_ON (bh ==NULL ); +memcpy (meta_group_info[i]->bb_bitmap, bh->b_data, + sb->s_blocksize); +put_bh (bh); + }
Please indent inside this scope.
fs/ext4/mballoc.c ext4_mb_store_history(struct ext4_alloca · line 2315
Quoted 4 lines
fs/ext4/mballoc.c +4
-0+#endif + +return 0 ; +exit_group_info:
Blank line after "return"
fs/ext4/mballoc.c ext4_mb_store_history(struct ext4_alloca · line 2344
Quoted 7 lines
fs/ext4/mballoc.c +7
-0+int ext4_mb_add_more_groupinfo (struct super_block *sb,ext4_group_t group, +struct ext4_group_desc *desc) +{ +/* Cache pages containing dynamic mb_alloc datas (buddy and bitmap +* datas) are set not up to date so that they will be re-initilaized +* during the next call to ext4_mb_load_buddy +*/
Comment continuation should line up '*' in a single column.
fs/ext4/mballoc.c ext4_mb_store_history(struct ext4_alloca · line 2399
Quoted 11 lines
static int
ext4_mb_init_backend(struct super_block *sb){fs/ext4/mballoc.c +9
-0+/* This is the total number of blocks used by GDT including +* the number of reserved blocks for GDT. +* The s_group_info array is allocated with this value +* to allow a clean online resize without a complex +* manipulation of pointer. +* The drawback is the unused memory when no resize +* occurs but it's very low in terms of pages +* (see comments below) +*/
Also align comment '*' in the same columns.
fs/ext4/mballoc.c ext4_mb_store_history(struct ext4_alloca · line 2401
Quoted 2 lines
fs/ext4/mballoc.c +2
-0+ num_meta_group_infos_max = num_meta_group_infos + +le16_to_cpu (es->s_reserved_gdt_blocks);
The only drawback of NOT handling this properly is that once (eventually) we allow resizing with META_BG this code will be broken again. It at least deserves a comment like "Need to handle this properly when META_BG resizing is allowed" so that it will show up on any grep for META_BG.
It probably also makes sense to round this up to the next power-of-two value, since kmalloc will do that internally anyways, and it gives us some resizing headroom for no cost.
fs/ext4/mballoc.c static int ext4_mb_init_backend(struct s · line 2436
Quoted 7 lines
fs/ext4/mballoc.c +2
-0@@ -2276,62 +2431,15 @@ static int ext4_mb_init_backend(struct s sbi->s_group_info[i] = meta_group_info; }for (i =0 ; i < sbi->s_groups_count; i++) { +if (ext4_mb_add_groupinfo (sb, i, desc) !=0 ) + goto err_freebuddy;
This is much nicer, great.
Cheers, Andreas
--
Andreas Dilger
Sr. Staff Engineer, Lustre Group
Sun Microsystems of Canada, Inc.
--
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
Thanks for your feedback !
Quoted 10 lines · Andreas Dilger
fs/ext4/mballoc.c ext4_mb_store_history(struct ext4_alloca · line 2401
Quoted 3 lines · Fr�d�ric Boh�
From: Frederic Bohe <[email protected]>
fs/ext4/mballoc.c +2
-0+ num_meta_group_infos_max = num_meta_group_infos + +le16_to_cpu (es->s_reserved_gdt_blocks);The only drawback of NOT handling this properly is that once (eventually) we allow resizing with
META_BGthis code will be broken again. It at least deserves a comment like "Need to handle this properly whenMETA_BGresizing is allowed" so that it will show up on any grep forMETA_BG.
Quoted 3 lines
It probably also makes sense to round this up to the next power-of-two value, since kmalloc will do that internally anyways, and it gives us some resizing headroom for no cost.
Do you have any idea of how this headroom could be used in the future ?
Regards,
Fred
--
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
Quoted 11 lines · Fr�d�ric Boh�
Quoted 10 lines · Andreas Dilger
fs/ext4/mballoc.c ext4_mb_store_history(struct ext4_alloca · line 2401
Quoted 3 lines · Fr�d�ric Boh�
From: Frederic Bohe <[email protected]>
fs/ext4/mballoc.c +2
-0+ num_meta_group_infos_max = num_meta_group_infos + +le16_to_cpu (es->s_reserved_gdt_blocks);The only drawback of NOT handling this properly is that once (eventually) we allow resizing with
META_BGthis code will be broken again. It at least deserves a comment like "Need to handle this properly whenMETA_BGresizing is allowed" so that it will show up on any grep forMETA_BG.
Quoted 5 lines
Quoted 3 lines
It probably also makes sense to round this up to the next power-of-two value, since kmalloc will do that internally anyways, and it gives us some resizing headroom for no cost.
Do you have any idea of how this headroom could be used in the future ?
For e.g. resize with META_BG, which does not need new reserved blocks to be added. Since the space is already allocated because of kmalloc use of 2^n slab size, we may as well make it "available" even if it isn't used.
Cheers, Andreas
--
Andreas Dilger
Sr. Staff Engineer, Lustre Group
Sun Microsystems of Canada, Inc.
--
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
Quoted 18 lines · Andreas Dilger
Quoted 5 lines · Fr�d�ric Boh�
From: Frederic Bohe <[email protected]>
static int
ext4_mb_init_backend(struct super_block *sb){fs/ext4/mballoc.c ext4_mb_store_history(struct ext4_alloca · line 2399
Quoted 9 lines
fs/ext4/mballoc.c +9
-0+/* This is the total number of blocks used by GDT including +* the number of reserved blocks for GDT. +* The s_group_info array is allocated with this value +* to allow a clean online resize without a complex +* manipulation of pointer. +* The drawback is the unused memory when no resize +* occurs but it's very low in terms of pages +* (see comments below) +*/ Also align comment '*' in the same columns.
Quoted 8 lines
fs/ext4/mballoc.c ext4_mb_store_history(struct ext4_alloca · line 2401
Quoted 2 lines
fs/ext4/mballoc.c +2
-0+ num_meta_group_infos_max = num_meta_group_infos + +le16_to_cpu (es->s_reserved_gdt_blocks);The only drawback of NOT handling this properly is that once (eventually) we allow resizing with
META_BGthis code will be broken again. It at least deserves a comment like "Need to handle this properly whenMETA_BGresizing is allowed" so that it will show up on any grep forMETA_BG.
It probably useful to document this limit in the change log too.
It would be nice to do it right now since we are here, if it's not too complicated. The locking cost to do dynamic re-allocation of s_groups_info seems low to me if we use read-write lock, as the write path is relatively rare. But I guess there are a lot of there places we need to worry to enable resize to any large with FLEX_BG/META_BG, and could deal with that later.
Mingming
Quoted 20 lines
It probably also makes sense to round this up to the next power-of-two value, since kmalloc will do that internally anyways, and it gives us some resizing headroom for no cost.
fs/ext4/mballoc.c static int ext4_mb_init_backend(struct s · line 2436
Quoted 7 lines
fs/ext4/mballoc.c +2
-0@@ -2276,62 +2431,15 @@ static int ext4_mb_init_backend(struct s sbi->s_group_info[i] = meta_group_info; }for (i =0 ; i < sbi->s_groups_count; i++) { +if (ext4_mb_add_groupinfo (sb, i, desc) !=0 ) + goto err_freebuddy;This is much nicer, great.
Cheers, Andreas
--
Andreas Dilger
Sr. Staff Engineer, Lustre Group
Sun Microsystems of Canada, Inc.
Quoted 4 lines
--
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
--
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