Blame view
fs/btrfs/compression.h
6.01 KB
9888c3402 btrfs: replace GP... |
1 |
/* SPDX-License-Identifier: GPL-2.0 */ |
c8b978188 Btrfs: Add zlib c... |
2 3 |
/* * Copyright (C) 2008 Oracle. All rights reserved. |
c8b978188 Btrfs: Add zlib c... |
4 |
*/ |
9888c3402 btrfs: replace GP... |
5 6 |
#ifndef BTRFS_COMPRESSION_H #define BTRFS_COMPRESSION_H |
c8b978188 Btrfs: Add zlib c... |
7 |
|
d5c1d68fd btrfs: compressio... |
8 |
#include <linux/sizes.h> |
c7ee1819d btrfs: make btrfs... |
9 |
struct btrfs_inode; |
ff7638665 btrfs: export com... |
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
/* * We want to make sure that amount of RAM required to uncompress an extent is * reasonable, so we limit the total size in ram of a compressed extent to * 128k. This is a crucial number because it also controls how easily we can * spread reads across cpus for decompression. * * We also want to make sure the amount of IO required to do a random read is * reasonably small, so we limit the size of a compressed extent to 128k. */ /* Maximum length of compressed data stored on disk */ #define BTRFS_MAX_COMPRESSED (SZ_128K) /* Maximum size of data before compression */ #define BTRFS_MAX_UNCOMPRESSED (SZ_128K) |
eae8d8252 btrfs: Fix wild m... |
24 |
#define BTRFS_ZLIB_DEFAULT_LEVEL 3 |
e1ddce71d btrfs: reduce arg... |
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
struct compressed_bio { /* number of bios pending for this compressed extent */ refcount_t pending_bios; /* the pages with the compressed data on them */ struct page **compressed_pages; /* inode that owns this data */ struct inode *inode; /* starting offset in the inode for our pages */ u64 start; /* number of bytes in the inode we're working on */ unsigned long len; /* number of bytes on disk */ unsigned long compressed_len; /* the compression algorithm for this bio */ int compress_type; /* number of compressed pages in the array */ unsigned long nr_pages; /* IO errors */ int errors; int mirror_num; /* for reads, this is the bio we are copying the data into */ struct bio *orig_bio; /* * the start of a variable length array of checksums only * used by reads */ |
10fe6ca80 btrfs: don't assu... |
61 |
u8 sums[]; |
e1ddce71d btrfs: reduce arg... |
62 |
}; |
1972708a8 btrfs: add helper... |
63 64 65 66 67 68 69 70 71 |
static inline unsigned int btrfs_compress_type(unsigned int type_level) { return (type_level & 0xF); } static inline unsigned int btrfs_compress_level(unsigned int type_level) { return ((type_level & 0xF0) >> 4); } |
f5c29bd9d Btrfs: add __init... |
72 |
void __init btrfs_init_compress(void); |
e67c718b5 btrfs: add more _... |
73 |
void __cold btrfs_exit_compress(void); |
261507a02 btrfs: Allow to a... |
74 |
|
f51d2b591 btrfs: allow to s... |
75 |
int btrfs_compress_pages(unsigned int type_level, struct address_space *mapping, |
38c314640 btrfs: merge leng... |
76 |
u64 start, struct page **pages, |
261507a02 btrfs: Allow to a... |
77 78 |
unsigned long *out_pages, unsigned long *total_in, |
e5d749023 btrfs: derive max... |
79 |
unsigned long *total_out); |
261507a02 btrfs: Allow to a... |
80 81 |
int btrfs_decompress(int type, unsigned char *data_in, struct page *dest_page, unsigned long start_byte, size_t srclen, size_t destlen); |
14a3357b4 btrfs: constify b... |
82 |
int btrfs_decompress_buf2page(const char *buf, unsigned long buf_start, |
3a39c18d6 btrfs: Extract du... |
83 |
unsigned long total_out, u64 disk_start, |
974b1adc3 btrfs: use bio it... |
84 |
struct bio *bio); |
261507a02 btrfs: Allow to a... |
85 |
|
c7ee1819d btrfs: make btrfs... |
86 |
blk_status_t btrfs_submit_compressed_write(struct btrfs_inode *inode, u64 start, |
c8b978188 Btrfs: Add zlib c... |
87 88 89 |
unsigned long len, u64 disk_start, unsigned long compressed_len, struct page **compressed_pages, |
f82b73593 Btrfs: add write_... |
90 |
unsigned long nr_pages, |
ec39f7696 Btrfs: use REQ_CG... |
91 92 |
unsigned int write_flags, struct cgroup_subsys_state *blkcg_css); |
4e4cbee93 block: switch bio... |
93 |
blk_status_t btrfs_submit_compressed_read(struct inode *inode, struct bio *bio, |
c8b978188 Btrfs: Add zlib c... |
94 |
int mirror_num, unsigned long bio_flags); |
ebb8765b2 btrfs: move btrfs... |
95 |
|
d0ab62ce2 btrfs: change set... |
96 |
unsigned int btrfs_compress_str2level(unsigned int type, const char *str); |
f51d2b591 btrfs: allow to s... |
97 |
|
ebb8765b2 btrfs: move btrfs... |
98 99 100 101 |
enum btrfs_compression_type { BTRFS_COMPRESS_NONE = 0, BTRFS_COMPRESS_ZLIB = 1, BTRFS_COMPRESS_LZO = 2, |
5c1aab1dd btrfs: Add zstd s... |
102 |
BTRFS_COMPRESS_ZSTD = 3, |
ce96b7ffd btrfs: use better... |
103 |
BTRFS_NR_COMPRESS_TYPES = 4, |
ebb8765b2 btrfs: move btrfs... |
104 |
}; |
92ee55303 btrfs: move to fu... |
105 |
struct workspace_manager { |
92ee55303 btrfs: move to fu... |
106 107 108 109 110 111 112 113 114 |
struct list_head idle_ws; spinlock_t ws_lock; /* Number of free workspaces */ int free_ws; /* Total number of allocated workspaces */ atomic_t total_ws; /* Waiters for a free workspace */ wait_queue_head_t ws_wait; }; |
5907a9bb1 btrfs: compressio... |
115 |
struct list_head *btrfs_get_workspace(int type, unsigned int level); |
a3bbd2a9e btrfs: compressio... |
116 |
void btrfs_put_workspace(int type, struct list_head *ws); |
92ee55303 btrfs: move to fu... |
117 |
|
261507a02 btrfs: Allow to a... |
118 |
struct btrfs_compress_op { |
be9510453 btrfs: compressio... |
119 |
struct workspace_manager *workspace_manager; |
e18333a7c btrfs: define com... |
120 121 122 |
/* Maximum level supported by the compression algorithm */ unsigned int max_level; unsigned int default_level; |
261507a02 btrfs: Allow to a... |
123 |
}; |
ca4ac360a btrfs: manage heu... |
124 |
/* The heuristic workspaces are managed via the 0th workspace manager */ |
ce96b7ffd btrfs: use better... |
125 |
#define BTRFS_NR_WORKSPACE_MANAGERS BTRFS_NR_COMPRESS_TYPES |
ca4ac360a btrfs: manage heu... |
126 127 |
extern const struct btrfs_compress_op btrfs_heuristic_compress; |
e8c9f1860 btrfs: constify s... |
128 129 |
extern const struct btrfs_compress_op btrfs_zlib_compress; extern const struct btrfs_compress_op btrfs_lzo_compress; |
5c1aab1dd btrfs: Add zstd s... |
130 |
extern const struct btrfs_compress_op btrfs_zstd_compress; |
261507a02 btrfs: Allow to a... |
131 |
|
e128f9c3f btrfs: compressio... |
132 |
const char* btrfs_compress_type2str(enum btrfs_compression_type type); |
aa53e3bfa btrfs: correctly ... |
133 |
bool btrfs_compress_is_valid_type(const char *str, size_t len); |
e128f9c3f btrfs: compressio... |
134 |
|
c2fcdcdf3 Btrfs: add skelet... |
135 |
int btrfs_compress_heuristic(struct inode *inode, u64 start, u64 end); |
cb4c91983 btrfs: compressio... |
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
int zlib_compress_pages(struct list_head *ws, struct address_space *mapping, u64 start, struct page **pages, unsigned long *out_pages, unsigned long *total_in, unsigned long *total_out); int zlib_decompress_bio(struct list_head *ws, struct compressed_bio *cb); int zlib_decompress(struct list_head *ws, unsigned char *data_in, struct page *dest_page, unsigned long start_byte, size_t srclen, size_t destlen); struct list_head *zlib_alloc_workspace(unsigned int level); void zlib_free_workspace(struct list_head *ws); struct list_head *zlib_get_workspace(unsigned int level); int lzo_compress_pages(struct list_head *ws, struct address_space *mapping, u64 start, struct page **pages, unsigned long *out_pages, unsigned long *total_in, unsigned long *total_out); int lzo_decompress_bio(struct list_head *ws, struct compressed_bio *cb); int lzo_decompress(struct list_head *ws, unsigned char *data_in, struct page *dest_page, unsigned long start_byte, size_t srclen, size_t destlen); struct list_head *lzo_alloc_workspace(unsigned int level); void lzo_free_workspace(struct list_head *ws); int zstd_compress_pages(struct list_head *ws, struct address_space *mapping, u64 start, struct page **pages, unsigned long *out_pages, unsigned long *total_in, unsigned long *total_out); int zstd_decompress_bio(struct list_head *ws, struct compressed_bio *cb); int zstd_decompress(struct list_head *ws, unsigned char *data_in, struct page *dest_page, unsigned long start_byte, size_t srclen, size_t destlen); void zstd_init_workspace_manager(void); void zstd_cleanup_workspace_manager(void); struct list_head *zstd_alloc_workspace(unsigned int level); void zstd_free_workspace(struct list_head *ws); struct list_head *zstd_get_workspace(unsigned int level); void zstd_put_workspace(struct list_head *ws); |
c8b978188 Btrfs: Add zlib c... |
170 |
#endif |