Skip to content

Commit d20f395

Browse files
committed
btrfs: compression: export alloc/free/get/put callbacks of all algos
The indirect calls will be replaced by a switch in compression.c. (Switch is faster than indirect calls with when Spectre mitigations are enabled). Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de> Reviewed-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 2510307 commit d20f395

4 files changed

Lines changed: 26 additions & 15 deletions

File tree

‎fs/btrfs/compression.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ int zlib_decompress_bio(struct list_head *ws, struct compressed_bio *cb);
3636
int zlib_decompress(struct list_head *ws, unsigned char *data_in,
3737
struct page *dest_page, unsigned long start_byte, size_t srclen,
3838
size_t destlen);
39+
struct list_head *zlib_alloc_workspace(unsigned int level);
40+
void zlib_free_workspace(struct list_head *ws);
41+
struct list_head *zlib_get_workspace(unsigned int level);
42+
void zlib_put_workspace(struct list_head *ws);
3943

4044
int lzo_compress_pages(struct list_head *ws, struct address_space *mapping,
4145
u64 start, struct page **pages, unsigned long *out_pages,
@@ -44,6 +48,10 @@ int lzo_decompress_bio(struct list_head *ws, struct compressed_bio *cb);
4448
int lzo_decompress(struct list_head *ws, unsigned char *data_in,
4549
struct page *dest_page, unsigned long start_byte, size_t srclen,
4650
size_t destlen);
51+
struct list_head *lzo_alloc_workspace(unsigned int level);
52+
void lzo_free_workspace(struct list_head *ws);
53+
struct list_head *lzo_get_workspace(unsigned int level);
54+
void lzo_put_workspace(struct list_head *ws);
4755

4856
int zstd_compress_pages(struct list_head *ws, struct address_space *mapping,
4957
u64 start, struct page **pages, unsigned long *out_pages,
@@ -54,6 +62,10 @@ int zstd_decompress(struct list_head *ws, unsigned char *data_in,
5462
size_t destlen);
5563
void zstd_init_workspace_manager(void);
5664
void zstd_cleanup_workspace_manager(void);
65+
struct list_head *zstd_alloc_workspace(unsigned int level);
66+
void zstd_free_workspace(struct list_head *ws);
67+
struct list_head *zstd_get_workspace(unsigned int level);
68+
void zstd_put_workspace(struct list_head *ws);
5769

5870
static const char* const btrfs_compress_types[] = { "", "zlib", "lzo", "zstd" };
5971

‎fs/btrfs/lzo.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,17 @@ struct workspace {
6363

6464
static struct workspace_manager wsm;
6565

66-
static struct list_head *lzo_get_workspace(unsigned int level)
66+
struct list_head *lzo_get_workspace(unsigned int level)
6767
{
6868
return btrfs_get_workspace(&wsm, level);
6969
}
7070

71-
static void lzo_put_workspace(struct list_head *ws)
71+
void lzo_put_workspace(struct list_head *ws)
7272
{
7373
btrfs_put_workspace(&wsm, ws);
7474
}
7575

76-
static void lzo_free_workspace(struct list_head *ws)
76+
void lzo_free_workspace(struct list_head *ws)
7777
{
7878
struct workspace *workspace = list_entry(ws, struct workspace, list);
7979

@@ -83,7 +83,7 @@ static void lzo_free_workspace(struct list_head *ws)
8383
kfree(workspace);
8484
}
8585

86-
static struct list_head *lzo_alloc_workspace(unsigned int level)
86+
struct list_head *lzo_alloc_workspace(unsigned int level)
8787
{
8888
struct workspace *workspace;
8989

‎fs/btrfs/zlib.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct workspace {
2929

3030
static struct workspace_manager wsm;
3131

32-
static struct list_head *zlib_get_workspace(unsigned int level)
32+
struct list_head *zlib_get_workspace(unsigned int level)
3333
{
3434
struct list_head *ws = btrfs_get_workspace(&wsm, level);
3535
struct workspace *workspace = list_entry(ws, struct workspace, list);
@@ -39,12 +39,12 @@ static struct list_head *zlib_get_workspace(unsigned int level)
3939
return ws;
4040
}
4141

42-
static void zlib_put_workspace(struct list_head *ws)
42+
void zlib_put_workspace(struct list_head *ws)
4343
{
4444
btrfs_put_workspace(&wsm, ws);
4545
}
4646

47-
static void zlib_free_workspace(struct list_head *ws)
47+
void zlib_free_workspace(struct list_head *ws)
4848
{
4949
struct workspace *workspace = list_entry(ws, struct workspace, list);
5050

@@ -53,7 +53,7 @@ static void zlib_free_workspace(struct list_head *ws)
5353
kfree(workspace);
5454
}
5555

56-
static struct list_head *zlib_alloc_workspace(unsigned int level)
56+
struct list_head *zlib_alloc_workspace(unsigned int level)
5757
{
5858
struct workspace *workspace;
5959
int workspacesize;

‎fs/btrfs/zstd.c‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,8 @@ static inline struct workspace *list_to_workspace(struct list_head *list)
9191
return container_of(list, struct workspace, list);
9292
}
9393

94-
static void zstd_free_workspace(struct list_head *ws);
95-
static struct list_head *zstd_alloc_workspace(unsigned int level);
96-
94+
void zstd_free_workspace(struct list_head *ws);
95+
struct list_head *zstd_alloc_workspace(unsigned int level);
9796
/*
9897
* zstd_reclaim_timer_fn - reclaim timer
9998
* @t: timer
@@ -261,7 +260,7 @@ static struct list_head *zstd_find_workspace(unsigned int level)
261260
* attempt to allocate a new workspace. If we fail to allocate one due to
262261
* memory pressure, go to sleep waiting for the max level workspace to free up.
263262
*/
264-
static struct list_head *zstd_get_workspace(unsigned int level)
263+
struct list_head *zstd_get_workspace(unsigned int level)
265264
{
266265
struct list_head *ws;
267266
unsigned int nofs_flag;
@@ -302,7 +301,7 @@ static struct list_head *zstd_get_workspace(unsigned int level)
302301
* isn't set, it is also set here. Only the max level workspace tries and wakes
303302
* up waiting workspaces.
304303
*/
305-
static void zstd_put_workspace(struct list_head *ws)
304+
void zstd_put_workspace(struct list_head *ws)
306305
{
307306
struct workspace *workspace = list_to_workspace(ws);
308307

@@ -332,7 +331,7 @@ static void zstd_put_workspace(struct list_head *ws)
332331
cond_wake_up(&wsm.wait);
333332
}
334333

335-
static void zstd_free_workspace(struct list_head *ws)
334+
void zstd_free_workspace(struct list_head *ws)
336335
{
337336
struct workspace *workspace = list_entry(ws, struct workspace, list);
338337

@@ -341,7 +340,7 @@ static void zstd_free_workspace(struct list_head *ws)
341340
kfree(workspace);
342341
}
343342

344-
static struct list_head *zstd_alloc_workspace(unsigned int level)
343+
struct list_head *zstd_alloc_workspace(unsigned int level)
345344
{
346345
struct workspace *workspace;
347346

0 commit comments

Comments
 (0)