ext4: Fix accounting of reserved metadata blocks
Theodore Ts'o
maintainerPATCH 1/2 ext4: Fix accounting of reserved metadata blocks
Commit 0637c6f had a typo which caused the reserved metadata blocks to
not be released correctly. Fix this.
--- fs/ext4/inode.c | 9 ++++----- 1 files changed, 4 insertions(+), 5 deletions(-)
fs/ext4/inode.c +4 -5
@@ -1076,9 +1076,8 @@ static void ext4_da_update_reserve_space(struct inode *inode, int used)* only when we have written all of the delayed * allocation blocks. */ - mdb_free = ei->i_allocated_meta_blocks; -percpu_counter_sub (&sbi->s_dirtyblocks_counter, mdb_free); - ei->i_allocated_meta_blocks =0 ; + mdb_free = ei->i_reserved_meta_blocks; + ei->i_reserved_meta_blocks =0 ; }spin_unlock (&EXT4_I (inode)->i_block_reservation_lock);
@@ -1889,8 +1888,8 @@ static void ext4_da_release_space(struct inode *inode, int to_free)* only when we have written all of the delayed * allocation blocks. */ - to_free += ei->i_allocated_meta_blocks; - ei->i_allocated_meta_blocks =0 ; + to_free += ei->i_reserved_meta_blocks; + ei->i_reserved_meta_blocks =0 ; }/* update fs dirty blocks counter */
Signature · 1 line
1.6.5.216.g5288a.dirty
Theodore Ts'o
maintainerPATCH 2/2 ext4: Calculate metadata requirements more accurately
In the past, ext4_calc_metadata_amount(), and its sub-functions ext4_ext_calc_metadata_amount() and ext4_indirect_calc_metadata_amount() badly over-estimated the number of metadata blocks that might be required for delayed allocation blocks. This didn't matter as much when functions which managed the reserved metadata blocks were more aggressive about dropping reserved metadata blocks as delayed allocation blocks were written, but unfortunately they were too aggressive. This was fixed in commit 0637c6f, but as a result the over-estimation by ext4_calc_metadata_amount() would lead to reserving 2-3 times the number of pending delayed allocation blocks as potentially required metadata blocks. So if there are 1 megabytes of blocks which have been not yet been allocation, up to 3 megabytes of space would get reserved out of the user's quota and from the file system free space pool until all of the inode's data blocks have been allocated.
This commit addresses this problem by much more accurately estimating the number of metadata blocks that will be required. It will still somewhat over-estimate the number of blocks needed, since it must make a worst case estimate not knowing which physical blocks will be needed, but it is much more accurate than before.
--- fs/ext4/ext4.h | 2 + fs/ext4/ext4_extents.h | 3 +- fs/ext4/extents.c | 49 ++++++++++++++++++++++++------------- fs/ext4/inode.c | 62 +++++++++++++++++++++++++++-------------------- fs/ext4/super.c | 1 + 5 files changed, 73 insertions(+), 44 deletions(-)
fs/ext4/ext4.h +2 -0
@@ -699,6 +699,8 @@ struct ext4_inode_info {unsigned int i_reserved_meta_blocks;unsigned int i_allocated_meta_blocks;unsigned short i_delalloc_reserved_flag; +sector_t i_da_metadata_calc_last_lblock; +int i_da_metadata_calc_len;/* on-disk additional length */ __u16 i_extra_isize;
fs/ext4/ext4_extents.h +2 -1
@@ -225,7 +225,8 @@ static inline void ext4_ext_mark_initialized(struct ext4_extent *ext) ext->ee_len =cpu_to_le16 (ext4_ext_get_actual_len (ext)); } -extern int ext4_ext_calc_metadata_amount (struct inode *inode,int blocks); +extern int ext4_ext_calc_metadata_amount (struct inode *inode, +sector_t lblocks);extern ext4_fsblk_t ext_pblock (struct ext4_extent *ex);extern ext4_fsblk_t idx_pblock (struct ext4_extent_idx *);extern void ext4_ext_store_pblock (struct ext4_extent *,ext4_fsblk_t );
fs/ext4/extents.c +32 -17
61 lines not on this page · raw message
fs/ext4/inode.c +36 -26
135 lines not on this page · raw message
fs/ext4/super.c +1 -0
@@ -702,6 +702,7 @@ static struct inode *ext4_alloc_inode(struct super_block *sb) ei->i_reserved_data_blocks =0 ; ei->i_reserved_meta_blocks =0 ; ei->i_allocated_meta_blocks =0 ; + ei->i_da_metadata_calc_len =0 ; ei->i_delalloc_reserved_flag =0 ;spin_lock_init (&(ei->i_block_reservation_lock));#ifdef CONFIG_QUOTA
Signature · 1 line
1.6.5.216.g5288a.dirty