* [PATCH 1/2] f2fs: fix to caclulate required free section correctly
@ 2018-01-10 10:18 Chao Yu
2018-01-10 10:18 ` [PATCH 2/2] f2fs: speed up defragment on sparse file Chao Yu
0 siblings, 1 reply; 2+ messages in thread
From: Chao Yu @ 2018-01-10 10:18 UTC (permalink / raw)
To: jaegeuk; +Cc: linux-f2fs-devel, linux-kernel, chao, Chao Yu
When calculating required free section during file defragmenting, we
should skip holes in file, otherwise we will probably fail to defrag
sparse file with large size.
Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
fs/f2fs/file.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 926757e6065c..2fb3bab05872 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -2140,10 +2140,12 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
continue;
}
- if (blk_end && blk_end != map.m_pblk) {
+ if (blk_end && blk_end != map.m_pblk)
fragmented = true;
- break;
- }
+
+ /* record total count of block that we're going to move */
+ total += map.m_len;
+
blk_end = map.m_pblk + map.m_len;
map.m_lblk += map.m_len;
@@ -2152,10 +2154,7 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
if (!fragmented)
goto out;
- map.m_lblk = pg_start;
- map.m_len = pg_end - pg_start;
-
- sec_num = (map.m_len + BLKS_PER_SEC(sbi) - 1) / BLKS_PER_SEC(sbi);
+ sec_num = (total + BLKS_PER_SEC(sbi) - 1) / BLKS_PER_SEC(sbi);
/*
* make sure there are enough free section for LFS allocation, this can
@@ -2167,6 +2166,10 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
goto out;
}
+ map.m_lblk = pg_start;
+ map.m_len = pg_end - pg_start;
+ total = 0;
+
while (map.m_lblk < pg_end) {
pgoff_t idx;
int cnt = 0;
--
2.15.0.55.gc2ece9dc4de6
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH 2/2] f2fs: speed up defragment on sparse file
2018-01-10 10:18 [PATCH 1/2] f2fs: fix to caclulate required free section correctly Chao Yu
@ 2018-01-10 10:18 ` Chao Yu
0 siblings, 0 replies; 2+ messages in thread
From: Chao Yu @ 2018-01-10 10:18 UTC (permalink / raw)
To: jaegeuk; +Cc: linux-f2fs-devel, linux-kernel, chao, Chao Yu
We have supported to get next page offset with valid mapping crossing
hole in f2fs_map_blocks, utilizing it to speed up defragment on sparse
file.
Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
fs/f2fs/data.c | 6 +++++-
fs/f2fs/file.c | 11 ++++++-----
2 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 882b5acc2b6f..d671657ade8a 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -1012,8 +1012,12 @@ int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
*map->m_next_pgofs = pgofs + 1;
goto sync_out;
}
- if (flag != F2FS_GET_BLOCK_FIEMAP)
+ if (flag != F2FS_GET_BLOCK_FIEMAP) {
+ /* for defragment case */
+ if (map->m_next_pgofs)
+ *map->m_next_pgofs = pgofs + 1;
goto sync_out;
+ }
}
}
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 2fb3bab05872..ac22ecda7787 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -2086,10 +2086,10 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
struct f2fs_defragment *range)
{
struct inode *inode = file_inode(filp);
- struct f2fs_map_blocks map = { .m_next_pgofs = NULL,
- .m_next_extent = NULL, .m_seg_type = NO_CHECK_TYPE };
+ struct f2fs_map_blocks map = { .m_next_extent = NULL,
+ .m_seg_type = NO_CHECK_TYPE };
struct extent_info ei = {0,0,0};
- pgoff_t pg_start, pg_end;
+ pgoff_t pg_start, pg_end, next_pgofs;
unsigned int blk_per_seg = sbi->blocks_per_seg;
unsigned int total = 0, sec_num;
block_t blk_end = 0;
@@ -2123,6 +2123,7 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
}
map.m_lblk = pg_start;
+ map.m_next_pgofs = &next_pgofs;
/*
* lookup mapping info in dnode page cache, skip defragmenting if all
@@ -2136,7 +2137,7 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
goto out;
if (!(map.m_flags & F2FS_MAP_FLAGS)) {
- map.m_lblk++;
+ map.m_lblk = next_pgofs;
continue;
}
@@ -2181,7 +2182,7 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi,
goto clear_out;
if (!(map.m_flags & F2FS_MAP_FLAGS)) {
- map.m_lblk++;
+ map.m_lblk = next_pgofs;
continue;
}
--
2.15.0.55.gc2ece9dc4de6
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-01-10 10:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-10 10:18 [PATCH 1/2] f2fs: fix to caclulate required free section correctly Chao Yu
2018-01-10 10:18 ` [PATCH 2/2] f2fs: speed up defragment on sparse file Chao Yu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).