[1/2] f2fs: fix wrong calculation of block age

Message ID 20230113125859.15651-1-qixiaoyu1@xiaomi.com
State New
Headers
Series [1/2] f2fs: fix wrong calculation of block age |

Commit Message

qixiaoyu1 Jan. 13, 2023, 12:58 p.m. UTC
  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>
---
 fs/f2fs/extent_cache.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
  

Comments

kernel test robot Jan. 14, 2023, 2:08 a.m. UTC | #1
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 <lkp@intel.com>

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

>> ERROR: modpost: "__udivdi3" [fs/f2fs/f2fs.ko] undefined!
  
kernel test robot Jan. 14, 2023, 5:20 a.m. UTC | #2
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 <lkp@intel.com>

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

>> ERROR: modpost: "__udivdi3" [fs/f2fs/f2fs.ko] undefined!
  
kernel test robot Jan. 14, 2023, 8:52 a.m. UTC | #3
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 <lkp@intel.com>

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
  

Patch

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 */