From nobody Thu Apr 9 10:37:26 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F592C54EE9 for ; Tue, 13 Sep 2022 11:06:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231874AbiIMLGx (ORCPT ); Tue, 13 Sep 2022 07:06:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231497AbiIMLGp (ORCPT ); Tue, 13 Sep 2022 07:06:45 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58E274662D for ; Tue, 13 Sep 2022 04:06:44 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id p18so11435700plr.8 for ; Tue, 13 Sep 2022 04:06:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=references:in-reply-to:references:in-reply-to:message-id:date :subject:cc:to:from:from:to:cc:subject:date; bh=Dna0jbzOe4cc+tkUwZnxiT+7ajfuKJQBNUXCBRN9zpY=; b=FguiKJYDPfwB9opcnzRmp2m7Zjz6vt088E9qXaPs3WSu56u5B8mDrVpjUGSZAL/DFg spRLkGQTl9+E2SJlbOX4bBumtrUVAJh0IyzqXs46lF4iPT1CAvIkIvdMdY4D0JwfZul0 blbmcBWbFuShVxk36ZmO1qNTGzC6COchLgHoFKP+JXtrApoEFApNNwZp4d/T724+J8J8 KLLAeUkw0eu2IEafc9Colz+7Rxk2OudJ3HnxKEys+F7HYrx9eKeovEKFTzrWxffv005K Bl1VHPPFxUJHI9tvJpL1yRXXmzTIHoOVHs3fJZNFl7Yh5qGHQSDlCGAdy4hYjTshbzTg AQSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=references:in-reply-to:references:in-reply-to:message-id:date :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date; bh=Dna0jbzOe4cc+tkUwZnxiT+7ajfuKJQBNUXCBRN9zpY=; b=5dX6B1MMubuhNWeQlTzKuZ2PHQih7XIGc0qQztaNaIXqhQTtV2+CxKXrgX3Tt1ffsB tGYTDSYJc4gIrZ1Mw+GTZMpwFjTsJd8NDmMJOMfoMXdxLzlsuW3Phys8zafQVt5+06aI qAQALw3cn/E3qsav4ewV05+J5VuTgcjHVUBU1SsM8kwY5P/zjbfqSnBaejy7boPr1gid I3sWy6TupxgdiCbF4tT6Bl8S0haGHuFdoxC76kO4iPmg//eHK8gVvGTFCNJTJMkq2u/O gYuweAMiWmxcA97LBZtTYrG/Inp33XpOWEDv+zHnR8Jo746XIcNvRujJMQZZo4mLBM1Q PjyA== X-Gm-Message-State: ACgBeo1cUbuM/5ydfijzCXIgpAkM+MucEf2GU9pTf6c0OWk9gMYm8gNV d0NoGfpNGRDjcsn3qU8DjrI= X-Google-Smtp-Source: AA6agR7hbfK/XhnYBW4UGtVSi43kFhgabslRYF4wkTOloB+sM7cGUSDPDfKT5ZIksBdwlnEv+9fjdQ== X-Received: by 2002:a17:90b:1e0d:b0:202:91ec:e167 with SMTP id pg13-20020a17090b1e0d00b0020291ece167mr3351243pjb.174.1663067203891; Tue, 13 Sep 2022 04:06:43 -0700 (PDT) Received: from localhost.localdomain ([156.236.96.165]) by smtp.gmail.com with ESMTPSA id cm3-20020a17090afa0300b002000d577cc3sm6888658pjb.55.2022.09.13.04.06.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Sep 2022 04:06:43 -0700 (PDT) From: Yue Hu To: xiang@kernel.org, chao@kernel.org Cc: linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org, zhangwen@coolpad.com, shaojunjun@coolpad.com, zbestahu@gmail.com, Yue Hu Subject: [RFC PATCH v4 1/2] erofs: support interlaced uncompressed data for compressed files Date: Tue, 13 Sep 2022 19:05:51 +0800 Message-Id: <2ef3d0fb6d1fa2d036ad4217d474d6efd12f63b9.1663066966.git.huyue2@coolpad.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Yue Hu Currently, uncompressed data is all handled in the shifted way, which means we have to shift the whole on-disk plain pcluster to get the logical data. However, since we are also using in-place I/O for uncompressed data, data copy will be reduced a lot if pcluster is recorded in the interlaced way as illustrated below: _______________________________________________________________ | | | |_ tail part |_ head part _| |<- blk0 ->| .. |<- blkn-2 ->|<- blkn-1 ->| The logical data then becomes: ________________________________________________________ |_ head part _|_ blk0 _| .. |_ blkn-2 _|_ tail part _| In addition, non-4k plain pclusters are also survived by the interlaced way, which can be used for non-4k lclusters as well. However, it's almost impossible to de-duplicate uncompressed data in the interlaced way, therefore shifted uncompressed data is still useful. Signed-off-by: Yue Hu Reviewed-by: Gao Xiang --- fs/erofs/decompressor.c | 47 ++++++++++++++++++++++++----------------- fs/erofs/erofs_fs.h | 2 ++ fs/erofs/internal.h | 1 + fs/erofs/zmap.c | 14 ++++++++---- 4 files changed, 41 insertions(+), 23 deletions(-) diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c index 2d55569f96ac..51b7ac7166d9 100644 --- a/fs/erofs/decompressor.c +++ b/fs/erofs/decompressor.c @@ -317,52 +317,61 @@ static int z_erofs_lz4_decompress(struct z_erofs_deco= mpress_req *rq, return ret; } =20 -static int z_erofs_shifted_transform(struct z_erofs_decompress_req *rq, - struct page **pagepool) +static int z_erofs_transform_plain(struct z_erofs_decompress_req *rq, + struct page **pagepool) { - const unsigned int nrpages_out =3D + const unsigned int inpages =3D PAGE_ALIGN(rq->inputsize) >> PAGE_SHIFT; + const unsigned int outpages =3D PAGE_ALIGN(rq->pageofs_out + rq->outputsize) >> PAGE_SHIFT; const unsigned int righthalf =3D min_t(unsigned int, rq->outputsize, PAGE_SIZE - rq->pageofs_out); const unsigned int lefthalf =3D rq->outputsize - righthalf; + const unsigned int interlaced_offset =3D + rq->alg =3D=3D Z_EROFS_COMPRESSION_SHIFTED ? 0 : rq->pageofs_out; unsigned char *src, *dst; =20 - if (nrpages_out > 2) { + if (outpages > 2 && rq->alg =3D=3D Z_EROFS_COMPRESSION_SHIFTED) { DBG_BUGON(1); - return -EIO; + return -EFSCORRUPTED; } =20 if (rq->out[0] =3D=3D *rq->in) { - DBG_BUGON(nrpages_out !=3D 1); + DBG_BUGON(rq->pageofs_out); return 0; } =20 - src =3D kmap_atomic(*rq->in) + rq->pageofs_in; + src =3D kmap_local_page(rq->in[inpages - 1]) + rq->pageofs_in; if (rq->out[0]) { - dst =3D kmap_atomic(rq->out[0]); - memcpy(dst + rq->pageofs_out, src, righthalf); - kunmap_atomic(dst); + dst =3D kmap_local_page(rq->out[0]); + memcpy(dst + rq->pageofs_out, src + interlaced_offset, + righthalf); + kunmap_local(dst); } =20 - if (nrpages_out =3D=3D 2) { - DBG_BUGON(!rq->out[1]); - if (rq->out[1] =3D=3D *rq->in) { + if (outpages > inpages) { + DBG_BUGON(!rq->out[outpages - 1]); + if (rq->out[outpages - 1] !=3D rq->in[inpages - 1]) { + dst =3D kmap_local_page(rq->out[outpages - 1]); + memcpy(dst, interlaced_offset ? src : + (src + righthalf), lefthalf); + kunmap_local(dst); + } else if (!interlaced_offset) { memmove(src, src + righthalf, lefthalf); - } else { - dst =3D kmap_atomic(rq->out[1]); - memcpy(dst, src + righthalf, lefthalf); - kunmap_atomic(dst); } } - kunmap_atomic(src); + kunmap_local(src); return 0; } =20 static struct z_erofs_decompressor decompressors[] =3D { [Z_EROFS_COMPRESSION_SHIFTED] =3D { - .decompress =3D z_erofs_shifted_transform, + .decompress =3D z_erofs_transform_plain, .name =3D "shifted" }, + [Z_EROFS_COMPRESSION_INTERLACED] =3D { + .decompress =3D z_erofs_transform_plain, + .name =3D "interlaced" + }, [Z_EROFS_COMPRESSION_LZ4] =3D { .decompress =3D z_erofs_lz4_decompress, .name =3D "lz4" diff --git a/fs/erofs/erofs_fs.h b/fs/erofs/erofs_fs.h index 2b48373f690b..5c1de6d7ad71 100644 --- a/fs/erofs/erofs_fs.h +++ b/fs/erofs/erofs_fs.h @@ -295,11 +295,13 @@ struct z_erofs_lzma_cfgs { * bit 1 : HEAD1 big pcluster (0 - off; 1 - on) * bit 2 : HEAD2 big pcluster (0 - off; 1 - on) * bit 3 : tailpacking inline pcluster (0 - off; 1 - on) + * bit 4 : interlaced plain pcluster (0 - off; 1 - on) */ #define Z_EROFS_ADVISE_COMPACTED_2B 0x0001 #define Z_EROFS_ADVISE_BIG_PCLUSTER_1 0x0002 #define Z_EROFS_ADVISE_BIG_PCLUSTER_2 0x0004 #define Z_EROFS_ADVISE_INLINE_PCLUSTER 0x0008 +#define Z_EROFS_ADVISE_INTERLACED_PCLUSTER 0x0010 =20 struct z_erofs_map_header { __le16 h_reserved1; diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index cfee49d33b95..f3ed36445d73 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -436,6 +436,7 @@ struct erofs_map_blocks { =20 enum { Z_EROFS_COMPRESSION_SHIFTED =3D Z_EROFS_COMPRESSION_MAX, + Z_EROFS_COMPRESSION_INTERLACED, Z_EROFS_COMPRESSION_RUNTIME_MAX }; =20 diff --git a/fs/erofs/zmap.c b/fs/erofs/zmap.c index d58549ca1df9..7196235a441c 100644 --- a/fs/erofs/zmap.c +++ b/fs/erofs/zmap.c @@ -679,12 +679,18 @@ static int z_erofs_do_map_blocks(struct inode *inode, goto out; } =20 - if (m.headtype =3D=3D Z_EROFS_VLE_CLUSTER_TYPE_PLAIN) - map->m_algorithmformat =3D Z_EROFS_COMPRESSION_SHIFTED; - else if (m.headtype =3D=3D Z_EROFS_VLE_CLUSTER_TYPE_HEAD2) + if (m.headtype =3D=3D Z_EROFS_VLE_CLUSTER_TYPE_PLAIN) { + if (vi->z_advise & Z_EROFS_ADVISE_INTERLACED_PCLUSTER) + map->m_algorithmformat =3D + Z_EROFS_COMPRESSION_INTERLACED; + else + map->m_algorithmformat =3D + Z_EROFS_COMPRESSION_SHIFTED; + } else if (m.headtype =3D=3D Z_EROFS_VLE_CLUSTER_TYPE_HEAD2) { map->m_algorithmformat =3D vi->z_algorithmtype[1]; - else + } else { map->m_algorithmformat =3D vi->z_algorithmtype[0]; + } =20 if ((flags & EROFS_GET_BLOCKS_FIEMAP) || ((flags & EROFS_GET_BLOCKS_READMORE) && --=20 2.17.1 From nobody Thu Apr 9 10:37:26 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00297C6FA89 for ; Tue, 13 Sep 2022 11:06:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231881AbiIMLGz (ORCPT ); Tue, 13 Sep 2022 07:06:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231847AbiIMLGs (ORCPT ); Tue, 13 Sep 2022 07:06:48 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCFF94F1A2 for ; Tue, 13 Sep 2022 04:06:46 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id i15-20020a17090a4b8f00b0020073b4ac27so10984135pjh.3 for ; Tue, 13 Sep 2022 04:06:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=references:in-reply-to:references:in-reply-to:message-id:date :subject:cc:to:from:from:to:cc:subject:date; bh=8mkzjSRjFKMU3g2uHBonaE+/cKBJcje4WHjCeYyn5Xs=; b=WRRnMuQ5Lf48hM8gQi6eeTIMn8UwJnvuDDpNilFcVdEIGaCsl9ERnAJriqEa1ZEfHN taPqlIEkH+OFk/LszRMqoYTit2d/0poDUZzo8T87CgsdSb2x8asvQS1jShoMpWyct+j/ FW+oHP3VvO35i2v2agVfE4FxT6GRPRHtRKbjtBQK0rlVFO1WhKmOeHHCYMPOMyJxXjfc vPo+SWwFsmh4sKXnrgSPEKz9GCVEFXe7hnrxlxt0bT1nTR08dOhbIkf84oKUay6BEH6x 0D0PT2JytXPkvA0/rpoUlPg2VYKKV9niGVtGHSbqcqhBhONJYcpU+pYlvIUfby+kGaIc pR5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=references:in-reply-to:references:in-reply-to:message-id:date :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date; bh=8mkzjSRjFKMU3g2uHBonaE+/cKBJcje4WHjCeYyn5Xs=; b=dbfIErPLdQJaxTnA5dJ+k9A5/Rw0h61ZaNLrgZHsVLM48xWVYWuwOvxee4gtWPbWbm m2QTONSDQ5hyyOv1jqdRJtFn9/A8uB5hT3figpjhjpqQHScjV2cZLC/hd0ZUBUT2odls /SqCH35tdF+Oh07b3nKxHqyLM1thLVVvULowzg0fCJonyYHsP66rdnSjYlrJZMJ/cGIh Jr1rDCqDqQfu9Eu00AhyLtoEGfLuuN37J3+723GyBfizcTWDkjxTdOKbDXWqZjIcuIeL N+yo/p5/3Qr/LIXEwV70TwaF87ijufm0i7T0e+9hjcvrHS2kqRE5ZpxunpRhTkOy08wX j/Vw== X-Gm-Message-State: ACgBeo3F/9Gp6vORGjQMRdpk1z/6zhaqe1o90B4RDDpVxw8v8CIRLSc3 fC+wHc6IBJA3daSVvVdt6/o= X-Google-Smtp-Source: AA6agR60i5Jmhi23RnPgayTyVAQVNdUGw6XHH2oPUEweOmGWsirHXAJ9qzxrdsZQNxE7kKnr0MKL2Q== X-Received: by 2002:a17:90b:4a89:b0:202:d56e:e202 with SMTP id lp9-20020a17090b4a8900b00202d56ee202mr3340730pjb.22.1663067206251; Tue, 13 Sep 2022 04:06:46 -0700 (PDT) Received: from localhost.localdomain ([156.236.96.165]) by smtp.gmail.com with ESMTPSA id cm3-20020a17090afa0300b002000d577cc3sm6888658pjb.55.2022.09.13.04.06.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Sep 2022 04:06:46 -0700 (PDT) From: Yue Hu To: xiang@kernel.org, chao@kernel.org Cc: linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org, zhangwen@coolpad.com, shaojunjun@coolpad.com, zbestahu@gmail.com, Yue Hu Subject: [RFC PATCH v4 2/2] erofs: support on-disk compressed fragments data Date: Tue, 13 Sep 2022 19:05:52 +0800 Message-Id: <6ded0c212d7da65b70c853fd04f21da229cdefb1.1663066966.git.huyue2@coolpad.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Yue Hu Introduce on-disk compressed fragments data feature. This approach adds a new field called `h_fragmentoff' in the per-file compression header to indicate the fragment offset of each tail pcluster or the whole file in the special packed inode. Similar to ztailpacking, it will also find and record the 'headlcn' of the tail pcluster when initializing per-inode zmap for making follow-on requests more easy. Signed-off-by: Yue Hu --- fs/erofs/erofs_fs.h | 29 +++++++++++++++++++++------ fs/erofs/internal.h | 16 ++++++++++++--- fs/erofs/super.c | 15 ++++++++++++++ fs/erofs/sysfs.c | 2 ++ fs/erofs/zdata.c | 48 ++++++++++++++++++++++++++++++++++++++++++++- fs/erofs/zmap.c | 48 +++++++++++++++++++++++++++++++++++++++++++-- 6 files changed, 146 insertions(+), 12 deletions(-) diff --git a/fs/erofs/erofs_fs.h b/fs/erofs/erofs_fs.h index 5c1de6d7ad71..aa976757328b 100644 --- a/fs/erofs/erofs_fs.h +++ b/fs/erofs/erofs_fs.h @@ -25,6 +25,7 @@ #define EROFS_FEATURE_INCOMPAT_DEVICE_TABLE 0x00000008 #define EROFS_FEATURE_INCOMPAT_COMPR_HEAD2 0x00000008 #define EROFS_FEATURE_INCOMPAT_ZTAILPACKING 0x00000010 +#define EROFS_FEATURE_INCOMPAT_FRAGMENTS 0x00000020 #define EROFS_ALL_FEATURE_INCOMPAT \ (EROFS_FEATURE_INCOMPAT_ZERO_PADDING | \ EROFS_FEATURE_INCOMPAT_COMPR_CFGS | \ @@ -32,7 +33,8 @@ EROFS_FEATURE_INCOMPAT_CHUNKED_FILE | \ EROFS_FEATURE_INCOMPAT_DEVICE_TABLE | \ EROFS_FEATURE_INCOMPAT_COMPR_HEAD2 | \ - EROFS_FEATURE_INCOMPAT_ZTAILPACKING) + EROFS_FEATURE_INCOMPAT_ZTAILPACKING | \ + EROFS_FEATURE_INCOMPAT_FRAGMENTS) =20 #define EROFS_SB_EXTSLOT_SIZE 16 =20 @@ -71,7 +73,9 @@ struct erofs_super_block { } __packed u1; __le16 extra_devices; /* # of devices besides the primary device */ __le16 devt_slotoff; /* startoff =3D devt_slotoff * devt_slotsize */ - __u8 reserved2[38]; + __u8 reserved[6]; + __le64 packed_nid; /* nid of the special packed inode */ + __u8 reserved2[24]; }; =20 /* @@ -296,17 +300,26 @@ struct z_erofs_lzma_cfgs { * bit 2 : HEAD2 big pcluster (0 - off; 1 - on) * bit 3 : tailpacking inline pcluster (0 - off; 1 - on) * bit 4 : interlaced plain pcluster (0 - off; 1 - on) + * bit 5 : fragment pcluster (0 - off; 1 - on) */ #define Z_EROFS_ADVISE_COMPACTED_2B 0x0001 #define Z_EROFS_ADVISE_BIG_PCLUSTER_1 0x0002 #define Z_EROFS_ADVISE_BIG_PCLUSTER_2 0x0004 #define Z_EROFS_ADVISE_INLINE_PCLUSTER 0x0008 #define Z_EROFS_ADVISE_INTERLACED_PCLUSTER 0x0010 +#define Z_EROFS_ADVISE_FRAGMENT_PCLUSTER 0x0020 =20 +#define Z_EROFS_FRAGMENT_INODE_BIT 7 struct z_erofs_map_header { - __le16 h_reserved1; - /* indicates the encoded size of tailpacking data */ - __le16 h_idata_size; + union { + /* fragment data offset in the packed inode */ + __le32 h_fragmentoff; + struct { + __le16 h_reserved1; + /* indicates the encoded size of tailpacking data */ + __le16 h_idata_size; + }; + }; __le16 h_advise; /* * bit 0-3 : algorithm type of head 1 (logical cluster type 01); @@ -315,7 +328,8 @@ struct z_erofs_map_header { __u8 h_algorithmtype; /* * bit 0-2 : logical cluster bits - 12, e.g. 0 for 4096; - * bit 3-7 : reserved. + * bit 3-6 : reserved; + * bit 7 : move the whole file into packed inode or not. */ __u8 h_clusterbits; }; @@ -421,6 +435,9 @@ static inline void erofs_check_ondisk_layout_definition= s(void) =20 BUILD_BUG_ON(BIT(Z_EROFS_VLE_DI_CLUSTER_TYPE_BITS) < Z_EROFS_VLE_CLUSTER_TYPE_MAX - 1); + WARN_ON(*(__le64 *)&(struct z_erofs_map_header) { + .h_clusterbits =3D 1 << Z_EROFS_FRAGMENT_INODE_BIT + } !=3D cpu_to_le64(1ULL << 63)); } =20 #endif diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h index f3ed36445d73..b133664b4ad2 100644 --- a/fs/erofs/internal.h +++ b/fs/erofs/internal.h @@ -120,6 +120,7 @@ struct erofs_sb_info { struct inode *managed_cache; =20 struct erofs_sb_lz4_info lz4; + struct inode *packed_inode; #endif /* CONFIG_EROFS_FS_ZIP */ struct erofs_dev_context *devs; struct dax_device *dax_dev; @@ -306,6 +307,7 @@ EROFS_FEATURE_FUNCS(chunked_file, incompat, INCOMPAT_CH= UNKED_FILE) EROFS_FEATURE_FUNCS(device_table, incompat, INCOMPAT_DEVICE_TABLE) EROFS_FEATURE_FUNCS(compr_head2, incompat, INCOMPAT_COMPR_HEAD2) EROFS_FEATURE_FUNCS(ztailpacking, incompat, INCOMPAT_ZTAILPACKING) +EROFS_FEATURE_FUNCS(fragments, incompat, INCOMPAT_FRAGMENTS) EROFS_FEATURE_FUNCS(sb_chksum, compat, COMPAT_SB_CHKSUM) =20 /* atomic flag definitions */ @@ -341,8 +343,13 @@ struct erofs_inode { unsigned char z_algorithmtype[2]; unsigned char z_logical_clusterbits; unsigned long z_tailextent_headlcn; - erofs_off_t z_idataoff; - unsigned short z_idata_size; + union { + struct { + erofs_off_t z_idataoff; + unsigned short z_idata_size; + }; + erofs_off_t z_fragmentoff; + }; }; #endif /* CONFIG_EROFS_FS_ZIP */ }; @@ -400,6 +407,7 @@ extern const struct address_space_operations z_erofs_ao= ps; enum { BH_Encoded =3D BH_PrivateStart, BH_FullMapped, + BH_Fragment, }; =20 /* Has a disk mapping */ @@ -410,6 +418,8 @@ enum { #define EROFS_MAP_ENCODED (1 << BH_Encoded) /* The length of extent is full */ #define EROFS_MAP_FULL_MAPPED (1 << BH_FullMapped) +/* Located in the special packed inode */ +#define EROFS_MAP_FRAGMENT (1 << BH_Fragment) =20 struct erofs_map_blocks { struct erofs_buf buf; @@ -431,7 +441,7 @@ struct erofs_map_blocks { #define EROFS_GET_BLOCKS_FIEMAP 0x0002 /* Used to map the whole extent if non-negligible data is requested for LZ= MA */ #define EROFS_GET_BLOCKS_READMORE 0x0004 -/* Used to map tail extent for tailpacking inline pcluster */ +/* Used to map tail extent for tailpacking inline or fragment pcluster */ #define EROFS_GET_BLOCKS_FINDTAIL 0x0008 =20 enum { diff --git a/fs/erofs/super.c b/fs/erofs/super.c index 3173debeaa5a..8170c0d8ab92 100644 --- a/fs/erofs/super.c +++ b/fs/erofs/super.c @@ -381,6 +381,17 @@ static int erofs_read_superblock(struct super_block *s= b) #endif sbi->islotbits =3D ilog2(sizeof(struct erofs_inode_compact)); sbi->root_nid =3D le16_to_cpu(dsb->root_nid); +#ifdef CONFIG_EROFS_FS_ZIP + sbi->packed_inode =3D NULL; + if (erofs_sb_has_fragments(sbi)) { + sbi->packed_inode =3D + erofs_iget(sb, le64_to_cpu(dsb->packed_nid), false); + if (IS_ERR(sbi->packed_inode)) { + ret =3D PTR_ERR(sbi->packed_inode); + goto out; + } + } +#endif sbi->inos =3D le64_to_cpu(dsb->inos); =20 sbi->build_time =3D le64_to_cpu(dsb->build_time); @@ -411,6 +422,8 @@ static int erofs_read_superblock(struct super_block *sb) erofs_info(sb, "EXPERIMENTAL compressed inline data feature in use. Use = at your own risk!"); if (erofs_is_fscache_mode(sb)) erofs_info(sb, "EXPERIMENTAL fscache-based on-demand read feature in use= . Use at your own risk!"); + if (erofs_sb_has_fragments(sbi)) + erofs_info(sb, "EXPERIMENTAL compressed fragments feature in use. Use at= your own risk!"); out: erofs_put_metabuf(&buf); return ret; @@ -908,6 +921,8 @@ static void erofs_put_super(struct super_block *sb) #ifdef CONFIG_EROFS_FS_ZIP iput(sbi->managed_cache); sbi->managed_cache =3D NULL; + iput(sbi->packed_inode); + sbi->packed_inode =3D NULL; #endif erofs_fscache_unregister_cookie(&sbi->s_fscache); } diff --git a/fs/erofs/sysfs.c b/fs/erofs/sysfs.c index c1383e508bbe..1b52395be82a 100644 --- a/fs/erofs/sysfs.c +++ b/fs/erofs/sysfs.c @@ -76,6 +76,7 @@ EROFS_ATTR_FEATURE(device_table); EROFS_ATTR_FEATURE(compr_head2); EROFS_ATTR_FEATURE(sb_chksum); EROFS_ATTR_FEATURE(ztailpacking); +EROFS_ATTR_FEATURE(fragments); =20 static struct attribute *erofs_feat_attrs[] =3D { ATTR_LIST(zero_padding), @@ -86,6 +87,7 @@ static struct attribute *erofs_feat_attrs[] =3D { ATTR_LIST(compr_head2), ATTR_LIST(sb_chksum), ATTR_LIST(ztailpacking), + ATTR_LIST(fragments), NULL, }; ATTRIBUTE_GROUPS(erofs_feat); diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index 5792ca9e0d5e..aa2a3cdeea57 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -650,6 +650,33 @@ static bool should_alloc_managed_pages(struct z_erofs_= decompress_frontend *fe, la < fe->headoffset; } =20 +static int z_erofs_read_fragment(struct inode *inode, erofs_off_t pos, + struct page *page, unsigned int pageofs, + unsigned int len) +{ + struct inode *packed_inode =3D EROFS_I_SB(inode)->packed_inode; + struct erofs_buf buf =3D __EROFS_BUF_INITIALIZER; + u8 *src, *dst; + unsigned int i, cnt; + + pos +=3D EROFS_I(inode)->z_fragmentoff; + for (i =3D 0; i < len; i +=3D cnt) { + cnt =3D min_t(unsigned int, len - i, + EROFS_BLKSIZ - erofs_blkoff(pos)); + src =3D erofs_bread(&buf, packed_inode, + erofs_blknr(pos), EROFS_KMAP); + if (IS_ERR(src)) + return PTR_ERR(src); + + dst =3D kmap_local_page(page); + memcpy(dst + pageofs + i, src + erofs_blkoff(pos), cnt); + kunmap_local(dst); + pos +=3D cnt; + } + erofs_put_metabuf(&buf); + return 0; +} + static int z_erofs_do_read_page(struct z_erofs_decompress_frontend *fe, struct page *page, struct page **pagepool) { @@ -688,7 +715,8 @@ static int z_erofs_do_read_page(struct z_erofs_decompre= ss_frontend *fe, /* didn't get a valid pcluster previously (very rare) */ } =20 - if (!(map->m_flags & EROFS_MAP_MAPPED)) + if (!(map->m_flags & EROFS_MAP_MAPPED) || + map->m_flags & EROFS_MAP_FRAGMENT) goto hitted; =20 err =3D z_erofs_collector_begin(fe); @@ -735,6 +763,24 @@ static int z_erofs_do_read_page(struct z_erofs_decompr= ess_frontend *fe, zero_user_segment(page, cur, end); goto next_part; } + if (map->m_flags & EROFS_MAP_FRAGMENT) { + unsigned int pageofs, skip, len; + + if (offset > map->m_la) { + pageofs =3D 0; + skip =3D offset - map->m_la; + } else { + pageofs =3D map->m_la & ~PAGE_MASK; + skip =3D 0; + } + len =3D min_t(unsigned int, map->m_llen - skip, end - cur); + err =3D z_erofs_read_fragment(inode, skip, page, pageofs, len); + if (err) + goto out; + ++spiltted; + tight =3D false; + goto next_part; + } =20 exclusive =3D (!cur && (!spiltted || tight)); if (cur) diff --git a/fs/erofs/zmap.c b/fs/erofs/zmap.c index 7196235a441c..6830999529d7 100644 --- a/fs/erofs/zmap.c +++ b/fs/erofs/zmap.c @@ -69,6 +69,16 @@ static int z_erofs_fill_inode_lazy(struct inode *inode) } =20 h =3D kaddr + erofs_blkoff(pos); + /* + * if the highest bit of the 8-byte map header is set, the whole file + * is stored in the packed inode. The rest bits keeps z_fragmentoff. + */ + if (h->h_clusterbits >> Z_EROFS_FRAGMENT_INODE_BIT) { + vi->z_advise =3D Z_EROFS_ADVISE_FRAGMENT_PCLUSTER; + vi->z_fragmentoff =3D le64_to_cpu(*(__le64 *)h) ^ (1ULL << 63); + vi->z_tailextent_headlcn =3D 0; + goto unmap_done; + } vi->z_advise =3D le16_to_cpu(h->h_advise); vi->z_algorithmtype[0] =3D h->h_algorithmtype & 15; vi->z_algorithmtype[1] =3D h->h_algorithmtype >> 4; @@ -123,6 +133,20 @@ static int z_erofs_fill_inode_lazy(struct inode *inode) if (err < 0) goto out_unlock; } + + if (vi->z_advise & Z_EROFS_ADVISE_FRAGMENT_PCLUSTER && + !(h->h_clusterbits >> Z_EROFS_FRAGMENT_INODE_BIT)) { + struct erofs_map_blocks map =3D { + .buf =3D __EROFS_BUF_INITIALIZER + }; + + vi->z_fragmentoff =3D le32_to_cpu(h->h_fragmentoff); + err =3D z_erofs_do_map_blocks(inode, &map, + EROFS_GET_BLOCKS_FINDTAIL); + erofs_put_metabuf(&map.buf); + if (err < 0) + goto out_unlock; + } /* paired with smp_mb() at the beginning of the function */ smp_mb(); set_bit(EROFS_I_Z_INITED_BIT, &vi->flags); @@ -598,6 +622,7 @@ static int z_erofs_do_map_blocks(struct inode *inode, { struct erofs_inode *const vi =3D EROFS_I(inode); bool ztailpacking =3D vi->z_advise & Z_EROFS_ADVISE_INLINE_PCLUSTER; + bool fragment =3D vi->z_advise & Z_EROFS_ADVISE_FRAGMENT_PCLUSTER; struct z_erofs_maprecorder m =3D { .inode =3D inode, .map =3D map, @@ -666,12 +691,20 @@ static int z_erofs_do_map_blocks(struct inode *inode, =20 map->m_llen =3D end - map->m_la; =20 - if (flags & EROFS_GET_BLOCKS_FINDTAIL) + if (flags & EROFS_GET_BLOCKS_FINDTAIL) { vi->z_tailextent_headlcn =3D m.lcn; + /* for non-compact indexes, fragmentoff is 64 bits */ + if (fragment && + vi->datalayout =3D=3D EROFS_INODE_FLAT_COMPRESSION_LEGACY) + vi->z_fragmentoff |=3D (u64)m.pblk << 32; + } if (ztailpacking && m.lcn =3D=3D vi->z_tailextent_headlcn) { map->m_flags |=3D EROFS_MAP_META; map->m_pa =3D vi->z_idataoff; map->m_plen =3D vi->z_idata_size; + } else if (fragment && m.lcn =3D=3D vi->z_tailextent_headlcn) { + map->m_flags |=3D EROFS_MAP_FRAGMENT; + DBG_BUGON(!map->m_la); } else { map->m_pa =3D blknr_to_addr(m.pblk); err =3D z_erofs_get_extent_compressedlen(&m, initial_lcn); @@ -715,6 +748,7 @@ int z_erofs_map_blocks_iter(struct inode *inode, struct erofs_map_blocks *map, int flags) { + struct erofs_inode *const vi =3D EROFS_I(inode); int err =3D 0; =20 trace_z_erofs_map_blocks_iter_enter(inode, map, flags); @@ -731,6 +765,15 @@ int z_erofs_map_blocks_iter(struct inode *inode, if (err) goto out; =20 + if ((vi->z_advise & Z_EROFS_ADVISE_FRAGMENT_PCLUSTER) && + !vi->z_tailextent_headlcn) { + map->m_la =3D 0; + map->m_llen =3D inode->i_size; + map->m_flags =3D EROFS_MAP_MAPPED | EROFS_MAP_FULL_MAPPED | + EROFS_MAP_FRAGMENT; + goto out; + } + err =3D z_erofs_do_map_blocks(inode, map, flags); out: trace_z_erofs_map_blocks_iter_exit(inode, map, flags, err); @@ -757,7 +800,8 @@ static int z_erofs_iomap_begin_report(struct inode *ino= de, loff_t offset, iomap->length =3D map.m_llen; if (map.m_flags & EROFS_MAP_MAPPED) { iomap->type =3D IOMAP_MAPPED; - iomap->addr =3D map.m_pa; + iomap->addr =3D map.m_flags & EROFS_MAP_FRAGMENT ? + IOMAP_NULL_ADDR : map.m_pa; } else { iomap->type =3D IOMAP_HOLE; iomap->addr =3D IOMAP_NULL_ADDR; --=20 2.17.1