From: Dennis Zhou <dennis@kernel.org>
To: David Sterba <dsterba@suse.com>,
Josef Bacik <josef@toxicpanda.com>, Chris Mason <clm@fb.com>,
Omar Sandoval <osandov@osandov.com>,
Nick Terrell <terrelln@fb.com>,
Nikolay Borisov <nborisov@suse.com>
Cc: kernel-team@fb.com, linux-btrfs@vger.kernel.org,
linux-kernel@vger.kernel.org, Dennis Zhou <dennis@kernel.org>
Subject: [PATCH 06/12] btrfs: add compression interface in (get/put)_workspace()
Date: Mon, 4 Feb 2019 15:20:02 -0500 [thread overview]
Message-ID: <20190204202008.51652-7-dennis@kernel.org> (raw)
In-Reply-To: <20190204202008.51652-1-dennis@kernel.org>
There are two levels of workspace management. First, alloc()/free()
which are responsible for actually creating and destroy workspaces.
Second, at a higher level, get()/put() which is the compression code
asking for a workspace from a workspace_manager.
The compression code shouldn't really care how it gets a workspace, but
that it got a workspace. This adds get_workspace() and put_workspace()
to be the higher level interface which is responsible for indexing into
the appropriate compression type. It also introduces
btrfs_put_workspace() and btrfs_get_workspace() to be the generic
implementations of the higher interface.
Signed-off-by: Dennis Zhou <dennis@kernel.org>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
---
fs/btrfs/compression.c | 57 +++++++++++++++++++++++++-----------------
1 file changed, 34 insertions(+), 23 deletions(-)
diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index b213d1efb586..98e1b222f78c 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -839,7 +839,7 @@ static void btrfs_cleanup_workspace_manager(struct workspace_manager *wsman)
* Preallocation makes a forward progress guarantees and we do not return
* errors.
*/
-static struct list_head *find_workspace(int type)
+static struct list_head *btrfs_get_workspace(struct workspace_manager *wsman)
{
struct list_head *workspace;
int cpus = num_online_cpus();
@@ -850,11 +850,11 @@ static struct list_head *find_workspace(int type)
wait_queue_head_t *ws_wait;
int *free_ws;
- idle_ws = &wsm[type].idle_ws;
- ws_lock = &wsm[type].ws_lock;
- total_ws = &wsm[type].total_ws;
- ws_wait = &wsm[type].ws_wait;
- free_ws = &wsm[type].free_ws;
+ idle_ws = &wsman->idle_ws;
+ ws_lock = &wsman->ws_lock;
+ total_ws = &wsman->total_ws;
+ ws_wait = &wsman->ws_wait;
+ free_ws = &wsman->free_ws;
again:
spin_lock(ws_lock);
@@ -885,7 +885,7 @@ static struct list_head *find_workspace(int type)
* context of btrfs_compress_bio/btrfs_compress_pages
*/
nofs_flag = memalloc_nofs_save();
- workspace = wsm[type].ops->alloc_workspace();
+ workspace = wsman->ops->alloc_workspace();
memalloc_nofs_restore(nofs_flag);
if (IS_ERR(workspace)) {
@@ -916,11 +916,17 @@ static struct list_head *find_workspace(int type)
return workspace;
}
+static struct list_head *get_workspace(int type)
+{
+ return btrfs_get_workspace(&wsm[type]);
+}
+
/*
* put a workspace struct back on the list or free it if we have enough
* idle ones sitting around
*/
-static void free_workspace(int type, struct list_head *workspace)
+static void btrfs_put_workspace(struct workspace_manager *wsman,
+ struct list_head *ws)
{
struct list_head *idle_ws;
spinlock_t *ws_lock;
@@ -928,27 +934,32 @@ static void free_workspace(int type, struct list_head *workspace)
wait_queue_head_t *ws_wait;
int *free_ws;
- idle_ws = &wsm[type].idle_ws;
- ws_lock = &wsm[type].ws_lock;
- total_ws = &wsm[type].total_ws;
- ws_wait = &wsm[type].ws_wait;
- free_ws = &wsm[type].free_ws;
+ idle_ws = &wsman->idle_ws;
+ ws_lock = &wsman->ws_lock;
+ total_ws = &wsman->total_ws;
+ ws_wait = &wsman->ws_wait;
+ free_ws = &wsman->free_ws;
spin_lock(ws_lock);
if (*free_ws <= num_online_cpus()) {
- list_add(workspace, idle_ws);
+ list_add(ws, idle_ws);
(*free_ws)++;
spin_unlock(ws_lock);
goto wake;
}
spin_unlock(ws_lock);
- wsm[type].ops->free_workspace(workspace);
+ wsman->ops->free_workspace(ws);
atomic_dec(total_ws);
wake:
cond_wake_up(ws_wait);
}
+static void put_workspace(int type, struct list_head *ws)
+{
+ return btrfs_put_workspace(&wsm[type], ws);
+}
+
/*
* Given an address space and start and length, compress the bytes into @pages
* that are allocated on demand.
@@ -982,14 +993,14 @@ int btrfs_compress_pages(unsigned int type_level, struct address_space *mapping,
struct list_head *workspace;
int ret;
- workspace = find_workspace(type);
+ workspace = get_workspace(type);
btrfs_compress_op[type]->set_level(workspace, type_level);
ret = btrfs_compress_op[type]->compress_pages(workspace, mapping,
start, pages,
out_pages,
total_in, total_out);
- free_workspace(type, workspace);
+ put_workspace(type, workspace);
return ret;
}
@@ -1013,9 +1024,9 @@ static int btrfs_decompress_bio(struct compressed_bio *cb)
int ret;
int type = cb->compress_type;
- workspace = find_workspace(type);
+ workspace = get_workspace(type);
ret = btrfs_compress_op[type]->decompress_bio(workspace, cb);
- free_workspace(type, workspace);
+ put_workspace(type, workspace);
return ret;
}
@@ -1031,13 +1042,13 @@ int btrfs_decompress(int type, unsigned char *data_in, struct page *dest_page,
struct list_head *workspace;
int ret;
- workspace = find_workspace(type);
+ workspace = get_workspace(type);
ret = btrfs_compress_op[type]->decompress(workspace, data_in,
dest_page, start_byte,
srclen, destlen);
- free_workspace(type, workspace);
+ put_workspace(type, workspace);
return ret;
}
@@ -1465,7 +1476,7 @@ static void heuristic_collect_sample(struct inode *inode, u64 start, u64 end,
*/
int btrfs_compress_heuristic(struct inode *inode, u64 start, u64 end)
{
- struct list_head *ws_list = find_workspace(0);
+ struct list_head *ws_list = get_workspace(0);
struct heuristic_ws *ws;
u32 i;
u8 byte;
@@ -1534,7 +1545,7 @@ int btrfs_compress_heuristic(struct inode *inode, u64 start, u64 end)
}
out:
- free_workspace(0, ws_list);
+ put_workspace(0, ws_list);
return ret;
}
--
2.17.1
next prev parent reply other threads:[~2019-02-04 20:20 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-04 20:19 [PATCH v2 00/12] btrfs: add zstd compression level support Dennis Zhou
2019-02-04 20:19 ` [PATCH 01/12] btrfs: add helpers for compression type and level Dennis Zhou
2019-02-04 20:19 ` [PATCH 02/12] btrfs: rename workspaces_list to workspace_manager Dennis Zhou
2019-02-04 20:19 ` [PATCH 03/12] btrfs: manage heuristic workspace as index 0 Dennis Zhou
2019-02-04 20:20 ` [PATCH 04/12] btrfs: unify compression ops with workspace_manager Dennis Zhou
2019-02-04 20:20 ` [PATCH 05/12] btrfs: add helper methods for workspace manager init and cleanup Dennis Zhou
2019-02-04 20:20 ` Dennis Zhou [this message]
2019-02-04 20:20 ` [PATCH 07/12] btrfs: move to fn pointers for get/put workspaces Dennis Zhou
2019-02-04 20:20 ` [PATCH 08/12] btrfs: plumb level through the compression interface Dennis Zhou
2019-02-04 20:20 ` [PATCH 09/12] btrfs: change set_level() to bound the level passed in Dennis Zhou
2019-02-05 19:06 ` David Sterba
2019-02-05 19:32 ` Dennis Zhou
2019-02-05 19:54 ` David Sterba
2019-02-05 19:59 ` Dennis Zhou
2019-02-06 16:48 ` [PATCH v2 " Dennis Zhou
2019-02-04 20:20 ` [PATCH 10/12] btrfs: zstd use the passed through level instead of default Dennis Zhou
2019-02-04 20:20 ` [PATCH 11/12] btrfs: make zstd memory requirements monotonic Dennis Zhou
2019-02-04 20:20 ` [PATCH 12/12] btrfs: add zstd compression level support Dennis Zhou
2019-02-05 19:26 ` [PATCH v2 " Dennis Zhou
2019-02-06 16:47 ` [PATCH v3 " Dennis Zhou
2019-02-05 14:57 ` [PATCH v2 00/12] " David Sterba
2019-02-05 16:03 ` Dennis Zhou
2019-02-05 16:27 ` David Sterba
2019-02-05 16:30 ` Dennis Zhou
2019-02-05 16:51 ` David Sterba
2019-02-05 17:07 ` David Sterba
2019-02-05 18:27 ` David Sterba
2019-02-05 18:30 ` Dennis Zhou
2019-02-05 20:48 ` Dennis Zhou
2019-02-06 15:15 ` David Sterba
2019-02-06 16:51 ` Dennis Zhou
2019-02-07 16:59 ` David Sterba
2019-02-07 17:36 ` Dennis Zhou
2019-02-08 13:22 ` David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190204202008.51652-7-dennis@kernel.org \
--to=dennis@kernel.org \
--cc=clm@fb.com \
--cc=dsterba@suse.com \
--cc=josef@toxicpanda.com \
--cc=kernel-team@fb.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nborisov@suse.com \
--cc=osandov@osandov.com \
--cc=terrelln@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).