ext4: minor cleanup
Subsystems (2)
v4 cover ext4: minor cleanup
v3->v4: remove "ext4: remove useless code in ext4_map_create_blocks" since we should keep this logic which needed for latter work from Yi[1].
v2->v3: remove "ext4: order mode should not take effect for DIO" since there is no measurable performance benefit
v1->v2: update comments for EXT4_GET_BLOCKS_SPLIT_NOMERGE
1. https://lore.kernel.org/linux-ext4/[email protected]/
Yang Erkun (3):
ext4: rename EXT4_GET_BLOCKS_PRE_IO
ext4: cleanup for ext4_map_blocks
ext4: correct the comments place for EXT4_EXT_MAY_ZEROOUT
fs/ext4/ext4.h | 21 +++++++++++++++------ fs/ext4/extents.c | 24 ++++++++++++------------ fs/ext4/inode.c | 18 ++++++++++-------- include/trace/events/ext4.h | 2 +- 4 files changed, 38 insertions(+), 27 deletions(-)
Signature · 1 line
2.39.2
PATCH v4 1/3 ext4: rename EXT4_GET_BLOCKS_PRE_IO
This flag has been generalized to split an unwritten extent when we do dio or dioread_nolock writeback, or to avoid merge new extents which was created by extents split. Update some related comments too.
--- fs/ext4/ext4.h | 21 +++++++++++++++------ fs/ext4/extents.c | 16 ++++++++-------- fs/ext4/inode.c | 2 +- include/trace/events/ext4.h | 2 +- 4 files changed, 25 insertions(+), 16 deletions(-)
fs/ext4/ext4.h +15 -6
@@ -694,13 +694,22 @@ enum {/* Caller is from the delayed allocation writeout path * finally doing the actual allocation of delayed blocks */ #define EXT4_GET_BLOCKS_DELALLOC_RESERVE 0x0004 -/* caller is from the direct IO path, request to creation of an -unwritten extents if not allocated, split the unwritten -extent if blocks has been preallocated already*/ -#define EXT4_GET_BLOCKS_PRE_IO 0x0008 -#define EXT4_GET_BLOCKS_CONVERT 0x0010 -#define EXT4_GET_BLOCKS_IO_CREATE_EXT (EXT4_GET_BLOCKS_PRE_IO|\ +/* +* This means that we cannot merge newly allocated extents, and if we +* found an unwritten extent, we need to split it. +*/ +#define EXT4_GET_BLOCKS_SPLIT_NOMERGE 0x0008 +/* +* Caller is from the dio or dioread_nolock buffered IO, reqest to +* create an unwritten extent if it does not exist or split the +* found unwritten extent. Also do not merge the newly created +* unwritten extent, io end will convert unwritten to written, +* and try to merge the written extent. +*/ +#define EXT4_GET_BLOCKS_IO_CREATE_EXT (EXT4_GET_BLOCKS_SPLIT_NOMERGE|\ EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT) +/* Convert unwritten extent to initialized. */ +#define EXT4_GET_BLOCKS_CONVERT 0x0010/* Eventual metadata allocation (due to growing extent tree) * should not fail, so try to use reserved blocks for that.*/ #define EXT4_GET_BLOCKS_METADATA_NOFAIL 0x0020
fs/ext4/extents.c +8 -8
@@ -333,7 +333,7 @@ ext4_force_split_extent_at(handle_t *handle, struct inode *inode, int nofail) {int unwritten =ext4_ext_is_unwritten (path[path->p_depth].p_ext); -int flags =EXT4_EX_NOCACHE |EXT4_GET_BLOCKS_PRE_IO ; +int flags =EXT4_EX_NOCACHE |EXT4_GET_BLOCKS_SPLIT_NOMERGE ;if (nofail) flags |=EXT4_GET_BLOCKS_METADATA_NOFAIL |EXT4_EX_NOFAIL ;
@@ -2002,7 +2002,7 @@ ext4_ext_insert_extent(handle_t *handle, struct inode *inode, }/* try to insert block into found extent and return */ -if (ex && !(gb_flags &EXT4_GET_BLOCKS_PRE_IO )) { +if (ex && !(gb_flags &EXT4_GET_BLOCKS_SPLIT_NOMERGE )) {/* * Try to see whether we should rather test the extent on
@@ -2181,7 +2181,7 @@ ext4_ext_insert_extent(handle_t *handle, struct inode *inode, merge:/* try to merge extents */ -if (!(gb_flags &EXT4_GET_BLOCKS_PRE_IO )) +if (!(gb_flags &EXT4_GET_BLOCKS_SPLIT_NOMERGE ))ext4_ext_try_to_merge (handle, inode, path, nearex);/* time to correct all indexes above */
@@ -3224,7 +3224,7 @@ static struct ext4_ext_path *ext4_split_extent_at(handle_t *handle,else ext4_ext_mark_initialized (ex); -if (!(flags &EXT4_GET_BLOCKS_PRE_IO )) +if (!(flags &EXT4_GET_BLOCKS_SPLIT_NOMERGE ))ext4_ext_try_to_merge (handle, inode, path, ex); err =ext4_ext_dirty (handle, inode, path + path->p_depth);
@@ -3368,7 +3368,7 @@ static struct ext4_ext_path *ext4_split_extent(handle_t *handle,if (map->m_lblk + map->m_len < ee_block + ee_len) { split_flag1 = split_flag &EXT4_EXT_MAY_ZEROOUT ; - flags1 = flags |EXT4_GET_BLOCKS_PRE_IO ; + flags1 = flags |EXT4_GET_BLOCKS_SPLIT_NOMERGE ;if (unwritten) split_flag1 |=EXT4_EXT_MARK_UNWRIT1 |EXT4_EXT_MARK_UNWRIT2 ;
@@ -3739,7 +3739,7 @@ static struct ext4_ext_path *ext4_split_convert_extents(handle_t *handle, EXT4_EXT_MAY_ZEROOUT :0 ; split_flag |= (EXT4_EXT_MARK_UNWRIT2 |EXT4_EXT_DATA_VALID2 ); } - flags |=EXT4_GET_BLOCKS_PRE_IO ; + flags |=EXT4_GET_BLOCKS_SPLIT_NOMERGE ;return ext4_split_extent (handle, inode, path, map, split_flag, flags, allocated); }
@@ -3911,7 +3911,7 @@ ext4_ext_handle_unwritten_extents(handle_t *handle, struct inode *inode, *allocated, newblock);/* get_block() before submitting IO, split the extent */ -if (flags &EXT4_GET_BLOCKS_PRE_IO ) { +if (flags &EXT4_GET_BLOCKS_SPLIT_NOMERGE ) { path =ext4_split_convert_extents (handle, inode, map, path, flags |EXT4_GET_BLOCKS_CONVERT , allocated);if (IS_ERR (path))
@@ -5618,7 +5618,7 @@ static int ext4_insert_range(struct file *file, loff_t offset, loff_t len) path =ext4_split_extent_at (handle, inode, path, start_lblk, split_flag,EXT4_EX_NOCACHE | -EXT4_GET_BLOCKS_PRE_IO | +EXT4_GET_BLOCKS_SPLIT_NOMERGE |EXT4_GET_BLOCKS_METADATA_NOFAIL ); }
fs/ext4/inode.c +1 -1
@@ -648,7 +648,7 @@ static int ext4_map_create_blocks(handle_t *handle, struct inode *inode,* If the extent has been zeroed out, we don't need to update * extent status tree. */ -if (flags &EXT4_GET_BLOCKS_PRE_IO && +if (flags &EXT4_GET_BLOCKS_SPLIT_NOMERGE &&ext4_es_lookup_extent (inode, map->m_lblk,NULL , &es)) {if (ext4_es_is_written (&es))return retval;
include/trace/events/ext4.h +1 -1
@@ -39,7 +39,7 @@ struct partial_cluster; { EXT4_GET_BLOCKS_CREATE, "CREATE" }, \ { EXT4_GET_BLOCKS_UNWRIT_EXT, "UNWRIT" }, \ { EXT4_GET_BLOCKS_DELALLOC_RESERVE, "DELALLOC" }, \ - { EXT4_GET_BLOCKS_PRE_IO, "PRE_IO" }, \ + { EXT4_GET_BLOCKS_SPLIT_NOMERGE, "SPLIT_NOMERGE" }, \ { EXT4_GET_BLOCKS_CONVERT, "CONVERT" }, \ { EXT4_GET_BLOCKS_METADATA_NOFAIL, "METADATA_NOFAIL" }, \ { EXT4_GET_BLOCKS_NO_NORMALIZE, "NO_NORMALIZE" }, \
Signature · 1 line
2.39.2
PATCH v4 2/3 ext4: cleanup for ext4_map_blocks
In reply to Yang ErkunRetval from ext4_map_create_blocks means we really create some blocks, cannot happened with m_flags without EXT4_MAP_UNWRITTEN and EXT4_MAP_MAPPED.
--- fs/ext4/inode.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
fs/ext4/inode.c +9 -7
@@ -810,7 +810,13 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,down_write (&EXT4_I (inode)->i_data_sem); retval =ext4_map_create_blocks (handle, inode, map, flags);up_write ((&EXT4_I (inode)->i_data_sem)); -if (retval >0 && map->m_flags &EXT4_MAP_MAPPED ) { + +if (retval <0 ) +ext_debug (inode,"failed with err %d\n" , retval); +if (retval <=0 ) +return retval; + +if (map->m_flags &EXT4_MAP_MAPPED ) { ret =check_block_validity (inode, map);if (ret !=0 )return ret;
@@ -839,12 +845,8 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,return ret; } } -if (retval >0 && (map->m_flags &EXT4_MAP_UNWRITTEN || - map->m_flags &EXT4_MAP_MAPPED )) -ext4_fc_track_range (handle, inode, map->m_lblk, - map->m_lblk + map->m_len -1 ); -if (retval <0 ) -ext_debug (inode,"failed with err %d\n" , retval); +ext4_fc_track_range (handle, inode, map->m_lblk, map->m_lblk + + map->m_len -1 );return retval; }
Signature · 1 line
2.39.2
PATCH v4 3/3 ext4: correct the comments place for EXT4_EXT_MAY_ZEROOUT
In reply to Yang ErkunMove the comments just before we set EXT4_EXT_MAY_ZEROOUT in ext4_split_convert_extents.
--- fs/ext4/extents.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/ext4/extents.c +4 -4
@@ -3721,10 +3721,6 @@ static struct ext4_ext_path *ext4_split_convert_extents(handle_t *handle, >> inode->i_sb->s_blocksize_bits;if (eof_block < map->m_lblk + map->m_len) eof_block = map->m_lblk + map->m_len; -/* -* It is safe to convert extent to initialized via explicit -* zeroout only if extent is fully inside i_size or new_size. -*/ depth =ext_depth (inode); ex = path[depth].p_ext; ee_block =le32_to_cpu (ex->ee_block);
@@ -3735,6 +3731,10 @@ static struct ext4_ext_path *ext4_split_convert_extents(handle_t *handle, split_flag |=EXT4_EXT_DATA_VALID1 ;/* Convert to initialized */ }else if (flags &EXT4_GET_BLOCKS_CONVERT ) { +/* +* It is safe to convert extent to initialized via explicit +* zeroout only if extent is fully inside i_size or new_size. +*/ split_flag |= ee_block + ee_len <= eof_block ?EXT4_EXT_MAY_ZEROOUT :0 ; split_flag |= (EXT4_EXT_MARK_UNWRIT2 |EXT4_EXT_DATA_VALID2 );
Signature · 1 line
2.39.2
Quoted 9 lines · Yang Erkun
v3->v4: remove "ext4: remove useless code inext4_map_create_blocks" since we should keep this logic which needed for latter work from Yi[1].
v2->v3: remove "ext4: order mode should not take effect for DIO" since there is no measurable performance benefit
v1->v2: update comments forEXT4_GET_BLOCKS_SPLIT_NOMERGE[...]
Applied, thanks!
[1/3] ext4: rename EXT4_GET_BLOCKS_PRE_IO
commit: dac092195b6a35bc7c9f11e2884cfecb1b25e20c
[2/3] ext4: cleanup for ext4_map_blocks
commit: a9272422316f6c0ddbdfd03e695079e2b3655995
[3/3] ext4: correct the comments place for EXT4_EXT_MAY_ZEROOUT
commit: cc742fd1d184bb2a11bacf50587d2c85290622e4Best regards,
Signature · 1 line
Theodore Ts'o <[email protected]>