Remove callback indirections in compression code
Subsystems (2)
David Sterba
maintainercover Remove callback indirections in compression code
The series removes all per-compression algorithm callbacks and replaces them with a switches. Lots of indirections are simplified and while it looks nice from design POV, we don't need to over-engineer it as we have only fixed known number of the users and not public API.
The cost of indirect function calls is also higher with enabled mitigations of the spectre vulnerability, so they've been incrementally removed from the whole kernel and from btrfs as well.
David Sterba (15):
btrfs: export compression and decompression callbacks
btrfs: switch compression callbacks to direct calls
btrfs: compression: attach workspace manager to the ops
btrfs: compression: let workspace manager init take only the type
btrfs: compression: inline init_workspace_manager
btrfs: compression: let workspace manager cleanup take only the type
btrfs: compression: inline cleanup_workspace_manager
btrfs: compression: export alloc/free/get/put callbacks of all algos
btrfs: compression: inline get_workspace
btrfs: compression: inline put_workspace
btrfs: compression: pass type to btrfs_get_workspace
btrfs: compression: inline alloc_workspace
btrfs: compression: pass type to btrfs_put_workspace
btrfs: compression: inline free_workspace
btrfs: compression: remove ops pointer from workspace_manager
fs/btrfs/compression.c | 241 +++++++++++++++++++++++++++++++---------- fs/btrfs/compression.h | 39 +------ fs/btrfs/lzo.c | 53 ++------- fs/btrfs/zlib.c | 52 ++------- fs/btrfs/zstd.c | 47 +++----- 5 files changed, 227 insertions(+), 205 deletions(-)
Signature · 1 line
2.23.0
David Sterba
maintainerPATCH 1/15 btrfs: export compression and decompression callbacks
Export compress_pages, decompress_bio and decompress callbacks for all compression algos. The indirect calls will be replaced by a switch.
--- fs/btrfs/compression.c | 24 ++++++++++++++++++++++++ fs/btrfs/lzo.c | 19 +++++++------------ fs/btrfs/zlib.c | 19 +++++++------------ fs/btrfs/zstd.c | 19 +++++++------------ 4 files changed, 45 insertions(+), 36 deletions(-)
fs/btrfs/compression.c +24 -0
@@ -29,6 +29,30 @@#include "extent_io.h" #include "extent_map.h" +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); + +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); + +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); +static const char *const btrfs_compress_types[] = {"" ,"zlib" ,"lzo" ,"zstd" };const char *btrfs_compress_type2str (enum btrfs_compression_type type)
fs/btrfs/lzo.c +7 -12
@@ -131,13 +131,9 @@ static inline size_t read_compress_length(const char *buf)return le32_to_cpu (dlen); } -static 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_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) { struct workspace *workspace = list_entry(ws, struct workspace, list);int ret =0 ;
@@ -303,7 +299,7 @@ static int lzo_compress_pages(struct list_head *ws,return ret; } -static int lzo_decompress_bio (struct list_head *ws,struct compressed_bio *cb) +int lzo_decompress_bio (struct list_head *ws,struct compressed_bio *cb) { struct workspace *workspace = list_entry(ws, struct workspace, list);int ret =0 , ret2;
@@ -444,10 +440,9 @@ static int lzo_decompress_bio(struct list_head *ws, struct compressed_bio *cb)return ret; } -static 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) +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 workspace *workspace = list_entry(ws, struct workspace, list);size_t in_len;
fs/btrfs/zlib.c +7 -12
@@ -88,13 +88,9 @@ static struct list_head *zlib_alloc_workspace(unsigned int level)return ERR_PTR (-ENOMEM ); } -static 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_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) { struct workspace *workspace = list_entry(ws, struct workspace, list);int ret;
@@ -228,7 +224,7 @@ static int zlib_compress_pages(struct list_head *ws,return ret; } -static int zlib_decompress_bio (struct list_head *ws,struct compressed_bio *cb) +int zlib_decompress_bio (struct list_head *ws,struct compressed_bio *cb) { struct workspace *workspace = list_entry(ws, struct workspace, list);int ret =0 , ret2;
@@ -319,10 +315,9 @@ static int zlib_decompress_bio(struct list_head *ws, struct compressed_bio *cb)return ret; } -static 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) +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 workspace *workspace = list_entry(ws, struct workspace, list);int ret =0 ;
fs/btrfs/zstd.c +7 -12
@@ -367,13 +367,9 @@ static struct list_head *zstd_alloc_workspace(unsigned int level)return ERR_PTR (-ENOMEM ); } -static 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_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) { struct workspace *workspace = list_entry(ws, struct workspace, list);ZSTD_CStream *stream;
@@ -548,7 +544,7 @@ static int zstd_compress_pages(struct list_head *ws,return ret; } -static int zstd_decompress_bio (struct list_head *ws,struct compressed_bio *cb) +int zstd_decompress_bio (struct list_head *ws,struct compressed_bio *cb) { struct workspace *workspace = list_entry(ws, struct workspace, list);struct page **pages_in = cb->compressed_pages;
@@ -626,10 +622,9 @@ static int zstd_decompress_bio(struct list_head *ws, struct compressed_bio *cb)return ret; } -static 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) +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) { struct workspace *workspace = list_entry(ws, struct workspace, list);ZSTD_DStream *stream;
Signature · 1 line
2.23.0
David Sterba
maintainerPATCH 2/15 btrfs: switch compression callbacks to direct calls
In reply to David SterbaThe indirect calls bring some overhead due to spectre vulnerability mitigations. The number of cases is small and below the threshold (10-20) where indirect call would be better.
--- fs/btrfs/compression.c | 77 +++++++++++++++++++++++++++++++++++++----- fs/btrfs/compression.h | 17 ---------- fs/btrfs/lzo.c | 3 -- fs/btrfs/zlib.c | 3 -- fs/btrfs/zstd.c | 3 -- 5 files changed, 69 insertions(+), 34 deletions(-)
fs/btrfs/compression.c +69 -8
@@ -86,6 +86,70 @@ bool btrfs_compress_is_valid_type(const char *str, size_t len)return false; } +static int compression_compress_pages (int type,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) +{ +switch (type) { +case BTRFS_COMPRESS_ZLIB : +return zlib_compress_pages (ws, mapping, start, pages, + out_pages, total_in, total_out); +case BTRFS_COMPRESS_LZO : +return lzo_compress_pages (ws, mapping, start, pages, + out_pages, total_in, total_out); +case BTRFS_COMPRESS_ZSTD : +return zstd_compress_pages (ws, mapping, start, pages, + out_pages, total_in, total_out); +case BTRFS_COMPRESS_NONE : +default : +/* +* This can't happen, the type is validated several times +* before we get here. As a sane fallback, return what the +* callers will understand as 'no compression happened'. +*/ +return -E2BIG ; + } +} + +static int compression_decompress_bio (int type,struct list_head *ws, +struct compressed_bio *cb) +{ +switch (type) { +case BTRFS_COMPRESS_ZLIB :return zlib_decompress_bio (ws, cb); +case BTRFS_COMPRESS_LZO :return lzo_decompress_bio (ws, cb); +case BTRFS_COMPRESS_ZSTD :return zstd_decompress_bio (ws, cb); +case BTRFS_COMPRESS_NONE : +default : +/* +* This can't happen, the type is validated several times +* before we get here. +*/ +BUG (); + } +} + +static int compression_decompress (int type,struct list_head *ws, +unsigned char *data_in,struct page *dest_page, +unsigned long start_byte,size_t srclen,size_t destlen) +{ +switch (type) { +case BTRFS_COMPRESS_ZLIB :return zlib_decompress (ws, data_in, dest_page, + start_byte, srclen, destlen); +case BTRFS_COMPRESS_LZO :return lzo_decompress (ws, data_in, dest_page, + start_byte, srclen, destlen); +case BTRFS_COMPRESS_ZSTD :return zstd_decompress (ws, data_in, dest_page, + start_byte, srclen, destlen); +case BTRFS_COMPRESS_NONE : +default : +/* +* This can't happen, the type is validated several times +* before we get here. +*/ +BUG (); + } +} +static int btrfs_decompress_bio (struct compressed_bio *cb); static inline int compressed_bio_size(struct btrfs_fs_info *fs_info,
@@ -1074,10 +1138,8 @@ int btrfs_compress_pages(unsigned int type_level, struct address_space *mapping, level =btrfs_compress_set_level (type, level); workspace =get_workspace (type, level); - ret = btrfs_compress_op[type]->compress_pages (workspace, mapping, - start, pages, - out_pages, - total_in, total_out); + ret =compression_compress_pages (type, workspace, mapping, start, pages, + out_pages, total_in, total_out);put_workspace (type, workspace);return ret; }
@@ -1103,7 +1165,7 @@ static int btrfs_decompress_bio(struct compressed_bio *cb)int type = cb->compress_type; workspace =get_workspace (type,0 ); - ret = btrfs_compress_op[type]->decompress_bio (workspace, cb); + ret =compression_decompress_bio (type, workspace, cb);put_workspace (type, workspace);return ret;
@@ -1121,9 +1183,8 @@ int btrfs_decompress(int type, unsigned char *data_in, struct page *dest_page,int ret; workspace =get_workspace (type,0 ); - ret = btrfs_compress_op[type]->decompress (workspace, data_in, - dest_page, start_byte, - srclen, destlen); + ret =compression_decompress (type, workspace, data_in, dest_page, + start_byte, srclen, destlen);put_workspace (type, workspace);return ret;
fs/btrfs/compression.h +0 -17
@@ -140,23 +140,6 @@ struct btrfs_compress_op {void (*free_workspace)(struct list_head *workspace); -int (*compress_pages)(struct list_head *workspace, -struct address_space *mapping, -u64 start, -struct page **pages, -unsigned long *out_pages, -unsigned long *total_in, -unsigned long *total_out); - -int (*decompress_bio)(struct list_head *workspace, -struct compressed_bio *cb); - -int (*decompress)(struct list_head *workspace, -unsigned char *data_in, -struct page *dest_page, -unsigned long start_byte, -size_t srclen,size_t destlen); -/* Maximum level supported by the compression algorithm */ unsigned int max_level;unsigned int default_level;
fs/btrfs/lzo.c +0 -3
@@ -509,9 +509,6 @@ const struct btrfs_compress_op btrfs_lzo_compress = { .put_workspace = lzo_put_workspace, .alloc_workspace = lzo_alloc_workspace, .free_workspace = lzo_free_workspace, - .compress_pages = lzo_compress_pages, - .decompress_bio = lzo_decompress_bio, - .decompress = lzo_decompress, .max_level = 1, .default_level = 1, };
fs/btrfs/zlib.c +0 -3
@@ -420,9 +420,6 @@ const struct btrfs_compress_op btrfs_zlib_compress = { .put_workspace = zlib_put_workspace, .alloc_workspace = zlib_alloc_workspace, .free_workspace = zlib_free_workspace, - .compress_pages = zlib_compress_pages, - .decompress_bio = zlib_decompress_bio, - .decompress = zlib_decompress, .max_level = 9, .default_level = BTRFS_ZLIB_DEFAULT_LEVEL, };
fs/btrfs/zstd.c +0 -3
@@ -713,9 +713,6 @@ const struct btrfs_compress_op btrfs_zstd_compress = { .put_workspace = zstd_put_workspace, .alloc_workspace = zstd_alloc_workspace, .free_workspace = zstd_free_workspace, - .compress_pages = zstd_compress_pages, - .decompress_bio = zstd_decompress_bio, - .decompress = zstd_decompress, .max_level = ZSTD_BTRFS_MAX_LEVEL, .default_level = ZSTD_BTRFS_DEFAULT_LEVEL, };
Signature · 1 line
2.23.0
David Sterba
maintainerPATCH 3/15 btrfs: compression: attach workspace manager to the ops
In reply to David SterbaThere's a lot of indirection when the generic code calls into algo-specific callbacks to reach the private workspace manager structure and back to the generic code.
To simplify that, export the workspace manager for heuristic, LZO and ZLIB, while ZSTD is going to use it's own manager.
--- fs/btrfs/compression.c | 1 + fs/btrfs/compression.h | 1 + fs/btrfs/lzo.c | 1 + fs/btrfs/zlib.c | 1 + fs/btrfs/zstd.c | 2 ++ 5 files changed, 6 insertions(+)
fs/btrfs/compression.c +1 -0
@@ -920,6 +920,7 @@ static struct list_head *alloc_heuristic_ws(unsigned int level) }const struct btrfs_compress_op btrfs_heuristic_compress = { + .workspace_manager = &heuristic_wsm, .init_workspace_manager = heuristic_init_workspace_manager, .cleanup_workspace_manager = heuristic_cleanup_workspace_manager, .get_workspace = heuristic_get_workspace,
fs/btrfs/compression.h +1 -0
@@ -140,6 +140,7 @@ struct btrfs_compress_op {void (*free_workspace)(struct list_head *workspace); +struct workspace_manager *workspace_manager;/* Maximum level supported by the compression algorithm */ unsigned int max_level;unsigned int default_level;
fs/btrfs/lzo.c +1 -0
@@ -503,6 +503,7 @@ int lzo_decompress(struct list_head *ws, unsigned char *data_in, }const struct btrfs_compress_op btrfs_lzo_compress = { + .workspace_manager = &wsm, .init_workspace_manager = lzo_init_workspace_manager, .cleanup_workspace_manager = lzo_cleanup_workspace_manager, .get_workspace = lzo_get_workspace,
fs/btrfs/zlib.c +1 -0
@@ -414,6 +414,7 @@ int zlib_decompress(struct list_head *ws, unsigned char *data_in, }const struct btrfs_compress_op btrfs_zlib_compress = { + .workspace_manager = &wsm, .init_workspace_manager = zlib_init_workspace_manager, .cleanup_workspace_manager = zlib_cleanup_workspace_manager, .get_workspace = zlib_get_workspace,
fs/btrfs/zstd.c +2 -0
@@ -707,6 +707,8 @@ int zstd_decompress(struct list_head *ws, unsigned char *data_in, }const struct btrfs_compress_op btrfs_zstd_compress = { +/* ZSTD uses own workspace manager */ + .workspace_manager =NULL , .init_workspace_manager = zstd_init_workspace_manager, .cleanup_workspace_manager = zstd_cleanup_workspace_manager, .get_workspace = zstd_get_workspace,
Signature · 1 line
2.23.0
David Sterba
maintainerPATCH 4/15 btrfs: compression: let workspace manager init take only the type
In reply to David SterbaWith the access to the workspace structures, we can look it up together with the compression ops inside the workspace manager init helper.
--- fs/btrfs/compression.c | 7 ++++--- fs/btrfs/compression.h | 3 +-- fs/btrfs/lzo.c | 2 +- fs/btrfs/zlib.c | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-)
fs/btrfs/compression.c +4 -3
@@ -862,7 +862,7 @@ static struct workspace_manager heuristic_wsm;static void heuristic_init_workspace_manager (void ) { -btrfs_init_workspace_manager (&heuristic_wsm, &btrfs_heuristic_compress); +btrfs_init_workspace_manager (BTRFS_COMPRESS_NONE ); }static void heuristic_cleanup_workspace_manager (void )
@@ -937,9 +937,10 @@ static const struct btrfs_compress_op * const btrfs_compress_op[] = { &btrfs_zstd_compress, }; -void btrfs_init_workspace_manager (struct workspace_manager *wsm, -const struct btrfs_compress_op *ops) +void btrfs_init_workspace_manager (int type) { +const struct btrfs_compress_op *ops = btrfs_compress_op[type]; +struct workspace_manager *wsm = ops->workspace_manager;struct list_head *workspace; wsm->ops = ops;
fs/btrfs/compression.h +1 -2
@@ -120,8 +120,7 @@ struct workspace_manager {wait_queue_head_t ws_wait; }; -void btrfs_init_workspace_manager (struct workspace_manager *wsm, -const struct btrfs_compress_op *ops); +void btrfs_init_workspace_manager (int type);struct list_head *btrfs_get_workspace (struct workspace_manager *wsm,unsigned int level);void btrfs_put_workspace (struct workspace_manager *wsm,struct list_head *ws);
fs/btrfs/lzo.c +1 -1
@@ -65,7 +65,7 @@ static struct workspace_manager wsm;static void lzo_init_workspace_manager (void ) { -btrfs_init_workspace_manager (&wsm, &btrfs_lzo_compress); +btrfs_init_workspace_manager (BTRFS_COMPRESS_LZO ); }static void lzo_cleanup_workspace_manager (void )
fs/btrfs/zlib.c +1 -1
@@ -31,7 +31,7 @@ static struct workspace_manager wsm;static void zlib_init_workspace_manager (void ) { -btrfs_init_workspace_manager (&wsm, &btrfs_zlib_compress); +btrfs_init_workspace_manager (BTRFS_COMPRESS_ZLIB ); }static void zlib_cleanup_workspace_manager (void )
Signature · 1 line
2.23.0
David Sterba
maintainerPATCH 5/15 btrfs: compression: inline init_workspace_manager
In reply to David SterbaReplace loop calling to all algos with a list of direct calls to the init manager callback. When that becomes trivial it is replaced by direct call to the helper.
--- fs/btrfs/compression.c | 17 ++++++----------- fs/btrfs/compression.h | 3 --- fs/btrfs/lzo.c | 6 ------ fs/btrfs/zlib.c | 6 ------ fs/btrfs/zstd.c | 3 +-- 5 files changed, 7 insertions(+), 28 deletions(-)
fs/btrfs/compression.c +6 -11
@@ -52,6 +52,7 @@ 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 );static const char *const btrfs_compress_types[] = {"" ,"zlib" ,"lzo" ,"zstd" };
@@ -860,11 +861,6 @@ struct heuristic_ws {static struct workspace_manager heuristic_wsm; -static void heuristic_init_workspace_manager (void ) -{ -btrfs_init_workspace_manager (BTRFS_COMPRESS_NONE ); -} -static void heuristic_cleanup_workspace_manager (void ) {btrfs_cleanup_workspace_manager (&heuristic_wsm);
@@ -921,7 +917,6 @@ static struct list_head *alloc_heuristic_ws(unsigned int level)const struct btrfs_compress_op btrfs_heuristic_compress = { .workspace_manager = &heuristic_wsm, - .init_workspace_manager = heuristic_init_workspace_manager, .cleanup_workspace_manager = heuristic_cleanup_workspace_manager, .get_workspace = heuristic_get_workspace, .put_workspace = heuristic_put_workspace,
@@ -937,7 +932,7 @@ static const struct btrfs_compress_op * const btrfs_compress_op[] = { &btrfs_zstd_compress, }; -void btrfs_init_workspace_manager (int type) +static void btrfs_init_workspace_manager (int type) {const struct btrfs_compress_op *ops = btrfs_compress_op[type];struct workspace_manager *wsm = ops->workspace_manager;
@@ -1194,10 +1189,10 @@ int btrfs_decompress(int type, unsigned char *data_in, struct page *dest_page,void __init btrfs_init_compress (void ) { -int i; - -for (i =0 ; i <BTRFS_NR_WORKSPACE_MANAGERS ; i++) - btrfs_compress_op[i]->init_workspace_manager (); +btrfs_init_workspace_manager (BTRFS_COMPRESS_NONE ); +btrfs_init_workspace_manager (BTRFS_COMPRESS_ZLIB ); +btrfs_init_workspace_manager (BTRFS_COMPRESS_LZO ); +zstd_init_workspace_manager (); }void __cold btrfs_exit_compress (void )
fs/btrfs/compression.h +0 -3
@@ -120,15 +120,12 @@ struct workspace_manager {wait_queue_head_t ws_wait; }; -void btrfs_init_workspace_manager (int type);struct list_head *btrfs_get_workspace (struct workspace_manager *wsm,unsigned int level);void btrfs_put_workspace (struct workspace_manager *wsm,struct list_head *ws);void btrfs_cleanup_workspace_manager (struct workspace_manager *wsm);struct btrfs_compress_op { -void (*init_workspace_manager)(void ); -void (*cleanup_workspace_manager)(void );struct list_head *(*get_workspace)(unsigned int level);
fs/btrfs/lzo.c +0 -6
@@ -63,11 +63,6 @@ struct workspace {static struct workspace_manager wsm; -static void lzo_init_workspace_manager (void ) -{ -btrfs_init_workspace_manager (BTRFS_COMPRESS_LZO ); -} -static void lzo_cleanup_workspace_manager (void ) {btrfs_cleanup_workspace_manager (&wsm);
@@ -504,7 +499,6 @@ int lzo_decompress(struct list_head *ws, unsigned char *data_in,const struct btrfs_compress_op btrfs_lzo_compress = { .workspace_manager = &wsm, - .init_workspace_manager = lzo_init_workspace_manager, .cleanup_workspace_manager = lzo_cleanup_workspace_manager, .get_workspace = lzo_get_workspace, .put_workspace = lzo_put_workspace,
fs/btrfs/zlib.c +0 -6
@@ -29,11 +29,6 @@ struct workspace {static struct workspace_manager wsm; -static void zlib_init_workspace_manager (void ) -{ -btrfs_init_workspace_manager (BTRFS_COMPRESS_ZLIB ); -} -static void zlib_cleanup_workspace_manager (void ) {btrfs_cleanup_workspace_manager (&wsm);
@@ -415,7 +410,6 @@ int zlib_decompress(struct list_head *ws, unsigned char *data_in,const struct btrfs_compress_op btrfs_zlib_compress = { .workspace_manager = &wsm, - .init_workspace_manager = zlib_init_workspace_manager, .cleanup_workspace_manager = zlib_cleanup_workspace_manager, .get_workspace = zlib_get_workspace, .put_workspace = zlib_put_workspace,
fs/btrfs/zstd.c +1 -2
@@ -168,7 +168,7 @@ static void zstd_calc_ws_mem_sizes(void) } } -static void zstd_init_workspace_manager (void ) +void zstd_init_workspace_manager (void ) {struct list_head *ws;int i;
@@ -709,7 +709,6 @@ int zstd_decompress(struct list_head *ws, unsigned char *data_in,const struct btrfs_compress_op btrfs_zstd_compress = {/* ZSTD uses own workspace manager */ .workspace_manager =NULL , - .init_workspace_manager = zstd_init_workspace_manager, .cleanup_workspace_manager = zstd_cleanup_workspace_manager, .get_workspace = zstd_get_workspace, .put_workspace = zstd_put_workspace,
Signature · 1 line
2.23.0
David Sterba
maintainerPATCH 6/15 btrfs: compression: let workspace manager cleanup take only the type
In reply to David SterbaWith the access to the workspace structures, we can look it up together with the compression ops inside the workspace manager cleanup helper.
--- fs/btrfs/compression.c | 6 ++++-- fs/btrfs/compression.h | 2 +- fs/btrfs/lzo.c | 2 +- fs/btrfs/zlib.c | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-)
fs/btrfs/compression.c +4 -2
@@ -863,7 +863,7 @@ static struct workspace_manager heuristic_wsm;static void heuristic_cleanup_workspace_manager (void ) { -btrfs_cleanup_workspace_manager (&heuristic_wsm); +btrfs_cleanup_workspace_manager (BTRFS_COMPRESS_NONE ); }static struct list_head *heuristic_get_workspace (unsigned int level)
@@ -960,10 +960,12 @@ static void btrfs_init_workspace_manager(int type) } } -void btrfs_cleanup_workspace_manager (struct workspace_manager *wsman) +void btrfs_cleanup_workspace_manager (int type) { +struct workspace_manager *wsman;struct list_head *ws; + wsman = btrfs_compress_op[type]->workspace_manager;while (!list_empty (&wsman->idle_ws)) { ws = wsman->idle_ws.next;list_del (ws);
fs/btrfs/compression.h +1 -1
@@ -123,7 +123,7 @@ struct workspace_manager {struct list_head *btrfs_get_workspace (struct workspace_manager *wsm,unsigned int level);void btrfs_put_workspace (struct workspace_manager *wsm,struct list_head *ws); -void btrfs_cleanup_workspace_manager (struct workspace_manager *wsm); +void btrfs_cleanup_workspace_manager (int type);struct btrfs_compress_op {void (*cleanup_workspace_manager)(void );
fs/btrfs/lzo.c +1 -1
@@ -65,7 +65,7 @@ static struct workspace_manager wsm;static void lzo_cleanup_workspace_manager (void ) { -btrfs_cleanup_workspace_manager (&wsm); +btrfs_cleanup_workspace_manager (BTRFS_COMPRESS_LZO ); }static struct list_head *lzo_get_workspace (unsigned int level)
fs/btrfs/zlib.c +1 -1
@@ -31,7 +31,7 @@ static struct workspace_manager wsm;static void zlib_cleanup_workspace_manager (void ) { -btrfs_cleanup_workspace_manager (&wsm); +btrfs_cleanup_workspace_manager (BTRFS_COMPRESS_ZLIB ); }static struct list_head *zlib_get_workspace (unsigned int level)
Signature · 1 line
2.23.0
David Sterba
maintainerPATCH 7/15 btrfs: compression: inline cleanup_workspace_manager
In reply to David SterbaReplace loop calling to all algos with a list of direct calls to the cleanup manager callback. When that becomes trivial it is replaced by direct call to the helper.
--- fs/btrfs/compression.c | 17 ++++++----------- fs/btrfs/compression.h | 3 --- fs/btrfs/lzo.c | 6 ------ fs/btrfs/zlib.c | 6 ------ fs/btrfs/zstd.c | 3 +-- 5 files changed, 7 insertions(+), 28 deletions(-)
fs/btrfs/compression.c +6 -11
@@ -53,6 +53,7 @@ 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 );static const char *const btrfs_compress_types[] = {"" ,"zlib" ,"lzo" ,"zstd" };
@@ -861,11 +862,6 @@ struct heuristic_ws {static struct workspace_manager heuristic_wsm; -static void heuristic_cleanup_workspace_manager (void ) -{ -btrfs_cleanup_workspace_manager (BTRFS_COMPRESS_NONE ); -} -static struct list_head *heuristic_get_workspace (unsigned int level) {return btrfs_get_workspace (&heuristic_wsm, level);
@@ -917,7 +913,6 @@ static struct list_head *alloc_heuristic_ws(unsigned int level)const struct btrfs_compress_op btrfs_heuristic_compress = { .workspace_manager = &heuristic_wsm, - .cleanup_workspace_manager = heuristic_cleanup_workspace_manager, .get_workspace = heuristic_get_workspace, .put_workspace = heuristic_put_workspace, .alloc_workspace = alloc_heuristic_ws,
@@ -960,7 +955,7 @@ static void btrfs_init_workspace_manager(int type) } } -void btrfs_cleanup_workspace_manager (int type) +static void btrfs_cleanup_workspace_manager (int type) {struct workspace_manager *wsman;struct list_head *ws;
@@ -1199,10 +1194,10 @@ void __init btrfs_init_compress(void)void __cold btrfs_exit_compress (void ) { -int i; - -for (i =0 ; i <BTRFS_NR_WORKSPACE_MANAGERS ; i++) - btrfs_compress_op[i]->cleanup_workspace_manager (); +btrfs_cleanup_workspace_manager (BTRFS_COMPRESS_NONE ); +btrfs_cleanup_workspace_manager (BTRFS_COMPRESS_ZLIB ); +btrfs_cleanup_workspace_manager (BTRFS_COMPRESS_LZO ); +zstd_cleanup_workspace_manager (); }/*
fs/btrfs/compression.h +0 -3
@@ -123,11 +123,8 @@ struct workspace_manager {struct list_head *btrfs_get_workspace (struct workspace_manager *wsm,unsigned int level);void btrfs_put_workspace (struct workspace_manager *wsm,struct list_head *ws); -void btrfs_cleanup_workspace_manager (int type);struct btrfs_compress_op { -void (*cleanup_workspace_manager)(void ); -struct list_head *(*get_workspace)(unsigned int level);void (*put_workspace)(struct list_head *ws);
fs/btrfs/lzo.c +0 -6
@@ -63,11 +63,6 @@ struct workspace {static struct workspace_manager wsm; -static void lzo_cleanup_workspace_manager (void ) -{ -btrfs_cleanup_workspace_manager (BTRFS_COMPRESS_LZO ); -} -static struct list_head *lzo_get_workspace (unsigned int level) {return btrfs_get_workspace (&wsm, level);
@@ -499,7 +494,6 @@ int lzo_decompress(struct list_head *ws, unsigned char *data_in,const struct btrfs_compress_op btrfs_lzo_compress = { .workspace_manager = &wsm, - .cleanup_workspace_manager = lzo_cleanup_workspace_manager, .get_workspace = lzo_get_workspace, .put_workspace = lzo_put_workspace, .alloc_workspace = lzo_alloc_workspace,
fs/btrfs/zlib.c +0 -6
@@ -29,11 +29,6 @@ struct workspace {static struct workspace_manager wsm; -static void zlib_cleanup_workspace_manager (void ) -{ -btrfs_cleanup_workspace_manager (BTRFS_COMPRESS_ZLIB ); -} -static struct list_head *zlib_get_workspace (unsigned int level) {struct list_head *ws =btrfs_get_workspace (&wsm, level);
@@ -410,7 +405,6 @@ int zlib_decompress(struct list_head *ws, unsigned char *data_in,const struct btrfs_compress_op btrfs_zlib_compress = { .workspace_manager = &wsm, - .cleanup_workspace_manager = zlib_cleanup_workspace_manager, .get_workspace = zlib_get_workspace, .put_workspace = zlib_put_workspace, .alloc_workspace = zlib_alloc_workspace,
fs/btrfs/zstd.c +1 -2
@@ -194,7 +194,7 @@ void zstd_init_workspace_manager(void) } } -static void zstd_cleanup_workspace_manager (void ) +void zstd_cleanup_workspace_manager (void ) {struct workspace *workspace;int i;
@@ -709,7 +709,6 @@ int zstd_decompress(struct list_head *ws, unsigned char *data_in,const struct btrfs_compress_op btrfs_zstd_compress = {/* ZSTD uses own workspace manager */ .workspace_manager =NULL , - .cleanup_workspace_manager = zstd_cleanup_workspace_manager, .get_workspace = zstd_get_workspace, .put_workspace = zstd_put_workspace, .alloc_workspace = zstd_alloc_workspace,
Signature · 1 line
2.23.0
David Sterba
maintainerPATCH 8/15 btrfs: compression: export alloc/free/get/put callbacks of all algos
In reply to David SterbaThe indirect calls will be replaced by a switch in compression.c. (Switch is faster than indirect calls with when Spectre mitigations are enabled).
--- fs/btrfs/compression.c | 12 ++++++++++++ fs/btrfs/lzo.c | 8 ++++---- fs/btrfs/zlib.c | 8 ++++---- fs/btrfs/zstd.c | 13 ++++++------- 4 files changed, 26 insertions(+), 15 deletions(-)
fs/btrfs/compression.c +12 -0
@@ -36,6 +36,10 @@ 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); +void zlib_put_workspace (struct list_head *ws); int lzo_compress_pages(struct list_head *ws, struct address_space *mapping, 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);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); +struct list_head *lzo_get_workspace (unsigned int level); +void lzo_put_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,
@@ -54,6 +62,10 @@ int zstd_decompress(struct list_head *ws, unsigned char *data_in, 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);static const char *const btrfs_compress_types[] = {"" ,"zlib" ,"lzo" ,"zstd" };
fs/btrfs/lzo.c +4 -4
@@ -63,17 +63,17 @@ struct workspace {static struct workspace_manager wsm; -static struct list_head *lzo_get_workspace (unsigned int level) +struct list_head *lzo_get_workspace (unsigned int level) {return btrfs_get_workspace (&wsm, level); } -static void lzo_put_workspace (struct list_head *ws) +void lzo_put_workspace (struct list_head *ws) {btrfs_put_workspace (&wsm, ws); } -static void lzo_free_workspace (struct list_head *ws) +void lzo_free_workspace (struct list_head *ws) { struct workspace *workspace = list_entry(ws, struct workspace, list);
@@ -83,7 +83,7 @@ static void lzo_free_workspace(struct list_head *ws)kfree (workspace); } -static struct list_head *lzo_alloc_workspace (unsigned int level) +struct list_head *lzo_alloc_workspace (unsigned int level) {struct workspace *workspace;
fs/btrfs/zlib.c +4 -4
@@ -29,7 +29,7 @@ struct workspace {static struct workspace_manager wsm; -static struct list_head *zlib_get_workspace (unsigned int level) +struct list_head *zlib_get_workspace (unsigned int level) {struct list_head *ws =btrfs_get_workspace (&wsm, level); struct workspace *workspace = list_entry(ws, struct workspace, list);
@@ -39,12 +39,12 @@ static struct list_head *zlib_get_workspace(unsigned int level)return ws; } -static void zlib_put_workspace (struct list_head *ws) +void zlib_put_workspace (struct list_head *ws) {btrfs_put_workspace (&wsm, ws); } -static void zlib_free_workspace (struct list_head *ws) +void zlib_free_workspace (struct list_head *ws) { struct workspace *workspace = list_entry(ws, struct workspace, list);
@@ -53,7 +53,7 @@ static void zlib_free_workspace(struct list_head *ws)kfree (workspace); } -static struct list_head *zlib_alloc_workspace (unsigned int level) +struct list_head *zlib_alloc_workspace (unsigned int level) {struct workspace *workspace;int workspacesize;
fs/btrfs/zstd.c +6 -7
@@ -91,9 +91,8 @@ static inline struct workspace *list_to_workspace(struct list_head *list) return container_of(list, struct workspace, list); } -static void zstd_free_workspace (struct list_head *ws); -static struct list_head *zstd_alloc_workspace (unsigned int level); - +void zstd_free_workspace (struct list_head *ws); +struct list_head *zstd_alloc_workspace (unsigned int level);/* * zstd_reclaim_timer_fn - reclaim timer * @t: timer
@@ -261,7 +260,7 @@ static struct list_head *zstd_find_workspace(unsigned int level)* attempt to allocate a new workspace. If we fail to allocate one due to * memory pressure, go to sleep waiting for the max level workspace to free up. */ -static struct list_head *zstd_get_workspace (unsigned int level) +struct list_head *zstd_get_workspace (unsigned int level) {struct list_head *ws;unsigned int nofs_flag;
@@ -302,7 +301,7 @@ static struct list_head *zstd_get_workspace(unsigned int level)* isn't set, it is also set here. Only the max level workspace tries and wakes * up waiting workspaces. */ -static void zstd_put_workspace (struct list_head *ws) +void zstd_put_workspace (struct list_head *ws) {struct workspace *workspace =list_to_workspace (ws);
@@ -332,7 +331,7 @@ static void zstd_put_workspace(struct list_head *ws)cond_wake_up (&wsm.wait); } -static void zstd_free_workspace (struct list_head *ws) +void zstd_free_workspace (struct list_head *ws) { struct workspace *workspace = list_entry(ws, struct workspace, list);
@@ -341,7 +340,7 @@ static void zstd_free_workspace(struct list_head *ws)kfree (workspace); } -static struct list_head *zstd_alloc_workspace (unsigned int level) +struct list_head *zstd_alloc_workspace (unsigned int level) {struct workspace *workspace;
Signature · 1 line
2.23.0
David Sterba
maintainerPATCH 9/15 btrfs: compression: inline get_workspace
In reply to David SterbaMajority of the callbacks is trivial, we don't gain anything by the indirection, so replace them by a switch function.
ZLIB needs to adjust level in the callback and ZSTD workspace management is complex, the rest is call to the helper.
--- fs/btrfs/compression.c | 23 +++++++++++++++-------- fs/btrfs/compression.h | 2 -- fs/btrfs/lzo.c | 6 ------ fs/btrfs/zlib.c | 1 - fs/btrfs/zstd.c | 1 - 5 files changed, 15 insertions(+), 18 deletions(-)
fs/btrfs/compression.c +15 -8
@@ -50,7 +50,6 @@ int lzo_decompress(struct list_head *ws, unsigned char *data_in, size_t destlen);struct list_head *lzo_alloc_workspace (unsigned int level);void lzo_free_workspace (struct list_head *ws); -struct list_head *lzo_get_workspace (unsigned int level);void lzo_put_workspace (struct list_head *ws); int zstd_compress_pages(struct list_head *ws, struct address_space *mapping,
@@ -874,11 +873,6 @@ struct heuristic_ws {static struct workspace_manager heuristic_wsm; -static struct list_head *heuristic_get_workspace (unsigned int level) -{ -return btrfs_get_workspace (&heuristic_wsm, level); -} -static void heuristic_put_workspace (struct list_head *ws) {btrfs_put_workspace (&heuristic_wsm, ws);
@@ -925,7 +919,6 @@ static struct list_head *alloc_heuristic_ws(unsigned int level)const struct btrfs_compress_op btrfs_heuristic_compress = { .workspace_manager = &heuristic_wsm, - .get_workspace = heuristic_get_workspace, .put_workspace = heuristic_put_workspace, .alloc_workspace = alloc_heuristic_ws, .free_workspace = free_heuristic_ws,
@@ -1067,7 +1060,21 @@ struct list_head *btrfs_get_workspace(struct workspace_manager *wsm,static struct list_head *get_workspace (int type,int level) { -return btrfs_compress_op[type]->get_workspace (level); +struct workspace_manager *wsm; + + wsm = btrfs_compress_op[type]->workspace_manager; +switch (type) { +case BTRFS_COMPRESS_NONE :return btrfs_get_workspace (wsm, level); +case BTRFS_COMPRESS_ZLIB :return zlib_get_workspace (level); +case BTRFS_COMPRESS_LZO :return btrfs_get_workspace (wsm, level); +case BTRFS_COMPRESS_ZSTD :return zstd_get_workspace (level); +default : +/* +* This can't happen, the type is validated several times +* before we get here. +*/ +BUG (); + } }/*
fs/btrfs/compression.h +0 -2
@@ -125,8 +125,6 @@ struct list_head *btrfs_get_workspace(struct workspace_manager *wsm,void btrfs_put_workspace (struct workspace_manager *wsm,struct list_head *ws);struct btrfs_compress_op { -struct list_head *(*get_workspace)(unsigned int level); -void (*put_workspace)(struct list_head *ws);struct list_head *(*alloc_workspace)(unsigned int level);
fs/btrfs/lzo.c +0 -6
@@ -63,11 +63,6 @@ struct workspace {static struct workspace_manager wsm; -struct list_head *lzo_get_workspace (unsigned int level) -{ -return btrfs_get_workspace (&wsm, level); -} -void lzo_put_workspace (struct list_head *ws) {btrfs_put_workspace (&wsm, ws);
@@ -494,7 +489,6 @@ int lzo_decompress(struct list_head *ws, unsigned char *data_in,const struct btrfs_compress_op btrfs_lzo_compress = { .workspace_manager = &wsm, - .get_workspace = lzo_get_workspace, .put_workspace = lzo_put_workspace, .alloc_workspace = lzo_alloc_workspace, .free_workspace = lzo_free_workspace,
fs/btrfs/zlib.c +0 -1
@@ -405,7 +405,6 @@ int zlib_decompress(struct list_head *ws, unsigned char *data_in,const struct btrfs_compress_op btrfs_zlib_compress = { .workspace_manager = &wsm, - .get_workspace = zlib_get_workspace, .put_workspace = zlib_put_workspace, .alloc_workspace = zlib_alloc_workspace, .free_workspace = zlib_free_workspace,
fs/btrfs/zstd.c +0 -1
@@ -708,7 +708,6 @@ int zstd_decompress(struct list_head *ws, unsigned char *data_in,const struct btrfs_compress_op btrfs_zstd_compress = {/* ZSTD uses own workspace manager */ .workspace_manager =NULL , - .get_workspace = zstd_get_workspace, .put_workspace = zstd_put_workspace, .alloc_workspace = zstd_alloc_workspace, .free_workspace = zstd_free_workspace,
Signature · 1 line
2.23.0
David Sterba
maintainerPATCH 10/15 btrfs: compression: inline put_workspace
In reply to David SterbaSimilar to get_workspace, majority of the callbacks is trivial, we don't gain anything by the indirection, so replace them by a switch function. Trivial callback implementations use the helper.
--- fs/btrfs/compression.c | 24 +++++++++++++++--------- fs/btrfs/compression.h | 2 -- fs/btrfs/lzo.c | 6 ------ fs/btrfs/zlib.c | 6 ------ fs/btrfs/zstd.c | 1 - 5 files changed, 15 insertions(+), 24 deletions(-)
fs/btrfs/compression.c +15 -9
@@ -39,7 +39,6 @@ int zlib_decompress(struct list_head *ws, unsigned char *data_in,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); -void zlib_put_workspace (struct list_head *ws); int lzo_compress_pages(struct list_head *ws, struct address_space *mapping, u64 start, struct page **pages, unsigned long *out_pages,
@@ -50,7 +49,6 @@ int lzo_decompress(struct list_head *ws, unsigned char *data_in, size_t destlen);struct list_head *lzo_alloc_workspace (unsigned int level);void lzo_free_workspace (struct list_head *ws); -void lzo_put_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,
@@ -873,11 +871,6 @@ struct heuristic_ws {static struct workspace_manager heuristic_wsm; -static void heuristic_put_workspace (struct list_head *ws) -{ -btrfs_put_workspace (&heuristic_wsm, ws); -} -static void free_heuristic_ws (struct list_head *ws) {struct heuristic_ws *workspace;
@@ -919,7 +912,6 @@ static struct list_head *alloc_heuristic_ws(unsigned int level)const struct btrfs_compress_op btrfs_heuristic_compress = { .workspace_manager = &heuristic_wsm, - .put_workspace = heuristic_put_workspace, .alloc_workspace = alloc_heuristic_ws, .free_workspace = free_heuristic_ws, };
@@ -1112,7 +1104,21 @@ void btrfs_put_workspace(struct workspace_manager *wsm, struct list_head *ws)static void put_workspace (int type,struct list_head *ws) { -return btrfs_compress_op[type]->put_workspace (ws); +struct workspace_manager *wsm; + + wsm = btrfs_compress_op[type]->workspace_manager; +switch (type) { +case BTRFS_COMPRESS_NONE :return btrfs_put_workspace (wsm, ws); +case BTRFS_COMPRESS_ZLIB :return btrfs_put_workspace (wsm, ws); +case BTRFS_COMPRESS_LZO :return btrfs_put_workspace (wsm, ws); +case BTRFS_COMPRESS_ZSTD :return zstd_put_workspace (ws); +default : +/* +* This can't happen, the type is validated several times +* before we get here. +*/ +BUG (); + } }/*
fs/btrfs/compression.h +0 -2
@@ -125,8 +125,6 @@ struct list_head *btrfs_get_workspace(struct workspace_manager *wsm,void btrfs_put_workspace (struct workspace_manager *wsm,struct list_head *ws);struct btrfs_compress_op { -void (*put_workspace)(struct list_head *ws); -struct list_head *(*alloc_workspace)(unsigned int level);void (*free_workspace)(struct list_head *workspace);
fs/btrfs/lzo.c +0 -6
@@ -63,11 +63,6 @@ struct workspace {static struct workspace_manager wsm; -void lzo_put_workspace (struct list_head *ws) -{ -btrfs_put_workspace (&wsm, ws); -} -void lzo_free_workspace (struct list_head *ws) { struct workspace *workspace = list_entry(ws, struct workspace, list);
@@ -489,7 +484,6 @@ int lzo_decompress(struct list_head *ws, unsigned char *data_in,const struct btrfs_compress_op btrfs_lzo_compress = { .workspace_manager = &wsm, - .put_workspace = lzo_put_workspace, .alloc_workspace = lzo_alloc_workspace, .free_workspace = lzo_free_workspace, .max_level =1 ,
fs/btrfs/zlib.c +0 -6
@@ -39,11 +39,6 @@ struct list_head *zlib_get_workspace(unsigned int level)return ws; } -void zlib_put_workspace (struct list_head *ws) -{ -btrfs_put_workspace (&wsm, ws); -} -void zlib_free_workspace (struct list_head *ws) { struct workspace *workspace = list_entry(ws, struct workspace, list);
@@ -405,7 +400,6 @@ int zlib_decompress(struct list_head *ws, unsigned char *data_in,const struct btrfs_compress_op btrfs_zlib_compress = { .workspace_manager = &wsm, - .put_workspace = zlib_put_workspace, .alloc_workspace = zlib_alloc_workspace, .free_workspace = zlib_free_workspace, .max_level =9 ,
fs/btrfs/zstd.c +0 -1
@@ -708,7 +708,6 @@ int zstd_decompress(struct list_head *ws, unsigned char *data_in,const struct btrfs_compress_op btrfs_zstd_compress = {/* ZSTD uses own workspace manager */ .workspace_manager =NULL , - .put_workspace = zstd_put_workspace, .alloc_workspace = zstd_alloc_workspace, .free_workspace = zstd_free_workspace, .max_level =ZSTD_BTRFS_MAX_LEVEL ,
Signature · 1 line
2.23.0
David Sterba
maintainerPATCH 11/15 btrfs: compression: pass type to btrfs_get_workspace
In reply to David SterbaWe can infer the workspace_manager from type and the type will be used in the following patch to call a common helper for alloc_workspace.
--- fs/btrfs/compression.c | 12 +++++------- fs/btrfs/compression.h | 3 +-- fs/btrfs/zlib.c | 2 +- 3 files changed, 7 insertions(+), 10 deletions(-)
fs/btrfs/compression.c +5 -7
@@ -972,9 +972,9 @@ static void btrfs_cleanup_workspace_manager(int type)* Preallocation makes a forward progress guarantees and we do not return * errors. */ -struct list_head *btrfs_get_workspace (struct workspace_manager *wsm, -unsigned int level) +struct list_head *btrfs_get_workspace (int type,unsigned int level) { +struct workspace_manager *wsm;struct list_head *workspace;int cpus =num_online_cpus ();unsigned nofs_flag;
@@ -984,6 +984,7 @@ struct list_head *btrfs_get_workspace(struct workspace_manager *wsm,wait_queue_head_t *ws_wait;int *free_ws; + wsm = btrfs_compress_op[type]->workspace_manager; idle_ws = &wsm->idle_ws; ws_lock = &wsm->ws_lock; total_ws = &wsm->total_ws;
@@ -1052,13 +1053,10 @@ struct list_head *btrfs_get_workspace(struct workspace_manager *wsm,static struct list_head *get_workspace (int type,int level) { -struct workspace_manager *wsm; - - wsm = btrfs_compress_op[type]->workspace_manager;switch (type) { -case BTRFS_COMPRESS_NONE :return btrfs_get_workspace (wsm, level); +case BTRFS_COMPRESS_NONE :return btrfs_get_workspace (type, level);case BTRFS_COMPRESS_ZLIB :return zlib_get_workspace (level); -case BTRFS_COMPRESS_LZO :return btrfs_get_workspace (wsm, level); +case BTRFS_COMPRESS_LZO :return btrfs_get_workspace (type, level);case BTRFS_COMPRESS_ZSTD :return zstd_get_workspace (level);default :/*
fs/btrfs/compression.h +1 -2
@@ -120,8 +120,7 @@ struct workspace_manager {wait_queue_head_t ws_wait; }; -struct list_head *btrfs_get_workspace (struct workspace_manager *wsm, -unsigned int level); +struct list_head *btrfs_get_workspace (int type,unsigned int level);void btrfs_put_workspace (struct workspace_manager *wsm,struct list_head *ws);struct btrfs_compress_op {
fs/btrfs/zlib.c +1 -1
@@ -31,7 +31,7 @@ static struct workspace_manager wsm;struct list_head *zlib_get_workspace (unsigned int level) { -struct list_head *ws =btrfs_get_workspace (&wsm, level); +struct list_head *ws =btrfs_get_workspace (BTRFS_COMPRESS_ZLIB , level); struct workspace *workspace = list_entry(ws, struct workspace, list); workspace->level = level;
Signature · 1 line
2.23.0
David Sterba
maintainerPATCH 12/15 btrfs: compression: inline alloc_workspace
In reply to David SterbaReplace indirect calls to alloc_workspace by switch and calls to the specific callbacks. This is mainly to get rid of the indirection due to spectre vulnerability mitigations.
--- fs/btrfs/compression.c | 21 ++++++++++++++++++--- fs/btrfs/compression.h | 2 -- fs/btrfs/lzo.c | 1 - fs/btrfs/zlib.c | 1 - fs/btrfs/zstd.c | 1 - 5 files changed, 18 insertions(+), 8 deletions(-)
fs/btrfs/compression.c +18 -3
@@ -912,7 +912,6 @@ static struct list_head *alloc_heuristic_ws(unsigned int level)const struct btrfs_compress_op btrfs_heuristic_compress = { .workspace_manager = &heuristic_wsm, - .alloc_workspace = alloc_heuristic_ws, .free_workspace = free_heuristic_ws, };
@@ -924,6 +923,22 @@ static const struct btrfs_compress_op * const btrfs_compress_op[] = { &btrfs_zstd_compress, }; +static struct list_head *alloc_workspace (int type,unsigned int level) +{ +switch (type) { +case BTRFS_COMPRESS_NONE :return alloc_heuristic_ws (level); +case BTRFS_COMPRESS_ZLIB :return zlib_alloc_workspace (level); +case BTRFS_COMPRESS_LZO :return lzo_alloc_workspace (level); +case BTRFS_COMPRESS_ZSTD :return zstd_alloc_workspace (level); +default : +/* +* This can't happen, the type is validated several times +* before we get here. +*/ +BUG (); + } +} +static void btrfs_init_workspace_manager (int type) {const struct btrfs_compress_op *ops = btrfs_compress_op[type];
@@ -941,7 +956,7 @@ static void btrfs_init_workspace_manager(int type)* Preallocate one workspace for each compression type so we can * guarantee forward progress in the worst case */ - workspace = wsm->ops->alloc_workspace (0 ); + workspace =alloc_workspace (type,0 );if (IS_ERR (workspace)) {pr_warn ("BTRFS: cannot preallocate compression workspace, will try later\n" );
@@ -1020,7 +1035,7 @@ struct list_head *btrfs_get_workspace(int type, unsigned int level)* context of btrfs_compress_bio/btrfs_compress_pages */ nofs_flag =memalloc_nofs_save (); - workspace = wsm->ops->alloc_workspace (level); + workspace =alloc_workspace (type, level);memalloc_nofs_restore (nofs_flag);if (IS_ERR (workspace)) {
fs/btrfs/compression.h +0 -2
@@ -124,8 +124,6 @@ struct list_head *btrfs_get_workspace(int type, unsigned int level);void btrfs_put_workspace (struct workspace_manager *wsm,struct list_head *ws);struct btrfs_compress_op { -struct list_head *(*alloc_workspace)(unsigned int level); -void (*free_workspace)(struct list_head *workspace);struct workspace_manager *workspace_manager;
fs/btrfs/lzo.c +0 -1
@@ -484,7 +484,6 @@ int lzo_decompress(struct list_head *ws, unsigned char *data_in,const struct btrfs_compress_op btrfs_lzo_compress = { .workspace_manager = &wsm, - .alloc_workspace = lzo_alloc_workspace, .free_workspace = lzo_free_workspace, .max_level =1 , .default_level =1 ,
fs/btrfs/zlib.c +0 -1
@@ -400,7 +400,6 @@ int zlib_decompress(struct list_head *ws, unsigned char *data_in,const struct btrfs_compress_op btrfs_zlib_compress = { .workspace_manager = &wsm, - .alloc_workspace = zlib_alloc_workspace, .free_workspace = zlib_free_workspace, .max_level =9 , .default_level =BTRFS_ZLIB_DEFAULT_LEVEL ,
fs/btrfs/zstd.c +0 -1
@@ -708,7 +708,6 @@ int zstd_decompress(struct list_head *ws, unsigned char *data_in,const struct btrfs_compress_op btrfs_zstd_compress = {/* ZSTD uses own workspace manager */ .workspace_manager =NULL , - .alloc_workspace = zstd_alloc_workspace, .free_workspace = zstd_free_workspace, .max_level =ZSTD_BTRFS_MAX_LEVEL , .default_level =ZSTD_BTRFS_DEFAULT_LEVEL ,
Signature · 1 line
2.23.0
David Sterba
maintainerPATCH 13/15 btrfs: compression: pass type to btrfs_put_workspace
In reply to David SterbaWe can infer the workspace_manager from type and the type will be used in the following patch to call a common helper for free_workspace.
--- fs/btrfs/compression.c | 13 ++++++------- fs/btrfs/compression.h | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-)
fs/btrfs/compression.c +6 -7
@@ -1086,14 +1086,16 @@ static struct list_head *get_workspace(int type, int level)* put a workspace struct back on the list or free it if we have enough * idle ones sitting around */ -void btrfs_put_workspace (struct workspace_manager *wsm,struct list_head *ws) +void btrfs_put_workspace (int type,struct list_head *ws) { +struct workspace_manager *wsm;struct list_head *idle_ws;spinlock_t *ws_lock;atomic_t *total_ws;wait_queue_head_t *ws_wait;int *free_ws; + wsm = btrfs_compress_op[type]->workspace_manager; idle_ws = &wsm->idle_ws; ws_lock = &wsm->ws_lock; total_ws = &wsm->total_ws;
@@ -1117,13 +1119,10 @@ void btrfs_put_workspace(struct workspace_manager *wsm, struct list_head *ws)static void put_workspace (int type,struct list_head *ws) { -struct workspace_manager *wsm; - - wsm = btrfs_compress_op[type]->workspace_manager;switch (type) { -case BTRFS_COMPRESS_NONE :return btrfs_put_workspace (wsm, ws); -case BTRFS_COMPRESS_ZLIB :return btrfs_put_workspace (wsm, ws); -case BTRFS_COMPRESS_LZO :return btrfs_put_workspace (wsm, ws); +case BTRFS_COMPRESS_NONE :return btrfs_put_workspace (type, ws); +case BTRFS_COMPRESS_ZLIB :return btrfs_put_workspace (type, ws); +case BTRFS_COMPRESS_LZO :return btrfs_put_workspace (type, ws);case BTRFS_COMPRESS_ZSTD :return zstd_put_workspace (ws);default :/*
fs/btrfs/compression.h +1 -1
@@ -121,7 +121,7 @@ struct workspace_manager { };struct list_head *btrfs_get_workspace (int type,unsigned int level); -void btrfs_put_workspace (struct workspace_manager *wsm,struct list_head *ws); +void btrfs_put_workspace (int type,struct list_head *ws);struct btrfs_compress_op {void (*free_workspace)(struct list_head *workspace);
Signature · 1 line
2.23.0
David Sterba
maintainerPATCH 14/15 btrfs: compression: inline free_workspace
In reply to David SterbaReplace indirect calls to free_workspace by switch and calls to the specific callbacks. This is mainly to get rid of the indirection due to spectre vulnerability mitigations.
--- fs/btrfs/compression.c | 21 ++++++++++++++++++--- fs/btrfs/compression.h | 2 -- fs/btrfs/lzo.c | 1 - fs/btrfs/zlib.c | 1 - fs/btrfs/zstd.c | 1 - 5 files changed, 18 insertions(+), 8 deletions(-)
fs/btrfs/compression.c +18 -3
@@ -912,7 +912,6 @@ static struct list_head *alloc_heuristic_ws(unsigned int level)const struct btrfs_compress_op btrfs_heuristic_compress = { .workspace_manager = &heuristic_wsm, - .free_workspace = free_heuristic_ws, };static const struct btrfs_compress_op *const btrfs_compress_op[] = {
@@ -939,6 +938,22 @@ static struct list_head *alloc_workspace(int type, unsigned int level) } } +static void free_workspace (int type,struct list_head *ws) +{ +switch (type) { +case BTRFS_COMPRESS_NONE :return free_heuristic_ws (ws); +case BTRFS_COMPRESS_ZLIB :return zlib_free_workspace (ws); +case BTRFS_COMPRESS_LZO :return lzo_free_workspace (ws); +case BTRFS_COMPRESS_ZSTD :return zstd_free_workspace (ws); +default : +/* +* This can't happen, the type is validated several times +* before we get here. +*/ +BUG (); + } +} +static void btrfs_init_workspace_manager (int type) {const struct btrfs_compress_op *ops = btrfs_compress_op[type];
@@ -976,7 +991,7 @@ static void btrfs_cleanup_workspace_manager(int type)while (!list_empty (&wsman->idle_ws)) { ws = wsman->idle_ws.next;list_del (ws); - wsman->ops->free_workspace (ws); +free_workspace (type, ws);atomic_dec (&wsman->total_ws); } }
@@ -1111,7 +1126,7 @@ void btrfs_put_workspace(int type, struct list_head *ws) }spin_unlock (ws_lock); - wsm->ops->free_workspace (ws); +free_workspace (type, ws);atomic_dec (total_ws); wake:cond_wake_up (ws_wait);
fs/btrfs/compression.h +0 -2
@@ -124,8 +124,6 @@ struct list_head *btrfs_get_workspace(int type, unsigned int level);void btrfs_put_workspace (int type,struct list_head *ws);struct btrfs_compress_op { -void (*free_workspace)(struct list_head *workspace); -struct workspace_manager *workspace_manager;/* Maximum level supported by the compression algorithm */ unsigned int max_level;
fs/btrfs/lzo.c +0 -1
@@ -484,7 +484,6 @@ int lzo_decompress(struct list_head *ws, unsigned char *data_in,const struct btrfs_compress_op btrfs_lzo_compress = { .workspace_manager = &wsm, - .free_workspace = lzo_free_workspace, .max_level =1 , .default_level =1 , };
fs/btrfs/zlib.c +0 -1
@@ -400,7 +400,6 @@ int zlib_decompress(struct list_head *ws, unsigned char *data_in,const struct btrfs_compress_op btrfs_zlib_compress = { .workspace_manager = &wsm, - .free_workspace = zlib_free_workspace, .max_level =9 , .default_level =BTRFS_ZLIB_DEFAULT_LEVEL , };
fs/btrfs/zstd.c +0 -1
@@ -708,7 +708,6 @@ int zstd_decompress(struct list_head *ws, unsigned char *data_in,const struct btrfs_compress_op btrfs_zstd_compress = {/* ZSTD uses own workspace manager */ .workspace_manager =NULL , - .free_workspace = zstd_free_workspace, .max_level =ZSTD_BTRFS_MAX_LEVEL , .default_level =ZSTD_BTRFS_DEFAULT_LEVEL , };
Signature · 1 line
2.23.0
David Sterba
maintainerPATCH 15/15 btrfs: compression: remove ops pointer from workspace_manager
In reply to David SterbaWe can infer the ops from the type that is now passed to all functions that would need it, this makes workspace_manager::ops redundant and can be removed.
--- fs/btrfs/compression.c | 6 ++---- fs/btrfs/compression.h | 1 - 2 files changed, 2 insertions(+), 5 deletions(-)
fs/btrfs/compression.c +2 -4
@@ -956,12 +956,10 @@ static void free_workspace(int type, struct list_head *ws)static void btrfs_init_workspace_manager (int type) { -const struct btrfs_compress_op *ops = btrfs_compress_op[type]; -struct workspace_manager *wsm = ops->workspace_manager; +struct workspace_manager *wsm;struct list_head *workspace; - wsm->ops = ops; - + wsm = btrfs_compress_op[type]->workspace_manager;INIT_LIST_HEAD (&wsm->idle_ws);spin_lock_init (&wsm->ws_lock);atomic_set (&wsm->total_ws,0 );
fs/btrfs/compression.h +0 -1
@@ -109,7 +109,6 @@ enum btrfs_compression_type { };struct workspace_manager { -const struct btrfs_compress_op *ops;struct list_head idle_ws;spinlock_t ws_lock;/* Number of free workspaces */
Signature · 1 line
2.23.0
Re: [PATCH 01/15] btrfs: export compression and decompression callbacks
In reply to David SterbaLooks good,
Signature · 9 lines
Johannes Thumshirn SUSE Labs Filesystems [email protected] +49 911 74053 689 SUSE Software Solutions Germany GmbH Maxfeldstr. 5 90409 Nürnberg Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Re: [PATCH 02/15] btrfs: switch compression callbacks to direct calls
In reply to David SterbaQuoted 27 lines · David Sterba
fs/btrfs/compression.c +27
-0+static int compression_decompress_bio (int type,struct list_head *ws, +struct compressed_bio *cb) +{ +switch (type) { +case BTRFS_COMPRESS_ZLIB :return zlib_decompress_bio (ws, cb); +case BTRFS_COMPRESS_LZO :return lzo_decompress_bio (ws, cb); +case BTRFS_COMPRESS_ZSTD :return zstd_decompress_bio (ws, cb); +case BTRFS_COMPRESS_NONE : +default : +/* +* This can't happen, the type is validated several times +* before we get here. +*/ +BUG (); + } +} + +static int compression_decompress (int type,struct list_head *ws, +unsigned char *data_in,struct page *dest_page, +unsigned long start_byte,size_t srclen,size_t destlen) +{ +switch (type) { +case BTRFS_COMPRESS_ZLIB :return zlib_decompress (ws, data_in, dest_page, + start_byte, srclen, destlen); +case BTRFS_COMPRESS_LZO :return lzo_decompress (ws, data_in, dest_page, + start_byte, srclen, destlen); + case BTRFS_COMPRESS_ZSTD: return zstd_decompress(ws, data_in, dest_page,
fs/btrfs/compression.c bool btrfs_compress_is_valid_type(const char *str, size_t len) · line 151
Quoted 10 lines
fs/btrfs/compression.c +10
-0+ start_byte, srclen, destlen); +case BTRFS_COMPRESS_NONE : +default : +/* +* This can't happen, the type is validated several times +* before we get here. +*/ +BUG (); + } +}
Hmm should we really BUG() here? Maybe throw in an ASSERT(), so we can catch it in debug builds but not halt the machine (even if it theoretically can't happen).
Signature · 9 lines
Johannes Thumshirn SUSE Labs Filesystems [email protected] +49 911 74053 689 SUSE Software Solutions Germany GmbH Maxfeldstr. 5 90409 Nürnberg Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Re: [PATCH 04/15] btrfs: compression: let workspace manager init take only the type
In reply to David SterbaSignature · 9 lines
Johannes Thumshirn SUSE Labs Filesystems [email protected] +49 911 74053 689 SUSE Software Solutions Germany GmbH Maxfeldstr. 5 90409 Nürnberg Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Re: [PATCH 05/15] btrfs: compression: inline init_workspace_manager
In reply to David SterbaLooks good,
Signature · 9 lines
Johannes Thumshirn SUSE Labs Filesystems [email protected] +49 911 74053 689 SUSE Software Solutions Germany GmbH Maxfeldstr. 5 90409 Nürnberg Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Re: [PATCH 03/15] btrfs: compression: attach workspace manager to the ops
In reply to David SterbaLooks good,
Signature · 9 lines
Johannes Thumshirn SUSE Labs Filesystems [email protected] +49 911 74053 689 SUSE Software Solutions Germany GmbH Maxfeldstr. 5 90409 Nürnberg Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Re: [PATCH 06/15] btrfs: compression: let workspace manager cleanup take only the type
In reply to David SterbaLooks good,
Signature · 9 lines
Johannes Thumshirn SUSE Labs Filesystems [email protected] +49 911 74053 689 SUSE Software Solutions Germany GmbH Maxfeldstr. 5 90409 Nürnberg Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Re: [PATCH 02/15] btrfs: switch compression callbacks to direct calls
In reply to Johannes ThumshirnQuoted 34 lines · Johannes Thumshirn
Quoted 33 lines · David Sterba
fs/btrfs/compression.c +33
-0+static int compression_decompress_bio (int type,struct list_head *ws, +struct compressed_bio *cb) +{ +switch (type) { +case BTRFS_COMPRESS_ZLIB :return zlib_decompress_bio (ws, cb); +case BTRFS_COMPRESS_LZO :return lzo_decompress_bio (ws, cb); +case BTRFS_COMPRESS_ZSTD :return zstd_decompress_bio (ws, cb); +case BTRFS_COMPRESS_NONE : +default : +/* +* This can't happen, the type is validated several times +* before we get here. +*/ +BUG (); + } +} + +static int compression_decompress (int type,struct list_head *ws, +unsigned char *data_in,struct page *dest_page, +unsigned long start_byte,size_t srclen,size_t destlen) +{ +switch (type) { +case BTRFS_COMPRESS_ZLIB :return zlib_decompress (ws, data_in, dest_page, + start_byte, srclen, destlen); +case BTRFS_COMPRESS_LZO :return lzo_decompress (ws, data_in, dest_page, + start_byte, srclen, destlen); +case BTRFS_COMPRESS_ZSTD :return zstd_decompress (ws, data_in, dest_page, + start_byte, srclen, destlen); +case BTRFS_COMPRESS_NONE : +default : +/* +* This can't happen, the type is validated several times +* before we get here.
Quoted 8 lines
fs/btrfs/compression.c bool btrfs_compress_is_valid_type(const char *str, size_t len) · line 130
Quoted 4 lines
fs/btrfs/compression.c +4
-0+*/ +BUG (); + } +}Hmm should we really
BUG()here? Maybe throw in anASSERT(), so we can catch it in debug builds but not halt the machine (even if it theoretically can't happen).
Debug builds would catch it for sure, regardless of bug or assert, but assert would not be on builds without CONFIG_BTRFS_ASSERT and continuing here is not correct. If the code reatches the switch with a wrong value, then the wrong value has been used to dereference an array in the caller, so the state of the system is not defined. I don't see a better option than BUG, thouth we don't want to add new ones. At least with the comment it should be clear that it's not somebody's laziness to do proper error handling, here it's not possible to do it at all.
Re: [PATCH 07/15] btrfs: compression: inline cleanup_workspace_manager
In reply to David SterbaLooks good,
Signature · 9 lines
Johannes Thumshirn SUSE Labs Filesystems [email protected] +49 911 74053 689 SUSE Software Solutions Germany GmbH Maxfeldstr. 5 90409 Nürnberg Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Re: [PATCH 08/15] btrfs: compression: export alloc/free/get/put callbacks of all algos
In reply to David SterbaLooks good,
Signature · 9 lines
Johannes Thumshirn SUSE Labs Filesystems [email protected] +49 911 74053 689 SUSE Software Solutions Germany GmbH Maxfeldstr. 5 90409 Nürnberg Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Re: [PATCH 09/15] btrfs: compression: inline get_workspace
In reply to David SterbaLooks good,
Signature · 9 lines
Johannes Thumshirn SUSE Labs Filesystems [email protected] +49 911 74053 689 SUSE Software Solutions Germany GmbH Maxfeldstr. 5 90409 Nürnberg Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Re: [PATCH 10/15] btrfs: compression: inline put_workspace
In reply to David SterbaLooks good,
Signature · 9 lines
Johannes Thumshirn SUSE Labs Filesystems [email protected] +49 911 74053 689 SUSE Software Solutions Germany GmbH Maxfeldstr. 5 90409 Nürnberg Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Re: [PATCH 11/15] btrfs: compression: pass type to btrfs_get_workspace
In reply to David SterbaLooks good,
Signature · 9 lines
Johannes Thumshirn SUSE Labs Filesystems [email protected] +49 911 74053 689 SUSE Software Solutions Germany GmbH Maxfeldstr. 5 90409 Nürnberg Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Re: [PATCH 12/15] btrfs: compression: inline alloc_workspace
In reply to David SterbaLooks good,
Signature · 9 lines
Johannes Thumshirn SUSE Labs Filesystems [email protected] +49 911 74053 689 SUSE Software Solutions Germany GmbH Maxfeldstr. 5 90409 Nürnberg Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Re: [PATCH 13/15] btrfs: compression: pass type to btrfs_put_workspace
In reply to David SterbaLooks good,
Signature · 9 lines
Johannes Thumshirn SUSE Labs Filesystems [email protected] +49 911 74053 689 SUSE Software Solutions Germany GmbH Maxfeldstr. 5 90409 Nürnberg Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Re: [PATCH 14/15] btrfs: compression: inline free_workspace
In reply to David SterbaLooks good,
Signature · 9 lines
Johannes Thumshirn SUSE Labs Filesystems [email protected] +49 911 74053 689 SUSE Software Solutions Germany GmbH Maxfeldstr. 5 90409 Nürnberg Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Re: [PATCH 15/15] btrfs: compression: remove ops pointer from workspace_manager
In reply to David SterbaLooks good,
Signature · 9 lines
Johannes Thumshirn SUSE Labs Filesystems [email protected] +49 911 74053 689 SUSE Software Solutions Germany GmbH Maxfeldstr. 5 90409 Nürnberg Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
Quoted 26 lines · David Sterba
The series removes all per-compression algorithm callbacks and replaces them with a switches. Lots of indirections are simplified and while it looks nice from design POV, we don't need to over-engineer it as we have only fixed known number of the users and not public API.
The cost of indirect function calls is also higher with enabled mitigations of the spectre vulnerability, so they've been incrementally removed from the whole kernel and from btrfs as well.
David Sterba (15):
btrfs: export compression and decompression callbacks
btrfs: switch compression callbacks to direct calls
btrfs: compression: attach workspace manager to the ops
btrfs: compression: let workspace manager init take only the type
btrfs: compression: inlineinit_workspace_manager
btrfs: compression: let workspace manager cleanup take only the type
btrfs: compression: inlinecleanup_workspace_manager
btrfs: compression: export alloc/free/get/put callbacks of all algos
btrfs: compression: inlineget_workspace
btrfs: compression: inlineput_workspace
btrfs: compression: pass type tobtrfs_get_workspace
btrfs: compression: inlinealloc_workspace
btrfs: compression: pass type tobtrfs_put_workspace
btrfs: compression: inlinefree_workspace
btrfs: compression: remove ops pointer fromworkspace_manager
Quoted 6 lines
fs/btrfs/compression.c | 241 +++++++++++++++++++++++++++++++---------- fs/btrfs/compression.h | 39 +------ fs/btrfs/lzo.c | 53 ++------- fs/btrfs/zlib.c | 52 ++------- fs/btrfs/zstd.c | 47 +++----- 5 files changed, 227 insertions(+), 205 deletions(-)
The whole series look good.
Quoted 1 line
Quoted 9 lines · David Sterba
The series removes all per-compression algorithm callbacks and replaces them with a switches. Lots of indirections are simplified and while it looks nice from design POV, we don't need to over-engineer it as we have only fixed known number of the users and not public API.
The cost of indirect function calls is also higher with enabled mitigations of the spectre vulnerability, so they've been incrementally removed from the whole kernel and from btrfs as well.
Quoted 16 lines
David Sterba (15):
btrfs: export compression and decompression callbacks
btrfs: switch compression callbacks to direct calls
btrfs: compression: attach workspace manager to the ops
btrfs: compression: let workspace manager init take only the type
btrfs: compression: inlineinit_workspace_manager
btrfs: compression: let workspace manager cleanup take only the type
btrfs: compression: inlinecleanup_workspace_manager
btrfs: compression: export alloc/free/get/put callbacks of all algos
btrfs: compression: inlineget_workspace
btrfs: compression: inlineput_workspace
btrfs: compression: pass type tobtrfs_get_workspace
btrfs: compression: inlinealloc_workspace
btrfs: compression: pass type tobtrfs_put_workspace
btrfs: compression: inlinefree_workspace
btrfs: compression: remove ops pointer fromworkspace_manager
Added to misc-next.