Skip to content

Commit 7d73453

Browse files
jankaratytso
authored andcommitted
ext4: fix warning in ext4_da_update_reserve_space()
reaim workfile.dbase test easily triggers warning in ext4_da_update_reserve_space(): EXT4-fs warning (device ram0): ext4_da_update_reserve_space:365: ino 12, allocated 1 with only 0 reserved metadata blocks (releasing 1 blocks with reserved 9 data blocks) The problem is that (one of) tests creates file and then randomly writes to it with O_SYNC. That results in writing back pages of the file in random order so we create extents for written blocks say 0, 2, 4, 6, 8 - this last allocation also allocates new block for extents. Then we writeout block 1 so we have extents 0-2, 4, 6, 8 and we release indirect extent block because extents fit in the inode again. Then we writeout block 10 and we need to allocate indirect extent block again which triggers the warning because we don't have the reservation anymore. Fix the problem by giving back freed metadata blocks resulting from extent merging into inode's reservation pool. Signed-off-by: Jan Kara <jack@suse.cz>
1 parent 1c8924e commit 7d73453

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

‎fs/ext4/ext4.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ enum {
581581
#define EXT4_FREE_BLOCKS_NO_QUOT_UPDATE 0x0008
582582
#define EXT4_FREE_BLOCKS_NOFREE_FIRST_CLUSTER 0x0010
583583
#define EXT4_FREE_BLOCKS_NOFREE_LAST_CLUSTER 0x0020
584+
#define EXT4_FREE_BLOCKS_RESERVE 0x0040
584585

585586
/*
586587
* ioctl commands

‎fs/ext4/extents.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1793,7 +1793,8 @@ static void ext4_ext_try_to_merge_up(handle_t *handle,
17931793

17941794
brelse(path[1].p_bh);
17951795
ext4_free_blocks(handle, inode, NULL, blk, 1,
1796-
EXT4_FREE_BLOCKS_METADATA | EXT4_FREE_BLOCKS_FORGET);
1796+
EXT4_FREE_BLOCKS_METADATA | EXT4_FREE_BLOCKS_FORGET |
1797+
EXT4_FREE_BLOCKS_RESERVE);
17971798
}
17981799

17991800
/*

‎fs/ext4/mballoc.c‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4585,6 +4585,7 @@ void ext4_free_blocks(handle_t *handle, struct inode *inode,
45854585
struct buffer_head *gd_bh;
45864586
ext4_group_t block_group;
45874587
struct ext4_sb_info *sbi;
4588+
struct ext4_inode_info *ei = EXT4_I(inode);
45884589
struct ext4_buddy e4b;
45894590
unsigned int count_clusters;
45904591
int err = 0;
@@ -4784,18 +4785,30 @@ void ext4_free_blocks(handle_t *handle, struct inode *inode,
47844785
ext4_block_bitmap_csum_set(sb, block_group, gdp, bitmap_bh);
47854786
ext4_group_desc_csum_set(sb, block_group, gdp);
47864787
ext4_unlock_group(sb, block_group);
4787-
percpu_counter_add(&sbi->s_freeclusters_counter, count_clusters);
47884788

47894789
if (sbi->s_log_groups_per_flex) {
47904790
ext4_group_t flex_group = ext4_flex_group(sbi, block_group);
47914791
atomic64_add(count_clusters,
47924792
&sbi->s_flex_groups[flex_group].free_clusters);
47934793
}
47944794

4795-
ext4_mb_unload_buddy(&e4b);
4796-
4797-
if (!(flags & EXT4_FREE_BLOCKS_NO_QUOT_UPDATE))
4795+
if (flags & EXT4_FREE_BLOCKS_RESERVE && ei->i_reserved_data_blocks) {
4796+
percpu_counter_add(&sbi->s_dirtyclusters_counter,
4797+
count_clusters);
4798+
spin_lock(&ei->i_block_reservation_lock);
4799+
if (flags & EXT4_FREE_BLOCKS_METADATA)
4800+
ei->i_reserved_meta_blocks += count_clusters;
4801+
else
4802+
ei->i_reserved_data_blocks += count_clusters;
4803+
spin_unlock(&ei->i_block_reservation_lock);
4804+
if (!(flags & EXT4_FREE_BLOCKS_NO_QUOT_UPDATE))
4805+
dquot_reclaim_block(inode,
4806+
EXT4_C2B(sbi, count_clusters));
4807+
} else if (!(flags & EXT4_FREE_BLOCKS_NO_QUOT_UPDATE))
47984808
dquot_free_block(inode, EXT4_C2B(sbi, count_clusters));
4809+
percpu_counter_add(&sbi->s_freeclusters_counter, count_clusters);
4810+
4811+
ext4_mb_unload_buddy(&e4b);
47994812

48004813
/* We dirtied the bitmap block */
48014814
BUFFER_TRACE(bitmap_bh, "dirtied bitmap block");

0 commit comments

Comments
 (0)