2023-01-13 13:37:55

by qixiaoyu1

[permalink] [raw]
Subject: [PATCH 1/2] 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 <[email protected]>
---
fs/f2fs/extent_cache.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c
index 342af24b2f8c..93a1ab186517 100644
--- a/fs/f2fs/extent_cache.c
+++ b/fs/f2fs/extent_cache.c
@@ -874,11 +874,7 @@ 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 new - new / 100 * LAST_AGE_WEIGHT + old / 100 * LAST_AGE_WEIGHT;
}

/* This returns a new age and allocated blocks in ei */
--
2.36.1


2023-01-14 02:15:28

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH 1/2] f2fs: fix wrong calculation of block age

Hi qixiaoyu1,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on v6.2-rc3]
[also build test ERROR on linus/master next-20230113]
[cannot apply to jaegeuk-f2fs/dev-test jaegeuk-f2fs/dev]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/qixiaoyu1/f2fs-add-sysfs-nodes-to-set-last_age_weight/20230113-211357
patch link: https://lore.kernel.org/r/20230113125859.15651-1-qixiaoyu1%40xiaomi.com
patch subject: [PATCH 1/2] f2fs: fix wrong calculation of block age
config: csky-randconfig-r014-20230112
compiler: csky-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/17ca20d13dd15a8fb4689cbe1817a8d037915199
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review qixiaoyu1/f2fs-add-sysfs-nodes-to-set-last_age_weight/20230113-211357
git checkout 17ca20d13dd15a8fb4689cbe1817a8d037915199
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=csky olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=csky SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>, old ones prefixed by <<):

>> ERROR: modpost: "__udivdi3" [fs/f2fs/f2fs.ko] undefined!

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests


Attachments:
(No filename) (1.91 kB)
config (147.75 kB)
Download all attachments

2023-01-14 05:30:23

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH 1/2] f2fs: fix wrong calculation of block age

Hi qixiaoyu1,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on v6.2-rc3]
[also build test ERROR on linus/master next-20230113]
[cannot apply to jaegeuk-f2fs/dev-test jaegeuk-f2fs/dev]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/qixiaoyu1/f2fs-add-sysfs-nodes-to-set-last_age_weight/20230113-211357
patch link: https://lore.kernel.org/r/20230113125859.15651-1-qixiaoyu1%40xiaomi.com
patch subject: [PATCH 1/2] f2fs: fix wrong calculation of block age
config: i386-randconfig-a002
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/17ca20d13dd15a8fb4689cbe1817a8d037915199
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review qixiaoyu1/f2fs-add-sysfs-nodes-to-set-last_age_weight/20230113-211357
git checkout 17ca20d13dd15a8fb4689cbe1817a8d037915199
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=i386 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>, old ones prefixed by <<):

>> ERROR: modpost: "__udivdi3" [fs/f2fs/f2fs.ko] undefined!

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests


Attachments:
(No filename) (1.96 kB)
config (172.00 kB)
Download all attachments

2023-01-14 09:25:56

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH 1/2] f2fs: fix wrong calculation of block age

Hi qixiaoyu1,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on v6.2-rc3]
[also build test ERROR on linus/master next-20230113]
[cannot apply to jaegeuk-f2fs/dev-test jaegeuk-f2fs/dev]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/qixiaoyu1/f2fs-add-sysfs-nodes-to-set-last_age_weight/20230113-211357
patch link: https://lore.kernel.org/r/20230113125859.15651-1-qixiaoyu1%40xiaomi.com
patch subject: [PATCH 1/2] f2fs: fix wrong calculation of block age
config: i386-randconfig-a014
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce (this is a W=1 build):
# https://github.com/intel-lab-lkp/linux/commit/17ca20d13dd15a8fb4689cbe1817a8d037915199
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review qixiaoyu1/f2fs-add-sysfs-nodes-to-set-last_age_weight/20230113-211357
git checkout 17ca20d13dd15a8fb4689cbe1817a8d037915199
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=i386 olddefconfig
make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>):

ld: fs/f2fs/extent_cache.o: in function `__calculate_block_age':
>> fs/f2fs/extent_cache.c:877: undefined reference to `__udivdi3'
>> ld: fs/f2fs/extent_cache.c:877: undefined reference to `__udivdi3'


vim +877 fs/f2fs/extent_cache.c

873
874 static unsigned long long __calculate_block_age(unsigned long long new,
875 unsigned long long old)
876 {
> 877 return new - new / 100 * LAST_AGE_WEIGHT + old / 100 * LAST_AGE_WEIGHT;
878 }
879

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests


Attachments:
(No filename) (2.04 kB)
config (171.20 kB)
Download all attachments

2023-01-16 03:43:06

by qixiaoyu1

[permalink] [raw]
Subject: [PATCH 1/2 v2] 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 <[email protected]>
Signed-off-by: xiongping1 <[email protected]>
---
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;
}

/* This returns a new age and allocated blocks in ei */
--
2.36.1

2023-01-28 03:36:26

by Chao Yu

[permalink] [raw]
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 <[email protected]>
> Signed-off-by: xiongping1 <[email protected]>
> ---
> 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 */

2023-01-29 11:18:54

by qixiaoyu1

[permalink] [raw]
Subject: Re: [PATCH 1/2 v2] f2fs: fix wrong calculation of block age

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 <[email protected]>
> > Signed-off-by: xiongping1 <[email protected]>
> > ---
> > 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 */

2023-02-01 12:23:15

by qixiaoyu1

[permalink] [raw]
Subject: Re: [PATCH 1/2 v2] f2fs: fix wrong calculation of block age

> >
> > 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,
>

Friendly ping

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

2023-02-01 12:57:42

by Chao Yu

[permalink] [raw]
Subject: Re: [PATCH 1/2 v2] f2fs: fix wrong calculation of block age

On 2023/2/1 20:23, qixiaoyu wrote:
>>>
>>> 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

Alright,

>> 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;

if (rem_new)
res += rem_new * (100 - LAST_AGE_WEIGHT) / 100;
if (rem_old)
res += rem_old * LAST_AGE_WEIGHT / 100;

Otherwise, it looks fine to me. :)

Thanks,

>>
>> Thanks,
>>
>
> Friendly ping
>
>>>> }
>>>> /* This returns a new age and allocated blocks in ei */

2023-02-01 14:05:10

by qixiaoyu1

[permalink] [raw]
Subject: Re: [PATCH 1/2 v2] f2fs: fix wrong calculation of block age

On Wed, Feb 01, 2023 at 08:57:33PM +0800, Chao Yu wrote:
> On 2023/2/1 20:23, qixiaoyu wrote:
> > > >
> > > > 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
>
> Alright,
>
> > > 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;
>
> if (rem_new)
> res += rem_new * (100 - LAST_AGE_WEIGHT) / 100;
> if (rem_old)
> res += rem_old * LAST_AGE_WEIGHT / 100;
>
> Otherwise, it looks fine to me. :)
>
> Thanks,
>

Thank you! I will update v3 soon :)

> > >
> > > Thanks,
> > >
> >
> > Friendly ping
> >
> > > > > }
> > > > > /* This returns a new age and allocated blocks in ei */

2023-02-02 08:20:52

by qixiaoyu1

[permalink] [raw]
Subject: [PATCH 1/2 v3] 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 <[email protected]>
Signed-off-by: xiongping1 <[email protected]>
---
Change log v1 -> v2:
- fix udiv
Change log v2 -> v3:
- keep the accuracy with div_u64_rem

fs/f2fs/extent_cache.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c
index 342af24b2f8c..d9f12f404beb 100644
--- a/fs/f2fs/extent_cache.c
+++ b/fs/f2fs/extent_cache.c
@@ -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 */
--
2.39.0


2023-02-02 08:20:57

by qixiaoyu1

[permalink] [raw]
Subject: [PATCH 2/2 v3] f2fs: add sysfs nodes to set last_age_weight

Signed-off-by: qixiaoyu1 <[email protected]>
Signed-off-by: xiongping1 <[email protected]>
---
Documentation/ABI/testing/sysfs-fs-f2fs | 5 +++++
fs/f2fs/extent_cache.c | 15 +++++++++------
fs/f2fs/f2fs.h | 1 +
fs/f2fs/sysfs.c | 11 +++++++++++
4 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs
index 9e3756625a81..11af7dbb6bc9 100644
--- a/Documentation/ABI/testing/sysfs-fs-f2fs
+++ b/Documentation/ABI/testing/sysfs-fs-f2fs
@@ -669,3 +669,8 @@ Contact: "Ping Xiong" <[email protected]>
Description: When DATA SEPARATION is on, it controls the age threshold to indicate
the data blocks as warm. By default it was initialized as 2621440 blocks
(equals to 10GB).
+
+What: /sys/fs/f2fs/<disk>/last_age_weight
+Date: January 2023
+Contact: "Ping Xiong" <[email protected]>
+Description: When DATA SEPARATION is on, it controls the weight of last data block age.
diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c
index d9f12f404beb..ce99882ba81c 100644
--- a/fs/f2fs/extent_cache.c
+++ b/fs/f2fs/extent_cache.c
@@ -871,19 +871,21 @@ void f2fs_update_read_extent_tree_range_compressed(struct inode *inode,
}
#endif

-static unsigned long long __calculate_block_age(unsigned long long new,
+static unsigned long long __calculate_block_age(struct f2fs_sb_info *sbi,
+ unsigned long long new,
unsigned long long old)
{
unsigned int rem_old, rem_new;
unsigned long long res;
+ unsigned int weight = sbi->last_age_weight;

- res = div_u64_rem(new, 100, &rem_new) * (100 - LAST_AGE_WEIGHT)
- + div_u64_rem(old, 100, &rem_old) * LAST_AGE_WEIGHT;
+ res = div_u64_rem(new, 100, &rem_new) * (100 - weight)
+ + div_u64_rem(old, 100, &rem_old) * weight;

if (rem_new)
- res += rem_new * (100 - LAST_AGE_WEIGHT) / 100;
+ res += rem_new * (100 - weight) / 100;
if (rem_old)
- res += rem_old * LAST_AGE_WEIGHT / 100;
+ res += rem_old * weight / 100;

return res;
}
@@ -917,7 +919,7 @@ static int __get_new_block_age(struct inode *inode, struct extent_info *ei,
cur_age = ULLONG_MAX - tei.last_blocks + cur_blocks;

if (tei.age)
- ei->age = __calculate_block_age(cur_age, tei.age);
+ ei->age = __calculate_block_age(sbi, cur_age, tei.age);
else
ei->age = cur_age;
ei->last_blocks = cur_blocks;
@@ -1233,6 +1235,7 @@ void f2fs_init_extent_cache_info(struct f2fs_sb_info *sbi)
atomic64_set(&sbi->allocated_data_blocks, 0);
sbi->hot_data_age_threshold = DEF_HOT_DATA_AGE_THRESHOLD;
sbi->warm_data_age_threshold = DEF_WARM_DATA_AGE_THRESHOLD;
+ sbi->last_age_weight = LAST_AGE_WEIGHT;
}

int __init f2fs_create_extent_cache(void)
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index e8953c3dc81a..c3609cbc28c7 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -1679,6 +1679,7 @@ struct f2fs_sb_info {
/* The threshold used for hot and warm data seperation*/
unsigned int hot_data_age_threshold;
unsigned int warm_data_age_threshold;
+ unsigned int last_age_weight;

/* basic filesystem units */
unsigned int log_sectors_per_block; /* log2 sectors per block */
diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
index 83a366f3ee80..a70cf674d8e7 100644
--- a/fs/f2fs/sysfs.c
+++ b/fs/f2fs/sysfs.c
@@ -686,6 +686,15 @@ static ssize_t __sbi_store(struct f2fs_attr *a,
return count;
}

+ if (!strcmp(a->attr.name, "last_age_weight")) {
+ if (t <= 0 || t >= 100)
+ return -EINVAL;
+ if (t == *ui)
+ return count;
+ *ui = (unsigned int)t;
+ return count;
+ }
+
*ui = (unsigned int)t;

return count;
@@ -944,6 +953,7 @@ F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, revoked_atomic_block, revoked_atomic_block)
/* For block age extent cache */
F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, hot_data_age_threshold, hot_data_age_threshold);
F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, warm_data_age_threshold, warm_data_age_threshold);
+F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, last_age_weight, last_age_weight);

#define ATTR_LIST(name) (&f2fs_attr_##name.attr)
static struct attribute *f2fs_attrs[] = {
@@ -1042,6 +1052,7 @@ static struct attribute *f2fs_attrs[] = {
ATTR_LIST(revoked_atomic_block),
ATTR_LIST(hot_data_age_threshold),
ATTR_LIST(warm_data_age_threshold),
+ ATTR_LIST(last_age_weight),
NULL,
};
ATTRIBUTE_GROUPS(f2fs);
--
2.39.0


2023-02-03 06:12:07

by Chao Yu

[permalink] [raw]
Subject: Re: [PATCH 1/2 v3] f2fs: fix wrong calculation of block age

On 2023/2/2 16:20, 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 <[email protected]>
> Signed-off-by: xiongping1 <[email protected]>

Reviewed-by: Chao Yu <[email protected]>

Thanks,

2023-02-03 08:32:09

by Chao Yu

[permalink] [raw]
Subject: Re: [PATCH 2/2 v3] f2fs: add sysfs nodes to set last_age_weight

On 2023/2/2 16:20, qixiaoyu1 wrote:
> Signed-off-by: qixiaoyu1 <[email protected]>
> Signed-off-by: xiongping1 <[email protected]>
> ---
> Documentation/ABI/testing/sysfs-fs-f2fs | 5 +++++
> fs/f2fs/extent_cache.c | 15 +++++++++------
> fs/f2fs/f2fs.h | 1 +
> fs/f2fs/sysfs.c | 11 +++++++++++
> 4 files changed, 26 insertions(+), 6 deletions(-)
>
> diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs
> index 9e3756625a81..11af7dbb6bc9 100644
> --- a/Documentation/ABI/testing/sysfs-fs-f2fs
> +++ b/Documentation/ABI/testing/sysfs-fs-f2fs
> @@ -669,3 +669,8 @@ Contact: "Ping Xiong" <[email protected]>
> Description: When DATA SEPARATION is on, it controls the age threshold to indicate
> the data blocks as warm. By default it was initialized as 2621440 blocks
> (equals to 10GB).
> +
> +What: /sys/fs/f2fs/<disk>/last_age_weight
> +Date: January 2023
> +Contact: "Ping Xiong" <[email protected]>
> +Description: When DATA SEPARATION is on, it controls the weight of last data block age.
> diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c
> index d9f12f404beb..ce99882ba81c 100644
> --- a/fs/f2fs/extent_cache.c
> +++ b/fs/f2fs/extent_cache.c
> @@ -871,19 +871,21 @@ void f2fs_update_read_extent_tree_range_compressed(struct inode *inode,
> }
> #endif
>
> -static unsigned long long __calculate_block_age(unsigned long long new,
> +static unsigned long long __calculate_block_age(struct f2fs_sb_info *sbi,
> + unsigned long long new,
> unsigned long long old)
> {
> unsigned int rem_old, rem_new;
> unsigned long long res;
> + unsigned int weight = sbi->last_age_weight;
>
> - res = div_u64_rem(new, 100, &rem_new) * (100 - LAST_AGE_WEIGHT)
> - + div_u64_rem(old, 100, &rem_old) * LAST_AGE_WEIGHT;
> + res = div_u64_rem(new, 100, &rem_new) * (100 - weight)
> + + div_u64_rem(old, 100, &rem_old) * weight;
>
> if (rem_new)
> - res += rem_new * (100 - LAST_AGE_WEIGHT) / 100;
> + res += rem_new * (100 - weight) / 100;
> if (rem_old)
> - res += rem_old * LAST_AGE_WEIGHT / 100;
> + res += rem_old * weight / 100;
>
> return res;
> }
> @@ -917,7 +919,7 @@ static int __get_new_block_age(struct inode *inode, struct extent_info *ei,
> cur_age = ULLONG_MAX - tei.last_blocks + cur_blocks;
>
> if (tei.age)
> - ei->age = __calculate_block_age(cur_age, tei.age);
> + ei->age = __calculate_block_age(sbi, cur_age, tei.age);
> else
> ei->age = cur_age;
> ei->last_blocks = cur_blocks;
> @@ -1233,6 +1235,7 @@ void f2fs_init_extent_cache_info(struct f2fs_sb_info *sbi)
> atomic64_set(&sbi->allocated_data_blocks, 0);
> sbi->hot_data_age_threshold = DEF_HOT_DATA_AGE_THRESHOLD;
> sbi->warm_data_age_threshold = DEF_WARM_DATA_AGE_THRESHOLD;
> + sbi->last_age_weight = LAST_AGE_WEIGHT;
> }
>
> int __init f2fs_create_extent_cache(void)
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index e8953c3dc81a..c3609cbc28c7 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -1679,6 +1679,7 @@ struct f2fs_sb_info {
> /* The threshold used for hot and warm data seperation*/
> unsigned int hot_data_age_threshold;
> unsigned int warm_data_age_threshold;
> + unsigned int last_age_weight;
>
> /* basic filesystem units */
> unsigned int log_sectors_per_block; /* log2 sectors per block */
> diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
> index 83a366f3ee80..a70cf674d8e7 100644
> --- a/fs/f2fs/sysfs.c
> +++ b/fs/f2fs/sysfs.c
> @@ -686,6 +686,15 @@ static ssize_t __sbi_store(struct f2fs_attr *a,
> return count;
> }
>
> + if (!strcmp(a->attr.name, "last_age_weight")) {
> + if (t <= 0 || t >= 100)

Could 0 or 100 be a valid value?

Thanks,

> + return -EINVAL;
> + if (t == *ui)
> + return count;
> + *ui = (unsigned int)t;
> + return count;
> + }
> +
> *ui = (unsigned int)t;
>
> return count;
> @@ -944,6 +953,7 @@ F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, revoked_atomic_block, revoked_atomic_block)
> /* For block age extent cache */
> F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, hot_data_age_threshold, hot_data_age_threshold);
> F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, warm_data_age_threshold, warm_data_age_threshold);
> +F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, last_age_weight, last_age_weight);
>
> #define ATTR_LIST(name) (&f2fs_attr_##name.attr)
> static struct attribute *f2fs_attrs[] = {
> @@ -1042,6 +1052,7 @@ static struct attribute *f2fs_attrs[] = {
> ATTR_LIST(revoked_atomic_block),
> ATTR_LIST(hot_data_age_threshold),
> ATTR_LIST(warm_data_age_threshold),
> + ATTR_LIST(last_age_weight),
> NULL,
> };
> ATTRIBUTE_GROUPS(f2fs);

2023-02-04 09:06:54

by qixiaoyu1

[permalink] [raw]
Subject: Re: [PATCH 2/2 v3] f2fs: add sysfs nodes to set last_age_weight

On Fri, Feb 03, 2023 at 04:31:58PM +0800, Chao Yu wrote:
> On 2023/2/2 16:20, qixiaoyu1 wrote:
> > Signed-off-by: qixiaoyu1 <[email protected]>
> > Signed-off-by: xiongping1 <[email protected]>
> > ---
> > Documentation/ABI/testing/sysfs-fs-f2fs | 5 +++++
> > fs/f2fs/extent_cache.c | 15 +++++++++------
> > fs/f2fs/f2fs.h | 1 +
> > fs/f2fs/sysfs.c | 11 +++++++++++
> > 4 files changed, 26 insertions(+), 6 deletions(-)
> >
> > diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs
> > index 9e3756625a81..11af7dbb6bc9 100644
> > --- a/Documentation/ABI/testing/sysfs-fs-f2fs
> > +++ b/Documentation/ABI/testing/sysfs-fs-f2fs
> > @@ -669,3 +669,8 @@ Contact: "Ping Xiong" <[email protected]>
> > Description: When DATA SEPARATION is on, it controls the age threshold to indicate
> > the data blocks as warm. By default it was initialized as 2621440 blocks
> > (equals to 10GB).
> > +
> > +What: /sys/fs/f2fs/<disk>/last_age_weight
> > +Date: January 2023
> > +Contact: "Ping Xiong" <[email protected]>
> > +Description: When DATA SEPARATION is on, it controls the weight of last data block age.
> > diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c
> > index d9f12f404beb..ce99882ba81c 100644
> > --- a/fs/f2fs/extent_cache.c
> > +++ b/fs/f2fs/extent_cache.c
> > @@ -871,19 +871,21 @@ void f2fs_update_read_extent_tree_range_compressed(struct inode *inode,
> > }
> > #endif
> > -static unsigned long long __calculate_block_age(unsigned long long new,
> > +static unsigned long long __calculate_block_age(struct f2fs_sb_info *sbi,
> > + unsigned long long new,
> > unsigned long long old)
> > {
> > unsigned int rem_old, rem_new;
> > unsigned long long res;
> > + unsigned int weight = sbi->last_age_weight;
> > - res = div_u64_rem(new, 100, &rem_new) * (100 - LAST_AGE_WEIGHT)
> > - + div_u64_rem(old, 100, &rem_old) * LAST_AGE_WEIGHT;
> > + res = div_u64_rem(new, 100, &rem_new) * (100 - weight)
> > + + div_u64_rem(old, 100, &rem_old) * weight;
> > if (rem_new)
> > - res += rem_new * (100 - LAST_AGE_WEIGHT) / 100;
> > + res += rem_new * (100 - weight) / 100;
> > if (rem_old)
> > - res += rem_old * LAST_AGE_WEIGHT / 100;
> > + res += rem_old * weight / 100;
> > return res;
> > }
> > @@ -917,7 +919,7 @@ static int __get_new_block_age(struct inode *inode, struct extent_info *ei,
> > cur_age = ULLONG_MAX - tei.last_blocks + cur_blocks;
> > if (tei.age)
> > - ei->age = __calculate_block_age(cur_age, tei.age);
> > + ei->age = __calculate_block_age(sbi, cur_age, tei.age);
> > else
> > ei->age = cur_age;
> > ei->last_blocks = cur_blocks;
> > @@ -1233,6 +1235,7 @@ void f2fs_init_extent_cache_info(struct f2fs_sb_info *sbi)
> > atomic64_set(&sbi->allocated_data_blocks, 0);
> > sbi->hot_data_age_threshold = DEF_HOT_DATA_AGE_THRESHOLD;
> > sbi->warm_data_age_threshold = DEF_WARM_DATA_AGE_THRESHOLD;
> > + sbi->last_age_weight = LAST_AGE_WEIGHT;
> > }
> > int __init f2fs_create_extent_cache(void)
> > diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> > index e8953c3dc81a..c3609cbc28c7 100644
> > --- a/fs/f2fs/f2fs.h
> > +++ b/fs/f2fs/f2fs.h
> > @@ -1679,6 +1679,7 @@ struct f2fs_sb_info {
> > /* The threshold used for hot and warm data seperation*/
> > unsigned int hot_data_age_threshold;
> > unsigned int warm_data_age_threshold;
> > + unsigned int last_age_weight;
> > /* basic filesystem units */
> > unsigned int log_sectors_per_block; /* log2 sectors per block */
> > diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
> > index 83a366f3ee80..a70cf674d8e7 100644
> > --- a/fs/f2fs/sysfs.c
> > +++ b/fs/f2fs/sysfs.c
> > @@ -686,6 +686,15 @@ static ssize_t __sbi_store(struct f2fs_attr *a,
> > return count;
> > }
> > + if (!strcmp(a->attr.name, "last_age_weight")) {
> > + if (t <= 0 || t >= 100)
>
> Could 0 or 100 be a valid value?
>
> Thanks,
>

0 and 100 can both be a valid value:

We may use 0 to set the new block age without refering to the previous
age. 100 doesn't make so much sence since the age will only be set
to a non-zero value on the first updated (after create, truncate,
etc.), but maybe we can do some tricks with a value of 100.

Let me update the patch.

> > + return -EINVAL;
> > + if (t == *ui)
> > + return count;
> > + *ui = (unsigned int)t;
> > + return count;
> > + }
> > +
> > *ui = (unsigned int)t;
> > return count;
> > @@ -944,6 +953,7 @@ F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, revoked_atomic_block, revoked_atomic_block)
> > /* For block age extent cache */
> > F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, hot_data_age_threshold, hot_data_age_threshold);
> > F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, warm_data_age_threshold, warm_data_age_threshold);
> > +F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, last_age_weight, last_age_weight);
> > #define ATTR_LIST(name) (&f2fs_attr_##name.attr)
> > static struct attribute *f2fs_attrs[] = {
> > @@ -1042,6 +1052,7 @@ static struct attribute *f2fs_attrs[] = {
> > ATTR_LIST(revoked_atomic_block),
> > ATTR_LIST(hot_data_age_threshold),
> > ATTR_LIST(warm_data_age_threshold),
> > + ATTR_LIST(last_age_weight),
> > NULL,
> > };
> > ATTRIBUTE_GROUPS(f2fs);

2023-02-04 09:44:10

by qixiaoyu1

[permalink] [raw]
Subject: [PATCH 2/2 v4] f2fs: add sysfs nodes to set last_age_weight

Signed-off-by: qixiaoyu1 <[email protected]>
Signed-off-by: xiongping1 <[email protected]>
---
change log v3 -> v4:
- allow 0 and 100 to a valid value

Documentation/ABI/testing/sysfs-fs-f2fs | 5 +++++
fs/f2fs/extent_cache.c | 15 +++++++++------
fs/f2fs/f2fs.h | 1 +
fs/f2fs/sysfs.c | 11 +++++++++++
4 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs
index 9e3756625a81..11af7dbb6bc9 100644
--- a/Documentation/ABI/testing/sysfs-fs-f2fs
+++ b/Documentation/ABI/testing/sysfs-fs-f2fs
@@ -669,3 +669,8 @@ Contact: "Ping Xiong" <[email protected]>
Description: When DATA SEPARATION is on, it controls the age threshold to indicate
the data blocks as warm. By default it was initialized as 2621440 blocks
(equals to 10GB).
+
+What: /sys/fs/f2fs/<disk>/last_age_weight
+Date: January 2023
+Contact: "Ping Xiong" <[email protected]>
+Description: When DATA SEPARATION is on, it controls the weight of last data block age.
diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c
index d9f12f404beb..ce99882ba81c 100644
--- a/fs/f2fs/extent_cache.c
+++ b/fs/f2fs/extent_cache.c
@@ -871,19 +871,21 @@ void f2fs_update_read_extent_tree_range_compressed(struct inode *inode,
}
#endif

-static unsigned long long __calculate_block_age(unsigned long long new,
+static unsigned long long __calculate_block_age(struct f2fs_sb_info *sbi,
+ unsigned long long new,
unsigned long long old)
{
unsigned int rem_old, rem_new;
unsigned long long res;
+ unsigned int weight = sbi->last_age_weight;

- res = div_u64_rem(new, 100, &rem_new) * (100 - LAST_AGE_WEIGHT)
- + div_u64_rem(old, 100, &rem_old) * LAST_AGE_WEIGHT;
+ res = div_u64_rem(new, 100, &rem_new) * (100 - weight)
+ + div_u64_rem(old, 100, &rem_old) * weight;

if (rem_new)
- res += rem_new * (100 - LAST_AGE_WEIGHT) / 100;
+ res += rem_new * (100 - weight) / 100;
if (rem_old)
- res += rem_old * LAST_AGE_WEIGHT / 100;
+ res += rem_old * weight / 100;

return res;
}
@@ -917,7 +919,7 @@ static int __get_new_block_age(struct inode *inode, struct extent_info *ei,
cur_age = ULLONG_MAX - tei.last_blocks + cur_blocks;

if (tei.age)
- ei->age = __calculate_block_age(cur_age, tei.age);
+ ei->age = __calculate_block_age(sbi, cur_age, tei.age);
else
ei->age = cur_age;
ei->last_blocks = cur_blocks;
@@ -1233,6 +1235,7 @@ void f2fs_init_extent_cache_info(struct f2fs_sb_info *sbi)
atomic64_set(&sbi->allocated_data_blocks, 0);
sbi->hot_data_age_threshold = DEF_HOT_DATA_AGE_THRESHOLD;
sbi->warm_data_age_threshold = DEF_WARM_DATA_AGE_THRESHOLD;
+ sbi->last_age_weight = LAST_AGE_WEIGHT;
}

int __init f2fs_create_extent_cache(void)
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index e8953c3dc81a..c3609cbc28c7 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -1679,6 +1679,7 @@ struct f2fs_sb_info {
/* The threshold used for hot and warm data seperation*/
unsigned int hot_data_age_threshold;
unsigned int warm_data_age_threshold;
+ unsigned int last_age_weight;

/* basic filesystem units */
unsigned int log_sectors_per_block; /* log2 sectors per block */
diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
index 83a366f3ee80..cd2fb52d1f3c 100644
--- a/fs/f2fs/sysfs.c
+++ b/fs/f2fs/sysfs.c
@@ -686,6 +686,15 @@ static ssize_t __sbi_store(struct f2fs_attr *a,
return count;
}

+ if (!strcmp(a->attr.name, "last_age_weight")) {
+ if (t < 0 || t > 100)
+ return -EINVAL;
+ if (t == *ui)
+ return count;
+ *ui = (unsigned int)t;
+ return count;
+ }
+
*ui = (unsigned int)t;

return count;
@@ -944,6 +953,7 @@ F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, revoked_atomic_block, revoked_atomic_block)
/* For block age extent cache */
F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, hot_data_age_threshold, hot_data_age_threshold);
F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, warm_data_age_threshold, warm_data_age_threshold);
+F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, last_age_weight, last_age_weight);

#define ATTR_LIST(name) (&f2fs_attr_##name.attr)
static struct attribute *f2fs_attrs[] = {
@@ -1042,6 +1052,7 @@ static struct attribute *f2fs_attrs[] = {
ATTR_LIST(revoked_atomic_block),
ATTR_LIST(hot_data_age_threshold),
ATTR_LIST(warm_data_age_threshold),
+ ATTR_LIST(last_age_weight),
NULL,
};
ATTRIBUTE_GROUPS(f2fs);
--
2.39.0


2023-02-06 03:40:31

by patchwork-bot+f2fs

[permalink] [raw]
Subject: Re: [f2fs-dev] [PATCH 1/2 v3] f2fs: fix wrong calculation of block age

Hello:

This series was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <[email protected]>:

On Thu, 2 Feb 2023 16:20:27 +0800 you 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 <[email protected]>
> Signed-off-by: xiongping1 <[email protected]>
>
> [...]

Here is the summary with links:
- [f2fs-dev,1/2,v3] f2fs: fix wrong calculation of block age
https://git.kernel.org/jaegeuk/f2fs/c/b03a41a495df
- [f2fs-dev,2/2,v3] f2fs: add sysfs nodes to set last_age_weight
(no matching commit)

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



2023-02-07 12:32:05

by Chao Yu

[permalink] [raw]
Subject: Re: [PATCH 2/2 v4] f2fs: add sysfs nodes to set last_age_weight

On 2023/2/4 17:43, qixiaoyu1 wrote:
> Signed-off-by: qixiaoyu1 <[email protected]>
> Signed-off-by: xiongping1 <[email protected]>
> ---
> change log v3 -> v4:
> - allow 0 and 100 to a valid value
>
> Documentation/ABI/testing/sysfs-fs-f2fs | 5 +++++
> fs/f2fs/extent_cache.c | 15 +++++++++------
> fs/f2fs/f2fs.h | 1 +
> fs/f2fs/sysfs.c | 11 +++++++++++
> 4 files changed, 26 insertions(+), 6 deletions(-)
>
> diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs
> index 9e3756625a81..11af7dbb6bc9 100644
> --- a/Documentation/ABI/testing/sysfs-fs-f2fs
> +++ b/Documentation/ABI/testing/sysfs-fs-f2fs
> @@ -669,3 +669,8 @@ Contact: "Ping Xiong" <[email protected]>
> Description: When DATA SEPARATION is on, it controls the age threshold to indicate
> the data blocks as warm. By default it was initialized as 2621440 blocks
> (equals to 10GB).
> +
> +What: /sys/fs/f2fs/<disk>/last_age_weight
> +Date: January 2023
> +Contact: "Ping Xiong" <[email protected]>
> +Description: When DATA SEPARATION is on, it controls the weight of last data block age.
> diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c
> index d9f12f404beb..ce99882ba81c 100644
> --- a/fs/f2fs/extent_cache.c
> +++ b/fs/f2fs/extent_cache.c
> @@ -871,19 +871,21 @@ void f2fs_update_read_extent_tree_range_compressed(struct inode *inode,
> }
> #endif
>
> -static unsigned long long __calculate_block_age(unsigned long long new,
> +static unsigned long long __calculate_block_age(struct f2fs_sb_info *sbi,
> + unsigned long long new,
> unsigned long long old)
> {
> unsigned int rem_old, rem_new;
> unsigned long long res;
> + unsigned int weight = sbi->last_age_weight;
>
> - res = div_u64_rem(new, 100, &rem_new) * (100 - LAST_AGE_WEIGHT)
> - + div_u64_rem(old, 100, &rem_old) * LAST_AGE_WEIGHT;
> + res = div_u64_rem(new, 100, &rem_new) * (100 - weight)
> + + div_u64_rem(old, 100, &rem_old) * weight;
>
> if (rem_new)
> - res += rem_new * (100 - LAST_AGE_WEIGHT) / 100;
> + res += rem_new * (100 - weight) / 100;
> if (rem_old)
> - res += rem_old * LAST_AGE_WEIGHT / 100;
> + res += rem_old * weight / 100;
>
> return res;
> }
> @@ -917,7 +919,7 @@ static int __get_new_block_age(struct inode *inode, struct extent_info *ei,
> cur_age = ULLONG_MAX - tei.last_blocks + cur_blocks;
>
> if (tei.age)
> - ei->age = __calculate_block_age(cur_age, tei.age);
> + ei->age = __calculate_block_age(sbi, cur_age, tei.age);
> else
> ei->age = cur_age;
> ei->last_blocks = cur_blocks;
> @@ -1233,6 +1235,7 @@ void f2fs_init_extent_cache_info(struct f2fs_sb_info *sbi)
> atomic64_set(&sbi->allocated_data_blocks, 0);
> sbi->hot_data_age_threshold = DEF_HOT_DATA_AGE_THRESHOLD;
> sbi->warm_data_age_threshold = DEF_WARM_DATA_AGE_THRESHOLD;
> + sbi->last_age_weight = LAST_AGE_WEIGHT;
> }
>
> int __init f2fs_create_extent_cache(void)
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index e8953c3dc81a..c3609cbc28c7 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -1679,6 +1679,7 @@ struct f2fs_sb_info {
> /* The threshold used for hot and warm data seperation*/
> unsigned int hot_data_age_threshold;
> unsigned int warm_data_age_threshold;
> + unsigned int last_age_weight;
>
> /* basic filesystem units */
> unsigned int log_sectors_per_block; /* log2 sectors per block */
> diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
> index 83a366f3ee80..cd2fb52d1f3c 100644
> --- a/fs/f2fs/sysfs.c
> +++ b/fs/f2fs/sysfs.c
> @@ -686,6 +686,15 @@ static ssize_t __sbi_store(struct f2fs_attr *a,
> return count;
> }
>
> + if (!strcmp(a->attr.name, "last_age_weight")) {
> + if (t < 0 || t > 100)

t is unsigned long variable, should never be less than 0.

Otherwise, it looks good to me, maybe Jaegeuk could fix it manually.

Reviewed-by: Chao Yu <[email protected]>

Thanks,

> + return -EINVAL;
> + if (t == *ui)
> + return count;
> + *ui = (unsigned int)t;
> + return count;
> + }
> +
> *ui = (unsigned int)t;
>
> return count;
> @@ -944,6 +953,7 @@ F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, revoked_atomic_block, revoked_atomic_block)
> /* For block age extent cache */
> F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, hot_data_age_threshold, hot_data_age_threshold);
> F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, warm_data_age_threshold, warm_data_age_threshold);
> +F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, last_age_weight, last_age_weight);
>
> #define ATTR_LIST(name) (&f2fs_attr_##name.attr)
> static struct attribute *f2fs_attrs[] = {
> @@ -1042,6 +1052,7 @@ static struct attribute *f2fs_attrs[] = {
> ATTR_LIST(revoked_atomic_block),
> ATTR_LIST(hot_data_age_threshold),
> ATTR_LIST(warm_data_age_threshold),
> + ATTR_LIST(last_age_weight),
> NULL,
> };
> ATTRIBUTE_GROUPS(f2fs);

2023-02-07 18:40:04

by Jaegeuk Kim

[permalink] [raw]
Subject: Re: [PATCH 2/2 v4] f2fs: add sysfs nodes to set last_age_weight

On 02/07, Chao Yu wrote:
> On 2023/2/4 17:43, qixiaoyu1 wrote:
> > Signed-off-by: qixiaoyu1 <[email protected]>
> > Signed-off-by: xiongping1 <[email protected]>
> > ---
> > change log v3 -> v4:
> > - allow 0 and 100 to a valid value
> >
> > Documentation/ABI/testing/sysfs-fs-f2fs | 5 +++++
> > fs/f2fs/extent_cache.c | 15 +++++++++------
> > fs/f2fs/f2fs.h | 1 +
> > fs/f2fs/sysfs.c | 11 +++++++++++
> > 4 files changed, 26 insertions(+), 6 deletions(-)
> >
> > diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs
> > index 9e3756625a81..11af7dbb6bc9 100644
> > --- a/Documentation/ABI/testing/sysfs-fs-f2fs
> > +++ b/Documentation/ABI/testing/sysfs-fs-f2fs
> > @@ -669,3 +669,8 @@ Contact: "Ping Xiong" <[email protected]>
> > Description: When DATA SEPARATION is on, it controls the age threshold to indicate
> > the data blocks as warm. By default it was initialized as 2621440 blocks
> > (equals to 10GB).
> > +
> > +What: /sys/fs/f2fs/<disk>/last_age_weight
> > +Date: January 2023
> > +Contact: "Ping Xiong" <[email protected]>
> > +Description: When DATA SEPARATION is on, it controls the weight of last data block age.
> > diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c
> > index d9f12f404beb..ce99882ba81c 100644
> > --- a/fs/f2fs/extent_cache.c
> > +++ b/fs/f2fs/extent_cache.c
> > @@ -871,19 +871,21 @@ void f2fs_update_read_extent_tree_range_compressed(struct inode *inode,
> > }
> > #endif
> > -static unsigned long long __calculate_block_age(unsigned long long new,
> > +static unsigned long long __calculate_block_age(struct f2fs_sb_info *sbi,
> > + unsigned long long new,
> > unsigned long long old)
> > {
> > unsigned int rem_old, rem_new;
> > unsigned long long res;
> > + unsigned int weight = sbi->last_age_weight;
> > - res = div_u64_rem(new, 100, &rem_new) * (100 - LAST_AGE_WEIGHT)
> > - + div_u64_rem(old, 100, &rem_old) * LAST_AGE_WEIGHT;
> > + res = div_u64_rem(new, 100, &rem_new) * (100 - weight)
> > + + div_u64_rem(old, 100, &rem_old) * weight;
> > if (rem_new)
> > - res += rem_new * (100 - LAST_AGE_WEIGHT) / 100;
> > + res += rem_new * (100 - weight) / 100;
> > if (rem_old)
> > - res += rem_old * LAST_AGE_WEIGHT / 100;
> > + res += rem_old * weight / 100;
> > return res;
> > }
> > @@ -917,7 +919,7 @@ static int __get_new_block_age(struct inode *inode, struct extent_info *ei,
> > cur_age = ULLONG_MAX - tei.last_blocks + cur_blocks;
> > if (tei.age)
> > - ei->age = __calculate_block_age(cur_age, tei.age);
> > + ei->age = __calculate_block_age(sbi, cur_age, tei.age);
> > else
> > ei->age = cur_age;
> > ei->last_blocks = cur_blocks;
> > @@ -1233,6 +1235,7 @@ void f2fs_init_extent_cache_info(struct f2fs_sb_info *sbi)
> > atomic64_set(&sbi->allocated_data_blocks, 0);
> > sbi->hot_data_age_threshold = DEF_HOT_DATA_AGE_THRESHOLD;
> > sbi->warm_data_age_threshold = DEF_WARM_DATA_AGE_THRESHOLD;
> > + sbi->last_age_weight = LAST_AGE_WEIGHT;
> > }
> > int __init f2fs_create_extent_cache(void)
> > diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> > index e8953c3dc81a..c3609cbc28c7 100644
> > --- a/fs/f2fs/f2fs.h
> > +++ b/fs/f2fs/f2fs.h
> > @@ -1679,6 +1679,7 @@ struct f2fs_sb_info {
> > /* The threshold used for hot and warm data seperation*/
> > unsigned int hot_data_age_threshold;
> > unsigned int warm_data_age_threshold;
> > + unsigned int last_age_weight;
> > /* basic filesystem units */
> > unsigned int log_sectors_per_block; /* log2 sectors per block */
> > diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
> > index 83a366f3ee80..cd2fb52d1f3c 100644
> > --- a/fs/f2fs/sysfs.c
> > +++ b/fs/f2fs/sysfs.c
> > @@ -686,6 +686,15 @@ static ssize_t __sbi_store(struct f2fs_attr *a,
> > return count;
> > }
> > + if (!strcmp(a->attr.name, "last_age_weight")) {
> > + if (t < 0 || t > 100)
>
> t is unsigned long variable, should never be less than 0.
>
> Otherwise, it looks good to me, maybe Jaegeuk could fix it manually.

Ok, applied.

>
> Reviewed-by: Chao Yu <[email protected]>
>
> Thanks,
>
> > + return -EINVAL;
> > + if (t == *ui)
> > + return count;
> > + *ui = (unsigned int)t;
> > + return count;
> > + }
> > +
> > *ui = (unsigned int)t;
> > return count;
> > @@ -944,6 +953,7 @@ F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, revoked_atomic_block, revoked_atomic_block)
> > /* For block age extent cache */
> > F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, hot_data_age_threshold, hot_data_age_threshold);
> > F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, warm_data_age_threshold, warm_data_age_threshold);
> > +F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, last_age_weight, last_age_weight);
> > #define ATTR_LIST(name) (&f2fs_attr_##name.attr)
> > static struct attribute *f2fs_attrs[] = {
> > @@ -1042,6 +1052,7 @@ static struct attribute *f2fs_attrs[] = {
> > ATTR_LIST(revoked_atomic_block),
> > ATTR_LIST(hot_data_age_threshold),
> > ATTR_LIST(warm_data_age_threshold),
> > + ATTR_LIST(last_age_weight),
> > NULL,
> > };
> > ATTRIBUTE_GROUPS(f2fs);