]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
btrfs: zstd: move zstd_parameters to the workspace
authorDavid Sterba <dsterba@suse.com>
Wed, 12 Feb 2025 20:22:02 +0000 (21:22 +0100)
committerDavid Sterba <dsterba@suse.com>
Tue, 18 Mar 2025 19:35:42 +0000 (20:35 +0100)
Reduce stack consumption of zstd_compress_folios() by 40 bytes
(10*sizeof(int)) as we can store struct zstd_parameters in the workspace
that is reused for each call.

typedef struct {
ZSTD_compressionParameters cParams;
ZSTD_frameParameters fParams;
} ZSTD_parameters;

typedef struct {
    unsigned windowLog;
    unsigned chainLog;
    unsigned hashLog;
    unsigned searchLog;
    unsigned minMatch;
    unsigned targetLength;
    ZSTD_strategy strategy;
} ZSTD_compressionParameters;

typedef struct {
    int contentSizeFlag;
    int checksumFlag;
    int noDictIDFlag;
} ZSTD_frameParameters;

Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/zstd.c

index a7bfbf8bea7d081035baa9a3123475d7a0e7fc41..5419c47b854fc77edc21025264230f75c829169a 100644 (file)
@@ -53,6 +53,7 @@ struct workspace {
        struct list_head lru_list;
        zstd_in_buffer in_buf;
        zstd_out_buffer out_buf;
+       zstd_parameters params;
 };
 
 /*
@@ -402,15 +403,14 @@ int zstd_compress_folios(struct list_head *ws, struct address_space *mapping,
        unsigned long max_out = nr_dest_folios * PAGE_SIZE;
        unsigned int pg_off;
        unsigned int cur_len;
-       zstd_parameters params = zstd_get_btrfs_parameters(workspace->req_level,
-                                                          len);
 
+       workspace->params = zstd_get_btrfs_parameters(workspace->req_level, len);
        *out_folios = 0;
        *total_out = 0;
        *total_in = 0;
 
        /* Initialize the stream */
-       stream = zstd_init_cstream(&params, len, workspace->mem,
+       stream = zstd_init_cstream(&workspace->params, len, workspace->mem,
                        workspace->size);
        if (unlikely(!stream)) {
                struct btrfs_inode *inode = BTRFS_I(mapping->host);