diff options
author | qixiaoyu1 <qxy65535@gmail.com> | 2023-02-02 16:20:27 +0800 |
---|---|---|
committer | Jaegeuk Kim <jaegeuk@kernel.org> | 2023-02-05 19:30:05 -0800 |
commit | b03a41a495df35f8e8d25220878bd6b8472d9396 (patch) | |
tree | 7be4793abf7e3c13db683e0344f6d1f484b3af30 /fs/f2fs | |
parent | a84153f939808102dfa10904aa0f743e734a3e1d (diff) | |
download | linux-stable-b03a41a495df35f8e8d25220878bd6b8472d9396.tar.gz linux-stable-b03a41a495df35f8e8d25220878bd6b8472d9396.tar.bz2 linux-stable-b03a41a495df35f8e8d25220878bd6b8472d9396.zip |
f2fs: fix wrong calculation of block age
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>
Diffstat (limited to 'fs/f2fs')
-rw-r--r-- | fs/f2fs/extent_cache.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c index 1daf8c88c09b..c8efc957c230 100644 --- a/fs/f2fs/extent_cache.c +++ b/fs/f2fs/extent_cache.c @@ -874,11 +874,18 @@ unlock_out: 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 */ |