* [PATCH v2] btrfs: use kmalloc for lzo de/compress buffer
@ 2013-02-18 7:56 Kyungsik Lee
2013-02-21 13:41 ` David Sterba
0 siblings, 1 reply; 3+ messages in thread
From: Kyungsik Lee @ 2013-02-18 7:56 UTC (permalink / raw)
To: Chris Mason, linux-btrfs, linux-kernel
Cc: hyojun.im, chan.jeong, raphael.andy.lee, Kyungsik Lee, David Sterba
The size of de/compress buffer is small enough to use kmalloc.
Allocating it with kmalloc rather than vmalloc is preferred.
This patch depends on my previous patch, “btrfs: fix decompress buffer size”.
v2: Using vmalloc for "workspace->mem" due to the size limit.
Signed-off-by: Kyungsik Lee <kyungsik.lee@lge.com>
Cc: David Sterba <dsterba@suse.cz>
---
fs/btrfs/lzo.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/fs/btrfs/lzo.c b/fs/btrfs/lzo.c
index 223893a..aaaab2e 100644
--- a/fs/btrfs/lzo.c
+++ b/fs/btrfs/lzo.c
@@ -40,8 +40,8 @@ static void lzo_free_workspace(struct list_head *ws)
{
struct workspace *workspace = list_entry(ws, struct workspace, list);
- vfree(workspace->buf);
- vfree(workspace->cbuf);
+ kfree(workspace->buf);
+ kfree(workspace->cbuf);
vfree(workspace->mem);
kfree(workspace);
}
@@ -55,8 +55,9 @@ static struct list_head *lzo_alloc_workspace(void)
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->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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] btrfs: use kmalloc for lzo de/compress buffer
2013-02-18 7:56 [PATCH v2] btrfs: use kmalloc for lzo de/compress buffer Kyungsik Lee
@ 2013-02-21 13:41 ` David Sterba
2013-02-22 8:26 ` Kyungsik Lee
0 siblings, 1 reply; 3+ messages in thread
From: David Sterba @ 2013-02-21 13:41 UTC (permalink / raw)
To: Kyungsik Lee
Cc: Chris Mason, linux-btrfs, linux-kernel, hyojun.im, chan.jeong,
raphael.andy.lee, David Sterba
On Mon, Feb 18, 2013 at 04:56:04PM +0900, Kyungsik Lee wrote:
> @@ -55,8 +55,9 @@ static struct list_head *lzo_alloc_workspace(void)
> 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->buf = kmalloc(PAGE_CACHE_SIZE, GFP_NOFS);
> + workspace->cbuf = kmalloc(lzo1x_worst_compress(PAGE_CACHE_SIZE),
This is still larger than usual page size and allocator may issue a
warning, so if we want to use kmalloc (it's ~4.4k in size and likely to
be available, but not always due to possible page fragmentation), the
__GFP_NOWARN should be supplied and if the allocation fails fall back to
vmalloc.
david
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] btrfs: use kmalloc for lzo de/compress buffer
2013-02-21 13:41 ` David Sterba
@ 2013-02-22 8:26 ` Kyungsik Lee
0 siblings, 0 replies; 3+ messages in thread
From: Kyungsik Lee @ 2013-02-22 8:26 UTC (permalink / raw)
To: dsterba
Cc: Chris Mason, linux-btrfs, linux-kernel, hyojun.im, chan.jeong,
raphael.andy.lee
On Thu, Feb 21, 2013 at 02:41:53PM +0100, David Sterba wrote:
> On Mon, Feb 18, 2013 at 04:56:04PM +0900, Kyungsik Lee wrote:
> > @@ -55,8 +55,9 @@ static struct list_head *lzo_alloc_workspace(void)
> > 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->buf = kmalloc(PAGE_CACHE_SIZE, GFP_NOFS);
> > + workspace->cbuf = kmalloc(lzo1x_worst_compress(PAGE_CACHE_SIZE),
>
> This is still larger than usual page size and allocator may issue a
> warning, so if we want to use kmalloc (it's ~4.4k in size and likely to
> be available, but not always due to possible page fragmentation), the
> __GFP_NOWARN should be supplied and if the allocation fails fall back to
> vmalloc.
Right, there shoud be another fixed verson for this.
Thanks,
Kyungsik
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-02-22 8:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-18 7:56 [PATCH v2] btrfs: use kmalloc for lzo de/compress buffer Kyungsik Lee
2013-02-21 13:41 ` David Sterba
2013-02-22 8:26 ` Kyungsik Lee
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).