linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
From: Chao Yu <chao@kernel.org>
To: qixiaoyu1 <qxy65535@gmail.com>, Jaegeuk Kim <jaegeuk@kernel.org>
Cc: xiongping1@xiaomi.com, qixiaoyu1@xiaomi.com,
	linux-kernel@vger.kernel.org,
	linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [f2fs-dev] [PATCH 1/2 v2] f2fs: fix wrong calculation of block age
Date: Sat, 28 Jan 2023 11:35:34 +0800	[thread overview]
Message-ID: <7c12ebaa-4d3d-e475-dfb2-7b459cd26e64@kernel.org> (raw)
In-Reply-To: <20230116030850.20260-1-qixiaoyu1@xiaomi.com>

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@xiaomi.com>
> Signed-off-by: xiongping1 <xiongping1@xiaomi.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 */


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

  parent reply	other threads:[~2023-01-28  3:35 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-13 12:58 [f2fs-dev] [PATCH 1/2] f2fs: fix wrong calculation of block age qixiaoyu1
2023-01-13 12:58 ` [f2fs-dev] [PATCH 2/2] f2fs: add sysfs nodes to set last_age_weight qixiaoyu1
2023-01-16  3:08 ` [f2fs-dev] [PATCH 1/2 v2] f2fs: fix wrong calculation of block age qixiaoyu1
2023-01-16  3:08   ` [f2fs-dev] [PATCH 2/2 v2] f2fs: add sysfs nodes to set last_age_weight qixiaoyu1
2023-01-28  3:35   ` Chao Yu [this message]
2023-01-29 11:18     ` [f2fs-dev] [PATCH 1/2 v2] f2fs: fix wrong calculation of block age qixiaoyu
2023-02-01 12:23       ` qixiaoyu
2023-02-01 12:57         ` Chao Yu
2023-02-01 14:04           ` qixiaoyu
2023-02-02  8:20           ` [f2fs-dev] [PATCH 1/2 v3] " qixiaoyu1
2023-02-02  8:20             ` [f2fs-dev] [PATCH 2/2 v3] f2fs: add sysfs nodes to set last_age_weight qixiaoyu1
2023-02-03  8:31               ` Chao Yu
2023-02-04  9:06                 ` qixiaoyu
2023-02-04  9:43                 ` [f2fs-dev] [PATCH 2/2 v4] " qixiaoyu1
2023-02-07 12:31                   ` Chao Yu
2023-02-07 18:39                     ` Jaegeuk Kim
2023-02-03  6:11             ` [f2fs-dev] [PATCH 1/2 v3] f2fs: fix wrong calculation of block age Chao Yu
2023-02-06  3:40             ` patchwork-bot+f2fs

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7c12ebaa-4d3d-e475-dfb2-7b459cd26e64@kernel.org \
    --to=chao@kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=qixiaoyu1@xiaomi.com \
    --cc=qxy65535@gmail.com \
    --cc=xiongping1@xiaomi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).