From: qixiaoyu <qxy65535@gmail.com>
To: Chao Yu <chao@kernel.org>, 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: [PATCH 1/2 v2] f2fs: fix wrong calculation of block age
Date: Sun, 29 Jan 2023 19:18:37 +0800 [thread overview]
Message-ID: <Y9ZWDVV3HJ431Fis@mi-HP-ProDesk-680-G4-MT> (raw)
In-Reply-To: <7c12ebaa-4d3d-e475-dfb2-7b459cd26e64@kernel.org>
On Sat, Jan 28, 2023 at 11:35:34AM +0800, Chao Yu wrote:
> 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,
>
We want to avoid overflow by doing the division first. To keep the accuracy, how
about updating as below:
res = div_u64_rem(new, 100, &rem_new) * (100 - LAST_AGE_WEIGHT)
+ div_u64_rem(old, 100, &rem_old) * LAST_AGE_WEIGHT;
res += rem_new * (100 - LAST_AGE_WEIGHT) / 100 + rem_old * LAST_AGE_WEIGHT / 100;
return res;
Thanks,
> > }
> > /* This returns a new age and allocated blocks in ei */
next prev parent reply other threads:[~2023-01-29 11:18 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-13 12:58 [PATCH 1/2] " qixiaoyu1
2023-01-13 12:58 ` [PATCH 2/2] f2fs: add sysfs nodes to set last_age_weight qixiaoyu1
2023-01-14 2:08 ` [PATCH 1/2] f2fs: fix wrong calculation of block age kernel test robot
2023-01-14 5:20 ` kernel test robot
2023-01-14 8:52 ` kernel test robot
2023-01-16 3:08 ` [PATCH 1/2 v2] " qixiaoyu1
2023-01-16 3:08 ` [PATCH 2/2 v2] f2fs: add sysfs nodes to set last_age_weight qixiaoyu1
2023-01-28 3:35 ` [PATCH 1/2 v2] f2fs: fix wrong calculation of block age Chao Yu
2023-01-29 11:18 ` qixiaoyu [this message]
2023-02-01 12:23 ` qixiaoyu
2023-02-01 12:57 ` Chao Yu
2023-02-01 14:04 ` qixiaoyu
2023-02-02 8:20 ` [PATCH 1/2 v3] " qixiaoyu1
2023-02-02 8:20 ` [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 ` [PATCH 2/2 v4] " qixiaoyu1
2023-02-07 12:31 ` Chao Yu
2023-02-07 18:39 ` Jaegeuk Kim
2023-02-03 6:11 ` [PATCH 1/2 v3] f2fs: fix wrong calculation of block age Chao Yu
2023-02-06 3:40 ` [f2fs-dev] " 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=Y9ZWDVV3HJ431Fis@mi-HP-ProDesk-680-G4-MT \
--to=qxy65535@gmail.com \
--cc=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=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
all inboxes | Powered by JetHome®