erofs: support deflate decompress by using Intel QAT
PATCH v3 1/1 erofs: support deflate decompress by using Intel QAT
This patch introdueces the use of the Intel QAT to decompress compressed data in the EROFS filesystem, aiming to improve the decompression speed of compressed datea.
We created a 285MiB compressed file and then used the following command to create EROFS images with different cluster size.
# mkfs.erofs -zdeflate,level=9 -C16384
fio command was used to test random read and small random read(~5%) and sequential read performance.
# fio -filename=testfile -bs=4k -rw=read -name=job1
# fio -filename=testfile -bs=4k -rw=randread -name=job1
# fio -filename=testfile -bs=4k -rw=randread --io_size=14m -name=job1Here are some performance numbers for reference:
Processors: Intel(R) Xeon(R) 6766E(144 core) Memory: 521 GiB
|-----------------------------------------------------------------------------| | | Cluster size | sequential read | randread | small randread(5%) | |-----------|--------------|-----------------|-----------|--------------------| | Intel QAT | 4096 | 538 MiB/s | 112 MiB/s | 20.76 MiB/s | | Intel QAT | 16384 | 699 MiB/s | 158 MiB/s | 21.02 MiB/s | | Intel QAT | 65536 | 917 MiB/s | 278 MiB/s | 20.90 MiB/s | | Intel QAT | 131072 | 1056 MiB/s | 351 MiB/s | 23.36 MiB/s | | Intel QAT | 262144 | 1145 MiB/s | 431 MiB/s | 26.66 MiB/s | | deflate | 4096 | 499 MiB/s | 108 MiB/s | 21.50 MiB/s | | deflate | 16384 | 422 MiB/s | 125 MiB/s | 18.94 MiB/s | | deflate | 65536 | 452 MiB/s | 159 MiB/s | 13.02 MiB/s | | deflate | 131072 | 452 MiB/s | 177 MiB/s | 11.44 MiB/s | | deflate | 262144 | 466 MiB/s | 194 MiB/s | 10.60 MiB/s |
---
v1: https://lore.kernel.org/linux-erofs/[email protected]/
v2: https://lore.kernel.org/linux-erofs/[email protected]/T/#t
Changes since v2:
- Add a new kernel config option CONFIG_EROFS_FS_ZIP_CRYPTO.
- Modify the sysfs interface to merge enable and disable into
a single entry point, and add a read function to view the current state.
- Optimize the relevant code,use the sg_alloc_table_from_pages_segment interface.
fs/erofs/Kconfig | 14 +++ fs/erofs/Makefile | 1 + fs/erofs/compress.h | 14 +++ fs/erofs/decompressor_crypto.c | 199 ++++++++++++++++++++++++++++++++ fs/erofs/decompressor_deflate.c | 16 ++- fs/erofs/sysfs.c | 36 ++++++ 6 files changed, 279 insertions(+), 1 deletion(-) create mode 100644 fs/erofs/decompressor_crypto.c
fs/erofs/Kconfig +14 -0
@@ -144,6 +144,20 @@ config EROFS_FS_ZIP_ZSTD If unsure, say N. +config EROFS_FS_ZIP_CRYPTO + bool "EROFS hardware decompression support (crypto interface)" + depends on EROFS_FS_ZIP + help + Saying Y here includes support for reading EROFS file systems + containing crypto compressed data. It gives better decompression + speed than the software-implemented compression, and it costs + lower CPU overhead. + + Crypto support is an experimental feature for now and so most + file systems will be readable without selecting this option. + + If unsure, say N. + config EROFS_FS_ONDEMAND bool "EROFS fscache-based on-demand read support (deprecated)" depends on EROFS_FS
fs/erofs/Makefile +1 -0
@@ -7,5 +7,6 @@ erofs-$(CONFIG_EROFS_FS_ZIP) += decompressor.o zmap.o zdata.o zutil.o erofs-$(CONFIG_EROFS_FS_ZIP_LZMA) += decompressor_lzma.o erofs-$(CONFIG_EROFS_FS_ZIP_DEFLATE) += decompressor_deflate.o erofs-$(CONFIG_EROFS_FS_ZIP_ZSTD) += decompressor_zstd.o +erofs-$(CONFIG_EROFS_FS_ZIP_CRYPTO) += decompressor_crypto.o erofs-$(CONFIG_EROFS_FS_BACKED_BY_FILE) += fileio.o erofs-$(CONFIG_EROFS_FS_ONDEMAND) += fscache.o
fs/erofs/compress.h +14 -0
@@ -70,10 +70,24 @@ struct z_erofs_stream_dctx {bool bounced;/* is the bounce buffer used now? */ }; +struct z_erofs_crypto_engine { +char *crypto_name; +bool enabled; +struct crypto_acomp *erofs_tfm; +}; + +extern struct z_erofs_crypto_engine z_erofs_crypto[Z_EROFS_COMPRESSION_MAX ][2 ]; +int z_erofs_stream_switch_bufs (struct z_erofs_stream_dctx *dctx,void **dst,void **src,struct page **pgpl);int z_erofs_fixup_insize (struct z_erofs_decompress_req *rq,const char *padbuf,unsigned int padbufsize);int __init z_erofs_init_decompressor (void );void z_erofs_exit_decompressor (void ); +int z_erofs_crypto_decompress (struct z_erofs_decompress_req *rq, +struct crypto_acomp *erofs_tfm,struct page **pgpl); +struct crypto_acomp *z_erofs_crypto_get_engine (int type); +int z_erofs_crypto_enable_engine (const char *name); +void z_erofs_crypto_disable_engine (void ); +int z_erofs_crypto_engine_format (char *buf);#endif
fs/erofs/decompressor_crypto.c new file +199 -0
199 lines not on this page · raw message
fs/erofs/decompressor_deflate.c +15 -1
@@ -97,7 +97,7 @@ static int z_erofs_load_deflate_config(struct super_block *sb,return -ENOMEM ; } -static int z_erofs_deflate_decompress (struct z_erofs_decompress_req *rq, +static int __z_erofs_deflate_decompress (struct z_erofs_decompress_req *rq,struct page **pgpl) {struct super_block *sb = rq->sb;
@@ -178,6 +178,20 @@ static int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,return err; } +static int z_erofs_deflate_decompress (struct z_erofs_decompress_req *rq, +struct page **pgpl) +{ +#ifdef CONFIG_EROFS_FS_ZIP_CRYPTO +struct crypto_acomp *erofs_tfm =NULL ; + + erofs_tfm =z_erofs_crypto_get_engine (Z_EROFS_COMPRESSION_DEFLATE ); +if (erofs_tfm && !rq->partial_decoding) +return z_erofs_crypto_decompress (rq, erofs_tfm, pgpl); + else +#endif +return __z_erofs_deflate_decompress (rq, pgpl); +} +const struct z_erofs_decompressor z_erofs_deflate_decomp = { .config = z_erofs_load_deflate_config, .decompress = z_erofs_deflate_decompress,
fs/erofs/sysfs.c +36 -0
@@ -7,12 +7,14 @@#include <linux/kobject.h> #include "internal.h" +#include "compress.h" enum { attr_feature, attr_drop_caches, attr_pointer_ui, attr_pointer_bool, + attr_crypto, };enum {
@@ -60,6 +62,9 @@ static struct erofs_attr erofs_attr_##_name = { \EROFS_ATTR_RW_UI (sync_decompress, erofs_mount_opts);EROFS_ATTR_FUNC (drop_caches,0200 );#endif +#ifdef CONFIG_EROFS_FS_ZIP_CRYPTO +EROFS_ATTR_FUNC (crypto,0644 ); +#endif static struct attribute *erofs_attrs[] = {#ifdef CONFIG_EROFS_FS_ZIP
@@ -95,6 +100,9 @@ static struct attribute *erofs_feat_attrs[] = {ATTR_LIST (fragments),ATTR_LIST (dedupe), ATTR_LIST(48bit), +#ifdef CONFIG_EROFS_FS_ZIP_CRYPTO +ATTR_LIST (crypto), +#endifNULL , };ATTRIBUTE_GROUPS (erofs_feat);
@@ -128,6 +136,10 @@ static ssize_t erofs_attr_show(struct kobject *kobj,if (!ptr)return 0 ;return sysfs_emit (buf,"%d\n" , *(bool *)ptr); +#ifdef CONFIG_EROFS_FS_ZIP_CRYPTO +case attr_crypto: +return z_erofs_crypto_engine_format (buf); +#endif }return 0 ; }
@@ -141,6 +153,10 @@ static ssize_t erofs_attr_store(struct kobject *kobj, struct attribute *attr,unsigned char *ptr =__struct_ptr (sbi, a->struct_type, a->offset);unsigned long t;int ret; +#ifdef CONFIG_EROFS_FS_ZIP_CRYPTO +char *crypto_name; +size_t sz; +#endif switch (a->attr_id) {case attr_pointer_ui:
@@ -181,6 +197,26 @@ static ssize_t erofs_attr_store(struct kobject *kobj, struct attribute *attr,if (t &1 )invalidate_mapping_pages (MNGD_MAPPING (sbi),0 ,-1 );return len; +#endif +#ifdef CONFIG_EROFS_FS_ZIP_CRYPTO +case attr_crypto: + buf =skip_spaces (buf); + sz =strlen (buf); + crypto_name =kstrdup (buf,GFP_KERNEL ); +if (!crypto_name) +return -ENOMEM ; + +/* ignore trailing newline */ +if (sz >0 && crypto_name[sz -1 ] =='\n' ) + crypto_name[sz -1 ] =0x00 ; + +if (strlen (crypto_name) >0 ) { + ret =z_erofs_crypto_enable_engine (crypto_name); +if (ret <0 ) +return ret; + }else +z_erofs_crypto_disable_engine (); +return len;#endif }return 0 ;
Signature · 1 line
2.31.1
fs/erofs/Kconfig config EROFS_FS_ZIP_ZSTD · line 159
Quoted 13 lines · Bo Liu
fs/erofs/Kconfig +13
-0+config EROFS_FS_ZIP_CRYPTO + bool "EROFS hardware decompression support (crypto interface)" + depends on EROFS_FS_ZIP + help + Saying Y here includes support for reading EROFS file systems + containing crypto compressed data. It gives better decompression + speed than the software-implemented compression, and it costs + lower CPU overhead. + + Crypto support is an experimental feature for now and so most + file systems will be readable without selecting this option. + + If unsure, say N.
I recommend not including the word "crypto" in any user facing part of this.
Compression algorithms are not cryptographic algorithms. The fact that the interface to access hardware compression accelerators is currently the "Crypto API" is an implementation quirk. It could be a different interface in the future.
Call it something clear like "hardware decompression".
- Eric
Hi Eric,
Quoted 17 lines · Eric Biggers
fs/erofs/Kconfig config EROFS_FS_ZIP_ZSTD · line 159
Quoted 13 lines · Bo Liu
fs/erofs/Kconfig +13
-0+config EROFS_FS_ZIP_CRYPTO + bool "EROFS hardware decompression support (crypto interface)" + depends on EROFS_FS_ZIP + help + Saying Y here includes support for reading EROFS file systems + containing crypto compressed data. It gives better decompression + speed than the software-implemented compression, and it costs + lower CPU overhead. + + Crypto support is an experimental feature for now and so most + file systems will be readable without selecting this option. + + If unsure, say N.I recommend not including the word "crypto" in any user facing part of this.
Quoted 6 lines
Compression algorithms are not cryptographic algorithms. The fact that the interface to access hardware compression accelerators is currently the "Crypto API" is an implementation quirk. It could be a different interface in the future.
Call it something clear like "hardware decompression".
Totally agreed on this since it's just an implementation detail, and I will try to make some extra time to polish this commit myself to fix some minor issues later.
Thanks,
Gao Xiang
Quoted 2 lines
- Eric
Quoted 220 lines · Bo Liu
[外部邮件] 此邮件来源于小米公司外部,请谨慎处理。若对邮件安全性存疑,请将邮件转发给[email protected]进行反馈
This patch introdueces the use of the Intel QAT to decompress compressed data in the EROFS filesystem, aiming to improve the decompression speed of compressed datea.
We created a 285MiB compressed file and then used the following command to create EROFS images with different cluster size.
# mkfs.erofs -zdeflate,level=9 -C16384fio command was used to test random read and small random read(~5%) and sequential read performance.
# fio -filename=testfile -bs=4k -rw=read -name=job1 # fio -filename=testfile -bs=4k -rw=randread -name=job1 # fio -filename=testfile -bs=4k -rw=randread --io_size=14m -name=job1Here are some performance numbers for reference:
Processors: Intel(R) Xeon(R) 6766E(144 core) Memory: 521 GiB|-----------------------------------------------------------------------------| | | Cluster size | sequential read | randread | small randread(5%) | |-----------|--------------|-----------------|-----------|--------------------| | Intel QAT | 4096 | 538 MiB/s | 112 MiB/s | 20.76 MiB/s | | Intel QAT | 16384 | 699 MiB/s | 158 MiB/s | 21.02 MiB/s | | Intel QAT | 65536 | 917 MiB/s | 278 MiB/s | 20.90 MiB/s | | Intel QAT | 131072 | 1056 MiB/s | 351 MiB/s | 23.36 MiB/s | | Intel QAT | 262144 | 1145 MiB/s | 431 MiB/s | 26.66 MiB/s | | deflate | 4096 | 499 MiB/s | 108 MiB/s | 21.50 MiB/s | | deflate | 16384 | 422 MiB/s | 125 MiB/s | 18.94 MiB/s | | deflate | 65536 | 452 MiB/s | 159 MiB/s | 13.02 MiB/s | | deflate | 131072 | 452 MiB/s | 177 MiB/s | 11.44 MiB/s | | deflate | 262144 | 466 MiB/s | 194 MiB/s | 10.60 MiB/s |Signed-off-by Bo Liu <[email protected]>---
v1: https://lore.kernel.org/linux-erofs/[email protected]/
v2: https://lore.kernel.org/linux-erofs/[email protected]/T/#tChanges since v2:
- Add a new kernel config optionCONFIG_EROFS_FS_ZIP_CRYPTO.
- Modify the sysfs interface to merge enable and disable into
a single entry point, and add a read function to view the current state.
- Optimize the relevant code,use thesg_alloc_table_from_pages_segmentinterface.fs/erofs/Kconfig | 14 +++ fs/erofs/Makefile | 1 + fs/erofs/compress.h | 14 +++ fs/erofs/decompressor_crypto.c | 199 ++++++++++++++++++++++++++++++++ fs/erofs/decompressor_deflate.c | 16 ++- fs/erofs/sysfs.c | 36 ++++++ 6 files changed, 279 insertions(+), 1 deletion(-)create mode 100644
fs/erofs/decompressor_crypto.cfs/erofs/Kconfig +14
-0@@ -144,6 +144,20 @@ config EROFS_FS_ZIP_ZSTD If unsure, say N. +config EROFS_FS_ZIP_CRYPTO + bool "EROFS hardware decompression support (crypto interface)" + depends on EROFS_FS_ZIP + help + Saying Y here includes support for reading EROFS file systems + containing crypto compressed data. It gives better decompression + speed than the software-implemented compression, and it costs + lower CPU overhead. + + Crypto support is an experimental feature for now and so most + file systems will be readable without selecting this option. + + If unsure, say N. + config EROFS_FS_ONDEMAND bool "EROFS fscache-based on-demand read support (deprecated)" depends on EROFS_FSfs/erofs/Makefile +1
-0@@ -7,5 +7,6 @@ erofs-$(CONFIG_EROFS_FS_ZIP) += decompressor.o zmap.o zdata.o zutil.o erofs-$(CONFIG_EROFS_FS_ZIP_LZMA) += decompressor_lzma.o erofs-$(CONFIG_EROFS_FS_ZIP_DEFLATE) += decompressor_deflate.o erofs-$(CONFIG_EROFS_FS_ZIP_ZSTD) += decompressor_zstd.o +erofs-$(CONFIG_EROFS_FS_ZIP_CRYPTO) += decompressor_crypto.o erofs-$(CONFIG_EROFS_FS_BACKED_BY_FILE) += fileio.o erofs-$(CONFIG_EROFS_FS_ONDEMAND) += fscache.ofs/erofs/compress.h +14
-0@@ -70,10 +70,24 @@ struct z_erofs_stream_dctx {bool bounced;/* is the bounce buffer used now? */ }; +struct z_erofs_crypto_engine { +char *crypto_name; +bool enabled; +struct crypto_acomp *erofs_tfm; +}; + +extern struct z_erofs_crypto_engine z_erofs_crypto[Z_EROFS_COMPRESSION_MAX ][2 ]; +int z_erofs_stream_switch_bufs (struct z_erofs_stream_dctx *dctx,void **dst,void **src,struct page **pgpl);int z_erofs_fixup_insize (struct z_erofs_decompress_req *rq,const char *padbuf,unsigned int padbufsize);int __init z_erofs_init_decompressor (void );void z_erofs_exit_decompressor (void ); +int z_erofs_crypto_decompress (struct z_erofs_decompress_req *rq, +struct crypto_acomp *erofs_tfm,struct page **pgpl); +struct crypto_acomp *z_erofs_crypto_get_engine (int type); +int z_erofs_crypto_enable_engine (const char *name); +void z_erofs_crypto_disable_engine (void ); +int z_erofs_crypto_engine_format (char *buf);#endif fs/erofs/decompressor_crypto.c new file +94
-0@@ -0,0 +1,199 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#include <linux/scatterlist.h> +#include <crypto/acompress.h> + +#include "compress.h" + +static int z_erofs_crypto_decompress_mem (struct z_erofs_decompress_req *rq, +struct crypto_acomp *erofs_tfm) +{ +struct sg_table st_src, st_dst; +struct acomp_req *req; +struct crypto_wait wait; +u8 *headpage; +int ret; + + headpage =kmap_local_page (*rq->in); + ret =z_erofs_fixup_insize (rq, headpage + rq->pageofs_in, + min_t(unsigned int, rq->inputsize, + rq->sb->s_blocksize - rq->pageofs_in)); +kunmap_local (headpage); +if (ret) +return ret; + + req =acomp_request_alloc (erofs_tfm); +if (!req) { +erofs_err (rq->sb,"failed to alloc decompress request" ); +return -ENOMEM ; + } + + ret =sg_alloc_table_from_pages_segment (&st_src, + rq->in, rq->inpages, rq->pageofs_in, + rq->inputsize,UINT_MAX ,GFP_KERNEL ); +if (ret <0 ) + goto failed_src_alloc; + + ret =sg_alloc_table_from_pages_segment (&st_dst, + rq->out, rq->outpages, rq->pageofs_out, + rq->outputsize,UINT_MAX ,GFP_KERNEL ); +if (ret <0 ) + goto failed_dst_alloc; + +acomp_request_set_params (req, st_src.sgl, + st_dst.sgl, rq->inputsize, rq->outputsize); + +crypto_init_wait (&wait); +acomp_request_set_callback (req,CRYPTO_TFM_REQ_MAY_BACKLOG , + crypto_req_done, &wait); + + ret =crypto_wait_req (crypto_acomp_decompress (req), &wait); +if (ret <0 ) { +erofs_err (rq->sb,"failed to decompress %d in[%u, %u] out[%u]" , + ret, rq->inputsize, rq->pageofs_in, rq->outputsize); + ret = -EIO ; + }else + ret =0 ; + +sg_free_table (&st_dst); +failed_dst_alloc: +sg_free_table (&st_src); +failed_src_alloc: +acomp_request_free (req); +return ret; +} + +int z_erofs_crypto_decompress (struct z_erofs_decompress_req *rq, +struct crypto_acomp *erofs_tfm,struct page **pgpl) +{ +int i; + +for (i =0 ; i < rq->outpages; i++) { +struct page *const page = rq->out[i]; +struct page *victim; + +if (!page) { + victim =__erofs_allocpage (pgpl, rq->gfp, true); +if (!victim) +return -ENOMEM ; +set_page_private (victim,Z_EROFS_SHORTLIVED_PAGE ); + rq->out[i] = victim; + } + } + +return z_erofs_crypto_decompress_mem (rq, erofs_tfm); +} + +struct crypto_acomp *z_erofs_crypto_get_engine (int type) +{ +int i =0 ; + +while (z_erofs_crypto[type][i].crypto_name) { +if (z_erofs_crypto[type][i].enabled) +return z_erofs_crypto[type][i].erofs_tfm; + i++; + }
fs/erofs/decompressor_crypto.c line 104
Quoted 10 lines
fs/erofs/decompressor_crypto.c new file +10
-0+return NULL ; +} + +static int z_erofs_crypto_get_compress_type (const char *name) +{ +int i, j; + +for (i =0 ; i <Z_EROFS_COMPRESSION_MAX ; i++) { + j =0 ; +while (z_erofs_crypto[i][j].crypto_name) {
Is it possible to use z_erofs_crypto_engine itself instead of crypto_name to check if there is a supported compression engine, like:
#define Z_EROFS_CRYPTO_ENGINE_MAX 1
struct z_erofs_crypto_engine *z_erofs_crypto[Z_EROFS_COMPRESSION_MAX][Z_EROFS_CRYPTO_ENGINE_MAX] = {
[Z_EROFS_COMPRESSION_LZ4] = { },
[Z_EROFS_COMPRESSION_LZMA] = { },
[Z_EROFS_COMPRESSION_DEFLATE] = {
&(struct z_erofs_crypto_engine) {
.crypto_name = "qat_deflate",
.enabled = false,
.erofs_tfm = NULL,
}
},
[Z_EROFS_COMPRESSION_ZSTD] = {
},
};for (i = 0; z_erofs_crypto[type][i]; ++i) {
...
}Quoted 11 lines
fs/erofs/decompressor_crypto.c new file +11
-0+if (!strcmp (name, z_erofs_crypto[i][j].crypto_name)) +return i; + + j++; + } + } +return -EINVAL ; +} + +int z_erofs_crypto_enable_engine (const char *name) +{
fs/erofs/decompressor_crypto.c line 125
Quoted 10 lines
fs/erofs/decompressor_crypto.c new file +10
-0+int i =0 , type; + + type =z_erofs_crypto_get_compress_type (name); +if (type <0 ) +return -EINVAL ; + +while (z_erofs_crypto[type][i].crypto_name) { +if (!strcmp (z_erofs_crypto[type][i].crypto_name, name)) { +if (z_erofs_crypto[type][i].enabled) +break ;
Maybe an error is needed to inform duplicate enable.
fs/erofs/decompressor_crypto.c line 137
Quoted 12 lines
fs/erofs/decompressor_crypto.c new file +12
-0+ + z_erofs_crypto[type][i].erofs_tfm = +crypto_alloc_acomp (z_erofs_crypto[type][i].crypto_name,0 ,0 ); +if (IS_ERR (z_erofs_crypto[type][i].erofs_tfm)) { + z_erofs_crypto[type][i].erofs_tfm =NULL ; +return -ENXIO ; + } + z_erofs_crypto[type][i].enabled = true; + }else if (z_erofs_crypto[type][i].enabled) { +if (z_erofs_crypto[type][i].erofs_tfm) +crypto_free_acomp (z_erofs_crypto[type][i].erofs_tfm); + z_erofs_crypto[type][i].enabled = false;
This may be concurrent with z_erofs_deflate_decompress, so it should be disabled first and may require a memory barrier.
Quoted 79 lines
fs/erofs/decompressor_crypto.c new file +62
-0+ } + i++; + } +return 0 ; +} + +void z_erofs_crypto_disable_engine (void ) +{ +int i =0 , type; + +for (type =0 ; type <Z_EROFS_COMPRESSION_MAX ; type++) { + i =0 ; +while (z_erofs_crypto[type][i].crypto_name) { +if (z_erofs_crypto[type][i].enabled && + z_erofs_crypto[type][i].erofs_tfm) { +crypto_free_acomp (z_erofs_crypto[type][i].erofs_tfm); + z_erofs_crypto[type][i].erofs_tfm =NULL ; + z_erofs_crypto[type][i].enabled = false; + } + i++; + } + } +} + +int z_erofs_crypto_engine_format (char *buf) +{ +int type, i, len =0 ; + +for (type =0 ; type <Z_EROFS_COMPRESSION_MAX ; type++) { + i =0 ; +while (z_erofs_crypto[type][i].crypto_name) { +if (z_erofs_crypto[type][i].enabled) + len +=scnprintf (buf + len,PATH_MAX - len,"%s " , + z_erofs_crypto[type][i].crypto_name); + i++; + } + } +return len; +} + +struct z_erofs_crypto_engine z_erofs_crypto[Z_EROFS_COMPRESSION_MAX ][2 ] = { + [Z_EROFS_COMPRESSION_LZ4 ] = { + (struct z_erofs_crypto_engine ) {NULL }, + (struct z_erofs_crypto_engine ) {NULL }, + }, + [Z_EROFS_COMPRESSION_LZMA ] = { + (struct z_erofs_crypto_engine ) {NULL }, + (struct z_erofs_crypto_engine ) {NULL }, + }, + [Z_EROFS_COMPRESSION_DEFLATE ] = { + (struct z_erofs_crypto_engine ) { + .crypto_name ="qat_deflate" , + .enabled = false, + .erofs_tfm =NULL , + }, + (struct z_erofs_crypto_engine ) {NULL }, + }, + [Z_EROFS_COMPRESSION_ZSTD ] = { + (struct z_erofs_crypto_engine ) {NULL }, + (struct z_erofs_crypto_engine ) {NULL }, + }, +};fs/erofs/decompressor_deflate.c +1
-1@@ -97,7 +97,7 @@ static int z_erofs_load_deflate_config(struct super_block *sb,return -ENOMEM ; } -static int z_erofs_deflate_decompress (struct z_erofs_decompress_req *rq, +static int __z_erofs_deflate_decompress (struct z_erofs_decompress_req *rq,struct page **pgpl) {struct super_block *sb = rq->sb;@@ -178,6 +178,20 @@ static int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,return err; }
fs/erofs/decompressor_deflate.c static int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq, · line 190
Quoted 10 lines
fs/erofs/decompressor_deflate.c +10
-0+static int z_erofs_deflate_decompress (struct z_erofs_decompress_req *rq, +struct page **pgpl) +{ +#ifdef CONFIG_EROFS_FS_ZIP_CRYPTO +struct crypto_acomp *erofs_tfm =NULL ; + + erofs_tfm =z_erofs_crypto_get_engine (Z_EROFS_COMPRESSION_DEFLATE ); +if (erofs_tfm && !rq->partial_decoding) +return z_erofs_crypto_decompress (rq, erofs_tfm, pgpl); +else
Unnecessary else.
Quoted 81 lines
fs/erofs/decompressor_deflate.c +4
-0+#endif +return __z_erofs_deflate_decompress (rq, pgpl); +} +const struct z_erofs_decompressor z_erofs_deflate_decomp = { .config = z_erofs_load_deflate_config, .decompress = z_erofs_deflate_decompress,fs/erofs/sysfs.c +25
-0@@ -7,12 +7,14 @@#include <linux/kobject.h> #include "internal.h" +#include "compress.h" enum { attr_feature, attr_drop_caches, attr_pointer_ui, attr_pointer_bool, + attr_crypto, };enum {@@ -60,6 +62,9 @@ static struct erofs_attr erofs_attr_##_name = { \EROFS_ATTR_RW_UI (sync_decompress, erofs_mount_opts);EROFS_ATTR_FUNC (drop_caches,0200 );#endif +#ifdef CONFIG_EROFS_FS_ZIP_CRYPTO +EROFS_ATTR_FUNC (crypto,0644 ); +#endif static struct attribute *erofs_attrs[] = {#ifdef CONFIG_EROFS_FS_ZIP @@ -95,6 +100,9 @@ static struct attribute *erofs_feat_attrs[] = {ATTR_LIST (fragments),ATTR_LIST (dedupe), ATTR_LIST(48bit), +#ifdef CONFIG_EROFS_FS_ZIP_CRYPTO +ATTR_LIST (crypto), +#endifNULL , };ATTRIBUTE_GROUPS (erofs_feat);@@ -128,6 +136,10 @@ static ssize_t erofs_attr_show(struct kobject *kobj,if (!ptr)return 0 ;return sysfs_emit (buf,"%d\n" , *(bool *)ptr); +#ifdef CONFIG_EROFS_FS_ZIP_CRYPTO +case attr_crypto: +return z_erofs_crypto_engine_format (buf); +#endif }return 0 ; }@@ -141,6 +153,10 @@ static ssize_t erofs_attr_store(struct kobject *kobj, struct attribute *attr,unsigned char *ptr =__struct_ptr (sbi, a->struct_type, a->offset);unsigned long t;int ret; +#ifdef CONFIG_EROFS_FS_ZIP_CRYPTO +char *crypto_name; +size_t sz; +#endif switch (a->attr_id) {case attr_pointer_ui:@@ -181,6 +197,26 @@ static ssize_t erofs_attr_store(struct kobject *kobj, struct attribute *attr,if (t &1 )invalidate_mapping_pages (MNGD_MAPPING (sbi),0 ,-1 );return len; +#endif +#ifdef CONFIG_EROFS_FS_ZIP_CRYPTO +case attr_crypto: + buf =skip_spaces (buf); + sz =strlen (buf); + crypto_name =kstrdup (buf,GFP_KERNEL ); +if (!crypto_name) +return -ENOMEM ; +
fs/erofs/sysfs.c static ssize_t erofs_attr_store(struct kobject *kobj, struct attribute *attr, · line 218
Quoted 10 lines
fs/erofs/sysfs.c +10
-0+/* ignore trailing newline */ +if (sz >0 && crypto_name[sz -1 ] =='\n' ) + crypto_name[sz -1 ] =0x00 ; + +if (strlen (crypto_name) >0 ) { + ret =z_erofs_crypto_enable_engine (crypto_name); +if (ret <0 ) +return ret; + }else +z_erofs_crypto_disable_engine ();
Is it possible to support disable a single engine?
Thanks,
Jianan
Quoted 8 lines
fs/erofs/sysfs.c +1
-1+return len;#endif }return 0 ; --2.31.1
Quoted 431 lines · Bo Liu
This patch introdueces the use of the Intel QAT to decompress compressed data in the EROFS filesystem, aiming to improve the decompression speed of compressed datea.
We created a 285MiB compressed file and then used the following command to create EROFS images with different cluster size.
# mkfs.erofs -zdeflate,level=9 -C16384fio command was used to test random read and small random read(~5%) and sequential read performance.
# fio -filename=testfile -bs=4k -rw=read -name=job1 # fio -filename=testfile -bs=4k -rw=randread -name=job1 # fio -filename=testfile -bs=4k -rw=randread --io_size=14m -name=job1Here are some performance numbers for reference:
Processors: Intel(R) Xeon(R) 6766E(144 core) Memory: 521 GiB|-----------------------------------------------------------------------------| | | Cluster size | sequential read | randread | small randread(5%) | |-----------|--------------|-----------------|-----------|--------------------| | Intel QAT | 4096 | 538 MiB/s | 112 MiB/s | 20.76 MiB/s | | Intel QAT | 16384 | 699 MiB/s | 158 MiB/s | 21.02 MiB/s | | Intel QAT | 65536 | 917 MiB/s | 278 MiB/s | 20.90 MiB/s | | Intel QAT | 131072 | 1056 MiB/s | 351 MiB/s | 23.36 MiB/s | | Intel QAT | 262144 | 1145 MiB/s | 431 MiB/s | 26.66 MiB/s | | deflate | 4096 | 499 MiB/s | 108 MiB/s | 21.50 MiB/s | | deflate | 16384 | 422 MiB/s | 125 MiB/s | 18.94 MiB/s | | deflate | 65536 | 452 MiB/s | 159 MiB/s | 13.02 MiB/s | | deflate | 131072 | 452 MiB/s | 177 MiB/s | 11.44 MiB/s | | deflate | 262144 | 466 MiB/s | 194 MiB/s | 10.60 MiB/s |Signed-off-by Bo Liu <[email protected]>---
v1: https://lore.kernel.org/linux-erofs/[email protected]/
v2: https://lore.kernel.org/linux-erofs/[email protected]/T/#tChanges since v2:
- Add a new kernel config optionCONFIG_EROFS_FS_ZIP_CRYPTO.
- Modify the sysfs interface to merge enable and disable into
a single entry point, and add a read function to view the current state.
- Optimize the relevant code,use thesg_alloc_table_from_pages_segmentinterface.fs/erofs/Kconfig | 14 +++ fs/erofs/Makefile | 1 + fs/erofs/compress.h | 14 +++ fs/erofs/decompressor_crypto.c | 199 ++++++++++++++++++++++++++++++++ fs/erofs/decompressor_deflate.c | 16 ++- fs/erofs/sysfs.c | 36 ++++++ 6 files changed, 279 insertions(+), 1 deletion(-)create mode 100644
fs/erofs/decompressor_crypto.cfs/erofs/Kconfig +14
-0@@ -144,6 +144,20 @@ config EROFS_FS_ZIP_ZSTD If unsure, say N. +config EROFS_FS_ZIP_CRYPTO + bool "EROFS hardware decompression support (crypto interface)" + depends on EROFS_FS_ZIP + help + Saying Y here includes support for reading EROFS file systems + containing crypto compressed data. It gives better decompression + speed than the software-implemented compression, and it costs + lower CPU overhead. + + Crypto support is an experimental feature for now and so most + file systems will be readable without selecting this option. + + If unsure, say N. + config EROFS_FS_ONDEMAND bool "EROFS fscache-based on-demand read support (deprecated)" depends on EROFS_FSfs/erofs/Makefile +1
-0@@ -7,5 +7,6 @@ erofs-$(CONFIG_EROFS_FS_ZIP) += decompressor.o zmap.o zdata.o zutil.o erofs-$(CONFIG_EROFS_FS_ZIP_LZMA) += decompressor_lzma.o erofs-$(CONFIG_EROFS_FS_ZIP_DEFLATE) += decompressor_deflate.o erofs-$(CONFIG_EROFS_FS_ZIP_ZSTD) += decompressor_zstd.o +erofs-$(CONFIG_EROFS_FS_ZIP_CRYPTO) += decompressor_crypto.o erofs-$(CONFIG_EROFS_FS_BACKED_BY_FILE) += fileio.o erofs-$(CONFIG_EROFS_FS_ONDEMAND) += fscache.ofs/erofs/compress.h +14
-0@@ -70,10 +70,24 @@ struct z_erofs_stream_dctx {bool bounced;/* is the bounce buffer used now? */ }; +struct z_erofs_crypto_engine { +char *crypto_name; +bool enabled; +struct crypto_acomp *erofs_tfm; +}; + +extern struct z_erofs_crypto_engine z_erofs_crypto[Z_EROFS_COMPRESSION_MAX ][2 ]; +int z_erofs_stream_switch_bufs (struct z_erofs_stream_dctx *dctx,void **dst,void **src,struct page **pgpl);int z_erofs_fixup_insize (struct z_erofs_decompress_req *rq,const char *padbuf,unsigned int padbufsize);int __init z_erofs_init_decompressor (void );void z_erofs_exit_decompressor (void ); +int z_erofs_crypto_decompress (struct z_erofs_decompress_req *rq, +struct crypto_acomp *erofs_tfm,struct page **pgpl); +struct crypto_acomp *z_erofs_crypto_get_engine (int type); +int z_erofs_crypto_enable_engine (const char *name); +void z_erofs_crypto_disable_engine (void ); +int z_erofs_crypto_engine_format (char *buf);#endif fs/erofs/decompressor_crypto.c new file +199
-0@@ -0,0 +1,199 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#include <linux/scatterlist.h> +#include <crypto/acompress.h> + +#include "compress.h" + +static int z_erofs_crypto_decompress_mem (struct z_erofs_decompress_req *rq, +struct crypto_acomp *erofs_tfm) +{ +struct sg_table st_src, st_dst; +struct acomp_req *req; +struct crypto_wait wait; +u8 *headpage; +int ret; + + headpage =kmap_local_page (*rq->in); + ret =z_erofs_fixup_insize (rq, headpage + rq->pageofs_in, + min_t(unsigned int, rq->inputsize, + rq->sb->s_blocksize - rq->pageofs_in)); +kunmap_local (headpage); +if (ret) +return ret; + + req =acomp_request_alloc (erofs_tfm); +if (!req) { +erofs_err (rq->sb,"failed to alloc decompress request" ); +return -ENOMEM ; + } + + ret =sg_alloc_table_from_pages_segment (&st_src, + rq->in, rq->inpages, rq->pageofs_in, + rq->inputsize,UINT_MAX ,GFP_KERNEL ); +if (ret <0 ) + goto failed_src_alloc; + + ret =sg_alloc_table_from_pages_segment (&st_dst, + rq->out, rq->outpages, rq->pageofs_out, + rq->outputsize,UINT_MAX ,GFP_KERNEL ); +if (ret <0 ) + goto failed_dst_alloc; + +acomp_request_set_params (req, st_src.sgl, + st_dst.sgl, rq->inputsize, rq->outputsize); + +crypto_init_wait (&wait); +acomp_request_set_callback (req,CRYPTO_TFM_REQ_MAY_BACKLOG , + crypto_req_done, &wait); + + ret =crypto_wait_req (crypto_acomp_decompress (req), &wait); +if (ret <0 ) { +erofs_err (rq->sb,"failed to decompress %d in[%u, %u] out[%u]" , + ret, rq->inputsize, rq->pageofs_in, rq->outputsize); + ret = -EIO ; + }else + ret =0 ; + +sg_free_table (&st_dst); +failed_dst_alloc: +sg_free_table (&st_src); +failed_src_alloc: +acomp_request_free (req); +return ret; +} + +int z_erofs_crypto_decompress (struct z_erofs_decompress_req *rq, +struct crypto_acomp *erofs_tfm,struct page **pgpl) +{ +int i; + +for (i =0 ; i < rq->outpages; i++) { +struct page *const page = rq->out[i]; +struct page *victim; + +if (!page) { + victim =__erofs_allocpage (pgpl, rq->gfp, true); +if (!victim) +return -ENOMEM ; +set_page_private (victim,Z_EROFS_SHORTLIVED_PAGE ); + rq->out[i] = victim; + } + } + +return z_erofs_crypto_decompress_mem (rq, erofs_tfm); +} + +struct crypto_acomp *z_erofs_crypto_get_engine (int type) +{ +int i =0 ; + +while (z_erofs_crypto[type][i].crypto_name) { +if (z_erofs_crypto[type][i].enabled) +return z_erofs_crypto[type][i].erofs_tfm; + i++; + } +return NULL ; +} + +static int z_erofs_crypto_get_compress_type (const char *name) +{ +int i, j; + +for (i =0 ; i <Z_EROFS_COMPRESSION_MAX ; i++) { + j =0 ; +while (z_erofs_crypto[i][j].crypto_name) { +if (!strcmp (name, z_erofs_crypto[i][j].crypto_name)) +return i; + + j++; + } + } +return -EINVAL ; +} + +int z_erofs_crypto_enable_engine (const char *name) +{ +int i =0 , type; + + type =z_erofs_crypto_get_compress_type (name); +if (type <0 ) +return -EINVAL ; + +while (z_erofs_crypto[type][i].crypto_name) { +if (!strcmp (z_erofs_crypto[type][i].crypto_name, name)) { +if (z_erofs_crypto[type][i].enabled) +break ; + + z_erofs_crypto[type][i].erofs_tfm = +crypto_alloc_acomp (z_erofs_crypto[type][i].crypto_name,0 ,0 ); +if (IS_ERR (z_erofs_crypto[type][i].erofs_tfm)) { + z_erofs_crypto[type][i].erofs_tfm =NULL ; +return -ENXIO ; + } + z_erofs_crypto[type][i].enabled = true; + }else if (z_erofs_crypto[type][i].enabled) { +if (z_erofs_crypto[type][i].erofs_tfm) +crypto_free_acomp (z_erofs_crypto[type][i].erofs_tfm); + z_erofs_crypto[type][i].enabled = false; + } + i++; + } +return 0 ; +} + +void z_erofs_crypto_disable_engine (void ) +{ +int i =0 , type; + +for (type =0 ; type <Z_EROFS_COMPRESSION_MAX ; type++) { + i =0 ; +while (z_erofs_crypto[type][i].crypto_name) { +if (z_erofs_crypto[type][i].enabled && + z_erofs_crypto[type][i].erofs_tfm) { +crypto_free_acomp (z_erofs_crypto[type][i].erofs_tfm); + z_erofs_crypto[type][i].erofs_tfm =NULL ; + z_erofs_crypto[type][i].enabled = false; + } + i++; + } + } +} + +int z_erofs_crypto_engine_format (char *buf) +{ +int type, i, len =0 ; + +for (type =0 ; type <Z_EROFS_COMPRESSION_MAX ; type++) { + i =0 ; +while (z_erofs_crypto[type][i].crypto_name) { +if (z_erofs_crypto[type][i].enabled) + len +=scnprintf (buf + len,PATH_MAX - len,"%s " , + z_erofs_crypto[type][i].crypto_name); + i++; + } + } +return len; +} + +struct z_erofs_crypto_engine z_erofs_crypto[Z_EROFS_COMPRESSION_MAX ][2 ] = { + [Z_EROFS_COMPRESSION_LZ4 ] = { + (struct z_erofs_crypto_engine ) {NULL }, + (struct z_erofs_crypto_engine ) {NULL }, + }, + [Z_EROFS_COMPRESSION_LZMA ] = { + (struct z_erofs_crypto_engine ) {NULL }, + (struct z_erofs_crypto_engine ) {NULL }, + }, + [Z_EROFS_COMPRESSION_DEFLATE ] = { + (struct z_erofs_crypto_engine ) { + .crypto_name ="qat_deflate" , + .enabled = false, + .erofs_tfm =NULL , + }, + (struct z_erofs_crypto_engine ) {NULL }, + }, + [Z_EROFS_COMPRESSION_ZSTD ] = { + (struct z_erofs_crypto_engine ) {NULL }, + (struct z_erofs_crypto_engine ) {NULL }, + }, +};fs/erofs/decompressor_deflate.c +15
-1@@ -97,7 +97,7 @@ static int z_erofs_load_deflate_config(struct super_block *sb,return -ENOMEM ; } -static int z_erofs_deflate_decompress (struct z_erofs_decompress_req *rq, +static int __z_erofs_deflate_decompress (struct z_erofs_decompress_req *rq,struct page **pgpl) {struct super_block *sb = rq->sb;@@ -178,6 +178,20 @@ static int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,return err; } +static int z_erofs_deflate_decompress (struct z_erofs_decompress_req *rq, +struct page **pgpl) +{ +#ifdef CONFIG_EROFS_FS_ZIP_CRYPTO +struct crypto_acomp *erofs_tfm =NULL ; + + erofs_tfm =z_erofs_crypto_get_engine (Z_EROFS_COMPRESSION_DEFLATE ); +if (erofs_tfm && !rq->partial_decoding) +return z_erofs_crypto_decompress (rq, erofs_tfm, pgpl); + else +#endif +return __z_erofs_deflate_decompress (rq, pgpl); +} +const struct z_erofs_decompressor z_erofs_deflate_decomp = { .config = z_erofs_load_deflate_config, .decompress = z_erofs_deflate_decompress,fs/erofs/sysfs.c +25
-0@@ -7,12 +7,14 @@#include <linux/kobject.h> #include "internal.h" +#include "compress.h" enum { attr_feature, attr_drop_caches, attr_pointer_ui, attr_pointer_bool, + attr_crypto, };enum {@@ -60,6 +62,9 @@ static struct erofs_attr erofs_attr_##_name = { \EROFS_ATTR_RW_UI (sync_decompress, erofs_mount_opts);EROFS_ATTR_FUNC (drop_caches,0200 );#endif +#ifdef CONFIG_EROFS_FS_ZIP_CRYPTO +EROFS_ATTR_FUNC (crypto,0644 ); +#endif static struct attribute *erofs_attrs[] = {#ifdef CONFIG_EROFS_FS_ZIP @@ -95,6 +100,9 @@ static struct attribute *erofs_feat_attrs[] = {ATTR_LIST (fragments),ATTR_LIST (dedupe), ATTR_LIST(48bit), +#ifdef CONFIG_EROFS_FS_ZIP_CRYPTO +ATTR_LIST (crypto), +#endifNULL , };ATTRIBUTE_GROUPS (erofs_feat);@@ -128,6 +136,10 @@ static ssize_t erofs_attr_show(struct kobject *kobj,if (!ptr)return 0 ;return sysfs_emit (buf,"%d\n" , *(bool *)ptr); +#ifdef CONFIG_EROFS_FS_ZIP_CRYPTO +case attr_crypto: +return z_erofs_crypto_engine_format (buf); +#endif }return 0 ; }@@ -141,6 +153,10 @@ static ssize_t erofs_attr_store(struct kobject *kobj, struct attribute *attr,unsigned char *ptr =__struct_ptr (sbi, a->struct_type, a->offset);unsigned long t;int ret; +#ifdef CONFIG_EROFS_FS_ZIP_CRYPTO +char *crypto_name; +size_t sz; +#endif switch (a->attr_id) {case attr_pointer_ui:@@ -181,6 +197,26 @@ static ssize_t erofs_attr_store(struct kobject *kobj, struct attribute *attr,if (t &1 )invalidate_mapping_pages (MNGD_MAPPING (sbi),0 ,-1 );return len; +#endif +#ifdef CONFIG_EROFS_FS_ZIP_CRYPTO +case attr_crypto: + buf =skip_spaces (buf); + sz =strlen (buf); + crypto_name =kstrdup (buf,GFP_KERNEL ); +if (!crypto_name) +return -ENOMEM ; +
fs/erofs/sysfs.c static ssize_t erofs_attr_store(struct kobject *kobj, struct attribute *attr, · line 218
Quoted 10 lines
fs/erofs/sysfs.c +10
-0+/* ignore trailing newline */ +if (sz >0 && crypto_name[sz -1 ] =='\n' ) + crypto_name[sz -1 ] =0x00 ; + +if (strlen (crypto_name) >0 ) { + ret =z_erofs_crypto_enable_engine (crypto_name); +if (ret <0 ) +return ret; + }else +z_erofs_crypto_disable_engine ();
Need kfree crypto_name after using it.
Thanks,
Hongbo
Quoted 4 lines
fs/erofs/sysfs.c +1
-0+return len;#endif }return 0 ;
PATCH v4 1/1 erofs: support DEFLATE decompression by using Intel QAT
In reply to Bo LiuFrom: Bo Liu <[email protected]>
This patch introduces the use of the Intel QAT to offload data compression in the EROFS filesystem, aiming to improve the decompression performance.
A 285MiB dataset is used with the following command to create EROFS images with different cluster sizes:
$ mkfs.erofs -zdeflate,level=9 -C16384
Fio is used to test the following read patterns:
# fio -filename=testfile -bs=4k -rw=read -name=job1
# fio -filename=testfile -bs=4k -rw=randread -name=job1
# fio -filename=testfile -bs=4k -rw=randread --io_size=14m -name=job1Here are some performance numbers for reference:
Processors: Intel(R) Xeon(R) 6766E(144 core) Memory: 521 GiB
|-----------------------------------------------------------------------------| | | Cluster size | sequential read | randread | small randread(5%) | |-----------|--------------|-----------------|-----------|--------------------| | Intel QAT | 4096 | 538 MiB/s | 112 MiB/s | 20.76 MiB/s | | Intel QAT | 16384 | 699 MiB/s | 158 MiB/s | 21.02 MiB/s | | Intel QAT | 65536 | 917 MiB/s | 278 MiB/s | 20.90 MiB/s | | Intel QAT | 131072 | 1056 MiB/s | 351 MiB/s | 23.36 MiB/s | | Intel QAT | 262144 | 1145 MiB/s | 431 MiB/s | 26.66 MiB/s | | deflate | 4096 | 499 MiB/s | 108 MiB/s | 21.50 MiB/s | | deflate | 16384 | 422 MiB/s | 125 MiB/s | 18.94 MiB/s | | deflate | 65536 | 452 MiB/s | 159 MiB/s | 13.02 MiB/s | | deflate | 131072 | 452 MiB/s | 177 MiB/s | 11.44 MiB/s | | deflate | 262144 | 466 MiB/s | 194 MiB/s | 10.60 MiB/s |
---
Hi Bo,
Please test/refine this version and complete sysfs documentation.
Thanks,
Gao Xiang
fs/erofs/Kconfig | 14 +++ fs/erofs/Makefile | 1 + fs/erofs/compress.h | 10 ++ fs/erofs/decompressor_crypto.c | 184 ++++++++++++++++++++++++++++++++ fs/erofs/decompressor_deflate.c | 20 +++- fs/erofs/sysfs.c | 35 +++++- fs/erofs/zdata.c | 1 + 7 files changed, 260 insertions(+), 5 deletions(-) create mode 100644 fs/erofs/decompressor_crypto.c
fs/erofs/Kconfig +14 -0
@@ -144,6 +144,20 @@ config EROFS_FS_ZIP_ZSTD If unsure, say N. +config EROFS_FS_ZIP_ACCEL + bool "EROFS hardware decompression support" + depends on EROFS_FS_ZIP + help + Saying Y here includes hardware accelerator support for reading + EROFS file systems containing compressed data. It gives better + decompression speed than the software-implemented decompression, and + it costs lower CPU overhead. + + Hardware accelerator support is an experimental feature for now and + file systems are still readable without selecting this option. + + If unsure, say N. + config EROFS_FS_ONDEMAND bool "EROFS fscache-based on-demand read support (deprecated)" depends on EROFS_FS
fs/erofs/Makefile +1 -0
@@ -7,5 +7,6 @@ erofs-$(CONFIG_EROFS_FS_ZIP) += decompressor.o zmap.o zdata.o zutil.o erofs-$(CONFIG_EROFS_FS_ZIP_LZMA) += decompressor_lzma.o erofs-$(CONFIG_EROFS_FS_ZIP_DEFLATE) += decompressor_deflate.o erofs-$(CONFIG_EROFS_FS_ZIP_ZSTD) += decompressor_zstd.o +erofs-$(CONFIG_EROFS_FS_ZIP_ACCEL) += decompressor_crypto.o erofs-$(CONFIG_EROFS_FS_BACKED_BY_FILE) += fileio.o erofs-$(CONFIG_EROFS_FS_ONDEMAND) += fscache.o
fs/erofs/compress.h +10 -0
@@ -76,4 +76,14 @@ int z_erofs_fixup_insize(struct z_erofs_decompress_req *rq, const char *padbuf, unsigned int padbufsize);int __init z_erofs_init_decompressor (void );void z_erofs_exit_decompressor (void ); +int z_erofs_crypto_decompress (struct z_erofs_decompress_req *rq, +struct page **pgpl); +int z_erofs_crypto_enable_engine (const char *name,int len); +#ifdef CONFIG_EROFS_FS_ZIP_ACCEL +void z_erofs_crypto_disable_all_engines (void ); +int z_erofs_crypto_show_engines (char *buf,int size,char sep); +#else +static inline void z_erofs_crypto_disable_all_engines (void ) {} +static inline int z_erofs_crypto_show_engines (char *buf,int size,char sep) {} +#endif #endif
fs/erofs/decompressor_crypto.c new file +184 -0
184 lines not on this page · raw message
fs/erofs/decompressor_deflate.c +18 -2
@@ -97,8 +97,8 @@ static int z_erofs_load_deflate_config(struct super_block *sb,return -ENOMEM ; } -static int z_erofs_deflate_decompress (struct z_erofs_decompress_req *rq, -struct page **pgpl) +static int __z_erofs_deflate_decompress (struct z_erofs_decompress_req *rq, +struct page **pgpl) {struct super_block *sb = rq->sb;struct z_erofs_stream_dctx dctx = { .rq = rq, .no =-1 , .ni =0 };
@@ -178,6 +178,22 @@ static int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,return err; } +static int z_erofs_deflate_decompress (struct z_erofs_decompress_req *rq, +struct page **pgpl) +{ +#ifdef CONFIG_EROFS_FS_ZIP_ACCEL +int err; + +if (!rq->partial_decoding) { + err =z_erofs_crypto_decompress (rq, pgpl); +if (err != -EOPNOTSUPP ) +return err; + + } +#endif +return __z_erofs_deflate_decompress (rq, pgpl); +} +const struct z_erofs_decompressor z_erofs_deflate_decomp = { .config = z_erofs_load_deflate_config, .decompress = z_erofs_deflate_decompress,
fs/erofs/sysfs.c +32 -3
@@ -7,12 +7,14 @@#include <linux/kobject.h> #include "internal.h" +#include "compress.h" enum { attr_feature, attr_drop_caches, attr_pointer_ui, attr_pointer_bool, + attr_accel, };enum {
@@ -60,14 +62,25 @@ static struct erofs_attr erofs_attr_##_name = { \EROFS_ATTR_RW_UI (sync_decompress, erofs_mount_opts);EROFS_ATTR_FUNC (drop_caches,0200 );#endif +#ifdef CONFIG_EROFS_FS_ZIP_ACCEL +EROFS_ATTR_FUNC (accel,0644 ); +#endif -static struct attribute *erofs_attrs[] = { +static struct attribute *erofs_sb_attrs[] = { #ifdef CONFIG_EROFS_FS_ZIP ATTR_LIST(sync_decompress), ATTR_LIST(drop_caches), #endif NULL, }; +ATTRIBUTE_GROUPS(erofs_sb); + +static struct attribute *erofs_attrs[] = { +#ifdef CONFIG_EROFS_FS_ZIP_ACCEL + ATTR_LIST(accel), +#endif + NULL, +}; ATTRIBUTE_GROUPS(erofs); /* Features this copy of erofs supports */
@@ -128,12 +141,14 @@ static ssize_t erofs_attr_show(struct kobject *kobj,if (!ptr)return 0 ;return sysfs_emit (buf,"%d\n" , *(bool *)ptr); +case attr_accel: +return z_erofs_crypto_show_engines (buf,PAGE_SIZE ,'\n' ); }return 0 ; }static ssize_t erofs_attr_store (struct kobject *kobj,struct attribute *attr, -const char *buf,size_t len) +const char *buf,size_t len) { struct erofs_sb_info *sbi = container_of(kobj, struct erofs_sb_info, s_kobj);
@@ -181,6 +196,19 @@ static ssize_t erofs_attr_store(struct kobject *kobj, struct attribute *attr,if (t &1 )invalidate_mapping_pages (MNGD_MAPPING (sbi),0 ,-1 );return len; +#endif +#ifdef CONFIG_EROFS_FS_ZIP_ACCEL +case attr_accel: + buf =skip_spaces (buf); +z_erofs_crypto_disable_all_engines (); +while (*buf) { + t =strcspn (buf,"\n" ); + ret =z_erofs_crypto_enable_engine (buf, t); +if (ret <0 ) +return ret; + buf += buf[t] =='\n' ? t +1 : t; + } +return len;#endif }return 0 ;
@@ -199,12 +227,13 @@ static const struct sysfs_ops erofs_attr_ops = { };static const struct kobj_type erofs_sb_ktype = { - .default_groups = erofs_groups, + .default_groups = erofs_sb_groups, .sysfs_ops = &erofs_attr_ops, .release = erofs_sb_release, };static const struct kobj_type erofs_ktype = { + .default_groups = erofs_groups, .sysfs_ops = &erofs_attr_ops, };
fs/erofs/zdata.c +1 -0
@@ -441,6 +441,7 @@ void z_erofs_exit_subsystem(void)z_erofs_destroy_pcpu_workers ();destroy_workqueue (z_erofs_workqueue);z_erofs_destroy_pcluster_pool (); +z_erofs_crypto_disable_all_engines ();z_erofs_exit_decompressor (); }
Signature · 1 line
2.43.5
kernel test robot
build botRe: [PATCH UNTESTED v4] erofs: support DEFLATE decompression by using Intel QAT
kernel test robot noticed the following build warnings:
Hi Gao,
kernel test robot noticed the following build warnings:
[auto build test WARNING on xiang-erofs/dev-test]
[also build test WARNING on xiang-erofs/dev xiang-erofs/fixes linus/master v6.15-rc7 next-20250521] [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/Gao-Xiang/erofs-support-DEFLATE-decompression-by-using-Intel-QAT/20250521-180531 base: https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git dev-test patch link: https://lore.kernel.org/r/20250521100326.2867828-1-hsiangkao%40linux.alibaba.com patch subject: [PATCH UNTESTED v4] erofs: support DEFLATE decompression by using Intel QAT config: arc-randconfig-001-20250522 (https://download.01.org/0day-ci/archive/20250522/[email protected]/config) compiler: arc-linux-gcc (GCC) 15.1.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250522/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
In file included from fs/erofs/decompressor_zstd.c:3:
fs/erofs/compress.h: In function 'z_erofs_crypto_show_engines':
>> fs/erofs/compress.h:87:1: warning: no return statement in function returning non-void [-Wreturn-type]
87 | static inline int z_erofs_crypto_show_engines(char *buf, int size, char sep) {}
| ^~~~~~vim +87 fs/erofs/compress.h
72
73 int z_erofs_stream_switch_bufs(struct z_erofs_stream_dctx *dctx, void **dst,
74 void **src, struct page **pgpl);
75 int z_erofs_fixup_insize(struct z_erofs_decompress_req *rq, const char *padbuf,
76 unsigned int padbufsize);
77 int __init z_erofs_init_decompressor(void);
78 void z_erofs_exit_decompressor(void);
79 int z_erofs_crypto_decompress(struct z_erofs_decompress_req *rq,
80 struct page **pgpl);
81 int z_erofs_crypto_enable_engine(const char *name, int len);
82 #ifdef CONFIG_EROFS_FS_ZIP_ACCEL
83 void z_erofs_crypto_disable_all_engines(void);
84 int z_erofs_crypto_show_engines(char *buf, int size, char sep);
85 #else
86 static inline void z_erofs_crypto_disable_all_engines(void) {}
> 87 static inline int z_erofs_crypto_show_engines(char *buf, int size, char sep) {}Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki