Commit 6f3a01ae authored by Chao Yu's avatar Chao Yu Committed by Jaegeuk Kim

f2fs: record average update time of segment

Previously, once we update one block in segment, we will update mtime of
segment to last time, making aged segment becoming freshest, result in
that GC with cost benefit algorithm missing such segment, So this patch
changes to record mtime as average block updating time instead of last
updating time.

It's not needed to reset mtime for prefree segment, as se->valid_blocks
is zero, then old se->mtime won't take any weight with below calculation:

	se->mtime = div_u64(se->mtime * se->valid_blocks + mtime,
					se->valid_blocks + 1);
Signed-off-by: default avatarChao Yu <yuchao0@huawei.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent d0b9e42a
...@@ -2154,6 +2154,22 @@ static void __set_sit_entry_type(struct f2fs_sb_info *sbi, int type, ...@@ -2154,6 +2154,22 @@ static void __set_sit_entry_type(struct f2fs_sb_info *sbi, int type,
__mark_sit_entry_dirty(sbi, segno); __mark_sit_entry_dirty(sbi, segno);
} }
static void update_segment_mtime(struct f2fs_sb_info *sbi, block_t blkaddr)
{
unsigned int segno = GET_SEGNO(sbi, blkaddr);
struct seg_entry *se = get_seg_entry(sbi, segno);
unsigned long long mtime = get_mtime(sbi, false);
if (!se->mtime)
se->mtime = mtime;
else
se->mtime = div_u64(se->mtime * se->valid_blocks + mtime,
se->valid_blocks + 1);
if (mtime > SIT_I(sbi)->max_mtime)
SIT_I(sbi)->max_mtime = mtime;
}
static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del) static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del)
{ {
struct seg_entry *se; struct seg_entry *se;
...@@ -2173,10 +2189,9 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del) ...@@ -2173,10 +2189,9 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del)
f2fs_bug_on(sbi, (new_vblocks < 0 || f2fs_bug_on(sbi, (new_vblocks < 0 ||
(new_vblocks > f2fs_usable_blks_in_seg(sbi, segno)))); (new_vblocks > f2fs_usable_blks_in_seg(sbi, segno))));
update_segment_mtime(sbi, blkaddr);
se->valid_blocks = new_vblocks; se->valid_blocks = new_vblocks;
se->mtime = get_mtime(sbi, false);
if (se->mtime > SIT_I(sbi)->max_mtime)
SIT_I(sbi)->max_mtime = se->mtime;
/* Update valid block bitmap */ /* Update valid block bitmap */
if (del > 0) { if (del > 0) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment