2019-07-31 23:57:31 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2019-06-24 15:22:54 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 HUAWEI, Inc.
|
2020-07-13 21:09:44 +08:00
|
|
|
* https://www.huawei.com/
|
2019-06-24 15:22:54 +08:00
|
|
|
*/
|
|
|
|
#ifndef __EROFS_FS_COMPRESS_H
|
|
|
|
#define __EROFS_FS_COMPRESS_H
|
|
|
|
|
2019-06-24 15:22:55 +08:00
|
|
|
#include "internal.h"
|
|
|
|
|
|
|
|
struct z_erofs_decompress_req {
|
2019-06-24 15:22:56 +08:00
|
|
|
struct super_block *sb;
|
2019-06-24 15:22:55 +08:00
|
|
|
struct page **in, **out;
|
2021-12-28 13:46:01 +08:00
|
|
|
unsigned short pageofs_in, pageofs_out;
|
2019-06-24 15:22:55 +08:00
|
|
|
unsigned int inputsize, outputsize;
|
|
|
|
|
2024-01-26 22:01:42 +08:00
|
|
|
unsigned int alg; /* the algorithm for decompression */
|
2022-07-15 23:42:03 +08:00
|
|
|
bool inplace_io, partial_decoding, fillgaps;
|
2024-01-26 22:01:42 +08:00
|
|
|
gfp_t gfp; /* allocation flags for extra temporary buffers */
|
2019-06-24 15:22:55 +08:00
|
|
|
};
|
|
|
|
|
2021-10-11 05:31:45 +08:00
|
|
|
struct z_erofs_decompressor {
|
2023-10-22 21:09:57 +08:00
|
|
|
int (*config)(struct super_block *sb, struct erofs_super_block *dsb,
|
|
|
|
void *data, int size);
|
2021-10-11 05:31:45 +08:00
|
|
|
int (*decompress)(struct z_erofs_decompress_req *rq,
|
2021-10-22 17:01:20 +08:00
|
|
|
struct page **pagepool);
|
2021-10-11 05:31:45 +08:00
|
|
|
char *name;
|
|
|
|
};
|
|
|
|
|
2020-12-08 17:58:32 +08:00
|
|
|
/* some special page->private (unsigned long, see below) */
|
|
|
|
#define Z_EROFS_SHORTLIVED_PAGE (-1UL << 2)
|
2020-12-09 20:37:17 +08:00
|
|
|
#define Z_EROFS_PREALLOCATED_PAGE (-2UL << 2)
|
2020-12-08 17:58:32 +08:00
|
|
|
|
2019-06-24 15:22:54 +08:00
|
|
|
/*
|
2020-12-08 17:58:32 +08:00
|
|
|
* For all pages in a pcluster, page->private should be one of
|
|
|
|
* Type Last 2bits page->private
|
|
|
|
* short-lived page 00 Z_EROFS_SHORTLIVED_PAGE
|
2020-12-09 20:37:17 +08:00
|
|
|
* preallocated page (tryalloc) 00 Z_EROFS_PREALLOCATED_PAGE
|
2020-12-08 17:58:32 +08:00
|
|
|
* cached/managed page 00 pointer to z_erofs_pcluster
|
|
|
|
* online page (file-backed, 01/10/11 sub-index << 2 | count
|
|
|
|
* some pages can be used for inplace I/O)
|
|
|
|
*
|
|
|
|
* page->mapping should be one of
|
|
|
|
* Type page->mapping
|
|
|
|
* short-lived page NULL
|
2020-12-09 20:37:17 +08:00
|
|
|
* preallocated page NULL
|
2020-12-08 17:58:32 +08:00
|
|
|
* cached/managed page non-NULL or NULL (invalidated/truncated page)
|
|
|
|
* online page non-NULL
|
|
|
|
*
|
|
|
|
* For all managed pages, PG_private should be set with 1 extra refcount,
|
|
|
|
* which is used for page reclaim / migration.
|
2019-06-24 15:22:54 +08:00
|
|
|
*/
|
|
|
|
|
2020-12-08 17:58:32 +08:00
|
|
|
/*
|
|
|
|
* short-lived pages are pages directly from buddy system with specific
|
|
|
|
* page->private (no need to set PagePrivate since these are non-LRU /
|
|
|
|
* non-movable pages and bypass reclaim / migration code).
|
|
|
|
*/
|
|
|
|
static inline bool z_erofs_is_shortlived_page(struct page *page)
|
2019-06-24 15:22:54 +08:00
|
|
|
{
|
2020-12-08 17:58:32 +08:00
|
|
|
if (page->private != Z_EROFS_SHORTLIVED_PAGE)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
DBG_BUGON(page->mapping);
|
|
|
|
return true;
|
2019-06-24 15:22:54 +08:00
|
|
|
}
|
|
|
|
|
2021-10-22 17:01:20 +08:00
|
|
|
static inline bool z_erofs_put_shortlivedpage(struct page **pagepool,
|
2020-12-08 17:58:32 +08:00
|
|
|
struct page *page)
|
2019-06-24 15:22:54 +08:00
|
|
|
{
|
2020-12-08 17:58:32 +08:00
|
|
|
if (!z_erofs_is_shortlived_page(page))
|
2019-06-24 15:22:54 +08:00
|
|
|
return false;
|
|
|
|
|
2020-12-08 17:58:32 +08:00
|
|
|
/* short-lived pages should not be used by others at the same time */
|
|
|
|
if (page_ref_count(page) > 1) {
|
2019-06-24 15:22:54 +08:00
|
|
|
put_page(page);
|
2020-12-08 17:58:32 +08:00
|
|
|
} else {
|
|
|
|
/* follow the pcluster rule above. */
|
2021-10-22 17:01:20 +08:00
|
|
|
erofs_pagepool_add(pagepool, page);
|
2020-12-08 17:58:32 +08:00
|
|
|
}
|
2019-06-24 15:22:54 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-12-28 13:46:01 +08:00
|
|
|
int z_erofs_fixup_insize(struct z_erofs_decompress_req *rq, const char *padbuf,
|
|
|
|
unsigned int padbufsize);
|
2023-04-26 16:44:49 +08:00
|
|
|
extern const struct z_erofs_decompressor erofs_decompressors[];
|
2019-06-24 15:22:55 +08:00
|
|
|
|
2021-10-11 05:31:45 +08:00
|
|
|
/* prototypes for specific algorithms */
|
2023-10-22 21:09:57 +08:00
|
|
|
int z_erofs_load_lzma_config(struct super_block *sb,
|
|
|
|
struct erofs_super_block *dsb, void *data, int size);
|
|
|
|
int z_erofs_load_deflate_config(struct super_block *sb,
|
|
|
|
struct erofs_super_block *dsb, void *data, int size);
|
2024-05-09 07:44:53 +08:00
|
|
|
int z_erofs_load_zstd_config(struct super_block *sb,
|
|
|
|
struct erofs_super_block *dsb, void *data, int size);
|
2021-10-11 05:31:45 +08:00
|
|
|
int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq,
|
2021-10-22 17:01:20 +08:00
|
|
|
struct page **pagepool);
|
erofs: DEFLATE compression support
Add DEFLATE compression as the 3rd supported algorithm.
DEFLATE is a popular generic-purpose compression algorithm for quite
long time (many advanced formats like gzip, zlib, zip, png are all
based on that) as Apple documentation written "If you require
interoperability with non-Apple devices, use COMPRESSION_ZLIB. [1]".
Due to its popularity, there are several hardware on-market DEFLATE
accelerators, such as (s390) DFLTCC, (Intel) IAA/QAT, (HiSilicon) ZIP
accelerator, etc. In addition, there are also several high-performence
IP cores and even open-source FPGA approches available for DEFLATE.
Therefore, it's useful to support DEFLATE compression in order to find
a way to utilize these accelerators for asynchronous I/Os and get
benefits from these later.
Besides, it's a good choice to trade off between compression ratios
and performance compared to LZ4 and LZMA. The DEFLATE core format is
simple as well as easy to understand, therefore the code size of its
decompressor is small even for the bootloader use cases. The runtime
memory consumption is quite limited too (e.g. 32K + ~7K for each zlib
stream). As usual, EROFS ourperforms similar approaches too.
Alternatively, DEFLATE could still be used for some specific files
since EROFS supports multiple compression algorithms in one image.
[1] https://developer.apple.com/documentation/compression/compression_algorithm
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20230810154859.118330-1-hsiangkao@linux.alibaba.com
2023-08-10 23:48:59 +08:00
|
|
|
int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,
|
|
|
|
struct page **pagepool);
|
2024-05-09 07:44:53 +08:00
|
|
|
int z_erofs_zstd_decompress(struct z_erofs_decompress_req *rq,
|
|
|
|
struct page **pgpl);
|
2019-06-24 15:22:54 +08:00
|
|
|
#endif
|