From patchwork Mon Oct 14 12:22:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 11188555 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4006D14DB for ; Mon, 14 Oct 2019 12:22:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 21F89217F9 for ; Mon, 14 Oct 2019 12:22:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729706AbfJNMWO (ORCPT ); Mon, 14 Oct 2019 08:22:14 -0400 Received: from mx2.suse.de ([195.135.220.15]:37274 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727038AbfJNMWO (ORCPT ); Mon, 14 Oct 2019 08:22:14 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id ABA26BD9F; Mon, 14 Oct 2019 12:22:11 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 525DADA7E3; Mon, 14 Oct 2019 14:22:24 +0200 (CEST) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 01/15] btrfs: export compression and decompression callbacks Date: Mon, 14 Oct 2019 14:22:24 +0200 Message-Id: X-Mailer: git-send-email 2.23.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Export compress_pages, decompress_bio and decompress callbacks for all compression algos. The indirect calls will be replaced by a switch. Signed-off-by: David Sterba Reviewed-by: Johannes Thumshirn --- 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(-) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index 93deaf0cc2b8..8611a8b3321a 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -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) diff --git a/fs/btrfs/lzo.c b/fs/btrfs/lzo.c index acad4174f68d..04a6815ea9cb 100644 --- a/fs/btrfs/lzo.c +++ b/fs/btrfs/lzo.c @@ -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; diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c index df1aace5df50..4091f94ba378 100644 --- a/fs/btrfs/zlib.c +++ b/fs/btrfs/zlib.c @@ -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; diff --git a/fs/btrfs/zstd.c b/fs/btrfs/zstd.c index 764d47b107e5..b3728220c329 100644 --- a/fs/btrfs/zstd.c +++ b/fs/btrfs/zstd.c @@ -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; From patchwork Mon Oct 14 12:22:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 11188557 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2FE0E912 for ; Mon, 14 Oct 2019 12:22:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 11DE921835 for ; Mon, 14 Oct 2019 12:22:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731934AbfJNMWQ (ORCPT ); Mon, 14 Oct 2019 08:22:16 -0400 Received: from mx2.suse.de ([195.135.220.15]:37290 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727038AbfJNMWQ (ORCPT ); Mon, 14 Oct 2019 08:22:16 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 1DDBCBE4A; Mon, 14 Oct 2019 12:22:14 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 9D72DDA7E3; Mon, 14 Oct 2019 14:22:26 +0200 (CEST) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 02/15] btrfs: switch compression callbacks to direct calls Date: Mon, 14 Oct 2019 14:22:26 +0200 Message-Id: X-Mailer: git-send-email 2.23.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org The 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. Signed-off-by: David Sterba --- 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(-) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index 8611a8b3321a..87bac8f73a99 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -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; diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h index 52dce1176f89..7db14d3166b5 100644 --- a/fs/btrfs/compression.h +++ b/fs/btrfs/compression.h @@ -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; diff --git a/fs/btrfs/lzo.c b/fs/btrfs/lzo.c index 04a6815ea9cb..9417944ec829 100644 --- a/fs/btrfs/lzo.c +++ b/fs/btrfs/lzo.c @@ -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, }; diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c index 4091f94ba378..8bb6f19ab369 100644 --- a/fs/btrfs/zlib.c +++ b/fs/btrfs/zlib.c @@ -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, }; diff --git a/fs/btrfs/zstd.c b/fs/btrfs/zstd.c index b3728220c329..5f17c741d167 100644 --- a/fs/btrfs/zstd.c +++ b/fs/btrfs/zstd.c @@ -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, }; From patchwork Mon Oct 14 12:22:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 11188561 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3375514DB for ; Mon, 14 Oct 2019 12:22:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1DC06217F9 for ; Mon, 14 Oct 2019 12:22:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731937AbfJNMWS (ORCPT ); Mon, 14 Oct 2019 08:22:18 -0400 Received: from mx2.suse.de ([195.135.220.15]:37308 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727038AbfJNMWS (ORCPT ); Mon, 14 Oct 2019 08:22:18 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 6D4BABDA4; Mon, 14 Oct 2019 12:22:16 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id F283FDA7E3; Mon, 14 Oct 2019 14:22:28 +0200 (CEST) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 03/15] btrfs: compression: attach workspace manager to the ops Date: Mon, 14 Oct 2019 14:22:28 +0200 Message-Id: X-Mailer: git-send-email 2.23.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org There'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. Signed-off-by: David Sterba Reviewed-by: Johannes Thumshirn --- 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(+) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index 87bac8f73a99..e650125b1d2b 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -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, diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h index 7db14d3166b5..7091eae063e5 100644 --- a/fs/btrfs/compression.h +++ b/fs/btrfs/compression.h @@ -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; diff --git a/fs/btrfs/lzo.c b/fs/btrfs/lzo.c index 9417944ec829..aff105cc80e7 100644 --- a/fs/btrfs/lzo.c +++ b/fs/btrfs/lzo.c @@ -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, diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c index 8bb6f19ab369..a5e8f0207473 100644 --- a/fs/btrfs/zlib.c +++ b/fs/btrfs/zlib.c @@ -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, diff --git a/fs/btrfs/zstd.c b/fs/btrfs/zstd.c index 5f17c741d167..4791e89e43e3 100644 --- a/fs/btrfs/zstd.c +++ b/fs/btrfs/zstd.c @@ -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, From patchwork Mon Oct 14 12:22:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 11188563 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2211514DB for ; Mon, 14 Oct 2019 12:22:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0CB1821848 for ; Mon, 14 Oct 2019 12:22:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731948AbfJNMWU (ORCPT ); Mon, 14 Oct 2019 08:22:20 -0400 Received: from mx2.suse.de ([195.135.220.15]:37362 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731938AbfJNMWU (ORCPT ); Mon, 14 Oct 2019 08:22:20 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id A9F8EBE59; Mon, 14 Oct 2019 12:22:18 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 5183EDA7E3; Mon, 14 Oct 2019 14:22:31 +0200 (CEST) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 04/15] btrfs: compression: let workspace manager init take only the type Date: Mon, 14 Oct 2019 14:22:31 +0200 Message-Id: <7096eaf28c495b2edbfc2cc4f57980ab7aee6643.1571054758.git.dsterba@suse.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org With the access to the workspace structures, we can look it up together with the compression ops inside the workspace manager init helper. Signed-off-by: David Sterba Reviewed-by: Johannes Thumshirn --- 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(-) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index e650125b1d2b..6adc7f6857d7 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -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; diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h index 7091eae063e5..10f82e791769 100644 --- a/fs/btrfs/compression.h +++ b/fs/btrfs/compression.h @@ -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); diff --git a/fs/btrfs/lzo.c b/fs/btrfs/lzo.c index aff105cc80e7..5b8470041bf6 100644 --- a/fs/btrfs/lzo.c +++ b/fs/btrfs/lzo.c @@ -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) diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c index a5e8f0207473..be964128dba3 100644 --- a/fs/btrfs/zlib.c +++ b/fs/btrfs/zlib.c @@ -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) From patchwork Mon Oct 14 12:22:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 11188567 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 26CA214DB for ; Mon, 14 Oct 2019 12:22:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 117BD217F9 for ; Mon, 14 Oct 2019 12:22:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731952AbfJNMWY (ORCPT ); Mon, 14 Oct 2019 08:22:24 -0400 Received: from mx2.suse.de ([195.135.220.15]:37408 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727038AbfJNMWY (ORCPT ); Mon, 14 Oct 2019 08:22:24 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 3192DBE62; Mon, 14 Oct 2019 12:22:22 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 9CC41DA7E3; Mon, 14 Oct 2019 14:22:33 +0200 (CEST) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 05/15] btrfs: compression: inline init_workspace_manager Date: Mon, 14 Oct 2019 14:22:33 +0200 Message-Id: X-Mailer: git-send-email 2.23.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Replace 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. Signed-off-by: David Sterba Reviewed-by: Johannes Thumshirn --- 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(-) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index 6adc7f6857d7..61b9cf095ee5 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -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) diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h index 10f82e791769..12a46139c389 100644 --- a/fs/btrfs/compression.h +++ b/fs/btrfs/compression.h @@ -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); diff --git a/fs/btrfs/lzo.c b/fs/btrfs/lzo.c index 5b8470041bf6..a55079477edf 100644 --- a/fs/btrfs/lzo.c +++ b/fs/btrfs/lzo.c @@ -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, diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c index be964128dba3..39f1d0f1b286 100644 --- a/fs/btrfs/zlib.c +++ b/fs/btrfs/zlib.c @@ -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, diff --git a/fs/btrfs/zstd.c b/fs/btrfs/zstd.c index 4791e89e43e3..8e7a804b05ee 100644 --- a/fs/btrfs/zstd.c +++ b/fs/btrfs/zstd.c @@ -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, From patchwork Mon Oct 14 12:22:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 11188569 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E983A14DB for ; Mon, 14 Oct 2019 12:22:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D48D4217F9 for ; Mon, 14 Oct 2019 12:22:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731954AbfJNMWZ (ORCPT ); Mon, 14 Oct 2019 08:22:25 -0400 Received: from mx2.suse.de ([195.135.220.15]:37454 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731938AbfJNMWY (ORCPT ); Mon, 14 Oct 2019 08:22:24 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 5BC7FBE79; Mon, 14 Oct 2019 12:22:23 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id EFB2DDA7E3; Mon, 14 Oct 2019 14:22:35 +0200 (CEST) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 06/15] btrfs: compression: let workspace manager cleanup take only the type Date: Mon, 14 Oct 2019 14:22:35 +0200 Message-Id: X-Mailer: git-send-email 2.23.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org With the access to the workspace structures, we can look it up together with the compression ops inside the workspace manager cleanup helper. Signed-off-by: David Sterba Reviewed-by: Johannes Thumshirn --- 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(-) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index 61b9cf095ee5..6c4dc62b9ab0 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -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); diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h index 12a46139c389..0deaa8e03836 100644 --- a/fs/btrfs/compression.h +++ b/fs/btrfs/compression.h @@ -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); diff --git a/fs/btrfs/lzo.c b/fs/btrfs/lzo.c index a55079477edf..6aa602040506 100644 --- a/fs/btrfs/lzo.c +++ b/fs/btrfs/lzo.c @@ -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) diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c index 39f1d0f1b286..7319e9f3d484 100644 --- a/fs/btrfs/zlib.c +++ b/fs/btrfs/zlib.c @@ -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) From patchwork Mon Oct 14 12:22:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 11188571 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CD4BF912 for ; Mon, 14 Oct 2019 12:22:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B7D84217D9 for ; Mon, 14 Oct 2019 12:22:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731963AbfJNMW2 (ORCPT ); Mon, 14 Oct 2019 08:22:28 -0400 Received: from mx2.suse.de ([195.135.220.15]:37476 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731938AbfJNMW1 (ORCPT ); Mon, 14 Oct 2019 08:22:27 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id AC33BBE7D; Mon, 14 Oct 2019 12:22:25 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 448D7DA7E3; Mon, 14 Oct 2019 14:22:38 +0200 (CEST) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 07/15] btrfs: compression: inline cleanup_workspace_manager Date: Mon, 14 Oct 2019 14:22:38 +0200 Message-Id: <6bb1515ce5b9446a7fb6b8a818f49f1307dcbe3d.1571054758.git.dsterba@suse.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Replace 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. Signed-off-by: David Sterba Reviewed-by: Johannes Thumshirn --- 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(-) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index 6c4dc62b9ab0..34921a120829 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -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(); } /* diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h index 0deaa8e03836..cf667e599b70 100644 --- a/fs/btrfs/compression.h +++ b/fs/btrfs/compression.h @@ -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); diff --git a/fs/btrfs/lzo.c b/fs/btrfs/lzo.c index 6aa602040506..6f4619e76c11 100644 --- a/fs/btrfs/lzo.c +++ b/fs/btrfs/lzo.c @@ -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, diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c index 7319e9f3d484..03c632c7deac 100644 --- a/fs/btrfs/zlib.c +++ b/fs/btrfs/zlib.c @@ -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, diff --git a/fs/btrfs/zstd.c b/fs/btrfs/zstd.c index 8e7a804b05ee..f575ce77ea3d 100644 --- a/fs/btrfs/zstd.c +++ b/fs/btrfs/zstd.c @@ -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, From patchwork Mon Oct 14 12:22:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 11188573 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B8F5014DB for ; Mon, 14 Oct 2019 12:22:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A2745217D9 for ; Mon, 14 Oct 2019 12:22:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731969AbfJNMWb (ORCPT ); Mon, 14 Oct 2019 08:22:31 -0400 Received: from mx2.suse.de ([195.135.220.15]:37494 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731938AbfJNMWa (ORCPT ); Mon, 14 Oct 2019 08:22:30 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 01962BE80; Mon, 14 Oct 2019 12:22:28 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 95C14DA7E3; Mon, 14 Oct 2019 14:22:40 +0200 (CEST) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 08/15] btrfs: compression: export alloc/free/get/put callbacks of all algos Date: Mon, 14 Oct 2019 14:22:40 +0200 Message-Id: <7f085aedf524e3b9b00d5dd30494607c62d2f08e.1571054758.git.dsterba@suse.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org The indirect calls will be replaced by a switch in compression.c. (Switch is faster than indirect calls with when Spectre mitigations are enabled). Signed-off-by: David Sterba Reviewed-by: Johannes Thumshirn --- 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(-) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index 34921a120829..f707db4a9a53 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -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" }; diff --git a/fs/btrfs/lzo.c b/fs/btrfs/lzo.c index 6f4619e76c11..18018619c019 100644 --- a/fs/btrfs/lzo.c +++ b/fs/btrfs/lzo.c @@ -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; diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c index 03c632c7deac..f2a56e999e5f 100644 --- a/fs/btrfs/zlib.c +++ b/fs/btrfs/zlib.c @@ -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; diff --git a/fs/btrfs/zstd.c b/fs/btrfs/zstd.c index f575ce77ea3d..2caf08e06e2f 100644 --- a/fs/btrfs/zstd.c +++ b/fs/btrfs/zstd.c @@ -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; From patchwork Mon Oct 14 12:22:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 11188575 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9A76D14DB for ; Mon, 14 Oct 2019 12:22:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 84B30217F9 for ; Mon, 14 Oct 2019 12:22:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731973AbfJNMWc (ORCPT ); Mon, 14 Oct 2019 08:22:32 -0400 Received: from mx2.suse.de ([195.135.220.15]:37534 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731968AbfJNMWc (ORCPT ); Mon, 14 Oct 2019 08:22:32 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 5C9CFBE87; Mon, 14 Oct 2019 12:22:30 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id E2B4DDA7E3; Mon, 14 Oct 2019 14:22:42 +0200 (CEST) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 09/15] btrfs: compression: inline get_workspace Date: Mon, 14 Oct 2019 14:22:42 +0200 Message-Id: X-Mailer: git-send-email 2.23.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Majority 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. Signed-off-by: David Sterba Reviewed-by: Johannes Thumshirn --- 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(-) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index f707db4a9a53..de9b06574f42 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -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(); + } } /* diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h index cf667e599b70..df7274c1a5d8 100644 --- a/fs/btrfs/compression.h +++ b/fs/btrfs/compression.h @@ -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); diff --git a/fs/btrfs/lzo.c b/fs/btrfs/lzo.c index 18018619c019..821e5c137971 100644 --- a/fs/btrfs/lzo.c +++ b/fs/btrfs/lzo.c @@ -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, diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c index f2a56e999e5f..7caa468efe94 100644 --- a/fs/btrfs/zlib.c +++ b/fs/btrfs/zlib.c @@ -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, diff --git a/fs/btrfs/zstd.c b/fs/btrfs/zstd.c index 2caf08e06e2f..c9fe0e2bd107 100644 --- a/fs/btrfs/zstd.c +++ b/fs/btrfs/zstd.c @@ -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, From patchwork Mon Oct 14 12:22:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 11188579 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5F2D3912 for ; Mon, 14 Oct 2019 12:22:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4A574217F9 for ; Mon, 14 Oct 2019 12:22:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731981AbfJNMWf (ORCPT ); Mon, 14 Oct 2019 08:22:35 -0400 Received: from mx2.suse.de ([195.135.220.15]:37550 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731968AbfJNMWe (ORCPT ); Mon, 14 Oct 2019 08:22:34 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id A9A86BE88; Mon, 14 Oct 2019 12:22:32 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 43E19DA7E3; Mon, 14 Oct 2019 14:22:45 +0200 (CEST) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 10/15] btrfs: compression: inline put_workspace Date: Mon, 14 Oct 2019 14:22:45 +0200 Message-Id: <243ec8e3ed32c12e7dca0bdafb9934f74ee1b5b6.1571054758.git.dsterba@suse.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Similar 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. Signed-off-by: David Sterba Reviewed-by: Johannes Thumshirn --- 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(-) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index de9b06574f42..9b9638557e19 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -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(); + } } /* diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h index df7274c1a5d8..b8ed97fc6db4 100644 --- a/fs/btrfs/compression.h +++ b/fs/btrfs/compression.h @@ -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); diff --git a/fs/btrfs/lzo.c b/fs/btrfs/lzo.c index 821e5c137971..bbf917c5ff2d 100644 --- a/fs/btrfs/lzo.c +++ b/fs/btrfs/lzo.c @@ -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, diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c index 7caa468efe94..610765640c8e 100644 --- a/fs/btrfs/zlib.c +++ b/fs/btrfs/zlib.c @@ -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, diff --git a/fs/btrfs/zstd.c b/fs/btrfs/zstd.c index c9fe0e2bd107..a346f1187fae 100644 --- a/fs/btrfs/zstd.c +++ b/fs/btrfs/zstd.c @@ -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, From patchwork Mon Oct 14 12:22:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 11188581 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C52BF14DB for ; Mon, 14 Oct 2019 12:22:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AF85B217D9 for ; Mon, 14 Oct 2019 12:22:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731985AbfJNMWh (ORCPT ); Mon, 14 Oct 2019 08:22:37 -0400 Received: from mx2.suse.de ([195.135.220.15]:37566 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731983AbfJNMWg (ORCPT ); Mon, 14 Oct 2019 08:22:36 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 03927BE8A; Mon, 14 Oct 2019 12:22:35 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 8CBE1DA7E3; Mon, 14 Oct 2019 14:22:47 +0200 (CEST) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 11/15] btrfs: compression: pass type to btrfs_get_workspace Date: Mon, 14 Oct 2019 14:22:47 +0200 Message-Id: <495a8c7d9931c06946f5683c1231582b1acf3584.1571054758.git.dsterba@suse.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We 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. Signed-off-by: David Sterba Reviewed-by: Johannes Thumshirn --- fs/btrfs/compression.c | 12 +++++------- fs/btrfs/compression.h | 3 +-- fs/btrfs/zlib.c | 2 +- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index 9b9638557e19..ffc94e15d86e 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -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: /* diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h index b8ed97fc6db4..accb1d61df87 100644 --- a/fs/btrfs/compression.h +++ b/fs/btrfs/compression.h @@ -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 { diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c index 610765640c8e..5679a2e41a52 100644 --- a/fs/btrfs/zlib.c +++ b/fs/btrfs/zlib.c @@ -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; From patchwork Mon Oct 14 12:22:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 11188583 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DA3E414DB for ; Mon, 14 Oct 2019 12:22:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C55ED217F9 for ; Mon, 14 Oct 2019 12:22:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731983AbfJNMWk (ORCPT ); Mon, 14 Oct 2019 08:22:40 -0400 Received: from mx2.suse.de ([195.135.220.15]:37576 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731987AbfJNMWj (ORCPT ); Mon, 14 Oct 2019 08:22:39 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 53A16BE8B; Mon, 14 Oct 2019 12:22:37 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id D7C01DA7E3; Mon, 14 Oct 2019 14:22:49 +0200 (CEST) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 12/15] btrfs: compression: inline alloc_workspace Date: Mon, 14 Oct 2019 14:22:49 +0200 Message-Id: X-Mailer: git-send-email 2.23.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Replace 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. Signed-off-by: David Sterba Reviewed-by: Johannes Thumshirn --- 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(-) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index ffc94e15d86e..4a8dab961f88 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -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)) { diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h index accb1d61df87..8336c2ef6b5a 100644 --- a/fs/btrfs/compression.h +++ b/fs/btrfs/compression.h @@ -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; diff --git a/fs/btrfs/lzo.c b/fs/btrfs/lzo.c index bbf917c5ff2d..39b2cf80f77c 100644 --- a/fs/btrfs/lzo.c +++ b/fs/btrfs/lzo.c @@ -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, diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c index 5679a2e41a52..c5dfab3ab082 100644 --- a/fs/btrfs/zlib.c +++ b/fs/btrfs/zlib.c @@ -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, diff --git a/fs/btrfs/zstd.c b/fs/btrfs/zstd.c index a346f1187fae..9413f741c2f6 100644 --- a/fs/btrfs/zstd.c +++ b/fs/btrfs/zstd.c @@ -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, From patchwork Mon Oct 14 12:22:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 11188585 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 22431912 for ; Mon, 14 Oct 2019 12:22:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0D209217F9 for ; Mon, 14 Oct 2019 12:22:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731996AbfJNMWl (ORCPT ); Mon, 14 Oct 2019 08:22:41 -0400 Received: from mx2.suse.de ([195.135.220.15]:37588 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731987AbfJNMWk (ORCPT ); Mon, 14 Oct 2019 08:22:40 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 9C2E3BE8D; Mon, 14 Oct 2019 12:22:39 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 36C29DA7E3; Mon, 14 Oct 2019 14:22:52 +0200 (CEST) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 13/15] btrfs: compression: pass type to btrfs_put_workspace Date: Mon, 14 Oct 2019 14:22:52 +0200 Message-Id: <2f1a94f4a4ef70a4bee360c86175a8e22e5712e1.1571054758.git.dsterba@suse.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We 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. Signed-off-by: David Sterba Reviewed-by: Johannes Thumshirn --- fs/btrfs/compression.c | 13 ++++++------- fs/btrfs/compression.h | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index 4a8dab961f88..2a77c91c194b 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -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: /* diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h index 8336c2ef6b5a..664b029cd5e4 100644 --- a/fs/btrfs/compression.h +++ b/fs/btrfs/compression.h @@ -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); From patchwork Mon Oct 14 12:22:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 11188587 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 746C014DB for ; Mon, 14 Oct 2019 12:22:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5F048217F9 for ; Mon, 14 Oct 2019 12:22:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731988AbfJNMWo (ORCPT ); Mon, 14 Oct 2019 08:22:44 -0400 Received: from mx2.suse.de ([195.135.220.15]:37598 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730375AbfJNMWo (ORCPT ); Mon, 14 Oct 2019 08:22:44 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 28240BE8E; Mon, 14 Oct 2019 12:22:42 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id BA700DA7E3; Mon, 14 Oct 2019 14:22:54 +0200 (CEST) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 14/15] btrfs: compression: inline free_workspace Date: Mon, 14 Oct 2019 14:22:54 +0200 Message-Id: <72c6b766cb35dbbc7087528a13522e8d7c7e5a89.1571054758.git.dsterba@suse.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Replace 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. Signed-off-by: David Sterba Reviewed-by: Johannes Thumshirn --- 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(-) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index 2a77c91c194b..b2342f99b093 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -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); diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h index 664b029cd5e4..14057498dcbb 100644 --- a/fs/btrfs/compression.h +++ b/fs/btrfs/compression.h @@ -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; diff --git a/fs/btrfs/lzo.c b/fs/btrfs/lzo.c index 39b2cf80f77c..aa9cd11f4b78 100644 --- a/fs/btrfs/lzo.c +++ b/fs/btrfs/lzo.c @@ -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, }; diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c index c5dfab3ab082..a6c90a003c12 100644 --- a/fs/btrfs/zlib.c +++ b/fs/btrfs/zlib.c @@ -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, }; diff --git a/fs/btrfs/zstd.c b/fs/btrfs/zstd.c index 9413f741c2f6..9a4871636c6c 100644 --- a/fs/btrfs/zstd.c +++ b/fs/btrfs/zstd.c @@ -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, }; From patchwork Mon Oct 14 12:22:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 11188589 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D7027912 for ; Mon, 14 Oct 2019 12:22:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B717A21835 for ; Mon, 14 Oct 2019 12:22:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732003AbfJNMWq (ORCPT ); Mon, 14 Oct 2019 08:22:46 -0400 Received: from mx2.suse.de ([195.135.220.15]:37614 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730375AbfJNMWp (ORCPT ); Mon, 14 Oct 2019 08:22:45 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 6A901BE8F; Mon, 14 Oct 2019 12:22:44 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 13D08DA7E3; Mon, 14 Oct 2019 14:22:57 +0200 (CEST) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 15/15] btrfs: compression: remove ops pointer from workspace_manager Date: Mon, 14 Oct 2019 14:22:57 +0200 Message-Id: <7fe1018a3a18485a0d3eeab1be89fd84603e46ea.1571054758.git.dsterba@suse.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We 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. Signed-off-by: David Sterba Reviewed-by: Johannes Thumshirn --- fs/btrfs/compression.c | 6 ++---- fs/btrfs/compression.h | 1 - 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c index b2342f99b093..53aee0db9d71 100644 --- a/fs/btrfs/compression.c +++ b/fs/btrfs/compression.c @@ -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); diff --git a/fs/btrfs/compression.h b/fs/btrfs/compression.h index 14057498dcbb..d253f7aa8ed5 100644 --- a/fs/btrfs/compression.h +++ b/fs/btrfs/compression.h @@ -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 */