^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2019 HUAWEI, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * https://www.huawei.com/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Created by Gao Xiang <gaoxiang25@huawei.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #ifndef __EROFS_FS_COMPRESS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #define __EROFS_FS_COMPRESS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) Z_EROFS_COMPRESSION_SHIFTED = Z_EROFS_COMPRESSION_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) Z_EROFS_COMPRESSION_RUNTIME_MAX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) struct z_erofs_decompress_req {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) struct super_block *sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) struct page **in, **out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) unsigned short pageofs_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) unsigned int inputsize, outputsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) /* indicate the algorithm will be used for decompression */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) unsigned int alg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) bool inplace_io, partial_decoding;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) /* some special page->private (unsigned long, see below) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define Z_EROFS_SHORTLIVED_PAGE (-1UL << 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define Z_EROFS_PREALLOCATED_PAGE (-2UL << 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * For all pages in a pcluster, page->private should be one of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * Type Last 2bits page->private
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * short-lived page 00 Z_EROFS_SHORTLIVED_PAGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * preallocated page (tryalloc) 00 Z_EROFS_PREALLOCATED_PAGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * cached/managed page 00 pointer to z_erofs_pcluster
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * online page (file-backed, 01/10/11 sub-index << 2 | count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * some pages can be used for inplace I/O)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * page->mapping should be one of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * Type page->mapping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * short-lived page NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * preallocated page NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * cached/managed page non-NULL or NULL (invalidated/truncated page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * online page non-NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * For all managed pages, PG_private should be set with 1 extra refcount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * which is used for page reclaim / migration.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * short-lived pages are pages directly from buddy system with specific
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * page->private (no need to set PagePrivate since these are non-LRU /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * non-movable pages and bypass reclaim / migration code).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) static inline bool z_erofs_is_shortlived_page(struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) if (page->private != Z_EROFS_SHORTLIVED_PAGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) DBG_BUGON(page->mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) static inline bool z_erofs_put_shortlivedpage(struct list_head *pagepool,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) if (!z_erofs_is_shortlived_page(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) /* short-lived pages should not be used by others at the same time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) if (page_ref_count(page) > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) /* follow the pcluster rule above. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) set_page_private(page, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) list_add(&page->lru, pagepool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) int z_erofs_decompress(struct z_erofs_decompress_req *rq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct list_head *pagepool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)