Re: [PATCH v3] erofs: support adjust lz4 history window size

2021-02-23 Thread Gao Xiang via Linux-erofs
On Tue, Feb 23, 2021 at 03:44:18PM +0800, Gao Xiang wrote:
> On Tue, Feb 23, 2021 at 03:31:19PM +0800, Huang Jianan via Linux-erofs wrote:
> > lz4 uses LZ4_DISTANCE_MAX to record history preservation. When
> > using rolling decompression, a block with a higher compression
> > ratio will cause a larger memory allocation (up to 64k). It may
> > cause a large resource burden in extreme cases on devices with
> > small memory and a large number of concurrent IOs. So appropriately
> > reducing this value can improve performance.
> > 
> > Decreasing this value will reduce the compression ratio (except
> > when input_size  > currently only supports 4k output, reducing this value will not
> > significantly reduce the compression benefits.
> > 
> > The maximum value of LZ4_DISTANCE_MAX defined by lz4 is 64k, and
> > we can only reduce this value. For the old kernel, it just can't
> > reduce the memory allocation during rolling decompression without
> > affecting the decompression result.
> > 
> > Signed-off-by: Huang Jianan 
> > Signed-off-by: Guo Weichao 
> > ---
> > 
> > change since v2:
> > - use z_erofs_load_lz4_config to calculate lz4_distance_pages
> > - add description about the compatibility of the old kernel version
> > - drop useless comment
> > 
> >  fs/erofs/decompressor.c | 22 ++
> >  fs/erofs/erofs_fs.h |  3 ++-
> >  fs/erofs/internal.h |  7 +++
> >  fs/erofs/super.c|  2 ++
> >  4 files changed, 29 insertions(+), 5 deletions(-)
> > 
> > diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c
> > index 1cb1ffd10569..0bb7903e3f9b 100644
> > --- a/fs/erofs/decompressor.c
> > +++ b/fs/erofs/decompressor.c
> > @@ -28,6 +28,18 @@ struct z_erofs_decompressor {
> > char *name;
> >  };
> >  
> > +int z_erofs_load_lz4_config(struct erofs_sb_info *sbi,
> > +   struct erofs_super_block *dsb)
> > +{
> > +   u16 distance = le16_to_cpu(dsb->lz4_max_distance);
> > +
> > +   sbi->lz4_max_distance_pages = distance ?
> > +   (DIV_ROUND_UP(distance, PAGE_SIZE) + 1) 
> > :
> 
> Unneeded parentheses here (I'll update it when applying).
> Otherwise it looks good to me.
> 
> Reviewed-by: Gao Xiang 
> 
> Thanks,
> Gao Xiang

Applied to dev-test temporarily with the following diff
(fix 80 char limitation, etc):

diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c
index 0bb7903e3f9b..49347e681a53 100644
--- a/fs/erofs/decompressor.c
+++ b/fs/erofs/decompressor.c
@@ -34,9 +34,8 @@ int z_erofs_load_lz4_config(struct erofs_sb_info *sbi,
u16 distance = le16_to_cpu(dsb->lz4_max_distance);
 
sbi->lz4_max_distance_pages = distance ?
-   (DIV_ROUND_UP(distance, PAGE_SIZE) + 1) 
:
+   DIV_ROUND_UP(distance, PAGE_SIZE) + 1 :
LZ4_MAX_DISTANCE_PAGES;
-
return 0;
 }
 
diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
index 4cb2395db45c..77965490dced 100644
--- a/fs/erofs/internal.h
+++ b/fs/erofs/internal.h
@@ -433,7 +433,7 @@ static inline void erofs_exit_shrinker(void) {}
 static inline int z_erofs_init_zip_subsystem(void) { return 0; }
 static inline void z_erofs_exit_zip_subsystem(void) {}
 static inline int z_erofs_load_lz4_config(struct erofs_sb_info *sbi,
- struct erofs_super_block *dsb) { 
return 0; }
+   struct erofs_super_block *dsb) { return 0; }
 #endif /* !CONFIG_EROFS_FS_ZIP */
 
 #define EFSCORRUPTEDEUCLEAN /* Filesystem is corrupted */
diff --git a/fs/erofs/super.c b/fs/erofs/super.c
index 11bc51e488dd..025c25d6e0f3 100644
--- a/fs/erofs/super.c
+++ b/fs/erofs/super.c
@@ -166,8 +166,6 @@ static int erofs_read_superblock(struct super_block *sb)
if (!check_layout_compatibility(sb, dsb))
goto out;
 
-   z_erofs_load_lz4_config(sbi, dsb);
-
sbi->blocks = le32_to_cpu(dsb->blocks);
sbi->meta_blkaddr = le32_to_cpu(dsb->meta_blkaddr);
 #ifdef CONFIG_EROFS_FS_XATTR
@@ -189,6 +187,9 @@ static int erofs_read_superblock(struct super_block *sb)
ret = -EFSCORRUPTED;
goto out;
}
+
+   /* parse on-disk compression configurations */
+   z_erofs_load_lz4_config(sbi, dsb);
ret = 0;
 out:
kunmap(page);



[xiang-erofs:dev-test] BUILD SUCCESS ddada3734cabbc0ce65b65391129a218a6d15e3e

2021-02-23 Thread kernel test robot
 allyesconfig
s390 allmodconfig
parisc   allyesconfig
s390defconfig
i386 allyesconfig
sparc   defconfig
i386   tinyconfig
i386defconfig
sparcallyesconfig
mips allyesconfig
powerpc  allyesconfig
powerpc   allnoconfig
i386 randconfig-a005-20210223
i386 randconfig-a006-20210223
i386 randconfig-a004-20210223
i386 randconfig-a003-20210223
i386 randconfig-a001-20210223
i386 randconfig-a002-20210223
x86_64   randconfig-a015-20210223
x86_64   randconfig-a011-20210223
x86_64   randconfig-a012-20210223
x86_64   randconfig-a016-20210223
x86_64   randconfig-a014-20210223
x86_64   randconfig-a013-20210223
i386 randconfig-a013-20210223
i386 randconfig-a012-20210223
i386 randconfig-a011-20210223
i386 randconfig-a014-20210223
i386 randconfig-a016-20210223
i386 randconfig-a015-20210223
riscvnommu_k210_defconfig
riscvallyesconfig
riscvnommu_virt_defconfig
riscv allnoconfig
riscv   defconfig
riscvallmodconfig
x86_64   allyesconfig
x86_64rhel-7.6-kselftests
x86_64  defconfig
x86_64   rhel-8.3
x86_64  rhel-8.3-kbuiltin
x86_64  kexec

clang tested configs:
x86_64   randconfig-a001-20210223
x86_64   randconfig-a002-20210223
x86_64   randconfig-a003-20210223
x86_64   randconfig-a005-20210223
x86_64   randconfig-a006-20210223
x86_64   randconfig-a004-20210223

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-...@lists.01.org