Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3250085pxf; Sun, 28 Mar 2021 18:24:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9jSjMqKg3I1Y/NKM4im1ED9SqIcOvOjpnbOz7GQA7FnsSWnrQLuBxQ8iEBrC/dwt+JSyD X-Received: by 2002:a17:906:4dce:: with SMTP id f14mr25766429ejw.349.1616981093991; Sun, 28 Mar 2021 18:24:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616981093; cv=none; d=google.com; s=arc-20160816; b=vv+7fJMZB6vUPuDR1n3k0DDP3NrfZQvn6waW3jiG80Urk1rd5tq9Y4ve3tB7wrI5O0 RA2GZOvsY52wFk90E2miWhG/EdcB4r/z9pMMBEDQ65C6GsdSAaN7OYrpOIrG2Knfy6jw hGLUx/WxqpDAZK1J6Kich2mBqJt7xTGaSkb74NSZP88dB+PJxc1d9lRLafElV4Bi1EKa +J1IaU4ZPQojit3Zior4xrdXXxXHJoz3eXqua2pppwYZPFxb8lKiLyl5kCG35wWnGxe8 mjnDOlFQuV4z2iyZzmn0utOzOPMTSrqbwEiRX7J7shIKT3ZxXEKrx1OenZhTUAbdWst9 P5ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Ni0BnRbHzXFf9QkSjmBBPdvhQ7Zelkwra5jmrRPeOJg=; b=U35xmSVEc5ZoRXmK3lOuN2FONRQhroE289k0poNJi9R/94PPbTQH9+t+Hb4cDpkUad EZx+lHjjrbvmc3AgkNbQ7K+sfEWH7IY2Lj48rKeJm+mzOVZawujbRhQnYWVQg3czkoSA aue/7LBCxfK/WCARUEF2egzX1ksMsv1ZIeyTTnf2Jl7V2mdcuHkJk0EQn6SNg/1be4aH 1r4DfLzenZiCqHt09oFwiMpzlJ8l+hxFPRLQM6gD7+wITu7Gl+tyEoSnHuCicccG1vwO LtI1KCQpFVfFwBpVTJP8sfuC9A/Fh9DW3lb+Hm+ydtCqZh+45GP7wrqZ1AeHOILVfKg2 D2jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@aol.com header.s=a2048 header.b=WJjaPW4E; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=aol.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cq5si12061505edb.98.2021.03.28.18.24.32; Sun, 28 Mar 2021 18:24:53 -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; dkim=pass header.i=@aol.com header.s=a2048 header.b=WJjaPW4E; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=aol.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231641AbhC2BXh (ORCPT + 99 others); Sun, 28 Mar 2021 21:23:37 -0400 Received: from sonic311-25.consmr.mail.gq1.yahoo.com ([98.137.65.206]:43518 "EHLO sonic311-25.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230458AbhC2BX1 (ORCPT ); Sun, 28 Mar 2021 21:23:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aol.com; s=a2048; t=1616981006; bh=Ni0BnRbHzXFf9QkSjmBBPdvhQ7Zelkwra5jmrRPeOJg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Subject:Reply-To; b=WJjaPW4E0qJutGEJjrlm4wRB1d+Cfqm5E2U5uTV9CnniIBJobGMOhjctUwdxHp/usaS6m1onIq+KC93W/QDZptZRn7021N1Wxyke9zhP3QUvEzgu6NA+hJAIVPrhwrdwhzrvJTGXzSg/P0+plU1RgpMlHB+5wEuz3t/RVF/b0g6EZKlAj8fxrEWAaV06vjrOyurqSLmIraNl9HDGZ1+3yFQvmmYsjr+EP4vMTGe95+qLYcMjKNym8H9jauLqiYINBdjB5Rg5ECpz9Fa99w68wIGoA+e/1URGFDErbEyfHBtxHY809EjhbdxfnBGLvwcwvLDf+Yfwlw4ZfK5Sx+9iJg== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1616981006; bh=VK9sFJ/pGW9fg/z00DxkNenin7A/ACnalUUuy9uY/4t=; h=X-Sonic-MF:From:To:Subject:Date:From:Subject; b=fFF2FItkWOCkusvqlC3ncLdO/YW67GG3t/HPtITvFkaG42gn2ZetbNdHmcSoGAwIuYzPS+f/wtq7/R+SJhURassT2u60UQ1FTv2rIo4dEJW/n56yfGphuE8K+VdOLXLLtq1AYBliAZfkpfXg71U3MC9j/KjczQtblqX9MnWl+e2H7sbKR23qQVG2egD3jOZ7ZApPX3x9sJNJtH3IYab8rC7mzxJffjugLkV8ZqXyJJvwVr/nFPQi5rPeGKB9BNibrjITnyHQXjDiK87qar2IZVX2yMD9EZH+u8AsiEVdpklNGziWoSSfW1MB6tvDK5+Y0B52HyWHEORWpz3D8IzdgQ== X-YMail-OSG: b9VfCLMVM1nDst7CAfCDtFQTI_kuyhT3OWbCrGLhwMZdZgRvQq7.TWeJkII8ymK z96uKzMC3no7l2fkFHyd_8jLL01.VQb5NJC_zrfWjQOdVnrh47fkvoQF1jJCmZNo5y9VjGtWoH0k XpDddLOEYAyYPVpkYt2FYCCxtnFPZDNSUYe2r4DWqiF7CB50gMASntczAcsG4gBfGnxxHDV22LYL .THuy_rZOshHpHZupIU7Xr_vf1rXnAYeunEBh7qFMgJAL_6p3s63eTt.X3gxl59zWbsAD5OW6rug 87AJEc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ocTrNR3oLUR24NEEefTWSnFgWkFOZdzKVRmfSUaFs70HWHGBDnv95e2QHJRTK2p 3cieWg.NOHIGACj_V8d3Ol1MvBmPagTLHr11vNoYY1yCf04BnAuMwicpN9xYK3MPPZ2JBwzb1Ydu US6NTCDrkyppDQt69dwpSvGkjJBBV8I8MJsaPynUysnTalsZ9q9izKj0Yar_8ku3D_jpWeuOWa5o 9f4q85q6rRrF3pTMcovENa1NxNZqe8_N0H5V2.X1q2EtpvBoiH1CJ4HcIcB2lvScaMl6qbkrlgOU cF4.WA1vl9Uk.pomgcJRv6C0f61x97mrcU.H0cJ.pISy43oFLZsuuBcfRY_iVbGEMQcWnNwoQwmU tQNOKihXkZwA6vJGFM8MD1T4tQ7u0jYeI4f7dGEoF0KBfH5rbDs6Yn1vGzkh_AYz.WimrVGHhMZO CLkgBV8qPHeRnl9Cf4TVt X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic311.consmr.mail.gq1.yahoo.com with HTTP; Mon, 29 Mar 2021 01:23:26 +0000 Received: by kubenode575.mail-prod1.omega.gq1.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID 3d9d64f8790c67205a0f6cb47abdabe6; Mon, 29 Mar 2021 01:23:23 +0000 (UTC) From: Gao Xiang To: linux-erofs@lists.ozlabs.org, Chao Yu , Chao Yu Cc: LKML , Huang Jianan , Guo Weichao , Gao Xiang Subject: [PATCH v2 2/4] erofs: support adjust lz4 history window size Date: Mon, 29 Mar 2021 09:23:06 +0800 Message-Id: <20210329012308.28743-3-hsiangkao@aol.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210329012308.28743-1-hsiangkao@aol.com> References: <20210329012308.28743-1-hsiangkao@aol.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Length: 5723 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Guo Weichao [ Gao Xiang: introduce struct erofs_sb_lz4_info for configurations. ] Reviewed-by: Chao Yu Signed-off-by: Gao Xiang --- fs/erofs/decompressor.c | 21 +++++++++++++++++---- fs/erofs/erofs_fs.h | 4 +++- fs/erofs/internal.h | 19 +++++++++++++++++++ fs/erofs/super.c | 4 +++- 4 files changed, 42 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..43467624ae3b 100644 --- a/fs/erofs/erofs_fs.h +++ b/fs/erofs/erofs_fs.h @@ -39,7 +39,9 @@ struct erofs_super_block { __u8 uuid[16]; /* 128-bit uuid for volume */ __u8 volume_name[16]; /* volume name */ __le32 feature_incompat; - __u8 reserved2[44]; + /* customized lz4 sliding window size instead of 64k by default */ + __le16 lz4_max_distance; + __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); -- 2.20.1