Skip to content

Commit

Permalink
f2fs: fix wrong calculation of block age
Browse files Browse the repository at this point in the history
Currently we wrongly calculate the new block age to
old * LAST_AGE_WEIGHT / 100.

Fix it to new * (100 - LAST_AGE_WEIGHT) / 100
                + old * LAST_AGE_WEIGHT / 100.

Signed-off-by: qixiaoyu1 <qixiaoyu1@xiaomi.com>
Signed-off-by: xiongping1 <xiongping1@xiaomi.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
  • Loading branch information
qixiaoyu1 authored and Jaegeuk Kim committed Feb 6, 2023
1 parent a84153f commit b03a41a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions fs/f2fs/extent_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -874,11 +874,18 @@ void f2fs_update_read_extent_tree_range_compressed(struct inode *inode,
static unsigned long long __calculate_block_age(unsigned long long new,
unsigned long long old)
{
unsigned long long diff;
unsigned int rem_old, rem_new;
unsigned long long res;

diff = (new >= old) ? new - (new - old) : new + (old - new);
res = div_u64_rem(new, 100, &rem_new) * (100 - LAST_AGE_WEIGHT)
+ div_u64_rem(old, 100, &rem_old) * LAST_AGE_WEIGHT;

return div_u64(diff * LAST_AGE_WEIGHT, 100);
if (rem_new)
res += rem_new * (100 - LAST_AGE_WEIGHT) / 100;
if (rem_old)
res += rem_old * LAST_AGE_WEIGHT / 100;

return res;
}

/* This returns a new age and allocated blocks in ei */
Expand Down

0 comments on commit b03a41a

Please sign in to comment.