f2fs: no need to punch hole far beyond the file size
PATCH 1/1 f2fs: no need to punch hole far beyond the file size
Punching hole with a length which far larger than file size will cause a long time looping in truncate_hole after lock_op, it can be reproduced as the following:
$ echo "abc" > file
$ xfs_io -c "fpunch 0 HUGE_LENGTH" fileThis may cause other I/Os blocked a long time. Let's fix this case by setting the hole to end after the page that contains i_size.
--- fs/f2fs/file.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/f2fs/file.c +8 -0
@@ -873,6 +873,14 @@ static int punch_hole(struct inode *inode, loff_t offset, loff_t len)if (ret)return ret; +/* +* If the hole extends beyond i_size, set the hole +* to end after the page that contains i_size +*/ +if (offset + len > inode->i_size) + len = inode->i_size +PAGE_CACHE_SIZE - + (inode->i_size & (PAGE_CACHE_SIZE -1 )) - offset; + pg_start = ((unsigned long long ) offset) >>PAGE_SHIFT ; pg_end = ((unsigned long long ) offset + len) >>PAGE_SHIFT ;
Signature · 6 lines
2.10.1 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
Chao Yu
maintainerQuoted 9 lines · Weichao Guo
Punching hole with a length which far larger than file size will cause a long time looping in
truncate_holeafterlock_op, it can be reproduced as the following:$ echo "abc" > file $ xfs_io -c "fpunch 0 HUGE_LENGTH" fileThis may cause other I/Os blocked a long time. Let's fix this case by setting the hole to end after the page that contains
i_size.
You know, we can reserve blocks across EOF through fallocate(fd, FALLOC_FL_KEEP_SIZE, ofs, len), so this patch will cause f2fs losing ability of punching preallocated blocks across EOF.
How about below change:
fs/f2fs/file.c +1 -1
@@ -847,7 +847,7 @@ int truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end) err =get_dnode_of_data (&dn, pg_start,LOOKUP_NODE );if (err) {if (err == -ENOENT ) { - pg_start++; + pg_start =get_next_page_offset (&dn, pg_start);continue ; }return err;
Thanks,
Quoted 16 lines
Signed-off-by Weichao Guo <[email protected]>--- fs/f2fs/file.c | 8 ++++++++ 1 file changed, 8 insertions(+)fs/f2fs/file.c +1
-0@@ -873,6 +873,14 @@ static int punch_hole(struct inode *inode, loff_t offset, loff_t len)if (ret)return ret; +/*
fs/f2fs/file.c static int punch_hole(struct inode *inode, loff_t offset, loff_t len) · line 886
Quoted 10 lines
fs/f2fs/file.c +7
-0+* If the hole extends beyond i_size, set the hole +* to end after the page that contains i_size +*/ +if (offset + len > inode->i_size) + len = inode->i_size +PAGE_CACHE_SIZE - + (inode->i_size & (PAGE_CACHE_SIZE -1 )) - offset; + pg_start = ((unsigned long long ) offset) >>PAGE_SHIFT ; pg_end = ((unsigned long long ) offset + len) >>PAGE_SHIFT ;
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot