Skip to content

Commit 2352e3e

Browse files
LiBaokun96tytso
authored andcommitted
ext4: make some fast commit functions reuse extents path
The ext4_find_extent() can update the extent path so that it does not have to allocate and free the path repeatedly, thus reducing the consumption of memory allocation and freeing in the following functions: ext4_ext_clear_bb ext4_ext_replay_set_iblocks ext4_fc_replay_add_range ext4_fc_set_bitmaps_and_counters No functional changes. Note that ext4_find_extent() does not support error pointers, so in this case set path to NULL first. Signed-off-by: Baokun Li <[email protected]> Reviewed-by: Jan Kara <[email protected]> Reviewed-by: Ojaswin Mujoo <[email protected]> Tested-by: Ojaswin Mujoo <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent a2c613b commit 2352e3e

File tree

2 files changed

+29
-33
lines changed

2 files changed

+29
-33
lines changed

fs/ext4/extents.c

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6033,12 +6033,9 @@ int ext4_ext_replay_set_iblocks(struct inode *inode)
60336033
if (IS_ERR(path))
60346034
return PTR_ERR(path);
60356035
ex = path[path->p_depth].p_ext;
6036-
if (!ex) {
6037-
ext4_free_ext_path(path);
6036+
if (!ex)
60386037
goto out;
6039-
}
60406038
end = le32_to_cpu(ex->ee_block) + ext4_ext_get_actual_len(ex);
6041-
ext4_free_ext_path(path);
60426039

60436040
/* Count the number of data blocks */
60446041
cur = 0;
@@ -6064,32 +6061,28 @@ int ext4_ext_replay_set_iblocks(struct inode *inode)
60646061
ret = skip_hole(inode, &cur);
60656062
if (ret < 0)
60666063
goto out;
6067-
path = ext4_find_extent(inode, cur, NULL, 0);
6064+
path = ext4_find_extent(inode, cur, path, 0);
60686065
if (IS_ERR(path))
60696066
goto out;
60706067
numblks += path->p_depth;
6071-
ext4_free_ext_path(path);
60726068
while (cur < end) {
6073-
path = ext4_find_extent(inode, cur, NULL, 0);
6069+
path = ext4_find_extent(inode, cur, path, 0);
60746070
if (IS_ERR(path))
60756071
break;
60766072
ex = path[path->p_depth].p_ext;
6077-
if (!ex) {
6078-
ext4_free_ext_path(path);
6079-
return 0;
6080-
}
6073+
if (!ex)
6074+
goto cleanup;
6075+
60816076
cur = max(cur + 1, le32_to_cpu(ex->ee_block) +
60826077
ext4_ext_get_actual_len(ex));
60836078
ret = skip_hole(inode, &cur);
6084-
if (ret < 0) {
6085-
ext4_free_ext_path(path);
6079+
if (ret < 0)
60866080
break;
6087-
}
6088-
path2 = ext4_find_extent(inode, cur, NULL, 0);
6089-
if (IS_ERR(path2)) {
6090-
ext4_free_ext_path(path);
6081+
6082+
path2 = ext4_find_extent(inode, cur, path2, 0);
6083+
if (IS_ERR(path2))
60916084
break;
6092-
}
6085+
60936086
for (i = 0; i <= max(path->p_depth, path2->p_depth); i++) {
60946087
cmp1 = cmp2 = 0;
60956088
if (i <= path->p_depth)
@@ -6101,13 +6094,14 @@ int ext4_ext_replay_set_iblocks(struct inode *inode)
61016094
if (cmp1 != cmp2 && cmp2 != 0)
61026095
numblks++;
61036096
}
6104-
ext4_free_ext_path(path);
6105-
ext4_free_ext_path(path2);
61066097
}
61076098

61086099
out:
61096100
inode->i_blocks = numblks << (inode->i_sb->s_blocksize_bits - 9);
61106101
ext4_mark_inode_dirty(NULL, inode);
6102+
cleanup:
6103+
ext4_free_ext_path(path);
6104+
ext4_free_ext_path(path2);
61116105
return 0;
61126106
}
61136107

@@ -6128,12 +6122,9 @@ int ext4_ext_clear_bb(struct inode *inode)
61286122
if (IS_ERR(path))
61296123
return PTR_ERR(path);
61306124
ex = path[path->p_depth].p_ext;
6131-
if (!ex) {
6132-
ext4_free_ext_path(path);
6133-
return 0;
6134-
}
6125+
if (!ex)
6126+
goto out;
61356127
end = le32_to_cpu(ex->ee_block) + ext4_ext_get_actual_len(ex);
6136-
ext4_free_ext_path(path);
61376128

61386129
cur = 0;
61396130
while (cur < end) {
@@ -6143,16 +6134,16 @@ int ext4_ext_clear_bb(struct inode *inode)
61436134
if (ret < 0)
61446135
break;
61456136
if (ret > 0) {
6146-
path = ext4_find_extent(inode, map.m_lblk, NULL, 0);
6147-
if (!IS_ERR_OR_NULL(path)) {
6137+
path = ext4_find_extent(inode, map.m_lblk, path, 0);
6138+
if (!IS_ERR(path)) {
61486139
for (j = 0; j < path->p_depth; j++) {
6149-
61506140
ext4_mb_mark_bb(inode->i_sb,
61516141
path[j].p_block, 1, false);
61526142
ext4_fc_record_regions(inode->i_sb, inode->i_ino,
61536143
0, path[j].p_block, 1, 1);
61546144
}
6155-
ext4_free_ext_path(path);
6145+
} else {
6146+
path = NULL;
61566147
}
61576148
ext4_mb_mark_bb(inode->i_sb, map.m_pblk, map.m_len, false);
61586149
ext4_fc_record_regions(inode->i_sb, inode->i_ino,
@@ -6161,5 +6152,7 @@ int ext4_ext_clear_bb(struct inode *inode)
61616152
cur = cur + map.m_len;
61626153
}
61636154

6155+
out:
6156+
ext4_free_ext_path(path);
61646157
return 0;
61656158
}

fs/ext4/fast_commit.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,7 +1792,7 @@ static int ext4_fc_replay_add_range(struct super_block *sb,
17921792

17931793
if (ret == 0) {
17941794
/* Range is not mapped */
1795-
path = ext4_find_extent(inode, cur, NULL, 0);
1795+
path = ext4_find_extent(inode, cur, path, 0);
17961796
if (IS_ERR(path))
17971797
goto out;
17981798
memset(&newex, 0, sizeof(newex));
@@ -1808,7 +1808,6 @@ static int ext4_fc_replay_add_range(struct super_block *sb,
18081808
up_write((&EXT4_I(inode)->i_data_sem));
18091809
if (IS_ERR(path))
18101810
goto out;
1811-
ext4_free_ext_path(path);
18121811
goto next;
18131812
}
18141813

@@ -1856,6 +1855,7 @@ static int ext4_fc_replay_add_range(struct super_block *sb,
18561855
ext4_ext_replay_shrink_inode(inode, i_size_read(inode) >>
18571856
sb->s_blocksize_bits);
18581857
out:
1858+
ext4_free_ext_path(path);
18591859
iput(inode);
18601860
return 0;
18611861
}
@@ -1956,12 +1956,13 @@ static void ext4_fc_set_bitmaps_and_counters(struct super_block *sb)
19561956
break;
19571957

19581958
if (ret > 0) {
1959-
path = ext4_find_extent(inode, map.m_lblk, NULL, 0);
1959+
path = ext4_find_extent(inode, map.m_lblk, path, 0);
19601960
if (!IS_ERR(path)) {
19611961
for (j = 0; j < path->p_depth; j++)
19621962
ext4_mb_mark_bb(inode->i_sb,
19631963
path[j].p_block, 1, true);
1964-
ext4_free_ext_path(path);
1964+
} else {
1965+
path = NULL;
19651966
}
19661967
cur += ret;
19671968
ext4_mb_mark_bb(inode->i_sb, map.m_pblk,
@@ -1972,6 +1973,8 @@ static void ext4_fc_set_bitmaps_and_counters(struct super_block *sb)
19721973
}
19731974
iput(inode);
19741975
}
1976+
1977+
ext4_free_ext_path(path);
19751978
}
19761979

19771980
/*

0 commit comments

Comments
 (0)