ext4: modify the implementation of quota reservation in bigalloc and delay-allocation
Subsystems (2)
PATCH 1/1 ext4: modify the implementation of quota reservation in bigalloc and delay-allocation
From: Robin Dong <[email protected]>
1. fix the bug reported by Eric Sandeen (http://www.spinics.net/lists/linux-ext4/msg30259.html)
2. change the argument of i_{reserved_data,reserved_meta,allocated_meta}_blocks to i_*_clusters
3. In the old logic When we try writing to a block which does not have a mapping, and bigalloc is enabled:
a) one block have been mapped, a whole cluster will be reserved.
b) While the block has not been mapped (and so the data on disk is
uninitialized) the cluster has indeed been allocated, so we don't need
to reserve any additional room for the block.
Imaging s_cluster_ratio is 4 and the clusters is: (follow the comment in fs/ext4/extent.c:4100)
[0-3], [4-7], [8-11]
The new quota-reservation logic have changed to this now:
1. delay-allocation write blocks 10&11
we reserve 1 cluster, the i_reserved_data_blocks is 1 now
2. delay-allocation write blocks 3 to 8
we reserve other 2 clusters, so 3 clusters totally, the i_reserved_data_blocks is 3 now
3. writeout the blocks 3 to 8
claim all 3 clusters, i_reserved_data_blocks is 0 now
At this moment, we really have allocated 3 clusters, and the remain 10&11 block would never occupy another cluster (it would definitely go into the [8-11] cluster), so, we don't need to reserve one more cluster quota (which is the old logic).
4. writeout the 10&11 blocks
the 10&11 blocks will be set EXT4_MAP_FROM_CLUSTER flag ( by get_implied_cluster_alloc as the 8~9 block have been allocated), and it will not call ext4_da_update_reserve_space any more
As this, no warning, no reserve-and-release ping pong.
--- fs/ext4/balloc.c | 4 +- fs/ext4/ext4.h | 6 +- fs/ext4/extents.c | 97 +++++++++++-------------------------------- fs/ext4/file.c | 2 +- fs/ext4/inode.c | 66 +++++++++++++++-------------- fs/ext4/super.c | 7 ++- include/trace/events/ext4.h | 42 +++++++++--------- 7 files changed, 90 insertions(+), 134 deletions(-)
fs/ext4/balloc.c +2 -2
@@ -426,7 +426,7 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,if (free_clusters - (nclusters + root_clusters + dirty_clusters) <EXT4_FREECLUSTERS_WATERMARK ) { - free_clusters =EXT4_C2B (sbi,percpu_counter_sum_positive (fcc)); + free_clusters =percpu_counter_sum_positive (fcc); dirty_clusters =percpu_counter_sum_positive (dcc); }/* Check whether we have space after accounting for current
@@ -518,7 +518,7 @@ ext4_fsblk_t ext4_new_meta_blocks(handle_t *handle, struct inode *inode,if (!(*errp) &&ext4_test_inode_state (inode,EXT4_STATE_DELALLOC_RESERVED )) {spin_lock (&EXT4_I (inode)->i_block_reservation_lock); -EXT4_I (inode)->i_allocated_meta_blocks += ar.len; +EXT4_I (inode)->i_allocated_meta_clusters += ar.len;spin_unlock (&EXT4_I (inode)->i_block_reservation_lock);dquot_alloc_block_nofail (inode,EXT4_C2B (EXT4_SB (inode->i_sb), ar.len));
fs/ext4/ext4.h +3 -3
@@ -869,9 +869,9 @@ struct ext4_inode_info {/* allocation reservation info for delalloc */ /* In case of bigalloc, these refer to clusters rather than blocks */ -unsigned int i_reserved_data_blocks; -unsigned int i_reserved_meta_blocks; -unsigned int i_allocated_meta_blocks; +unsigned int i_reserved_data_clusters; +unsigned int i_reserved_meta_clusters; +unsigned int i_allocated_meta_clusters;ext4_lblk_t i_da_metadata_calc_last_lblock;int i_da_metadata_calc_len;
fs/ext4/extents.c +25 -72
120 lines not on this page · raw message
fs/ext4/file.c +1 -1
@@ -43,7 +43,7 @@ static int ext4_release_file(struct inode *inode, struct file *filp)/* if we are the last writer on the inode, drop the block reservation */ if ((filp->f_mode &FMODE_WRITE ) && (atomic_read (&inode->i_writecount) ==1 ) && - !EXT4_I (inode)->i_reserved_data_blocks) + !EXT4_I (inode)->i_reserved_data_clusters) {down_write (&EXT4_I (inode)->i_data_sem);ext4_discard_preallocations (inode);
fs/ext4/inode.c +34 -32
145 lines not on this page · raw message
fs/ext4/super.c +4 -3
@@ -899,9 +899,9 @@ static struct inode *ext4_alloc_inode(struct super_block *sb)memset (&ei->i_cached_extent,0 ,sizeof (struct ext4_ext_cache ));INIT_LIST_HEAD (&ei->i_prealloc_list);spin_lock_init (&ei->i_prealloc_lock); - ei->i_reserved_data_blocks =0 ; - ei->i_reserved_meta_blocks =0 ; - ei->i_allocated_meta_blocks =0 ; + ei->i_reserved_data_clusters =0 ; + ei->i_reserved_meta_clusters =0 ; + ei->i_allocated_meta_clusters =0 ; ei->i_da_metadata_calc_len =0 ;spin_lock_init (&(ei->i_block_reservation_lock));#ifdef CONFIG_QUOTA
@@ -4646,6 +4646,7 @@ static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf) EXT4_C2B(sbi, sbi->s_overhead_last)); bfree =percpu_counter_sum_positive (&sbi->s_freeclusters_counter) -percpu_counter_sum_positive (&sbi->s_dirtyclusters_counter); +/* prevent underflow in case that few free space is available */ buf->f_bfree =EXT4_C2B (sbi,max_t (s64, bfree,0 )); buf->f_bavail = buf->f_bfree -ext4_r_blocks_count (es);
include/trace/events/ext4.h +21 -21
89 lines not on this page · raw message
Signature · 1 line
1.7.3.2