Re: [PATCH v2 3/4] btrfs: Add zstd support
From: David Sterba
Date: Tue Jul 18 2017 - 14:22:32 EST
On Thu, Jun 29, 2017 at 12:41:07PM -0700, Nick Terrell wrote:
> +static void zstd_free_workspace(struct list_head *ws)
> +{
> + struct workspace *workspace = list_entry(ws, struct workspace, list);
> +
> + vfree(workspace->mem);
> + kfree(workspace->buf);
> + kfree(workspace);
> +}
> +
> +static struct list_head *zstd_alloc_workspace(void)
> +{
> + ZSTD_parameters params =
> + zstd_get_btrfs_parameters(ZSTD_BTRFS_MAX_INPUT);
> + struct workspace *workspace;
> +
> + workspace = kzalloc(sizeof(*workspace), GFP_NOFS);
> + if (!workspace)
> + return ERR_PTR(-ENOMEM);
> +
> + workspace->size = max_t(size_t,
> + ZSTD_CStreamWorkspaceBound(params.cParams),
> + ZSTD_DStreamWorkspaceBound(ZSTD_BTRFS_MAX_INPUT));
> + workspace->mem = vmalloc(workspace->size);
> + workspace->buf = kmalloc(PAGE_SIZE, GFP_NOFS);
> + if (!workspace->mem || !workspace->buf)
> + goto fail;
> +
> + INIT_LIST_HEAD(&workspace->list);
> +
> + return &workspace->list;
> +fail:
> + zstd_free_workspace(&workspace->list);
> + return ERR_PTR(-ENOMEM);
> +}
In the next iteration, please update the workspace allocations so that
they use kvmalloc/kvfree and GFP_KERNEL (eg. 6acafd1eff426).