The size of de/compress buffer and LZO1X_MEM_COMPRESS is small enough.
Allocating it with kmalloc rather than vmalloc is preferred.
This patch depends on my previous patch, “btrfs: fix decompress buffer size”.
Signed-off-by: Kyungsik Lee <kyungsik.lee@lge.com>
Cc: David Sterba <dsterba@suse.cz>
---
fs/btrfs/lzo.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/fs/btrfs/lzo.c b/fs/btrfs/lzo.c
index 223893a..f223742 100644
--- a/fs/btrfs/lzo.c
+++ b/fs/btrfs/lzo.c
@@ -18,7 +18,6 @@
#include <linux/kernel.h>
#include <linux/slab.h>
-#include <linux/vmalloc.h>
#include <linux/init.h>
#include <linux/err.h>
#include <linux/sched.h>
@@ -40,9 +39,9 @@ static void lzo_free_workspace(struct list_head *ws)
{
struct workspace *workspace = list_entry(ws, struct workspace, list);
- vfree(workspace->buf);
- vfree(workspace->cbuf);
- vfree(workspace->mem);
+ kfree(workspace->buf);
+ kfree(workspace->cbuf);
+ kfree(workspace->mem);
kfree(workspace);
}
@@ -54,9 +53,10 @@ static struct list_head *lzo_alloc_workspace(void)
if (!workspace)
return ERR_PTR(-ENOMEM);
- workspace->mem = vmalloc(LZO1X_MEM_COMPRESS);
- workspace->buf = vmalloc(PAGE_CACHE_SIZE);
- workspace->cbuf = vmalloc(lzo1x_worst_compress(PAGE_CACHE_SIZE));
+ workspace->mem = kmalloc(LZO1X_MEM_COMPRESS, GFP_NOFS);
+ workspace->buf = kmalloc(PAGE_CACHE_SIZE, GFP_NOFS);
+ workspace->cbuf = kmalloc(lzo1x_worst_compress(PAGE_CACHE_SIZE),
+ GFP_NOFS);
if (!workspace->mem || !workspace->buf || !workspace->cbuf)
goto fail;
--
1.8.0.3
David Sterba
2013-Feb-15 13:17 UTC
Re: [PATCH] btrfs: use kmalloc for lzo de/compress buffer
On Fri, Feb 15, 2013 at 10:08:21PM +0900, Kyungsik Lee wrote:> The size of de/compress buffer and LZO1X_MEM_COMPRESS is small enough.Unfortunatelly it is not. include/linux/lzo.h: #define LZO1X_MEM_COMPRESS (16384 * sizeof(unsigned char *)) 128k with 8 byte pointers> @@ -54,9 +53,10 @@ static struct list_head *lzo_alloc_workspace(void) > if (!workspace) > return ERR_PTR(-ENOMEM); > > - workspace->mem = vmalloc(LZO1X_MEM_COMPRESS);vmalloc needed> - workspace->buf = vmalloc(PAGE_CACHE_SIZE);kmalloc is ok here> - workspace->cbuf = vmalloc(lzo1x_worst_compress(PAGE_CACHE_SIZE));#define lzo1x_worst_compress(x) ((x) + ((x) / 16) + 64 + 3) 4096+4096/16+64+3 = 4419 vmalloc needed as well david