Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp2101003pxf; Sat, 27 Mar 2021 02:39:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlFqLbZ8Hze6E6tgYSbkLCAci4a6VsjywtZqNIruETGjrjCrVW+446MYnrw7E3YaWxhCl+ X-Received: by 2002:aa7:dd4d:: with SMTP id o13mr19970066edw.53.1616837990805; Sat, 27 Mar 2021 02:39:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616837990; cv=none; d=google.com; s=arc-20160816; b=tTVJB7kUgyfoAcCmXAGQeGKPgDV+WgM+GWZ+gaO+5sUAkm0+V7Jk0nm5MRPDEXz8JC vlQmeSDJaHYwC6MNebZqhsZoneG42SP4Vqeio+ijeXFy/lKISt8f0FIGo8LHvnQzjmwf Wt4ULGVVGjtWGhSAg5PxbpKV98H2K8KotXVnJUu7/I28kGTM6LRxBITvY+FCDS3pYecf n5j+C/7EclKGTgnpP03iU/xzYC5TEo7qqrE7lpcXCuMqIRzZYmmkoz3RfcAiVZ6pFULh f4lPQDl54EixxczFl+rrB08GQBqg9vktvisH3GaU8p7hgxPRZvAZG5MV7bE4yO2/7CxI PMQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=3mvHOVSqBu9oVjvvi26zsGTNxzdfW9D7QTid2orLcW4=; b=Av09MwqU2DfB0vWFyWhjEqVALQHwbZo/QORc8jl6ctzOj0sHIj21AoIJf0vzkJ0jRh 5RlFrUZVK0azEvG3sf60Z9ynEqhHz1hYo08zXXOLueztaqwXWB3x0UsCVVu1T9BGL0/0 EG13HzaFIu7waR/kYNay0HVRwtrrOZffE2zS0WwGz5FFeVyXVljQHRbwNzW2ZldrErfq 8OUkluTFLKjS1qrm45j/KxvCe9O9Im0v7618417McD3B5qnAKEwJWgfdjsoh7VhqEoQh eihHCKW1+Z7FwYdkf7Ym0/p62jTMHZizPSHNtVjcVr0mX8n1dmMAqkp+IZ+gvxrw6IKd NDkg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v21si8937439edq.151.2021.03.27.02.39.28; Sat, 27 Mar 2021 02:39:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231372AbhC0Jep (ORCPT + 99 others); Sat, 27 Mar 2021 05:34:45 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:15355 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231150AbhC0Jeh (ORCPT ); Sat, 27 Mar 2021 05:34:37 -0400 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4F6tss0nTyz8vRN; Sat, 27 Mar 2021 17:32:33 +0800 (CST) Received: from [10.136.110.154] (10.136.110.154) by smtp.huawei.com (10.3.19.214) with Microsoft SMTP Server (TLS) id 14.3.498.0; Sat, 27 Mar 2021 17:34:34 +0800 Subject: Re: [PATCH 2/4] erofs: support adjust lz4 history window size To: Gao Xiang , , Chao Yu CC: LKML , Huang Jianan , Guo Weichao , Gao Xiang References: <20210327034936.12537-1-hsiangkao@aol.com> <20210327034936.12537-3-hsiangkao@aol.com> From: Chao Yu Message-ID: <8169edfd-de1d-e2de-4805-c7e3ce8d7502@huawei.com> Date: Sat, 27 Mar 2021 17:34:33 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20210327034936.12537-3-hsiangkao@aol.com> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.136.110.154] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/3/27 11:49, Gao Xiang wrote: > From: Huang Jianan > > 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 > [ Gao Xiang: introduce struct erofs_sb_lz4_info for configurations. ] > Signed-off-by: Gao Xiang > --- > fs/erofs/decompressor.c | 21 +++++++++++++++++---- > fs/erofs/erofs_fs.h | 3 ++- > fs/erofs/internal.h | 19 +++++++++++++++++++ > fs/erofs/super.c | 4 +++- > 4 files changed, 41 insertions(+), 6 deletions(-) > > diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c > index 80e8871aef71..93411e9df9b6 100644 > --- a/fs/erofs/decompressor.c > +++ b/fs/erofs/decompressor.c > @@ -28,6 +28,17 @@ struct z_erofs_decompressor { > char *name; > }; > > +int z_erofs_load_lz4_config(struct super_block *sb, > + struct erofs_super_block *dsb) > +{ > + u16 distance = le16_to_cpu(dsb->lz4_max_distance); > + > + EROFS_SB(sb)->lz4.max_distance_pages = distance ? > + DIV_ROUND_UP(distance, PAGE_SIZE) + 1 : > + LZ4_MAX_DISTANCE_PAGES; > + return 0; > +} > + > static int z_erofs_lz4_prepare_destpages(struct z_erofs_decompress_req *rq, > struct list_head *pagepool) > { > @@ -36,6 +47,8 @@ static int z_erofs_lz4_prepare_destpages(struct z_erofs_decompress_req *rq, > struct page *availables[LZ4_MAX_DISTANCE_PAGES] = { NULL }; > unsigned long bounced[DIV_ROUND_UP(LZ4_MAX_DISTANCE_PAGES, > BITS_PER_LONG)] = { 0 }; > + unsigned int lz4_max_distance_pages = > + EROFS_SB(rq->sb)->lz4.max_distance_pages; > void *kaddr = NULL; > unsigned int i, j, top; > > @@ -44,14 +57,14 @@ static int z_erofs_lz4_prepare_destpages(struct z_erofs_decompress_req *rq, > struct page *const page = rq->out[i]; > struct page *victim; > > - if (j >= LZ4_MAX_DISTANCE_PAGES) > + if (j >= lz4_max_distance_pages) > j = 0; > > /* 'valid' bounced can only be tested after a complete round */ > if (test_bit(j, bounced)) { > - DBG_BUGON(i < LZ4_MAX_DISTANCE_PAGES); > - DBG_BUGON(top >= LZ4_MAX_DISTANCE_PAGES); > - availables[top++] = rq->out[i - LZ4_MAX_DISTANCE_PAGES]; > + DBG_BUGON(i < lz4_max_distance_pages); > + DBG_BUGON(top >= lz4_max_distance_pages); > + availables[top++] = rq->out[i - lz4_max_distance_pages]; > } > > if (page) { > diff --git a/fs/erofs/erofs_fs.h b/fs/erofs/erofs_fs.h > index 9ad1615f4474..b27d0e4e4ab5 100644 > --- a/fs/erofs/erofs_fs.h > +++ b/fs/erofs/erofs_fs.h > @@ -39,7 +39,8 @@ struct erofs_super_block { > __u8 uuid[16]; /* 128-bit uuid for volume */ > __u8 volume_name[16]; /* volume name */ > __le32 feature_incompat; > - __u8 reserved2[44]; > + __le16 lz4_max_distance; It missed to add comments, otherwise it looks good to me. Reviewed-by: Chao Yu Thanks, > + __u8 reserved2[42]; > }; > > /* > diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h > index d29fc0c56032..1de60992c3dd 100644 > --- a/fs/erofs/internal.h > +++ b/fs/erofs/internal.h > @@ -59,6 +59,12 @@ struct erofs_fs_context { > unsigned int mount_opt; > }; > > +/* all filesystem-wide lz4 configurations */ > +struct erofs_sb_lz4_info { > + /* # of pages needed for EROFS lz4 rolling decompression */ > + u16 max_distance_pages; > +}; > + > struct erofs_sb_info { > #ifdef CONFIG_EROFS_FS_ZIP > /* list for all registered superblocks, mainly for shrinker */ > @@ -72,6 +78,8 @@ struct erofs_sb_info { > > /* pseudo inode to manage cached pages */ > struct inode *managed_cache; > + > + struct erofs_sb_lz4_info lz4; > #endif /* CONFIG_EROFS_FS_ZIP */ > u32 blocks; > u32 meta_blkaddr; > @@ -432,6 +440,8 @@ int erofs_try_to_free_all_cached_pages(struct erofs_sb_info *sbi, > struct erofs_workgroup *egrp); > int erofs_try_to_free_cached_page(struct address_space *mapping, > struct page *page); > +int z_erofs_load_lz4_config(struct super_block *sb, > + struct erofs_super_block *dsb); > #else > static inline void erofs_shrinker_register(struct super_block *sb) {} > static inline void erofs_shrinker_unregister(struct super_block *sb) {} > @@ -439,6 +449,15 @@ static inline int erofs_init_shrinker(void) { return 0; } > 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 super_block *sb, > + struct erofs_super_block *dsb) > +{ > + if (dsb->lz4_max_distance) { > + erofs_err(sb, "lz4 algorithm isn't enabled"); > + return -EINVAL; > + } > + return 0; > +} > #endif /* !CONFIG_EROFS_FS_ZIP */ > > #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */ > diff --git a/fs/erofs/super.c b/fs/erofs/super.c > index 991b99eaf22a..3212e4f73f85 100644 > --- a/fs/erofs/super.c > +++ b/fs/erofs/super.c > @@ -187,7 +187,9 @@ static int erofs_read_superblock(struct super_block *sb) > ret = -EFSCORRUPTED; > goto out; > } > - ret = 0; > + > + /* parse on-disk compression configurations */ > + ret = z_erofs_load_lz4_config(sb, dsb); > out: > kunmap(page); > put_page(page); >