mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-14 06:24:53 +08:00
7c35de4df1
Add Zstandard compression as the 4th supported algorithm since it becomes more popular now and some end users have asked this for quite a while [1][2]. Each EROFS physical cluster contains only one valid standard Zstandard frame as described in [3] so that decompression can be performed on a per-pcluster basis independently. Currently, it just leverages multi-call stream decompression APIs with internal sliding window buffers. One-shot or bufferless decompression could be implemented later for even better performance if needed. [1] https://github.com/erofs/erofs-utils/issues/6 [2] https://lore.kernel.org/r/Y08h+z6CZdnS1XBm@B-P7TQMD6M-0146.lan [3] https://www.rfc-editor.org/rfc/rfc8478.txt Acked-by: Chao Yu <chao@kernel.org> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com> Link: https://lore.kernel.org/r/20240508234453.17896-1-xiang@kernel.org
102 lines
3.3 KiB
C
102 lines
3.3 KiB
C
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
/*
|
|
* Copyright (C) 2019 HUAWEI, Inc.
|
|
* https://www.huawei.com/
|
|
*/
|
|
#ifndef __EROFS_FS_COMPRESS_H
|
|
#define __EROFS_FS_COMPRESS_H
|
|
|
|
#include "internal.h"
|
|
|
|
struct z_erofs_decompress_req {
|
|
struct super_block *sb;
|
|
struct page **in, **out;
|
|
unsigned short pageofs_in, pageofs_out;
|
|
unsigned int inputsize, outputsize;
|
|
|
|
unsigned int alg; /* the algorithm for decompression */
|
|
bool inplace_io, partial_decoding, fillgaps;
|
|
gfp_t gfp; /* allocation flags for extra temporary buffers */
|
|
};
|
|
|
|
struct z_erofs_decompressor {
|
|
int (*config)(struct super_block *sb, struct erofs_super_block *dsb,
|
|
void *data, int size);
|
|
int (*decompress)(struct z_erofs_decompress_req *rq,
|
|
struct page **pagepool);
|
|
char *name;
|
|
};
|
|
|
|
/* some special page->private (unsigned long, see below) */
|
|
#define Z_EROFS_SHORTLIVED_PAGE (-1UL << 2)
|
|
#define Z_EROFS_PREALLOCATED_PAGE (-2UL << 2)
|
|
|
|
/*
|
|
* 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
|
|
* preallocated page (tryalloc) 00 Z_EROFS_PREALLOCATED_PAGE
|
|
* 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
|
|
* preallocated page NULL
|
|
* 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.
|
|
*/
|
|
|
|
/*
|
|
* 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)
|
|
{
|
|
if (page->private != Z_EROFS_SHORTLIVED_PAGE)
|
|
return false;
|
|
|
|
DBG_BUGON(page->mapping);
|
|
return true;
|
|
}
|
|
|
|
static inline bool z_erofs_put_shortlivedpage(struct page **pagepool,
|
|
struct page *page)
|
|
{
|
|
if (!z_erofs_is_shortlived_page(page))
|
|
return false;
|
|
|
|
/* short-lived pages should not be used by others at the same time */
|
|
if (page_ref_count(page) > 1) {
|
|
put_page(page);
|
|
} else {
|
|
/* follow the pcluster rule above. */
|
|
erofs_pagepool_add(pagepool, page);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
int z_erofs_fixup_insize(struct z_erofs_decompress_req *rq, const char *padbuf,
|
|
unsigned int padbufsize);
|
|
extern const struct z_erofs_decompressor erofs_decompressors[];
|
|
|
|
/* prototypes for specific algorithms */
|
|
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);
|
|
int z_erofs_load_zstd_config(struct super_block *sb,
|
|
struct erofs_super_block *dsb, void *data, int size);
|
|
int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq,
|
|
struct page **pagepool);
|
|
int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,
|
|
struct page **pagepool);
|
|
int z_erofs_zstd_decompress(struct z_erofs_decompress_req *rq,
|
|
struct page **pgpl);
|
|
#endif
|