]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
btrfs: cleanup the per-module compression workspace managers
authorQu Wenruo <wqu@suse.com>
Thu, 14 Aug 2025 00:59:58 +0000 (10:29 +0930)
committerDavid Sterba <dsterba@suse.com>
Tue, 23 Sep 2025 06:49:16 +0000 (08:49 +0200)
Since all workspaces are handled by the per-fs workspace managers, we
can safely remove the old per-module managers.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/compression.c
fs/btrfs/compression.h
fs/btrfs/lzo.c
fs/btrfs/zlib.c
fs/btrfs/zstd.c

index cd479016d73d867175e27134d356a7d27a250ca9..ff2bf3f358a54e0bfc72472fbb5b2997905a534b 100644 (file)
@@ -688,8 +688,6 @@ struct heuristic_ws {
        struct list_head list;
 };
 
-static struct workspace_manager heuristic_wsm;
-
 static void free_heuristic_ws(struct list_head *ws)
 {
        struct heuristic_ws *workspace;
@@ -729,9 +727,7 @@ fail:
        return ERR_PTR(-ENOMEM);
 }
 
-const struct btrfs_compress_op btrfs_heuristic_compress = {
-       .workspace_manager = &heuristic_wsm,
-};
+const struct btrfs_compress_op btrfs_heuristic_compress = { 0 };
 
 static const struct btrfs_compress_op * const btrfs_compress_op[] = {
        /* The heuristic is represented as compression type 0 */
@@ -807,32 +803,6 @@ static int alloc_workspace_manager(struct btrfs_fs_info *fs_info,
        return 0;
 }
 
-static void btrfs_init_workspace_manager(struct btrfs_fs_info *fs_info, int type)
-{
-       struct workspace_manager *wsm;
-       struct list_head *workspace;
-
-       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);
-       init_waitqueue_head(&wsm->ws_wait);
-
-       /*
-        * Preallocate one workspace for each compression type so we can
-        * guarantee forward progress in the worst case
-        */
-       workspace = alloc_workspace(fs_info, type, 0);
-       if (IS_ERR(workspace)) {
-               btrfs_warn(fs_info,
-                          "cannot preallocate compression workspace, will try later");
-       } else {
-               atomic_set(&wsm->total_ws, 1);
-               wsm->free_ws = 1;
-               list_add(workspace, &wsm->idle_ws);
-       }
-}
-
 static void free_workspace_manager(struct btrfs_fs_info *fs_info,
                                   enum btrfs_compression_type type)
 {
@@ -853,20 +823,6 @@ static void free_workspace_manager(struct btrfs_fs_info *fs_info,
        kfree(gwsm);
 }
 
-static 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);
-               free_workspace(type, ws);
-               atomic_dec(&wsman->total_ws);
-       }
-}
-
 /*
  * This finds an available workspace or allocates a new one.
  * If it's not possible to allocate a new one, waits until there's one.
@@ -1192,11 +1148,6 @@ int __init btrfs_init_compress(void)
        if (!compr_pool.shrinker)
                return -ENOMEM;
 
-       btrfs_init_workspace_manager(NULL, BTRFS_COMPRESS_NONE);
-       btrfs_init_workspace_manager(NULL, BTRFS_COMPRESS_ZLIB);
-       btrfs_init_workspace_manager(NULL, BTRFS_COMPRESS_LZO);
-       zstd_init_workspace_manager(NULL);
-
        spin_lock_init(&compr_pool.lock);
        INIT_LIST_HEAD(&compr_pool.list);
        compr_pool.count = 0;
@@ -1217,10 +1168,6 @@ void __cold btrfs_exit_compress(void)
        btrfs_compr_pool_scan(NULL, NULL);
        shrinker_free(compr_pool.shrinker);
 
-       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();
        bioset_exit(&btrfs_compressed_bioset);
 }
 
index 70a3294bd14a8dc2fb249abf1f63c833d1393d09..4fa4d3b9fa570a5bb1fa037bd226f72847a69933 100644 (file)
@@ -183,8 +183,6 @@ int zstd_decompress(struct list_head *ws, const u8 *data_in,
                size_t destlen);
 int zstd_alloc_workspace_manager(struct btrfs_fs_info *fs_info);
 void zstd_free_workspace_manager(struct btrfs_fs_info *fs_info);
-void zstd_init_workspace_manager(struct btrfs_fs_info *fs_info);
-void zstd_cleanup_workspace_manager(void);
 struct list_head *zstd_alloc_workspace(struct btrfs_fs_info *fs_info, int level);
 void zstd_free_workspace(struct list_head *ws);
 struct list_head *zstd_get_workspace(struct btrfs_fs_info *fs_info, int level);
index 82407d7d9502eb88f8a2b2b24685f4b86f86e5b6..3456a1dcd420733556e85ecef7e9dfba09f7aa4c 100644 (file)
@@ -68,8 +68,6 @@ struct workspace {
        struct list_head list;
 };
 
-static struct workspace_manager wsm;
-
 void lzo_free_workspace(struct list_head *ws)
 {
        struct workspace *workspace = list_entry(ws, struct workspace, list);
@@ -489,7 +487,6 @@ out:
 }
 
 const struct btrfs_compress_op btrfs_lzo_compress = {
-       .workspace_manager      = &wsm,
        .max_level              = 1,
        .default_level          = 1,
 };
index 5fc045aeaa199e2d9b0330610dca77fb8838a024..aecc5805404505b04eb0c07baf44d1de95a39413 100644 (file)
@@ -34,8 +34,6 @@ struct workspace {
        int level;
 };
 
-static struct workspace_manager wsm;
-
 struct list_head *zlib_get_workspace(struct btrfs_fs_info *fs_info, unsigned int level)
 {
        struct list_head *ws = btrfs_get_workspace(fs_info, BTRFS_COMPRESS_ZLIB, level);
@@ -483,7 +481,6 @@ out:
 }
 
 const struct btrfs_compress_op btrfs_zlib_compress = {
-       .workspace_manager      = &wsm,
        .min_level              = 1,
        .max_level              = 9,
        .default_level          = BTRFS_ZLIB_DEFAULT_LEVEL,
index 41019fcebc13aad64b9eb1cf6136e00bd48c78c8..d514a73a4015f5fcce553c43014a1b47d89e7201 100644 (file)
@@ -86,8 +86,6 @@ struct zstd_workspace_manager {
        struct timer_list timer;
 };
 
-static struct zstd_workspace_manager wsm;
-
 static size_t zstd_ws_mem_sizes[ZSTD_BTRFS_MAX_LEVEL];
 
 static inline struct workspace *list_to_workspace(struct list_head *list)
@@ -212,31 +210,6 @@ int zstd_alloc_workspace_manager(struct btrfs_fs_info *fs_info)
        return 0;
 }
 
-void zstd_init_workspace_manager(struct btrfs_fs_info *fs_info)
-{
-       struct list_head *ws;
-       int i;
-
-       zstd_calc_ws_mem_sizes();
-
-       wsm.ops = &btrfs_zstd_compress;
-       spin_lock_init(&wsm.lock);
-       init_waitqueue_head(&wsm.wait);
-       timer_setup(&wsm.timer, zstd_reclaim_timer_fn, 0);
-
-       INIT_LIST_HEAD(&wsm.lru_list);
-       for (i = 0; i < ZSTD_BTRFS_MAX_LEVEL; i++)
-               INIT_LIST_HEAD(&wsm.idle_ws[i]);
-
-       ws = zstd_alloc_workspace(fs_info, ZSTD_BTRFS_MAX_LEVEL);
-       if (IS_ERR(ws)) {
-               btrfs_warn(NULL, "cannot preallocate zstd compression workspace");
-       } else {
-               set_bit(ZSTD_BTRFS_MAX_LEVEL - 1, &wsm.active_map);
-               list_add(ws, &wsm.idle_ws[ZSTD_BTRFS_MAX_LEVEL - 1]);
-       }
-}
-
 void zstd_free_workspace_manager(struct btrfs_fs_info *fs_info)
 {
        struct zstd_workspace_manager *zwsm = fs_info->compr_wsm[BTRFS_COMPRESS_ZSTD];
@@ -260,26 +233,6 @@ void zstd_free_workspace_manager(struct btrfs_fs_info *fs_info)
        kfree(zwsm);
 }
 
-void zstd_cleanup_workspace_manager(void)
-{
-       struct workspace *workspace;
-       int i;
-
-       spin_lock_bh(&wsm.lock);
-       for (i = 0; i < ZSTD_BTRFS_MAX_LEVEL; i++) {
-               while (!list_empty(&wsm.idle_ws[i])) {
-                       workspace = container_of(wsm.idle_ws[i].next,
-                                                struct workspace, list);
-                       list_del(&workspace->list);
-                       list_del(&workspace->lru_list);
-                       zstd_free_workspace(&workspace->list);
-               }
-       }
-       spin_unlock_bh(&wsm.lock);
-
-       timer_delete_sync(&wsm.timer);
-}
-
 /*
  * Find workspace for given level.
  *
@@ -775,8 +728,6 @@ finish:
 }
 
 const struct btrfs_compress_op btrfs_zstd_compress = {
-       /* ZSTD uses own workspace manager */
-       .workspace_manager = NULL,
        .min_level      = ZSTD_BTRFS_MIN_LEVEL,
        .max_level      = ZSTD_BTRFS_MAX_LEVEL,
        .default_level  = ZSTD_BTRFS_DEFAULT_LEVEL,