Skip to content

Commit 8d71fc2

Browse files
Xin Yingregkh
authored andcommitted
ext4: prevent used blocks from being allocated during fast commit replay
commit 599ea31 upstream. During fast commit replay procedure, we clear inode blocks bitmap in ext4_ext_clear_bb(), this may cause ext4_mb_new_blocks_simple() allocate blocks still in use. Make ext4_fc_record_regions() also record physical disk regions used by inodes during replay procedure. Then ext4_mb_new_blocks_simple() can excludes these blocks in use. Signed-off-by: Xin Yin <yinxin.x@bytedance.com> Link: https://lore.kernel.org/r/20220110035141.1980-2-yinxin.x@bytedance.com Signed-off-by: Theodore Ts'o <tytso@mit.edu> Cc: stable@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent ef2053a commit 8d71fc2

3 files changed

Lines changed: 22 additions & 5 deletions

File tree

fs/ext4/ext4.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2779,6 +2779,9 @@ void ext4_fc_replay_cleanup(struct super_block *sb);
27792779
int ext4_fc_commit(journal_t *journal, tid_t commit_tid);
27802780
int __init ext4_fc_init_dentry_cache(void);
27812781
void ext4_fc_destroy_dentry_cache(void);
2782+
int ext4_fc_record_regions(struct super_block *sb, int ino,
2783+
ext4_lblk_t lblk, ext4_fsblk_t pblk,
2784+
int len, int replay);
27822785

27832786
/* mballoc.c */
27842787
extern const struct seq_operations ext4_mb_seq_groups_ops;

fs/ext4/extents.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6088,11 +6088,15 @@ int ext4_ext_clear_bb(struct inode *inode)
60886088

60896089
ext4_mb_mark_bb(inode->i_sb,
60906090
path[j].p_block, 1, 0);
6091+
ext4_fc_record_regions(inode->i_sb, inode->i_ino,
6092+
0, path[j].p_block, 1, 1);
60916093
}
60926094
ext4_ext_drop_refs(path);
60936095
kfree(path);
60946096
}
60956097
ext4_mb_mark_bb(inode->i_sb, map.m_pblk, map.m_len, 0);
6098+
ext4_fc_record_regions(inode->i_sb, inode->i_ino,
6099+
map.m_lblk, map.m_pblk, map.m_len, 1);
60966100
}
60976101
cur = cur + map.m_len;
60986102
}

fs/ext4/fast_commit.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,16 +1558,23 @@ static int ext4_fc_replay_create(struct super_block *sb, struct ext4_fc_tl *tl,
15581558
}
15591559

15601560
/*
1561-
* Record physical disk regions which are in use as per fast commit area. Our
1562-
* simple replay phase allocator excludes these regions from allocation.
1561+
* Record physical disk regions which are in use as per fast commit area,
1562+
* and used by inodes during replay phase. Our simple replay phase
1563+
* allocator excludes these regions from allocation.
15631564
*/
1564-
static int ext4_fc_record_regions(struct super_block *sb, int ino,
1565-
ext4_lblk_t lblk, ext4_fsblk_t pblk, int len)
1565+
int ext4_fc_record_regions(struct super_block *sb, int ino,
1566+
ext4_lblk_t lblk, ext4_fsblk_t pblk, int len, int replay)
15661567
{
15671568
struct ext4_fc_replay_state *state;
15681569
struct ext4_fc_alloc_region *region;
15691570

15701571
state = &EXT4_SB(sb)->s_fc_replay_state;
1572+
/*
1573+
* during replay phase, the fc_regions_valid may not same as
1574+
* fc_regions_used, update it when do new additions.
1575+
*/
1576+
if (replay && state->fc_regions_used != state->fc_regions_valid)
1577+
state->fc_regions_used = state->fc_regions_valid;
15711578
if (state->fc_regions_used == state->fc_regions_size) {
15721579
state->fc_regions_size +=
15731580
EXT4_FC_REPLAY_REALLOC_INCREMENT;
@@ -1585,6 +1592,9 @@ static int ext4_fc_record_regions(struct super_block *sb, int ino,
15851592
region->pblk = pblk;
15861593
region->len = len;
15871594

1595+
if (replay)
1596+
state->fc_regions_valid++;
1597+
15881598
return 0;
15891599
}
15901600

@@ -1954,7 +1964,7 @@ static int ext4_fc_replay_scan(journal_t *journal,
19541964
ret = ext4_fc_record_regions(sb,
19551965
le32_to_cpu(ext.fc_ino),
19561966
le32_to_cpu(ex->ee_block), ext4_ext_pblock(ex),
1957-
ext4_ext_get_actual_len(ex));
1967+
ext4_ext_get_actual_len(ex), 0);
19581968
if (ret < 0)
19591969
break;
19601970
ret = JBD2_FC_REPLAY_CONTINUE;

0 commit comments

Comments
 (0)