David Sterba | c1d7c51 | 2018-04-03 19:23:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2016-present, Facebook, Inc. |
| 4 | * All rights reserved. |
| 5 | * |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 6 | */ |
David Sterba | c1d7c51 | 2018-04-03 19:23:33 +0200 | [diff] [blame] | 7 | |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 8 | #include <linux/bio.h> |
Dennis Zhou | 3f93aef | 2019-02-04 15:20:08 -0500 | [diff] [blame] | 9 | #include <linux/bitmap.h> |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 10 | #include <linux/err.h> |
| 11 | #include <linux/init.h> |
| 12 | #include <linux/kernel.h> |
| 13 | #include <linux/mm.h> |
Dennis Zhou | 3f93aef | 2019-02-04 15:20:08 -0500 | [diff] [blame] | 14 | #include <linux/sched/mm.h> |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 15 | #include <linux/pagemap.h> |
| 16 | #include <linux/refcount.h> |
| 17 | #include <linux/sched.h> |
| 18 | #include <linux/slab.h> |
| 19 | #include <linux/zstd.h> |
David Sterba | 602cbe9 | 2019-08-21 18:48:25 +0200 | [diff] [blame] | 20 | #include "misc.h" |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 21 | #include "compression.h" |
Dennis Zhou | 3f93aef | 2019-02-04 15:20:08 -0500 | [diff] [blame] | 22 | #include "ctree.h" |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 23 | |
| 24 | #define ZSTD_BTRFS_MAX_WINDOWLOG 17 |
| 25 | #define ZSTD_BTRFS_MAX_INPUT (1 << ZSTD_BTRFS_MAX_WINDOWLOG) |
| 26 | #define ZSTD_BTRFS_DEFAULT_LEVEL 3 |
Dennis Zhou | d3c6ab7 | 2019-02-04 15:20:07 -0500 | [diff] [blame] | 27 | #define ZSTD_BTRFS_MAX_LEVEL 15 |
Dennis Zhou | 3f93aef | 2019-02-04 15:20:08 -0500 | [diff] [blame] | 28 | /* 307s to avoid pathologically clashing with transaction commit */ |
| 29 | #define ZSTD_BTRFS_RECLAIM_JIFFIES (307 * HZ) |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 30 | |
Dennis Zhou | e0dc87a | 2019-02-04 15:20:06 -0500 | [diff] [blame] | 31 | static ZSTD_parameters zstd_get_btrfs_parameters(unsigned int level, |
| 32 | size_t src_len) |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 33 | { |
Dennis Zhou | e0dc87a | 2019-02-04 15:20:06 -0500 | [diff] [blame] | 34 | ZSTD_parameters params = ZSTD_getParams(level, src_len, 0); |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 35 | |
| 36 | if (params.cParams.windowLog > ZSTD_BTRFS_MAX_WINDOWLOG) |
| 37 | params.cParams.windowLog = ZSTD_BTRFS_MAX_WINDOWLOG; |
| 38 | WARN_ON(src_len > ZSTD_BTRFS_MAX_INPUT); |
| 39 | return params; |
| 40 | } |
| 41 | |
| 42 | struct workspace { |
| 43 | void *mem; |
| 44 | size_t size; |
| 45 | char *buf; |
Dennis Zhou | 3f93aef | 2019-02-04 15:20:08 -0500 | [diff] [blame] | 46 | unsigned int level; |
Dennis Zhou | e0dc87a | 2019-02-04 15:20:06 -0500 | [diff] [blame] | 47 | unsigned int req_level; |
Dennis Zhou | 3f93aef | 2019-02-04 15:20:08 -0500 | [diff] [blame] | 48 | unsigned long last_used; /* jiffies */ |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 49 | struct list_head list; |
Dennis Zhou | 3f93aef | 2019-02-04 15:20:08 -0500 | [diff] [blame] | 50 | struct list_head lru_list; |
David Sterba | 431e982 | 2017-11-15 18:27:39 +0100 | [diff] [blame] | 51 | ZSTD_inBuffer in_buf; |
| 52 | ZSTD_outBuffer out_buf; |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 53 | }; |
| 54 | |
Dennis Zhou | 3f93aef | 2019-02-04 15:20:08 -0500 | [diff] [blame] | 55 | /* |
| 56 | * Zstd Workspace Management |
| 57 | * |
| 58 | * Zstd workspaces have different memory requirements depending on the level. |
| 59 | * The zstd workspaces are managed by having individual lists for each level |
| 60 | * and a global lru. Forward progress is maintained by protecting a max level |
| 61 | * workspace. |
| 62 | * |
| 63 | * Getting a workspace is done by using the bitmap to identify the levels that |
| 64 | * have available workspaces and scans up. This lets us recycle higher level |
| 65 | * workspaces because of the monotonic memory guarantee. A workspace's |
| 66 | * last_used is only updated if it is being used by the corresponding memory |
| 67 | * level. Putting a workspace involves adding it back to the appropriate places |
| 68 | * and adding it back to the lru if necessary. |
| 69 | * |
| 70 | * A timer is used to reclaim workspaces if they have not been used for |
| 71 | * ZSTD_BTRFS_RECLAIM_JIFFIES. This helps keep only active workspaces around. |
| 72 | * The upper bound is provided by the workqueue limit which is 2 (percpu limit). |
| 73 | */ |
| 74 | |
| 75 | struct zstd_workspace_manager { |
| 76 | const struct btrfs_compress_op *ops; |
| 77 | spinlock_t lock; |
| 78 | struct list_head lru_list; |
| 79 | struct list_head idle_ws[ZSTD_BTRFS_MAX_LEVEL]; |
| 80 | unsigned long active_map; |
| 81 | wait_queue_head_t wait; |
| 82 | struct timer_list timer; |
| 83 | }; |
| 84 | |
| 85 | static struct zstd_workspace_manager wsm; |
Dennis Zhou | 92ee5530 | 2019-02-04 15:20:03 -0500 | [diff] [blame] | 86 | |
Dennis Zhou | d3c6ab7 | 2019-02-04 15:20:07 -0500 | [diff] [blame] | 87 | static size_t zstd_ws_mem_sizes[ZSTD_BTRFS_MAX_LEVEL]; |
| 88 | |
Dennis Zhou | 3f93aef | 2019-02-04 15:20:08 -0500 | [diff] [blame] | 89 | static inline struct workspace *list_to_workspace(struct list_head *list) |
| 90 | { |
| 91 | return container_of(list, struct workspace, list); |
| 92 | } |
| 93 | |
Dennis Zhou | b242349 | 2019-02-27 16:21:28 -0500 | [diff] [blame] | 94 | static void zstd_free_workspace(struct list_head *ws); |
| 95 | static struct list_head *zstd_alloc_workspace(unsigned int level); |
| 96 | |
Dennis Zhou | 3f93aef | 2019-02-04 15:20:08 -0500 | [diff] [blame] | 97 | /* |
| 98 | * zstd_reclaim_timer_fn - reclaim timer |
| 99 | * @t: timer |
| 100 | * |
| 101 | * This scans the lru_list and attempts to reclaim any workspace that hasn't |
| 102 | * been used for ZSTD_BTRFS_RECLAIM_JIFFIES. |
| 103 | */ |
| 104 | static void zstd_reclaim_timer_fn(struct timer_list *timer) |
| 105 | { |
| 106 | unsigned long reclaim_threshold = jiffies - ZSTD_BTRFS_RECLAIM_JIFFIES; |
| 107 | struct list_head *pos, *next; |
| 108 | |
Dennis Zhou | fee13fe | 2019-05-17 19:16:26 -0400 | [diff] [blame] | 109 | spin_lock_bh(&wsm.lock); |
Dennis Zhou | 3f93aef | 2019-02-04 15:20:08 -0500 | [diff] [blame] | 110 | |
| 111 | if (list_empty(&wsm.lru_list)) { |
Dennis Zhou | fee13fe | 2019-05-17 19:16:26 -0400 | [diff] [blame] | 112 | spin_unlock_bh(&wsm.lock); |
Dennis Zhou | 3f93aef | 2019-02-04 15:20:08 -0500 | [diff] [blame] | 113 | return; |
| 114 | } |
| 115 | |
| 116 | list_for_each_prev_safe(pos, next, &wsm.lru_list) { |
| 117 | struct workspace *victim = container_of(pos, struct workspace, |
| 118 | lru_list); |
| 119 | unsigned int level; |
| 120 | |
| 121 | if (time_after(victim->last_used, reclaim_threshold)) |
| 122 | break; |
| 123 | |
| 124 | /* workspace is in use */ |
| 125 | if (victim->req_level) |
| 126 | continue; |
| 127 | |
| 128 | level = victim->level; |
| 129 | list_del(&victim->lru_list); |
| 130 | list_del(&victim->list); |
Dennis Zhou | b242349 | 2019-02-27 16:21:28 -0500 | [diff] [blame] | 131 | zstd_free_workspace(&victim->list); |
Dennis Zhou | 3f93aef | 2019-02-04 15:20:08 -0500 | [diff] [blame] | 132 | |
| 133 | if (list_empty(&wsm.idle_ws[level - 1])) |
| 134 | clear_bit(level - 1, &wsm.active_map); |
| 135 | |
| 136 | } |
| 137 | |
| 138 | if (!list_empty(&wsm.lru_list)) |
| 139 | mod_timer(&wsm.timer, jiffies + ZSTD_BTRFS_RECLAIM_JIFFIES); |
| 140 | |
Dennis Zhou | fee13fe | 2019-05-17 19:16:26 -0400 | [diff] [blame] | 141 | spin_unlock_bh(&wsm.lock); |
Dennis Zhou | 3f93aef | 2019-02-04 15:20:08 -0500 | [diff] [blame] | 142 | } |
| 143 | |
Dennis Zhou | d3c6ab7 | 2019-02-04 15:20:07 -0500 | [diff] [blame] | 144 | /* |
| 145 | * zstd_calc_ws_mem_sizes - calculate monotonic memory bounds |
| 146 | * |
| 147 | * It is possible based on the level configurations that a higher level |
| 148 | * workspace uses less memory than a lower level workspace. In order to reuse |
| 149 | * workspaces, this must be made a monotonic relationship. This precomputes |
| 150 | * the required memory for each level and enforces the monotonicity between |
| 151 | * level and memory required. |
| 152 | */ |
| 153 | static void zstd_calc_ws_mem_sizes(void) |
| 154 | { |
| 155 | size_t max_size = 0; |
| 156 | unsigned int level; |
| 157 | |
| 158 | for (level = 1; level <= ZSTD_BTRFS_MAX_LEVEL; level++) { |
| 159 | ZSTD_parameters params = |
| 160 | zstd_get_btrfs_parameters(level, ZSTD_BTRFS_MAX_INPUT); |
| 161 | size_t level_size = |
| 162 | max_t(size_t, |
| 163 | ZSTD_CStreamWorkspaceBound(params.cParams), |
| 164 | ZSTD_DStreamWorkspaceBound(ZSTD_BTRFS_MAX_INPUT)); |
| 165 | |
| 166 | max_size = max_t(size_t, max_size, level_size); |
| 167 | zstd_ws_mem_sizes[level - 1] = max_size; |
| 168 | } |
| 169 | } |
| 170 | |
Dennis Zhou | 92ee5530 | 2019-02-04 15:20:03 -0500 | [diff] [blame] | 171 | static void zstd_init_workspace_manager(void) |
| 172 | { |
Dennis Zhou | 3f93aef | 2019-02-04 15:20:08 -0500 | [diff] [blame] | 173 | struct list_head *ws; |
| 174 | int i; |
| 175 | |
Dennis Zhou | d3c6ab7 | 2019-02-04 15:20:07 -0500 | [diff] [blame] | 176 | zstd_calc_ws_mem_sizes(); |
| 177 | |
Dennis Zhou | 3f93aef | 2019-02-04 15:20:08 -0500 | [diff] [blame] | 178 | wsm.ops = &btrfs_zstd_compress; |
| 179 | spin_lock_init(&wsm.lock); |
| 180 | init_waitqueue_head(&wsm.wait); |
| 181 | timer_setup(&wsm.timer, zstd_reclaim_timer_fn, 0); |
| 182 | |
| 183 | INIT_LIST_HEAD(&wsm.lru_list); |
| 184 | for (i = 0; i < ZSTD_BTRFS_MAX_LEVEL; i++) |
| 185 | INIT_LIST_HEAD(&wsm.idle_ws[i]); |
| 186 | |
Dennis Zhou | b242349 | 2019-02-27 16:21:28 -0500 | [diff] [blame] | 187 | ws = zstd_alloc_workspace(ZSTD_BTRFS_MAX_LEVEL); |
Dennis Zhou | 3f93aef | 2019-02-04 15:20:08 -0500 | [diff] [blame] | 188 | if (IS_ERR(ws)) { |
| 189 | pr_warn( |
| 190 | "BTRFS: cannot preallocate zstd compression workspace\n"); |
| 191 | } else { |
| 192 | set_bit(ZSTD_BTRFS_MAX_LEVEL - 1, &wsm.active_map); |
| 193 | list_add(ws, &wsm.idle_ws[ZSTD_BTRFS_MAX_LEVEL - 1]); |
| 194 | } |
Dennis Zhou | 92ee5530 | 2019-02-04 15:20:03 -0500 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | static void zstd_cleanup_workspace_manager(void) |
| 198 | { |
Dennis Zhou | 3f93aef | 2019-02-04 15:20:08 -0500 | [diff] [blame] | 199 | struct workspace *workspace; |
| 200 | int i; |
| 201 | |
Dennis Zhou | fee13fe | 2019-05-17 19:16:26 -0400 | [diff] [blame] | 202 | spin_lock_bh(&wsm.lock); |
Dennis Zhou | 3f93aef | 2019-02-04 15:20:08 -0500 | [diff] [blame] | 203 | for (i = 0; i < ZSTD_BTRFS_MAX_LEVEL; i++) { |
| 204 | while (!list_empty(&wsm.idle_ws[i])) { |
| 205 | workspace = container_of(wsm.idle_ws[i].next, |
| 206 | struct workspace, list); |
| 207 | list_del(&workspace->list); |
| 208 | list_del(&workspace->lru_list); |
Dennis Zhou | b242349 | 2019-02-27 16:21:28 -0500 | [diff] [blame] | 209 | zstd_free_workspace(&workspace->list); |
Dennis Zhou | 3f93aef | 2019-02-04 15:20:08 -0500 | [diff] [blame] | 210 | } |
| 211 | } |
Dennis Zhou | fee13fe | 2019-05-17 19:16:26 -0400 | [diff] [blame] | 212 | spin_unlock_bh(&wsm.lock); |
Dennis Zhou | d386515 | 2019-02-22 14:53:48 -0500 | [diff] [blame] | 213 | |
| 214 | del_timer_sync(&wsm.timer); |
Dennis Zhou | 92ee5530 | 2019-02-04 15:20:03 -0500 | [diff] [blame] | 215 | } |
| 216 | |
Dennis Zhou | 3f93aef | 2019-02-04 15:20:08 -0500 | [diff] [blame] | 217 | /* |
| 218 | * zstd_find_workspace - find workspace |
| 219 | * @level: compression level |
| 220 | * |
| 221 | * This iterates over the set bits in the active_map beginning at the requested |
| 222 | * compression level. This lets us utilize already allocated workspaces before |
| 223 | * allocating a new one. If the workspace is of a larger size, it is used, but |
| 224 | * the place in the lru_list and last_used times are not updated. This is to |
| 225 | * offer the opportunity to reclaim the workspace in favor of allocating an |
| 226 | * appropriately sized one in the future. |
| 227 | */ |
| 228 | static struct list_head *zstd_find_workspace(unsigned int level) |
| 229 | { |
| 230 | struct list_head *ws; |
| 231 | struct workspace *workspace; |
| 232 | int i = level - 1; |
| 233 | |
Dennis Zhou | fee13fe | 2019-05-17 19:16:26 -0400 | [diff] [blame] | 234 | spin_lock_bh(&wsm.lock); |
Dennis Zhou | 3f93aef | 2019-02-04 15:20:08 -0500 | [diff] [blame] | 235 | for_each_set_bit_from(i, &wsm.active_map, ZSTD_BTRFS_MAX_LEVEL) { |
| 236 | if (!list_empty(&wsm.idle_ws[i])) { |
| 237 | ws = wsm.idle_ws[i].next; |
| 238 | workspace = list_to_workspace(ws); |
| 239 | list_del_init(ws); |
| 240 | /* keep its place if it's a lower level using this */ |
| 241 | workspace->req_level = level; |
| 242 | if (level == workspace->level) |
| 243 | list_del(&workspace->lru_list); |
| 244 | if (list_empty(&wsm.idle_ws[i])) |
| 245 | clear_bit(i, &wsm.active_map); |
Dennis Zhou | fee13fe | 2019-05-17 19:16:26 -0400 | [diff] [blame] | 246 | spin_unlock_bh(&wsm.lock); |
Dennis Zhou | 3f93aef | 2019-02-04 15:20:08 -0500 | [diff] [blame] | 247 | return ws; |
| 248 | } |
| 249 | } |
Dennis Zhou | fee13fe | 2019-05-17 19:16:26 -0400 | [diff] [blame] | 250 | spin_unlock_bh(&wsm.lock); |
Dennis Zhou | 3f93aef | 2019-02-04 15:20:08 -0500 | [diff] [blame] | 251 | |
| 252 | return NULL; |
| 253 | } |
| 254 | |
| 255 | /* |
| 256 | * zstd_get_workspace - zstd's get_workspace |
| 257 | * @level: compression level |
| 258 | * |
| 259 | * If @level is 0, then any compression level can be used. Therefore, we begin |
| 260 | * scanning from 1. We first scan through possible workspaces and then after |
| 261 | * attempt to allocate a new workspace. If we fail to allocate one due to |
| 262 | * memory pressure, go to sleep waiting for the max level workspace to free up. |
| 263 | */ |
Dennis Zhou | 7bf4994 | 2019-02-04 15:20:04 -0500 | [diff] [blame] | 264 | static struct list_head *zstd_get_workspace(unsigned int level) |
Dennis Zhou | 92ee5530 | 2019-02-04 15:20:03 -0500 | [diff] [blame] | 265 | { |
Dennis Zhou | 3f93aef | 2019-02-04 15:20:08 -0500 | [diff] [blame] | 266 | struct list_head *ws; |
| 267 | unsigned int nofs_flag; |
Dennis Zhou | e0dc87a | 2019-02-04 15:20:06 -0500 | [diff] [blame] | 268 | |
Dennis Zhou | 3f93aef | 2019-02-04 15:20:08 -0500 | [diff] [blame] | 269 | /* level == 0 means we can use any workspace */ |
| 270 | if (!level) |
| 271 | level = 1; |
| 272 | |
| 273 | again: |
| 274 | ws = zstd_find_workspace(level); |
| 275 | if (ws) |
| 276 | return ws; |
| 277 | |
| 278 | nofs_flag = memalloc_nofs_save(); |
Dennis Zhou | b242349 | 2019-02-27 16:21:28 -0500 | [diff] [blame] | 279 | ws = zstd_alloc_workspace(level); |
Dennis Zhou | 3f93aef | 2019-02-04 15:20:08 -0500 | [diff] [blame] | 280 | memalloc_nofs_restore(nofs_flag); |
| 281 | |
| 282 | if (IS_ERR(ws)) { |
| 283 | DEFINE_WAIT(wait); |
| 284 | |
| 285 | prepare_to_wait(&wsm.wait, &wait, TASK_UNINTERRUPTIBLE); |
| 286 | schedule(); |
| 287 | finish_wait(&wsm.wait, &wait); |
| 288 | |
| 289 | goto again; |
| 290 | } |
Dennis Zhou | e0dc87a | 2019-02-04 15:20:06 -0500 | [diff] [blame] | 291 | |
| 292 | return ws; |
Dennis Zhou | 92ee5530 | 2019-02-04 15:20:03 -0500 | [diff] [blame] | 293 | } |
| 294 | |
Dennis Zhou | 3f93aef | 2019-02-04 15:20:08 -0500 | [diff] [blame] | 295 | /* |
| 296 | * zstd_put_workspace - zstd put_workspace |
| 297 | * @ws: list_head for the workspace |
| 298 | * |
| 299 | * When putting back a workspace, we only need to update the LRU if we are of |
| 300 | * the requested compression level. Here is where we continue to protect the |
| 301 | * max level workspace or update last_used accordingly. If the reclaim timer |
| 302 | * isn't set, it is also set here. Only the max level workspace tries and wakes |
| 303 | * up waiting workspaces. |
| 304 | */ |
Dennis Zhou | 92ee5530 | 2019-02-04 15:20:03 -0500 | [diff] [blame] | 305 | static void zstd_put_workspace(struct list_head *ws) |
| 306 | { |
Dennis Zhou | 3f93aef | 2019-02-04 15:20:08 -0500 | [diff] [blame] | 307 | struct workspace *workspace = list_to_workspace(ws); |
| 308 | |
Dennis Zhou | fee13fe | 2019-05-17 19:16:26 -0400 | [diff] [blame] | 309 | spin_lock_bh(&wsm.lock); |
Dennis Zhou | 3f93aef | 2019-02-04 15:20:08 -0500 | [diff] [blame] | 310 | |
| 311 | /* A node is only taken off the lru if we are the corresponding level */ |
| 312 | if (workspace->req_level == workspace->level) { |
| 313 | /* Hide a max level workspace from reclaim */ |
| 314 | if (list_empty(&wsm.idle_ws[ZSTD_BTRFS_MAX_LEVEL - 1])) { |
| 315 | INIT_LIST_HEAD(&workspace->lru_list); |
| 316 | } else { |
| 317 | workspace->last_used = jiffies; |
| 318 | list_add(&workspace->lru_list, &wsm.lru_list); |
| 319 | if (!timer_pending(&wsm.timer)) |
| 320 | mod_timer(&wsm.timer, |
| 321 | jiffies + ZSTD_BTRFS_RECLAIM_JIFFIES); |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | set_bit(workspace->level - 1, &wsm.active_map); |
| 326 | list_add(&workspace->list, &wsm.idle_ws[workspace->level - 1]); |
| 327 | workspace->req_level = 0; |
| 328 | |
Dennis Zhou | fee13fe | 2019-05-17 19:16:26 -0400 | [diff] [blame] | 329 | spin_unlock_bh(&wsm.lock); |
Dennis Zhou | 3f93aef | 2019-02-04 15:20:08 -0500 | [diff] [blame] | 330 | |
| 331 | if (workspace->level == ZSTD_BTRFS_MAX_LEVEL) |
| 332 | cond_wake_up(&wsm.wait); |
Dennis Zhou | 92ee5530 | 2019-02-04 15:20:03 -0500 | [diff] [blame] | 333 | } |
| 334 | |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 335 | static void zstd_free_workspace(struct list_head *ws) |
| 336 | { |
| 337 | struct workspace *workspace = list_entry(ws, struct workspace, list); |
| 338 | |
| 339 | kvfree(workspace->mem); |
| 340 | kfree(workspace->buf); |
| 341 | kfree(workspace); |
| 342 | } |
| 343 | |
Dennis Zhou | 7bf4994 | 2019-02-04 15:20:04 -0500 | [diff] [blame] | 344 | static struct list_head *zstd_alloc_workspace(unsigned int level) |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 345 | { |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 346 | struct workspace *workspace; |
| 347 | |
| 348 | workspace = kzalloc(sizeof(*workspace), GFP_KERNEL); |
| 349 | if (!workspace) |
| 350 | return ERR_PTR(-ENOMEM); |
| 351 | |
Dennis Zhou | d3c6ab7 | 2019-02-04 15:20:07 -0500 | [diff] [blame] | 352 | workspace->size = zstd_ws_mem_sizes[level - 1]; |
Dennis Zhou | 3f93aef | 2019-02-04 15:20:08 -0500 | [diff] [blame] | 353 | workspace->level = level; |
| 354 | workspace->req_level = level; |
| 355 | workspace->last_used = jiffies; |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 356 | workspace->mem = kvmalloc(workspace->size, GFP_KERNEL); |
| 357 | workspace->buf = kmalloc(PAGE_SIZE, GFP_KERNEL); |
| 358 | if (!workspace->mem || !workspace->buf) |
| 359 | goto fail; |
| 360 | |
| 361 | INIT_LIST_HEAD(&workspace->list); |
Dennis Zhou | 3f93aef | 2019-02-04 15:20:08 -0500 | [diff] [blame] | 362 | INIT_LIST_HEAD(&workspace->lru_list); |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 363 | |
| 364 | return &workspace->list; |
| 365 | fail: |
| 366 | zstd_free_workspace(&workspace->list); |
| 367 | return ERR_PTR(-ENOMEM); |
| 368 | } |
| 369 | |
David Sterba | c4bf665 | 2019-10-01 22:38:34 +0200 | [diff] [blame^] | 370 | int zstd_compress_pages(struct list_head *ws, struct address_space *mapping, |
| 371 | u64 start, struct page **pages, unsigned long *out_pages, |
| 372 | unsigned long *total_in, unsigned long *total_out) |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 373 | { |
| 374 | struct workspace *workspace = list_entry(ws, struct workspace, list); |
| 375 | ZSTD_CStream *stream; |
| 376 | int ret = 0; |
| 377 | int nr_pages = 0; |
| 378 | struct page *in_page = NULL; /* The current page to read */ |
| 379 | struct page *out_page = NULL; /* The current page to write to */ |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 380 | unsigned long tot_in = 0; |
| 381 | unsigned long tot_out = 0; |
| 382 | unsigned long len = *total_out; |
| 383 | const unsigned long nr_dest_pages = *out_pages; |
| 384 | unsigned long max_out = nr_dest_pages * PAGE_SIZE; |
Dennis Zhou | e0dc87a | 2019-02-04 15:20:06 -0500 | [diff] [blame] | 385 | ZSTD_parameters params = zstd_get_btrfs_parameters(workspace->req_level, |
| 386 | len); |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 387 | |
| 388 | *out_pages = 0; |
| 389 | *total_out = 0; |
| 390 | *total_in = 0; |
| 391 | |
| 392 | /* Initialize the stream */ |
| 393 | stream = ZSTD_initCStream(params, len, workspace->mem, |
| 394 | workspace->size); |
| 395 | if (!stream) { |
| 396 | pr_warn("BTRFS: ZSTD_initCStream failed\n"); |
| 397 | ret = -EIO; |
| 398 | goto out; |
| 399 | } |
| 400 | |
| 401 | /* map in the first page of input data */ |
| 402 | in_page = find_get_page(mapping, start >> PAGE_SHIFT); |
David Sterba | 431e982 | 2017-11-15 18:27:39 +0100 | [diff] [blame] | 403 | workspace->in_buf.src = kmap(in_page); |
| 404 | workspace->in_buf.pos = 0; |
| 405 | workspace->in_buf.size = min_t(size_t, len, PAGE_SIZE); |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 406 | |
| 407 | |
| 408 | /* Allocate and map in the output buffer */ |
| 409 | out_page = alloc_page(GFP_NOFS | __GFP_HIGHMEM); |
| 410 | if (out_page == NULL) { |
| 411 | ret = -ENOMEM; |
| 412 | goto out; |
| 413 | } |
| 414 | pages[nr_pages++] = out_page; |
David Sterba | 431e982 | 2017-11-15 18:27:39 +0100 | [diff] [blame] | 415 | workspace->out_buf.dst = kmap(out_page); |
| 416 | workspace->out_buf.pos = 0; |
| 417 | workspace->out_buf.size = min_t(size_t, max_out, PAGE_SIZE); |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 418 | |
| 419 | while (1) { |
| 420 | size_t ret2; |
| 421 | |
David Sterba | 431e982 | 2017-11-15 18:27:39 +0100 | [diff] [blame] | 422 | ret2 = ZSTD_compressStream(stream, &workspace->out_buf, |
| 423 | &workspace->in_buf); |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 424 | if (ZSTD_isError(ret2)) { |
| 425 | pr_debug("BTRFS: ZSTD_compressStream returned %d\n", |
| 426 | ZSTD_getErrorCode(ret2)); |
| 427 | ret = -EIO; |
| 428 | goto out; |
| 429 | } |
| 430 | |
| 431 | /* Check to see if we are making it bigger */ |
David Sterba | 431e982 | 2017-11-15 18:27:39 +0100 | [diff] [blame] | 432 | if (tot_in + workspace->in_buf.pos > 8192 && |
| 433 | tot_in + workspace->in_buf.pos < |
| 434 | tot_out + workspace->out_buf.pos) { |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 435 | ret = -E2BIG; |
| 436 | goto out; |
| 437 | } |
| 438 | |
| 439 | /* We've reached the end of our output range */ |
David Sterba | 431e982 | 2017-11-15 18:27:39 +0100 | [diff] [blame] | 440 | if (workspace->out_buf.pos >= max_out) { |
| 441 | tot_out += workspace->out_buf.pos; |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 442 | ret = -E2BIG; |
| 443 | goto out; |
| 444 | } |
| 445 | |
| 446 | /* Check if we need more output space */ |
David Sterba | 431e982 | 2017-11-15 18:27:39 +0100 | [diff] [blame] | 447 | if (workspace->out_buf.pos == workspace->out_buf.size) { |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 448 | tot_out += PAGE_SIZE; |
| 449 | max_out -= PAGE_SIZE; |
| 450 | kunmap(out_page); |
| 451 | if (nr_pages == nr_dest_pages) { |
| 452 | out_page = NULL; |
| 453 | ret = -E2BIG; |
| 454 | goto out; |
| 455 | } |
| 456 | out_page = alloc_page(GFP_NOFS | __GFP_HIGHMEM); |
| 457 | if (out_page == NULL) { |
| 458 | ret = -ENOMEM; |
| 459 | goto out; |
| 460 | } |
| 461 | pages[nr_pages++] = out_page; |
David Sterba | 431e982 | 2017-11-15 18:27:39 +0100 | [diff] [blame] | 462 | workspace->out_buf.dst = kmap(out_page); |
| 463 | workspace->out_buf.pos = 0; |
| 464 | workspace->out_buf.size = min_t(size_t, max_out, |
| 465 | PAGE_SIZE); |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | /* We've reached the end of the input */ |
David Sterba | 431e982 | 2017-11-15 18:27:39 +0100 | [diff] [blame] | 469 | if (workspace->in_buf.pos >= len) { |
| 470 | tot_in += workspace->in_buf.pos; |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 471 | break; |
| 472 | } |
| 473 | |
| 474 | /* Check if we need more input */ |
David Sterba | 431e982 | 2017-11-15 18:27:39 +0100 | [diff] [blame] | 475 | if (workspace->in_buf.pos == workspace->in_buf.size) { |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 476 | tot_in += PAGE_SIZE; |
| 477 | kunmap(in_page); |
| 478 | put_page(in_page); |
| 479 | |
| 480 | start += PAGE_SIZE; |
| 481 | len -= PAGE_SIZE; |
| 482 | in_page = find_get_page(mapping, start >> PAGE_SHIFT); |
David Sterba | 431e982 | 2017-11-15 18:27:39 +0100 | [diff] [blame] | 483 | workspace->in_buf.src = kmap(in_page); |
| 484 | workspace->in_buf.pos = 0; |
| 485 | workspace->in_buf.size = min_t(size_t, len, PAGE_SIZE); |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 486 | } |
| 487 | } |
| 488 | while (1) { |
| 489 | size_t ret2; |
| 490 | |
David Sterba | 431e982 | 2017-11-15 18:27:39 +0100 | [diff] [blame] | 491 | ret2 = ZSTD_endStream(stream, &workspace->out_buf); |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 492 | if (ZSTD_isError(ret2)) { |
| 493 | pr_debug("BTRFS: ZSTD_endStream returned %d\n", |
| 494 | ZSTD_getErrorCode(ret2)); |
| 495 | ret = -EIO; |
| 496 | goto out; |
| 497 | } |
| 498 | if (ret2 == 0) { |
David Sterba | 431e982 | 2017-11-15 18:27:39 +0100 | [diff] [blame] | 499 | tot_out += workspace->out_buf.pos; |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 500 | break; |
| 501 | } |
David Sterba | 431e982 | 2017-11-15 18:27:39 +0100 | [diff] [blame] | 502 | if (workspace->out_buf.pos >= max_out) { |
| 503 | tot_out += workspace->out_buf.pos; |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 504 | ret = -E2BIG; |
| 505 | goto out; |
| 506 | } |
| 507 | |
| 508 | tot_out += PAGE_SIZE; |
| 509 | max_out -= PAGE_SIZE; |
| 510 | kunmap(out_page); |
| 511 | if (nr_pages == nr_dest_pages) { |
| 512 | out_page = NULL; |
| 513 | ret = -E2BIG; |
| 514 | goto out; |
| 515 | } |
| 516 | out_page = alloc_page(GFP_NOFS | __GFP_HIGHMEM); |
| 517 | if (out_page == NULL) { |
| 518 | ret = -ENOMEM; |
| 519 | goto out; |
| 520 | } |
| 521 | pages[nr_pages++] = out_page; |
David Sterba | 431e982 | 2017-11-15 18:27:39 +0100 | [diff] [blame] | 522 | workspace->out_buf.dst = kmap(out_page); |
| 523 | workspace->out_buf.pos = 0; |
| 524 | workspace->out_buf.size = min_t(size_t, max_out, PAGE_SIZE); |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | if (tot_out >= tot_in) { |
| 528 | ret = -E2BIG; |
| 529 | goto out; |
| 530 | } |
| 531 | |
| 532 | ret = 0; |
| 533 | *total_in = tot_in; |
| 534 | *total_out = tot_out; |
| 535 | out: |
| 536 | *out_pages = nr_pages; |
| 537 | /* Cleanup */ |
| 538 | if (in_page) { |
| 539 | kunmap(in_page); |
| 540 | put_page(in_page); |
| 541 | } |
| 542 | if (out_page) |
| 543 | kunmap(out_page); |
| 544 | return ret; |
| 545 | } |
| 546 | |
David Sterba | c4bf665 | 2019-10-01 22:38:34 +0200 | [diff] [blame^] | 547 | int zstd_decompress_bio(struct list_head *ws, struct compressed_bio *cb) |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 548 | { |
| 549 | struct workspace *workspace = list_entry(ws, struct workspace, list); |
| 550 | struct page **pages_in = cb->compressed_pages; |
| 551 | u64 disk_start = cb->start; |
| 552 | struct bio *orig_bio = cb->orig_bio; |
| 553 | size_t srclen = cb->compressed_len; |
| 554 | ZSTD_DStream *stream; |
| 555 | int ret = 0; |
| 556 | unsigned long page_in_index = 0; |
| 557 | unsigned long total_pages_in = DIV_ROUND_UP(srclen, PAGE_SIZE); |
| 558 | unsigned long buf_start; |
| 559 | unsigned long total_out = 0; |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 560 | |
| 561 | stream = ZSTD_initDStream( |
| 562 | ZSTD_BTRFS_MAX_INPUT, workspace->mem, workspace->size); |
| 563 | if (!stream) { |
| 564 | pr_debug("BTRFS: ZSTD_initDStream failed\n"); |
| 565 | ret = -EIO; |
| 566 | goto done; |
| 567 | } |
| 568 | |
David Sterba | 431e982 | 2017-11-15 18:27:39 +0100 | [diff] [blame] | 569 | workspace->in_buf.src = kmap(pages_in[page_in_index]); |
| 570 | workspace->in_buf.pos = 0; |
| 571 | workspace->in_buf.size = min_t(size_t, srclen, PAGE_SIZE); |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 572 | |
David Sterba | 431e982 | 2017-11-15 18:27:39 +0100 | [diff] [blame] | 573 | workspace->out_buf.dst = workspace->buf; |
| 574 | workspace->out_buf.pos = 0; |
| 575 | workspace->out_buf.size = PAGE_SIZE; |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 576 | |
| 577 | while (1) { |
| 578 | size_t ret2; |
| 579 | |
David Sterba | 431e982 | 2017-11-15 18:27:39 +0100 | [diff] [blame] | 580 | ret2 = ZSTD_decompressStream(stream, &workspace->out_buf, |
| 581 | &workspace->in_buf); |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 582 | if (ZSTD_isError(ret2)) { |
| 583 | pr_debug("BTRFS: ZSTD_decompressStream returned %d\n", |
| 584 | ZSTD_getErrorCode(ret2)); |
| 585 | ret = -EIO; |
| 586 | goto done; |
| 587 | } |
| 588 | buf_start = total_out; |
David Sterba | 431e982 | 2017-11-15 18:27:39 +0100 | [diff] [blame] | 589 | total_out += workspace->out_buf.pos; |
| 590 | workspace->out_buf.pos = 0; |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 591 | |
David Sterba | 431e982 | 2017-11-15 18:27:39 +0100 | [diff] [blame] | 592 | ret = btrfs_decompress_buf2page(workspace->out_buf.dst, |
| 593 | buf_start, total_out, disk_start, orig_bio); |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 594 | if (ret == 0) |
| 595 | break; |
| 596 | |
David Sterba | 431e982 | 2017-11-15 18:27:39 +0100 | [diff] [blame] | 597 | if (workspace->in_buf.pos >= srclen) |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 598 | break; |
| 599 | |
| 600 | /* Check if we've hit the end of a frame */ |
| 601 | if (ret2 == 0) |
| 602 | break; |
| 603 | |
David Sterba | 431e982 | 2017-11-15 18:27:39 +0100 | [diff] [blame] | 604 | if (workspace->in_buf.pos == workspace->in_buf.size) { |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 605 | kunmap(pages_in[page_in_index++]); |
| 606 | if (page_in_index >= total_pages_in) { |
David Sterba | 431e982 | 2017-11-15 18:27:39 +0100 | [diff] [blame] | 607 | workspace->in_buf.src = NULL; |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 608 | ret = -EIO; |
| 609 | goto done; |
| 610 | } |
| 611 | srclen -= PAGE_SIZE; |
David Sterba | 431e982 | 2017-11-15 18:27:39 +0100 | [diff] [blame] | 612 | workspace->in_buf.src = kmap(pages_in[page_in_index]); |
| 613 | workspace->in_buf.pos = 0; |
| 614 | workspace->in_buf.size = min_t(size_t, srclen, PAGE_SIZE); |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 615 | } |
| 616 | } |
| 617 | ret = 0; |
| 618 | zero_fill_bio(orig_bio); |
| 619 | done: |
David Sterba | 431e982 | 2017-11-15 18:27:39 +0100 | [diff] [blame] | 620 | if (workspace->in_buf.src) |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 621 | kunmap(pages_in[page_in_index]); |
| 622 | return ret; |
| 623 | } |
| 624 | |
David Sterba | c4bf665 | 2019-10-01 22:38:34 +0200 | [diff] [blame^] | 625 | int zstd_decompress(struct list_head *ws, unsigned char *data_in, |
| 626 | struct page *dest_page, unsigned long start_byte, size_t srclen, |
| 627 | size_t destlen) |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 628 | { |
| 629 | struct workspace *workspace = list_entry(ws, struct workspace, list); |
| 630 | ZSTD_DStream *stream; |
| 631 | int ret = 0; |
| 632 | size_t ret2; |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 633 | unsigned long total_out = 0; |
| 634 | unsigned long pg_offset = 0; |
| 635 | char *kaddr; |
| 636 | |
| 637 | stream = ZSTD_initDStream( |
| 638 | ZSTD_BTRFS_MAX_INPUT, workspace->mem, workspace->size); |
| 639 | if (!stream) { |
| 640 | pr_warn("BTRFS: ZSTD_initDStream failed\n"); |
| 641 | ret = -EIO; |
| 642 | goto finish; |
| 643 | } |
| 644 | |
| 645 | destlen = min_t(size_t, destlen, PAGE_SIZE); |
| 646 | |
David Sterba | 431e982 | 2017-11-15 18:27:39 +0100 | [diff] [blame] | 647 | workspace->in_buf.src = data_in; |
| 648 | workspace->in_buf.pos = 0; |
| 649 | workspace->in_buf.size = srclen; |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 650 | |
David Sterba | 431e982 | 2017-11-15 18:27:39 +0100 | [diff] [blame] | 651 | workspace->out_buf.dst = workspace->buf; |
| 652 | workspace->out_buf.pos = 0; |
| 653 | workspace->out_buf.size = PAGE_SIZE; |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 654 | |
| 655 | ret2 = 1; |
David Sterba | 431e982 | 2017-11-15 18:27:39 +0100 | [diff] [blame] | 656 | while (pg_offset < destlen |
| 657 | && workspace->in_buf.pos < workspace->in_buf.size) { |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 658 | unsigned long buf_start; |
| 659 | unsigned long buf_offset; |
| 660 | unsigned long bytes; |
| 661 | |
| 662 | /* Check if the frame is over and we still need more input */ |
| 663 | if (ret2 == 0) { |
| 664 | pr_debug("BTRFS: ZSTD_decompressStream ended early\n"); |
| 665 | ret = -EIO; |
| 666 | goto finish; |
| 667 | } |
David Sterba | 431e982 | 2017-11-15 18:27:39 +0100 | [diff] [blame] | 668 | ret2 = ZSTD_decompressStream(stream, &workspace->out_buf, |
| 669 | &workspace->in_buf); |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 670 | if (ZSTD_isError(ret2)) { |
| 671 | pr_debug("BTRFS: ZSTD_decompressStream returned %d\n", |
| 672 | ZSTD_getErrorCode(ret2)); |
| 673 | ret = -EIO; |
| 674 | goto finish; |
| 675 | } |
| 676 | |
| 677 | buf_start = total_out; |
David Sterba | 431e982 | 2017-11-15 18:27:39 +0100 | [diff] [blame] | 678 | total_out += workspace->out_buf.pos; |
| 679 | workspace->out_buf.pos = 0; |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 680 | |
| 681 | if (total_out <= start_byte) |
| 682 | continue; |
| 683 | |
| 684 | if (total_out > start_byte && buf_start < start_byte) |
| 685 | buf_offset = start_byte - buf_start; |
| 686 | else |
| 687 | buf_offset = 0; |
| 688 | |
| 689 | bytes = min_t(unsigned long, destlen - pg_offset, |
David Sterba | 431e982 | 2017-11-15 18:27:39 +0100 | [diff] [blame] | 690 | workspace->out_buf.size - buf_offset); |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 691 | |
| 692 | kaddr = kmap_atomic(dest_page); |
David Sterba | 431e982 | 2017-11-15 18:27:39 +0100 | [diff] [blame] | 693 | memcpy(kaddr + pg_offset, workspace->out_buf.dst + buf_offset, |
| 694 | bytes); |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 695 | kunmap_atomic(kaddr); |
| 696 | |
| 697 | pg_offset += bytes; |
| 698 | } |
| 699 | ret = 0; |
| 700 | finish: |
| 701 | if (pg_offset < destlen) { |
| 702 | kaddr = kmap_atomic(dest_page); |
| 703 | memset(kaddr + pg_offset, 0, destlen - pg_offset); |
| 704 | kunmap_atomic(kaddr); |
| 705 | } |
| 706 | return ret; |
| 707 | } |
| 708 | |
| 709 | const struct btrfs_compress_op btrfs_zstd_compress = { |
Dennis Zhou | 92ee5530 | 2019-02-04 15:20:03 -0500 | [diff] [blame] | 710 | .init_workspace_manager = zstd_init_workspace_manager, |
| 711 | .cleanup_workspace_manager = zstd_cleanup_workspace_manager, |
| 712 | .get_workspace = zstd_get_workspace, |
| 713 | .put_workspace = zstd_put_workspace, |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 714 | .alloc_workspace = zstd_alloc_workspace, |
| 715 | .free_workspace = zstd_free_workspace, |
| 716 | .compress_pages = zstd_compress_pages, |
| 717 | .decompress_bio = zstd_decompress_bio, |
| 718 | .decompress = zstd_decompress, |
David Sterba | e18333a | 2019-08-09 16:25:34 +0200 | [diff] [blame] | 719 | .max_level = ZSTD_BTRFS_MAX_LEVEL, |
| 720 | .default_level = ZSTD_BTRFS_DEFAULT_LEVEL, |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 721 | }; |