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