diff mbox series

[04/11] btrfs: unify compression ops with workspace_manager

Message ID 20190128212437.11597-5-dennis@kernel.org (mailing list archive)
State New, archived
Headers show
Series btrfs: add zstd compression level support | expand

Commit Message

Dennis Zhou Jan. 28, 2019, 9:24 p.m. UTC
Make the workspace_manager own the interface operations rather than
managing index-paired arrays for the workspace_manager and compression
operations.

Signed-off-by: Dennis Zhou <dennis@kernel.org>
---
 fs/btrfs/compression.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

Comments

Nikolay Borisov Jan. 29, 2019, 7:54 a.m. UTC | #1
On 28.01.19 г. 23:24 ч., Dennis Zhou wrote:
> Make the workspace_manager own the interface operations rather than
> managing index-paired arrays for the workspace_manager and compression
> operations.
> 
> Signed-off-by: Dennis Zhou <dennis@kernel.org>

Reviewed-by: Nikolay Borisov <nborisov@suse.com>

> ---
>  fs/btrfs/compression.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
> index bda7e8d2cbc7..b7e986e16640 100644
> --- a/fs/btrfs/compression.c
> +++ b/fs/btrfs/compression.c
> @@ -777,6 +777,7 @@ const struct btrfs_compress_op btrfs_heuristic_compress = {
>  };
>  
>  struct workspace_manager {
> +	const struct btrfs_compress_op *ops;
>  	struct list_head idle_ws;
>  	spinlock_t ws_lock;
>  	/* Number of free workspaces */
> @@ -802,6 +803,8 @@ void __init btrfs_init_compress(void)
>  	int i;
>  
>  	for (i = 0; i < BTRFS_COMPRESS_TYPES; i++) {
> +		wsm[i].ops = btrfs_compress_op[i];
> +
>  		INIT_LIST_HEAD(&wsm[i].idle_ws);
>  		spin_lock_init(&wsm[i].ws_lock);
>  		atomic_set(&wsm[i].total_ws, 0);
> @@ -811,7 +814,7 @@ void __init btrfs_init_compress(void)
>  		 * Preallocate one workspace for each compression type so
>  		 * we can guarantee forward progress in the worst case
>  		 */
> -		workspace = btrfs_compress_op[i]->alloc_workspace();
> +		workspace = wsm[i].ops->alloc_workspace();
>  		if (IS_ERR(workspace)) {
>  			pr_warn("BTRFS: cannot preallocate compression workspace, will try later\n");
>  		} else {
> @@ -874,7 +877,7 @@ static struct list_head *find_workspace(int type)
>  	 * context of btrfs_compress_bio/btrfs_compress_pages
>  	 */
>  	nofs_flag = memalloc_nofs_save();
> -	workspace = btrfs_compress_op[type]->alloc_workspace();
> +	workspace = wsm[type].ops->alloc_workspace();
>  	memalloc_nofs_restore(nofs_flag);
>  
>  	if (IS_ERR(workspace)) {
> @@ -932,7 +935,7 @@ static void free_workspace(int type, struct list_head *workspace)
>  	}
>  	spin_unlock(ws_lock);
>  
> -	btrfs_compress_op[type]->free_workspace(workspace);
> +	wsm[type].ops->free_workspace(workspace);
>  	atomic_dec(total_ws);
>  wake:
>  	cond_wake_up(ws_wait);
> @@ -950,7 +953,7 @@ static void free_workspaces(void)
>  		while (!list_empty(&wsm[i].idle_ws)) {
>  			workspace = wsm[i].idle_ws.next;
>  			list_del(workspace);
> -			btrfs_compress_op[i]->free_workspace(workspace);
> +			wsm[i].ops->free_workspace(workspace);
>  			atomic_dec(&wsm[i].total_ws);
>  		}
>  	}
>
Josef Bacik Jan. 29, 2019, 6:03 p.m. UTC | #2
On Mon, Jan 28, 2019 at 04:24:30PM -0500, Dennis Zhou wrote:
> Make the workspace_manager own the interface operations rather than
> managing index-paired arrays for the workspace_manager and compression
> operations.
> 
> Signed-off-by: Dennis Zhou <dennis@kernel.org>

Reviewed-by: Josef Bacik <josef@toxicpanda.com>

Thanks,

Josef
diff mbox series

Patch

diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
index bda7e8d2cbc7..b7e986e16640 100644
--- a/fs/btrfs/compression.c
+++ b/fs/btrfs/compression.c
@@ -777,6 +777,7 @@  const struct btrfs_compress_op btrfs_heuristic_compress = {
 };
 
 struct workspace_manager {
+	const struct btrfs_compress_op *ops;
 	struct list_head idle_ws;
 	spinlock_t ws_lock;
 	/* Number of free workspaces */
@@ -802,6 +803,8 @@  void __init btrfs_init_compress(void)
 	int i;
 
 	for (i = 0; i < BTRFS_COMPRESS_TYPES; i++) {
+		wsm[i].ops = btrfs_compress_op[i];
+
 		INIT_LIST_HEAD(&wsm[i].idle_ws);
 		spin_lock_init(&wsm[i].ws_lock);
 		atomic_set(&wsm[i].total_ws, 0);
@@ -811,7 +814,7 @@  void __init btrfs_init_compress(void)
 		 * Preallocate one workspace for each compression type so
 		 * we can guarantee forward progress in the worst case
 		 */
-		workspace = btrfs_compress_op[i]->alloc_workspace();
+		workspace = wsm[i].ops->alloc_workspace();
 		if (IS_ERR(workspace)) {
 			pr_warn("BTRFS: cannot preallocate compression workspace, will try later\n");
 		} else {
@@ -874,7 +877,7 @@  static struct list_head *find_workspace(int type)
 	 * context of btrfs_compress_bio/btrfs_compress_pages
 	 */
 	nofs_flag = memalloc_nofs_save();
-	workspace = btrfs_compress_op[type]->alloc_workspace();
+	workspace = wsm[type].ops->alloc_workspace();
 	memalloc_nofs_restore(nofs_flag);
 
 	if (IS_ERR(workspace)) {
@@ -932,7 +935,7 @@  static void free_workspace(int type, struct list_head *workspace)
 	}
 	spin_unlock(ws_lock);
 
-	btrfs_compress_op[type]->free_workspace(workspace);
+	wsm[type].ops->free_workspace(workspace);
 	atomic_dec(total_ws);
 wake:
 	cond_wake_up(ws_wait);
@@ -950,7 +953,7 @@  static void free_workspaces(void)
 		while (!list_empty(&wsm[i].idle_ws)) {
 			workspace = wsm[i].idle_ws.next;
 			list_del(workspace);
-			btrfs_compress_op[i]->free_workspace(workspace);
+			wsm[i].ops->free_workspace(workspace);
 			atomic_dec(&wsm[i].total_ws);
 		}
 	}