Commit 6acafd1e authored by David Sterba's avatar David Sterba

btrfs: switch to kvmalloc and GFP_KERNEL in lzo/zlib alloc_workspace

The compression workspace buffers are larger than a page so we use
vmalloc, unconditionally. This is not always necessary as there might be
contiguous memory available.

Let's use the kvmalloc helpers that will try kmalloc first and fallback
to vmalloc. For that they require GFP_KERNEL flags. As we now have the
alloc_workspace calls protected by memalloc_nofs in the critical
contexts, we can safely use GFP_KERNEL.
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 389a6cfc
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/vmalloc.h> #include <linux/mm.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/sched.h> #include <linux/sched.h>
...@@ -41,9 +41,9 @@ static void lzo_free_workspace(struct list_head *ws) ...@@ -41,9 +41,9 @@ static void lzo_free_workspace(struct list_head *ws)
{ {
struct workspace *workspace = list_entry(ws, struct workspace, list); struct workspace *workspace = list_entry(ws, struct workspace, list);
vfree(workspace->buf); kvfree(workspace->buf);
vfree(workspace->cbuf); kvfree(workspace->cbuf);
vfree(workspace->mem); kvfree(workspace->mem);
kfree(workspace); kfree(workspace);
} }
...@@ -55,9 +55,9 @@ static struct list_head *lzo_alloc_workspace(void) ...@@ -55,9 +55,9 @@ static struct list_head *lzo_alloc_workspace(void)
if (!workspace) if (!workspace)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
workspace->mem = vmalloc(LZO1X_MEM_COMPRESS); workspace->mem = kvmalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL);
workspace->buf = vmalloc(lzo1x_worst_compress(PAGE_SIZE)); workspace->buf = kvmalloc(lzo1x_worst_compress(PAGE_SIZE), GFP_KERNEL);
workspace->cbuf = vmalloc(lzo1x_worst_compress(PAGE_SIZE)); workspace->cbuf = kvmalloc(lzo1x_worst_compress(PAGE_SIZE), GFP_KERNEL);
if (!workspace->mem || !workspace->buf || !workspace->cbuf) if (!workspace->mem || !workspace->buf || !workspace->cbuf)
goto fail; goto fail;
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/zlib.h> #include <linux/zlib.h>
#include <linux/zutil.h> #include <linux/zutil.h>
#include <linux/vmalloc.h> #include <linux/mm.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/sched.h> #include <linux/sched.h>
...@@ -43,7 +43,7 @@ static void zlib_free_workspace(struct list_head *ws) ...@@ -43,7 +43,7 @@ static void zlib_free_workspace(struct list_head *ws)
{ {
struct workspace *workspace = list_entry(ws, struct workspace, list); struct workspace *workspace = list_entry(ws, struct workspace, list);
vfree(workspace->strm.workspace); kvfree(workspace->strm.workspace);
kfree(workspace->buf); kfree(workspace->buf);
kfree(workspace); kfree(workspace);
} }
...@@ -59,7 +59,7 @@ static struct list_head *zlib_alloc_workspace(void) ...@@ -59,7 +59,7 @@ static struct list_head *zlib_alloc_workspace(void)
workspacesize = max(zlib_deflate_workspacesize(MAX_WBITS, MAX_MEM_LEVEL), workspacesize = max(zlib_deflate_workspacesize(MAX_WBITS, MAX_MEM_LEVEL),
zlib_inflate_workspacesize()); zlib_inflate_workspacesize());
workspace->strm.workspace = vmalloc(workspacesize); workspace->strm.workspace = kvmalloc(workspacesize, GFP_KERNEL);
workspace->buf = kmalloc(PAGE_SIZE, GFP_KERNEL); workspace->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
if (!workspace->strm.workspace || !workspace->buf) if (!workspace->strm.workspace || !workspace->buf)
goto fail; goto fail;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment