lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <7c12ebaa-4d3d-e475-dfb2-7b459cd26e64@kernel.org>
Date:   Sat, 28 Jan 2023 11:35:34 +0800
From:   Chao Yu <chao@...nel.org>
To:     qixiaoyu1 <qxy65535@...il.com>, Jaegeuk Kim <jaegeuk@...nel.org>
Cc:     linux-kernel@...r.kernel.org,
        linux-f2fs-devel@...ts.sourceforge.net, qixiaoyu1@...omi.com,
        xiongping1@...omi.com
Subject: Re: [PATCH 1/2 v2] f2fs: fix wrong calculation of block age

On 2023/1/16 11:08, qixiaoyu1 wrote:
> 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@...omi.com>
> Signed-off-by: xiongping1 <xiongping1@...omi.com>
> ---
> Change log v1 -> v2:
>   - fix udiv
> 
>   fs/f2fs/extent_cache.c | 7 ++-----
>   1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c
> index 342af24b2f8c..ad5533f178fd 100644
> --- a/fs/f2fs/extent_cache.c
> +++ b/fs/f2fs/extent_cache.c
> @@ -874,11 +874,8 @@ 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;
> -
> -	diff = (new >= old) ? new - (new - old) : new + (old - new);
> -
> -	return div_u64(diff * LAST_AGE_WEIGHT, 100);
> +	return div_u64(new, 100) * (100 - LAST_AGE_WEIGHT)
> +		+ div_u64(old, 100) * LAST_AGE_WEIGHT;

How about updating as below to avoid lossing accuracy if new is less than 100?

return div_u64(new * (100 - LAST_AGE_WEIGHT), 100) +
		div_u64(old * LAST_AGE_WEIGHT, 100);

Thanks,

>   }
>   
>   /* This returns a new age and allocated blocks in ei */

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ