ext4: Don't allow lg prealloc list to be grow large.
PATCH 1/1 ext4: Don't allow lg prealloc list to be grow large.
The locality group prealloc list is freed only when there is a block allocation failure. This can result in large number of per cpu locality group prealloc space and also make the ext4_mb_use_preallocated expensive. Add a tunable max_lg_prealloc which default to 1000. If we have more than 1000 Per-CPU prealloc space and if we fail to find a suitable prealloc space during allocation we will now free all the prealloc space in the locality group.
--- fs/ext4/ext4_sb.h | 1 + fs/ext4/mballoc.c | 151 +++++++++++++++++++++++++++++++++++++++------------- fs/ext4/mballoc.h | 6 ++ 3 files changed, 120 insertions(+), 38 deletions(-)
fs/ext4/ext4_sb.h +1 -0
@@ -115,6 +115,7 @@ struct ext4_sb_info {/* where last allocation was done - for stream allocation */ unsigned long s_mb_last_group;unsigned long s_mb_last_start; +unsigned long s_mb_max_lg_prealloc;/* history to debug policy */ struct ext4_mb_history *s_mb_history;
fs/ext4/mballoc.c +113 -37
217 lines not on this page · raw message
PATCH 1/1 ext4: Improve error handling in mballoc
Don't call BUG_ON on file system failures. Instead use ext4_error and also handle the continue case properly.
--- fs/ext4/mballoc.c | 34 +++++++++++++++++++++++----------- 1 files changed, 23 insertions(+), 11 deletions(-)
fs/ext4/mballoc.c +23 -11
@@ -3737,20 +3737,23 @@ ext4_mb_discard_group_preallocations(struct super_block *sb, bitmap_bh =ext4_read_block_bitmap (sb, group);if (bitmap_bh ==NULL ) { -/* error handling here */ -ext4_mb_release_desc (&e4b); -BUG_ON (bitmap_bh ==NULL ); +ext4_error (sb, __func__,"Error in reading block " +"bitmap for %lu\n" , group); +return 0 ; } err =ext4_mb_load_buddy (sb, group, &e4b); -BUG_ON (err !=0 );/* error handling here */ +if (err) { +ext4_error (sb, __func__,"Error in loading buddy " +"information for %lu\n" , group); +put_bh (bitmap_bh); +return 0 ; + }if (needed ==0 ) needed =EXT4_BLOCKS_PER_GROUP (sb) +1 ; - grp =ext4_get_group_info (sb, group);INIT_LIST_HEAD (&list); - ac =kmem_cache_alloc (ext4_ac_cachep,GFP_NOFS ); repeat:ext4_lock_group (sb, group);
@@ -3907,13 +3910,18 @@ void ext4_mb_discard_inode_preallocations(struct inode *inode)ext4_get_group_no_and_offset (sb, pa->pa_pstart, &group,NULL ); err =ext4_mb_load_buddy (sb, group, &e4b); -BUG_ON (err !=0 );/* error handling here */ +if (err) { +ext4_error (sb, __func__,"Error in loading buddy " +"information for %lu\n" , group); +continue ; + } bitmap_bh =ext4_read_block_bitmap (sb, group);if (bitmap_bh ==NULL ) { -/* error handling here */ +ext4_error (sb, __func__,"Error in reading block " +"bitmap for %lu\n" , group);ext4_mb_release_desc (&e4b); -BUG_ON (bitmap_bh ==NULL ); +continue ; }ext4_lock_group (sb, group);
@@ -4425,11 +4433,15 @@ void ext4_mb_free_blocks(handle_t *handle, struct inode *inode, count -= overflow; } bitmap_bh =ext4_read_block_bitmap (sb, block_group); -if (!bitmap_bh) +if (!bitmap_bh) { + err = -EIO ; goto error_return; + } gdp =ext4_get_group_desc (sb, block_group, &gd_bh); -if (!gdp) +if (!gdp) { + err = -EIO ; goto error_return; + } if (in_range(ext4_block_bitmap(sb, gdp), block, count) || in_range(ext4_inode_bitmap(sb, gdp), block, count) ||
Signature · 1 line
1.5.6.3.439.g1e10.dirty
Quoted 6 lines · Aneesh Kumar K.V
The locality group prealloc list is freed only when there is a block allocation failure. This can result in large number of per cpu locality group prealloc space and also make the
ext4_mb_use_preallocatedexpensive. Add a tunablemax_lg_preallocwhich default to 1000. If we have more than 1000 Per-CPU prealloc space and if we fail to find a suitable prealloc space during allocation we will now free all the prealloc space in the locality group.
It looks like this helps, but does not fare as well as the "perfectly tuned" default (where the prealloc size is a multiple of the 20k/5 block file size used in the test.)
I've added a plot of a delalloc run with your patch to the graph at:
http://people.redhat.com/esandeen/ext4/fs_mark.png
-Eric