Skip to content

Commit 599ea31

Browse files
Xin Yintytso
authored andcommitted
ext4: prevent used blocks from being allocated during fast commit replay
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]> Cc: [email protected]
1 parent 6eeaf88 commit 599ea31

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

fs/ext4/ext4.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2934,6 +2934,9 @@ void ext4_fc_replay_cleanup(struct super_block *sb);
29342934
int ext4_fc_commit(journal_t *journal, tid_t commit_tid);
29352935
int __init ext4_fc_init_dentry_cache(void);
29362936
void ext4_fc_destroy_dentry_cache(void);
2937+
int ext4_fc_record_regions(struct super_block *sb, int ino,
2938+
ext4_lblk_t lblk, ext4_fsblk_t pblk,
2939+
int len, int replay);
29372940

29382941
/* mballoc.c */
29392942
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
@@ -6093,11 +6093,15 @@ int ext4_ext_clear_bb(struct inode *inode)
60936093

60946094
ext4_mb_mark_bb(inode->i_sb,
60956095
path[j].p_block, 1, 0);
6096+
ext4_fc_record_regions(inode->i_sb, inode->i_ino,
6097+
0, path[j].p_block, 1, 1);
60966098
}
60976099
ext4_ext_drop_refs(path);
60986100
kfree(path);
60996101
}
61006102
ext4_mb_mark_bb(inode->i_sb, map.m_pblk, map.m_len, 0);
6103+
ext4_fc_record_regions(inode->i_sb, inode->i_ino,
6104+
map.m_lblk, map.m_pblk, map.m_len, 1);
61016105
}
61026106
cur = cur + map.m_len;
61036107
}

fs/ext4/fast_commit.c

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

15651565
/*
1566-
* Record physical disk regions which are in use as per fast commit area. Our
1567-
* simple replay phase allocator excludes these regions from allocation.
1566+
* Record physical disk regions which are in use as per fast commit area,
1567+
* and used by inodes during replay phase. Our simple replay phase
1568+
* allocator excludes these regions from allocation.
15681569
*/
1569-
static int ext4_fc_record_regions(struct super_block *sb, int ino,
1570-
ext4_lblk_t lblk, ext4_fsblk_t pblk, int len)
1570+
int ext4_fc_record_regions(struct super_block *sb, int ino,
1571+
ext4_lblk_t lblk, ext4_fsblk_t pblk, int len, int replay)
15711572
{
15721573
struct ext4_fc_replay_state *state;
15731574
struct ext4_fc_alloc_region *region;
15741575

15751576
state = &EXT4_SB(sb)->s_fc_replay_state;
1577+
/*
1578+
* during replay phase, the fc_regions_valid may not same as
1579+
* fc_regions_used, update it when do new additions.
1580+
*/
1581+
if (replay && state->fc_regions_used != state->fc_regions_valid)
1582+
state->fc_regions_used = state->fc_regions_valid;
15761583
if (state->fc_regions_used == state->fc_regions_size) {
15771584
state->fc_regions_size +=
15781585
EXT4_FC_REPLAY_REALLOC_INCREMENT;
@@ -1590,6 +1597,9 @@ static int ext4_fc_record_regions(struct super_block *sb, int ino,
15901597
region->pblk = pblk;
15911598
region->len = len;
15921599

1600+
if (replay)
1601+
state->fc_regions_valid++;
1602+
15931603
return 0;
15941604
}
15951605

@@ -1937,7 +1947,7 @@ static int ext4_fc_replay_scan(journal_t *journal,
19371947
ret = ext4_fc_record_regions(sb,
19381948
le32_to_cpu(ext.fc_ino),
19391949
le32_to_cpu(ex->ee_block), ext4_ext_pblock(ex),
1940-
ext4_ext_get_actual_len(ex));
1950+
ext4_ext_get_actual_len(ex), 0);
19411951
if (ret < 0)
19421952
break;
19431953
ret = JBD2_FC_REPLAY_CONTINUE;

0 commit comments

Comments
 (0)