Commit 966edfb0 authored by Gao Xiang's avatar Gao Xiang

erofs: rename some generic methods in decompressor

Previously, some LZ4 methods were named with `generic'. However, while
evaluating the effective LZMA approach, it seems they aren't quite
generic at all (e.g. no need preparing dstpages for most LZMA cases.)

Avoid such naming instead.

Link: https://lore.kernel.org/r/20211010213145.17462-7-xiang@kernel.orgAcked-by: default avatarChao Yu <chao@kernel.org>
Signed-off-by: default avatarGao Xiang <hsiangkao@linux.alibaba.com>
parent 0a434e0a
...@@ -17,13 +17,8 @@ ...@@ -17,13 +17,8 @@
#endif #endif
struct z_erofs_decompressor { struct z_erofs_decompressor {
/* int (*decompress)(struct z_erofs_decompress_req *rq,
* if destpages have sparsed pages, fill them with bounce pages. struct list_head *pagepool);
* it also check whether destpages indicate continuous physical memory.
*/
int (*prepare_destpages)(struct z_erofs_decompress_req *rq,
struct list_head *pagepool);
int (*decompress)(struct z_erofs_decompress_req *rq, u8 *out);
char *name; char *name;
}; };
...@@ -63,8 +58,12 @@ int z_erofs_load_lz4_config(struct super_block *sb, ...@@ -63,8 +58,12 @@ int z_erofs_load_lz4_config(struct super_block *sb,
return erofs_pcpubuf_growsize(sbi->lz4.max_pclusterblks); return erofs_pcpubuf_growsize(sbi->lz4.max_pclusterblks);
} }
static int z_erofs_lz4_prepare_destpages(struct z_erofs_decompress_req *rq, /*
struct list_head *pagepool) * Fill all gaps with bounce pages if it's a sparse page list. Also check if
* all physical pages are consecutive, which can be seen for moderate CR.
*/
static int z_erofs_lz4_prepare_dstpages(struct z_erofs_decompress_req *rq,
struct list_head *pagepool)
{ {
const unsigned int nr = const unsigned int nr =
PAGE_ALIGN(rq->pageofs_out + rq->outputsize) >> PAGE_SHIFT; PAGE_ALIGN(rq->pageofs_out + rq->outputsize) >> PAGE_SHIFT;
...@@ -119,7 +118,7 @@ static int z_erofs_lz4_prepare_destpages(struct z_erofs_decompress_req *rq, ...@@ -119,7 +118,7 @@ static int z_erofs_lz4_prepare_destpages(struct z_erofs_decompress_req *rq,
return kaddr ? 1 : 0; return kaddr ? 1 : 0;
} }
static void *z_erofs_handle_inplace_io(struct z_erofs_decompress_req *rq, static void *z_erofs_lz4_handle_inplace_io(struct z_erofs_decompress_req *rq,
void *inpage, unsigned int *inputmargin, int *maptype, void *inpage, unsigned int *inputmargin, int *maptype,
bool support_0padding) bool support_0padding)
{ {
...@@ -189,7 +188,8 @@ static void *z_erofs_handle_inplace_io(struct z_erofs_decompress_req *rq, ...@@ -189,7 +188,8 @@ static void *z_erofs_handle_inplace_io(struct z_erofs_decompress_req *rq,
return src; return src;
} }
static int z_erofs_lz4_decompress(struct z_erofs_decompress_req *rq, u8 *out) static int z_erofs_lz4_decompress_mem(struct z_erofs_decompress_req *rq,
u8 *out)
{ {
unsigned int inputmargin; unsigned int inputmargin;
u8 *headpage, *src; u8 *headpage, *src;
...@@ -216,8 +216,8 @@ static int z_erofs_lz4_decompress(struct z_erofs_decompress_req *rq, u8 *out) ...@@ -216,8 +216,8 @@ static int z_erofs_lz4_decompress(struct z_erofs_decompress_req *rq, u8 *out)
} }
rq->inputsize -= inputmargin; rq->inputsize -= inputmargin;
src = z_erofs_handle_inplace_io(rq, headpage, &inputmargin, &maptype, src = z_erofs_lz4_handle_inplace_io(rq, headpage, &inputmargin,
support_0padding); &maptype, support_0padding);
if (IS_ERR(src)) if (IS_ERR(src))
return PTR_ERR(src); return PTR_ERR(src);
...@@ -259,23 +259,11 @@ static int z_erofs_lz4_decompress(struct z_erofs_decompress_req *rq, u8 *out) ...@@ -259,23 +259,11 @@ static int z_erofs_lz4_decompress(struct z_erofs_decompress_req *rq, u8 *out)
return ret; return ret;
} }
static struct z_erofs_decompressor decompressors[] = { static int z_erofs_lz4_decompress(struct z_erofs_decompress_req *rq,
[Z_EROFS_COMPRESSION_SHIFTED] = { struct list_head *pagepool)
.name = "shifted"
},
[Z_EROFS_COMPRESSION_LZ4] = {
.prepare_destpages = z_erofs_lz4_prepare_destpages,
.decompress = z_erofs_lz4_decompress,
.name = "lz4"
},
};
static int z_erofs_decompress_generic(struct z_erofs_decompress_req *rq,
struct list_head *pagepool)
{ {
const unsigned int nrpages_out = const unsigned int nrpages_out =
PAGE_ALIGN(rq->pageofs_out + rq->outputsize) >> PAGE_SHIFT; PAGE_ALIGN(rq->pageofs_out + rq->outputsize) >> PAGE_SHIFT;
const struct z_erofs_decompressor *alg = decompressors + rq->alg;
unsigned int dst_maptype; unsigned int dst_maptype;
void *dst; void *dst;
int ret; int ret;
...@@ -289,7 +277,7 @@ static int z_erofs_decompress_generic(struct z_erofs_decompress_req *rq, ...@@ -289,7 +277,7 @@ static int z_erofs_decompress_generic(struct z_erofs_decompress_req *rq,
} }
/* general decoding path which can be used for all cases */ /* general decoding path which can be used for all cases */
ret = alg->prepare_destpages(rq, pagepool); ret = z_erofs_lz4_prepare_dstpages(rq, pagepool);
if (ret < 0) if (ret < 0)
return ret; return ret;
if (ret) { if (ret) {
...@@ -304,7 +292,7 @@ static int z_erofs_decompress_generic(struct z_erofs_decompress_req *rq, ...@@ -304,7 +292,7 @@ static int z_erofs_decompress_generic(struct z_erofs_decompress_req *rq,
dst_maptype = 2; dst_maptype = 2;
dstmap_out: dstmap_out:
ret = alg->decompress(rq, dst + rq->pageofs_out); ret = z_erofs_lz4_decompress_mem(rq, dst + rq->pageofs_out);
if (!dst_maptype) if (!dst_maptype)
kunmap_atomic(dst); kunmap_atomic(dst);
...@@ -313,7 +301,7 @@ static int z_erofs_decompress_generic(struct z_erofs_decompress_req *rq, ...@@ -313,7 +301,7 @@ static int z_erofs_decompress_generic(struct z_erofs_decompress_req *rq,
return ret; return ret;
} }
static int z_erofs_shifted_transform(const struct z_erofs_decompress_req *rq, static int z_erofs_shifted_transform(struct z_erofs_decompress_req *rq,
struct list_head *pagepool) struct list_head *pagepool)
{ {
const unsigned int nrpages_out = const unsigned int nrpages_out =
...@@ -352,10 +340,19 @@ static int z_erofs_shifted_transform(const struct z_erofs_decompress_req *rq, ...@@ -352,10 +340,19 @@ static int z_erofs_shifted_transform(const struct z_erofs_decompress_req *rq,
return 0; return 0;
} }
static struct z_erofs_decompressor decompressors[] = {
[Z_EROFS_COMPRESSION_SHIFTED] = {
.decompress = z_erofs_shifted_transform,
.name = "shifted"
},
[Z_EROFS_COMPRESSION_LZ4] = {
.decompress = z_erofs_lz4_decompress,
.name = "lz4"
},
};
int z_erofs_decompress(struct z_erofs_decompress_req *rq, int z_erofs_decompress(struct z_erofs_decompress_req *rq,
struct list_head *pagepool) struct list_head *pagepool)
{ {
if (rq->alg == Z_EROFS_COMPRESSION_SHIFTED) return decompressors[rq->alg].decompress(rq, pagepool);
return z_erofs_shifted_transform(rq, pagepool);
return z_erofs_decompress_generic(rq, pagepool);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment