]> git.hungrycats.org Git - linux/commitdiff
btrfs: zstd: prevent leak of workspace below maximum level
authorFilipe Manana <fdmanana@suse.com>
Wed, 28 Oct 2026 16:06:27 +0000 (16:06 +0000)
committerDavid Sterba <dsterba@suse.com>
Fri, 30 Oct 2026 20:36:19 +0000 (21:36 +0100)
When putting a workspace we always protect the workspace for the maximum
level from reclaim, since it can be used not just for that level but as
well for any level below it. However the logic is flawed because if we do
the put for a workspace at level 10 for example (maximum is level 15) and
there is currently no idle workspace for the maximum level because all
are currently being used, we don't add the workspace to the LRU list and
that can result in leaking it if we don't get more compression or
decompression requests for level 10 or any level below 10.

Fix this by skipping the addition to the LRU list only if the level of
the workspace matches the maximum level too (besides the list of idle
workspaces for the maximum level being empty).

Fixes: 3f93aef535c8 ("btrfs: add zstd compression level support")
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/zstd.c

index cc92d0b1b948cd1dcadcf5c93f4ee2b0ac0d659d..9b7c7f43527f7fa8590fa52f940b0ad55485f22f 100644 (file)
@@ -347,7 +347,8 @@ void zstd_put_workspace(struct btrfs_fs_info *fs_info, struct list_head *ws)
        /* A node is only taken off the lru if we are the corresponding level */
        if (clip_level(workspace->req_level) == workspace->level) {
                /* Hide a max level workspace from reclaim */
-               if (list_empty(&zwsm->idle_ws[ZSTD_BTRFS_MAX_LEVEL - 1])) {
+               if (workspace->level == ZSTD_BTRFS_MAX_LEVEL - 1 &&
+                   list_empty(&zwsm->idle_ws[ZSTD_BTRFS_MAX_LEVEL - 1])) {
                        INIT_LIST_HEAD(&workspace->lru_list);
                } else {
                        workspace->last_used = jiffies;